-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 ADT variant infomation to StableMIR and finish implementing TyKind::internal() #118516
Conversation
r? @spastorino (rustbot has picked a reviewer for you, use r? to override) |
This PR changes Stable MIR cc @oli-obk, @celinval, @spastorino, @ouz-a |
☔ The latest upstream changes (presumably #118543) made this pull request unmergeable. Please resolve the merge conflicts. |
07ef379
to
f8d4a62
Compare
This will allow us to provide methods to create `Ty` inside the stable MIR, which can be helpful while handling pointers and other stuff.
f8d4a62
to
e19c7cd
Compare
r? @ouz-a Do you think you can take a look at this one too? I don't know if @spastorino will have time. |
Will try to review this week. |
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.
Overall looks very good, I'm happy that you provided very detailed documentation, and have a clear goal with this PR. just left a nit and a comment.
Although, we would like to avoid crashes whenever possible, and that's why I wanted to make this API fallible. It's looking pretty hard to do proper validation. I think many of our APIs will unfortunately depend on the user doing the correct thing since at the MIR level we are working on, we expect types to have been checked already.
r=me when green |
…iaskrgr Rollup of 7 pull requests Successful merges: - rust-lang#116496 (Provide context when `?` can't be called because of `Result<_, E>`) - rust-lang#117563 (docs: clarify explicitly freeing heap allocated memory) - rust-lang#117874 (`riscv32` platform support) - rust-lang#118516 (Add ADT variant infomation to StableMIR and finish implementing TyKind::internal()) - rust-lang#118650 (add comment about keeping flags in sync between bootstrap.py and bootstrap.rs) - rust-lang#118664 (docs: remove rust-lang#110800 from release notes) - rust-lang#118669 (library: fix comment about const assert in win api) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#118516 - celinval:smir-variants, r=ouz-a Add ADT variant infomation to StableMIR and finish implementing TyKind::internal() Introduce a `VariantDef` type and a mechanism to retrieve the definition from an `AdtDef`. The `VariantDef` representation itself is just a combination of `AdtDef` and `VariantIdx`, which allow us to retrieve further information of a variant. I don't think we need to cache extra information for now, and we can translate on an on demand manner. I am leaving the fields public today due to rust-lang/project-stable-mir#56, but they shouldn't. For this PR, I've only added a method to retrieve the variant name, and its fields. I also added an implementation of `RustcInternal` that allow users to retrieve more information using Rust internal APIs. I have also finished the implementation of `RustcInternal` for `TyKind` which fixes rust-lang/project-stable-mir#46. ## Motivation Both of these changes are needed in order to properly interpret things like projections. For example, - The variant definition is used to find out which variant we are downcasting to. - Being able to create `Ty` from `TyKind` helps for example processing each stage of a projection, like the code in `place.ty()`.
The main changes needed to make this migration besides a few method call tweaks were: 1. Adapt `FunctionCtx` to cache information about the StableMIR version of instance and its body. - I also cleaned up how we were handling basic blocks which were unnecessary. 2. Created a new ty_stable module that provide stable versions to retrieve type information from StableMIR. - I decided to keep these separate so it is cleaner for now. I foresee that the type module will still rely on internal APIs for the next little while, so separating them here made sense to me. 3. Since `Place` when retrieved from StableMIR body already comes monomorphized, I modified the existing `codegen_place` to preemptively monomorphize Place before converting it to a Stable version and invoking `codegen_place_stable`. ### Call-outs Leaving this as a draft for now since this still depends on the following PRs to be merged into the Rust compiler: - rust-lang/rust#118524 - rust-lang/rust#118516 --------- Co-authored-by: Adrian Palacios <[email protected]>
Introduce a
VariantDef
type and a mechanism to retrieve the definition from anAdtDef
.The
VariantDef
representation itself is just a combination ofAdtDef
andVariantIdx
, which allow us to retrieve further information of a variant. I don't think we need to cache extra information for now, and we can translate on an on demand manner. I am leaving the fields public today due to rust-lang/project-stable-mir#56, but they shouldn't. For this PR, I've only added a method to retrieve the variant name, and its fields. I also added an implementation ofRustcInternal
that allow users to retrieve more information using Rust internal APIs.I have also finished the implementation of
RustcInternal
forTyKind
which fixes rust-lang/project-stable-mir#46.Motivation
Both of these changes are needed in order to properly interpret things like projections. For example,
Ty
fromTyKind
helps for example processing each stage of a projection, like the code inplace.ty()
.