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

clarify semantics of ConstantIndex MIR projection #131285

Merged
merged 1 commit into from
Oct 5, 2024

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Oct 5, 2024

This documents what Miri does:

if n < min_length {
// This can only be reached in ConstProp and non-rustc-MIR.
throw_ub!(BoundsCheckFailed { len: min_length, index: n });
}

I am not sure what exactly the purpose of this min_length field is, TBH... but this seems like the most obvious meaning it could have?

@rustbot
Copy link
Collaborator

rustbot commented Oct 5, 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
Copy link
Collaborator

rustbot commented Oct 5, 2024

This PR changes MIR

cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras

This PR changes Stable MIR

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

@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 5, 2024
@cjgillot
Copy link
Contributor

cjgillot commented Oct 5, 2024

It's only meaningful use is in borrowck, where it's used to check conflict between two ConstantIndex projections.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Oct 5, 2024

📌 Commit f0ddc7b has been approved by cjgillot

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 5, 2024
@RalfJung
Copy link
Member Author

RalfJung commented Oct 5, 2024

What exactly needs to be true about the semantics of this for whatever borrowck is doing to be sound?

If we can declare this field as being entirely irrelevant for the semantics, that'd surely make things a bit simpler, but then borrowck couldn't "trust" its value.

@cjgillot
Copy link
Contributor

cjgillot commented Oct 5, 2024

When checking conflict between [+offset1 of min_length1] and [-offset2 of min_length2], borrowck can conclude they are disjoint if offset1 + offset2 < max(min_length1, min_length2). If that inequality is not verified, the places may point to the same memory.

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 5, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#130555 ( Initial support for riscv32{e|em|emc}_unknown_none_elf)
 - rust-lang#131280 (Handle `rustc_interface` cases of `rustc::potential_query_instability` lint)
 - rust-lang#131281 (make Cell unstably const)
 - rust-lang#131285 (clarify semantics of ConstantIndex MIR projection)
 - rust-lang#131299 (fix typo in 'lang item with track_caller' message)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c45f902 into rust-lang:master Oct 5, 2024
6 checks passed
@rustbot rustbot added this to the 1.83.0 milestone Oct 5, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 5, 2024
Rollup merge of rust-lang#131285 - RalfJung:mir-projection-sem, r=cjgillot

clarify semantics of ConstantIndex MIR projection

This documents what Miri does:
https://github.com/rust-lang/rust/blob/c4ce8c114b06840c3521a189ee44958b713fb33a/compiler/rustc_const_eval/src/interpret/projection.rs#L272-L275

I am not sure what exactly the purpose of this `min_length` field is, TBH... but this seems like the most obvious meaning it could have?
@RalfJung RalfJung deleted the mir-projection-sem branch October 6, 2024 08:42
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.

4 participants