Skip to content

Add a section on identifiers in the MIR #951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 7, 2020

Conversation

camelid
Copy link
Member

@camelid camelid commented Nov 11, 2020

r? @oli-obk

By the way, let me know if there are other people I can ping for review so I
don't assign every MIR PR to you :)

@rustbot modify labels: waiting-on-review

@rustbot rustbot added the S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content label Nov 11, 2020
@jyn514
Copy link
Member

jyn514 commented Nov 11, 2020

By the way, let me know if there are other people I can ping for review so I
don't assign every MIR PR to you :)

I think RalfJung and jonas-schievink would both be good reviewers.

@camelid
Copy link
Member Author

camelid commented Nov 11, 2020

By the way, let me know if there are other people I can ping for review so I
don't assign every MIR PR to you :)

I think RalfJung and jonas-schievink would both be good reviewers.

Yeah, I just wasn't sure if they're open to reviewing dev-guide PRs.

@camelid
Copy link
Member Author

camelid commented Nov 11, 2020

That's weird... CI passed but there's a broken link: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.GlobalId.html

cc @mark-i-m since you know more about linkcheck :)

@mark-i-m
Copy link
Member

It might be due to caching. I wonder if we can turn that off now...

@oli-obk
Copy link
Contributor

oli-obk commented Nov 11, 2020

we do have wg-mir-opt that you can (I think you can?) ping, but I have no problem getting pinged and potentially forwarding to someone else.

@camelid
Copy link
Member Author

camelid commented Nov 22, 2020

@oli-obk Could you re-review this? I think it's ready!

Copy link
Contributor

@LeSeulArtichaut LeSeulArtichaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As someone who's never really touched MIR, this makes things clearer to me! ❤️
I think it would be worth it to also mention how to use those identifiers (i.e. get the XData with X through Body::x), but I'm not really sure...

In the HIR part of the chapter I had only written:

These identifiers can be converted into one another through the [HIR map][map].
See the [HIR chapter][hir-map] for more detailed information.

So 🤷‍♂️... @jyn514 @oli-obk what do you think?

@jyn514
Copy link
Member

jyn514 commented Nov 22, 2020

cc @robinhundt

camelid and others added 2 commits November 23, 2020 15:04
Co-authored-by: Léo Lanteri Thauvin <leseulartichaut@gmail.com>
Comment on lines 82 to 84
- [`Promoted`] identifies a promoted constant within another item (related to
const evaluation). Note: it is unique only locally within the item, so it should be associated with a `DefId`;
[`GlobalId`] must be used if you need to *globally* identify the promoted.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oli-obk The change you applied confuses me: the text now says

Note: it is unique only locally within the item, so it should be associated with a DefId;
[GlobalId] must be used if you need to globally identify the promoted.

So which one is it? It says that you should associate it with a DefId, but it also says use GlobalId.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GlobalId is the combination of DefId + Substs + Option<Promoted>. You can identify a promoted with just a DefId and Promoted, but you may not be able to compute its value without the Substs, because it's still polymorphic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what should I change this sentence to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess something like must be used if you need a globally unique identifier for the monomorphic version of a promoted? Is that filled with too many weird words or do you think someone who gets to this section the first time will be able to understand it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, but didn't you say that you can identify a promoted with just DefId and Promoted, and you only need GlobalId in order to actually compute the value?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My mental model was always that GlobalId identifies the monomorphic version of sth, DefId identifies a definition (potentially polymorphic) and (DefId, Promoted) identifies a promoted within a definition (also potentially polymorphic). But "identifying a monomorphic version" may not really be a thing...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know what, how about we just say "GlobalId gives you more information (TODO)" and come back to this later? That way we can get the rest of it merged :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally wouldn't mind, especially given that this PR itself removes a giant TODO :)

@LeSeulArtichaut LeSeulArtichaut merged commit 1135856 into rust-lang:master Dec 7, 2020
@LeSeulArtichaut
Copy link
Contributor

Thanks for your work on this @camelid :)

@camelid camelid deleted the mir-ids branch December 7, 2020 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants