Skip to content

use PlaceRef abstraction more consistently #80647

Description

@RalfJung

We have quite a bit of code that needs to work with the projections that make up a Place or PlaceRef. Much of it works with the projections array directly, which is rather verbose. We now have better APIs that avoid having to "break the abstraction" of Place/PlaceRef: we have Place::iter_projections and PlaceRef::last_projection.

It would be good to clean things up by using these higher-level APIs consistently. To do that, you'll need to find places where the lower-level API is used. One good way to find these places is to grep for Place::ty_from -- this helper function is only useful when a PlaceRef has been broken apart into its constituents, so it is a sign that some higher-level APIs can be used. In almost all cases, the code will either "do something with the last projection (if any)", in which case it should use PlaceRef::last_projection, or it will iterate all the projections, in which case it should use Place::iter_projections (usually iteration starts with the outermost projection, i.e., you should use place.iter_projections().rev()).

You can see #80624 for some examples for the kinds of changes that are needed to perform this cleanup.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions