Skip to content
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

Fix crash due to CrateItem::kind() not handling constructors #119135

Merged
merged 3 commits into from
Dec 21, 2023

Conversation

celinval
Copy link
Contributor

Also add a method to get the instance instantiation arguments, and include that information in the instance debug.

@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 2023

r? @ouz-a

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 19, 2023
@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 2023

This PR changes Stable MIR

cc @oli-obk, @celinval, @spastorino, @ouz-a

@@ -142,6 +147,7 @@ impl Debug for Instance {
f.debug_struct("Instance")
.field("kind", &self.kind)
.field("def", &self.mangled_name())
.field("args", &self.args())
Copy link
Member

Choose a reason for hiding this comment

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

In the future, please pull unrelated changes at least into a separate commit, but ideally into a separate PR. This has nothing to do with what's mentioned in the title of the PR, which is a one-liner 😓

Copy link
Contributor Author

@celinval celinval Dec 19, 2023

Choose a reason for hiding this comment

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

Fair. Sorry about that. I wasn't sure if you had a preference.

Copy link
Member

Choose a reason for hiding this comment

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

No worries, just surprising to see so many changes when I expected a one-liner 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created #119141 for that, and I'll remove it from here.

compiler/rustc_smir/src/rustc_smir/mod.rs Outdated Show resolved Hide resolved
@compiler-errors
Copy link
Member

Actually, sorry for the back and forth. I looked a bit deeper -- I don't think that unit structs have a body at all.

Maybe let's leave this unreachable!(), or something...? What do you think?

@compiler-errors
Copy link
Member

Maybe it would make sense if I understood a bit about how you encountered this crash -- if you got it from a Call terminator, then we shouldn't expect to see any CtorKind::Const in MIR anyways, and in that case, it's probably best to leave it unreachable for now.

@celinval
Copy link
Contributor Author

Maybe it would make sense if I understood a bit about how you encountered this crash -- if you got it from a Call terminator, then we shouldn't expect to see any CtorKind::Const in MIR anyways, and in that case, it's probably best to leave it unreachable for now.

Just to make sure I understand, DefKind::Ctor(_, CtorKind::Const) should be unreachable, and DefKind::Ctor(_, CtorKind::Fn) should be classified as function.

To provide more context, I added a test that crashes without this fix, but succeeds after the fix. The test was crashing with the following message:

Not a valid item kind: Ctor(Struct, Fn)

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

Hmmm... maybe we should just make a new ItemKind::Ctor(CtorKind::{Fn, Const})?

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

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

r=me when ci is green

@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Dec 19, 2023

📌 Commit 79ff316 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 19, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 20, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#118691 (Add check for possible CStr literals in pre-2021)
 - rust-lang#118973 (rustc_codegen_ssa: Don't drop `IncorrectCguReuseType` , make `rustc_expected_cgu_reuse` attr work)
 - rust-lang#119071 (-Znext-solver: adapt overflow rules to avoid breakage)
 - rust-lang#119089 (effects: fix a comment)
 - rust-lang#119094 (Add function ABI and type layout to StableMIR)
 - rust-lang#119102 (Add arm-none-eabi and armv7r-none-eabi platform-support documentation.)
 - rust-lang#119107 (subtype_predicate: remove unnecessary probe)

Failed merges:

 - rust-lang#119135 (Fix crash due to `CrateItem::kind()` not handling constructors)
 - rust-lang#119141 (Add method to get instance instantiation arguments)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Contributor

bors commented Dec 20, 2023

☔ The latest upstream changes (presumably #119156) made this pull request unmergeable. Please resolve the merge conflicts.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 20, 2023
@bors
Copy link
Contributor

bors commented Dec 20, 2023

🔒 Merge conflict

This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again.

How do I rebase?

Assuming self is your fork and upstream is this repository, you can resolve the conflict following these steps:

  1. git checkout smir-small-changes (switch to your branch)
  2. git fetch upstream master (retrieve the latest master)
  3. git rebase upstream/master -p (rebase on top of it)
  4. Follow the on-screen instruction to resolve conflicts (check git status if you got lost).
  5. git push self smir-small-changes --force-with-lease (update this PR)

You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial.

Please avoid the "Resolve conflicts" button on GitHub. It uses git merge instead of git rebase which makes the PR commit history more difficult to read.

Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Cargo.lock conflict is handled during merge and rebase. This is normal, and you should still perform step 5 to update this PR.

Error message
Auto-merging compiler/stable_mir/src/lib.rs
Auto-merging compiler/rustc_smir/src/rustc_smir/mod.rs
CONFLICT (content): Merge conflict in compiler/rustc_smir/src/rustc_smir/mod.rs
Automatic merge failed; fix conflicts and then commit the result.

@celinval
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 20, 2023
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Dec 20, 2023

📌 Commit 7ab38b8 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 20, 2023
celinval added a commit to model-checking/kani that referenced this pull request Dec 20, 2023
…to use StableMIR (#2959)

We still need internal APIs to handle things like:

- **FnAbi:** Support is pending this PR to be merged:
rust-lang/rust#119094
- **Filter non-function items:** Also pending a fix on the rust side:
rust-lang/rust#119135
- **Checking for reachable functions:** This is not needed in theory,
but std lib build fails since it unncovers an existing issue in Kani
with a function that was not previously included. I'll create an issue
for that. It's unrelated to this change though.
- **Function attribute handling**
- **Span error**

Co-authored-by: Adrian Palacios <73246657+adpaco-aws@users.noreply.github.com>
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 21, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#119135 (Fix crash due to `CrateItem::kind()` not handling constructors)
 - rust-lang#119141 (Add method to get instance instantiation arguments)
 - rust-lang#119145 (Give `VariantData::Struct`  named fields, to clairfy `recovered`.)
 - rust-lang#119167 (E0761: module directory has .rs suffix)
 - rust-lang#119168 (resolve: Stop feeding visibilities for import list stems)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b55887d into rust-lang:master Dec 21, 2023
11 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Dec 21, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 21, 2023
Rollup merge of rust-lang#119135 - celinval:smir-small-changes, r=compiler-errors

Fix crash due to `CrateItem::kind()` not handling constructors

Also add a method to get the instance instantiation arguments, and include that information in the instance debug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants