Add ADT variant infomation to StableMIR and finish implementing TyKind::internal()#118516
Merged
bors merged 4 commits intorust-lang:masterfrom Dec 6, 2023
Merged
Add ADT variant infomation to StableMIR and finish implementing TyKind::internal()#118516bors merged 4 commits intorust-lang:masterfrom
bors merged 4 commits intorust-lang:masterfrom
Conversation
Collaborator
|
r? @spastorino (rustbot has picked a reviewer for you, use r? to override) |
Collaborator
|
This PR changes Stable MIR cc @oli-obk, @celinval, @spastorino, @ouz-a |
Collaborator
|
☔ The latest upstream changes (presumably #118543) made this pull request unmergeable. Please resolve the merge conflicts. |
ghost
reviewed
Dec 2, 2023
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
Contributor
Author
|
r? @ouz-a Do you think you can take a look at this one too? I don't know if @spastorino will have time. |
Contributor
|
Will try to review this week. |
ouz-a
suggested changes
Dec 5, 2023
Contributor
ouz-a
left a comment
There was a problem hiding this comment.
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.
ouz-a
approved these changes
Dec 5, 2023
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.
Contributor
|
r=me when green |
Contributor
Author
Collaborator
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Dec 6, 2023
…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
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Dec 6, 2023
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()`.
adpaco-aws
added a commit
to model-checking/kani
that referenced
this pull request
Dec 9, 2023
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 <73246657+adpaco-aws@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce a
VariantDeftype and a mechanism to retrieve the definition from anAdtDef.The
VariantDefrepresentation itself is just a combination ofAdtDefandVariantIdx, 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 ofRustcInternalthat allow users to retrieve more information using Rust internal APIs.I have also finished the implementation of
RustcInternalforTyKindwhich fixes rust-lang/project-stable-mir#46.Motivation
Both of these changes are needed in order to properly interpret things like projections. For example,
TyfromTyKindhelps for example processing each stage of a projection, like the code inplace.ty().