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
Add documentation on v0 symbol mangling. #97571
base: master
Are you sure you want to change the base?
Conversation
|
(rust-highfive has picked a reviewer for you, use r? to override) |
|
Before this is merged, there are a variety of questions to resolve:
Deviations from the RFC:
|
This comment has been hidden.
This comment has been hidden.
|
Shouldn't this go in the reference? And then have the CLI option link to that? I don't think we describe language concerns in the r? @michaelwoerister cc @lqd |
|
I'm going to try to do a point-by-point reply to #97571 (comment) (but some of this feels like it's going over things discussed before the RFC was accepted? I suppose those things tend to get lost to time)
|
|
Thank you for the detailed response!
Hm, my impression was the opposite, that this is not a part of the language and just an implementation-specific concern. The RFC was accepted by the compiler team, not the lang team. And it isn't really clear what consequence it has for the language if it isn't to be used as a stable ABI or have well-defined translation from Rust entities. I can imagine in the future that this could potentially provide the basis for a stable ABI, but that seems very far out, no?
Yea, I waffled a bit on how to organize it. I decided to move it to a separate chapter.
OK, I removed the limit.
I can understand how something like |
| ``` | ||
|
|
||
| [`rustc-demangle`]: https://crates.io/crates/rustc-demangle | ||
| [`rustfilt`]: https://crates.io/crates/rustfilt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is recommending tools via crates.io the norm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's about a hundred references to crates via crates.io in the current documentation. Is there some other way you would recommend? We could link directly to the GitHub project, but I figure the crates.io page provides links to GitHub which should be good to find it, and the crates.io links should be somewhat more permanent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh well yeah looking at that page in-particular it seems like they "recommend" using cargo install rather than having binaries/installers. I was specifically meaning tools rather than crates / libraries but yeah this crates pages is probably the most sensible page for this tool
|
Wow, that is some extensive documentation
Nope, there is no deeper meaning to that. Would have been nice to catch that during RFC review, but I guess now that there are demanglers in external tools, it's too late to change it. |
|
| > inherent-impl → `M` *[impl-path]* *[type]* | ||
|
|
||
| An *inherent-impl* indicates a path to an [inherent implementation][reference-inherent-impl]. | ||
| It consists of the character `M` followed by an *[impl-path]* to the impl's parent followed by the *[type]* representing the `Self` type of the impl. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be something like
It consists of the character
Mfollowed by an [impl-path], which uniquely identifies theimplblock the item is defined in.
impl-path is the parent of the impl plus the index of the impl within the parent. We just don't emit the index (disambiguator) if it's equal to zero.
| > │└─────────┬──────────┘└────┬──────┘ | ||
| > │ │ │ | ||
| > │ │ └── Self type "Example" | ||
| > │ └─────────────────── path to the impl's parent "mycrate" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example should probably contain a disambiguator for the impl-path to make it more representative. Most impl-paths will have one.
| followed by a *[path]* which is a path representing the parent of the entity, | ||
| followed by an *[identifier]* of the entity. | ||
|
|
||
| The identifier of the entity may be empty when the entity is not named. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not quite accurate, I think. The string part of the identifier is empty, but there still would be the disambiguator (unless it's zero).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tweaked the wording to make try to make it clearer. I wasn't trying to say that there is no identifier, just that its length is zero.
| This helps differentiate symbols that would otherwise be identical, | ||
| for example the monomorphization of a function from an external crate may result in a duplicate if another crate is also instantiating the same generic function with the same types. | ||
|
|
||
| In practice, the instantiating crate is also the crate where the symbol is defined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| In practice, the instantiating crate is also the crate where the symbol is defined, | |
| In practice, the instantiating crate is also often the crate where the symbol is defined, |
|
Great docs, @ehuss! I left some comments in a few places but that's mostly nit-picking. |
Demanglers should be prepared for any arbitrary length number.
|
@michaelwoerister Do any of these comments apply to anything taken from the RFC text? It would be nice to fix them there (since IMO a diff of the RFC and reference should mostly have large-scale reorganization and additions, not e.g. spelling fixes in copied text). |
No, I don't think so. |
This adds official documentation for the v0 symbol mangling format, migrating the documentation from RFC 2603.
The format was originally stabilized as the
-C symbol-mangling-versionoption, but the specifics were not stabilized (per #90128 (comment)).Per the discussion at #93661 (comment) this adds those specifics as an official description of the format.
cc #89917