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

compiler: Error on layout of enums with invalid reprs #131843

Merged
merged 2 commits into from
Oct 20, 2024

Conversation

workingjubilee
Copy link
Member

@workingjubilee workingjubilee commented Oct 17, 2024

Surprising no one, the ICEs with the same message have the same root cause.

Invalid reprs can reach layout computation for various reasons. For instance, the compiler may want to use its layout computations to discern if a combination of layout-affecting attributes results in a valid type to begin with by e.g. computing its size. When the input is bad, return an error reflecting that the answer to the question is not a useful one.

@rustbot
Copy link
Collaborator

rustbot commented Oct 17, 2024

r? @cjgillot

rustbot has assigned @cjgillot.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Oct 17, 2024
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Oct 17, 2024

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

@rust-log-analyzer

This comment has been minimized.

@workingjubilee
Copy link
Member Author

No idea why my brain insisted it wasn't fully imported.

@rust-log-analyzer

This comment has been minimized.

@workingjubilee
Copy link
Member Author

huh, I thought ./x.py test rust-analyzer would've...

@workingjubilee
Copy link
Member Author

oddly ./x.py build rust-analyzer works but ./x.py test rust-analyzer doesn't.

I'll take it, I guess!

@@ -39,7 +39,7 @@ enum NicheBias {
End,
}

#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Copy link
Member Author

Choose a reason for hiding this comment

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

I think rust-analyzer's derives of these are probably unnecessary but I'm not gonna fight that war today.

Copy link
Member

@lnicola lnicola Oct 18, 2024

Choose a reason for hiding this comment

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

I think they're needed because we put the Result<Arc<Layout>, LayoutError>s into a salsa database.

Copy link
Member Author

Choose a reason for hiding this comment

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

Huh, interesting.

@lnicola
Copy link
Member

lnicola commented Oct 17, 2024

Yeah, the r-a test suite doesn't get run (and probably doesn't pass, I think there were some issues on i386).

@rust-log-analyzer

This comment has been minimized.

@workingjubilee workingjubilee changed the title compiler: Do not ICE on impossible reprs compiler: Do not ICE if a union has an invalid repr for a field Oct 17, 2024
@workingjubilee workingjubilee changed the title compiler: Do not ICE if a union has an invalid repr for a field compiler: Do not ICE when union fields have invalid reprs Oct 17, 2024
@rust-log-analyzer

This comment has been minimized.

@workingjubilee
Copy link
Member Author

workingjubilee commented Oct 17, 2024

how bizarre. debug asserts!

@workingjubilee workingjubilee force-pushed the thaw-impossible-reprs branch 2 times, most recently from 5a9c4dd to 12ce35a Compare October 18, 2024 00:26
@workingjubilee
Copy link
Member Author

Hm I feel like this should go to
r? @lukas-code

@rustbot rustbot assigned lukas-code and unassigned cjgillot Oct 19, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Oct 19, 2024

oddly ./x.py build rust-analyzer works but ./x.py test rust-analyzer doesn't.

r-a isn't setup as a test step in boopstrap, it is setup as a build step

@workingjubilee
Copy link
Member Author

ah, is it finally time to promote it to its own directory?
git mv ./src/bootstrap ./boopstrap

compiler/rustc_ty_utils/src/layout/invariant.rs Outdated Show resolved Hide resolved
Comment on lines 312 to 340
assert_eq!(
common_align, field.align.abi,
"non-Aggregate field with matching ABI but differing alignment"
);
Copy link
Member

Choose a reason for hiding this comment

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

This assert is similar to the one in the sanity check: Hitting it means that an invalid layout was already created elsewhere.

Instead of trying to make the consumers of layouts work with invalid layouts, I think we should find the place where the invalid layouts are created to begin with and emit the LayoutCalculatorError::ReprConflict there.

Copy link
Member Author

Choose a reason for hiding this comment

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

Philosophical discussion about the meaning of ICEs aside, that does result in a much smaller fix. I feel a bit silly for heading down that path as far as I did. Thanks!

@workingjubilee workingjubilee changed the title compiler: Do not ICE when union fields have invalid reprs compiler: Error on layout of enums with invalid reprs Oct 20, 2024
Copy link
Member

@lukas-code lukas-code left a comment

Choose a reason for hiding this comment

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

Thanks!

@lukas-code
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Oct 20, 2024

📌 Commit 9f4c915 has been approved by lukas-code

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 Oct 20, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 20, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#121560 (Allow `#[deny]` inside `#[forbid]` as a no-op)
 - rust-lang#131365 (Fix missing rustfmt in msi installer rust-lang#101993)
 - rust-lang#131647 (Register `src/tools/unicode-table-generator` as a runnable tool)
 - rust-lang#131843 (compiler: Error on layout of enums with invalid reprs)
 - rust-lang#131926 (Align boolean option descriptions in `configure.py`)
 - rust-lang#131961 (compiletest: tidy up how `tidy` and `tidy` (html version) are disambiguated)
 - rust-lang#131962 (Make `llvm::set_section` take a `&CStr`)
 - rust-lang#131964 (add latest crash tests)
 - rust-lang#131965 (remove outdated comment)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6d43de6 into rust-lang:master Oct 20, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Oct 20, 2024
@workingjubilee workingjubilee deleted the thaw-impossible-reprs branch October 20, 2024 19:01
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 20, 2024
Rollup merge of rust-lang#131843 - workingjubilee:thaw-impossible-reprs, r=lukas-code

compiler: Error on layout of enums with invalid reprs

Surprising no one, the ICEs with the same message have the same root cause.

Invalid reprs can reach layout computation for various reasons. For instance, the compiler may want to use its layout computations to discern if a combination of layout-affecting attributes results in a valid type to begin with by e.g. computing its size. When the input is bad, return an error reflecting that the answer to the question is not a useful one.
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
8 participants