Skip to content

Promoteds can contain raw pointers, but these must still only point to immutable allocations - #67603

Merged
bors merged 8 commits into
rust-lang:masterfrom
oli-obk:no_mut_static_ref_from_const
Jan 15, 2020
Merged

Promoteds can contain raw pointers, but these must still only point to immutable allocations#67603
bors merged 8 commits into
rust-lang:masterfrom
oli-obk:no_mut_static_ref_from_const

Conversation

@oli-obk

Copy link
Copy Markdown
Contributor

fixes#67601

r? @RalfJung

cc @wesleywiser in order to not change behaviour in this PR, const prop uses the constant rules for interning, but at least there's an explicit mode for it now that we can think about this in the future

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 25, 2019
Comment threadsrc/librustc_mir/interpret/intern.rs Outdated
Comment threadsrc/librustc_mir/interpret/intern.rs Outdated
Comment threadsrc/librustc_mir/interpret/intern.rs Outdated
@bors

bors commented Dec 26, 2019

Copy link
Copy Markdown
Collaborator

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

Comment threadsrc/librustc_mir/interpret/intern.rs Outdated
@RalfJungRalfJung 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-review Status: Awaiting review from the assignee but also interested parties. labels Jan 2, 2020
@SimonSapin

Copy link
Copy Markdown
Contributor

Friendly ping: what’s next for this PR? Can I help?

@oli-obk

Copy link
Copy Markdown
ContributorAuthor

I just haven't gotten to it. Probably Tuesday or some other day next week

@oli-obk
oli-obkforce-pushed the no_mut_static_ref_from_const branch from cc9326c to 1af201cCompareJanuary 8, 2020 09:17
@oli-obk

Copy link
Copy Markdown
ContributorAuthor

I addressed all review comments and marked the issue as a stable to nightly regression

Comment threadsrc/librustc_mir/interpret/intern.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right, I was thinking about this branch here when asking about nested allocations in constants. Isn't this unreachable then?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It is reachable, but I'm entirely unclean on why it is reachable

constRAW_TRAIT_OBJ_CONTENT_INVALID:*constdynTrait = &unsafe{BoolTransmute{val:3}.bl}as*const_;

hits the InternKind::Constant arm.

See the MIR on https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=3bc6c8b165b614bbe6cf5566d30752de there's no StorageDead for the allocation containing the bool with bit pattern 3.

I'm not really sure what's going on there. Technically, since we're inside a constant, shouldn't this trigger promotion and promote the transmuted value?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Under unleash it's also reached in

constMUTABLE_BEHIND_RAW:*muti32 = &UnsafeCell::new(42)as*const_as*mut_;

but that triggers the delay_span_bug as expected.

Also under unleash, but without an ICE (just triggering the dynamic checks in interp):

constMUTABLE_BEHIND_RAW:*muti32 = &UnsafeCell::new(42)as*const_as*mut_;//~^ WARN: skipping const checksconstMUTATING_BEHIND_RAW:() = {// Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.unsafe{*MUTABLE_BEHIND_RAW = 99//~ ERROR any use of this value will cause an error}};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not really sure what's going on there. Technically, since we're inside a constant, shouldn't this trigger promotion and promote the transmuted value?

Ah, this must be the "not-promotion" also described in this document (Ctrl-F "looks like"). That makes sense.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What I don't understand though is why RAW_TRAIT_OBJ_CONTENT_INVALID doesn't trigger the ICE. Why is the allocation already immutable?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(The PR doesn't change anything here so this doesn't block landing, but I'd really like to understand this and then see it documented.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would find documentation here immensely helpful.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

If you have a holistic view of what happens, it would really help to write that down.

I don't, which is why my answers are so confusing. They are just a brain dump of me discovering what is going on, not me understanding it entirely

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

These issues are preexisting, so after this PR is merged I'll open a new one to write docs and actually figure out what is going on

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't, which is why my answers are so confusing. They are just a brain dump of me discovering what is going on, not me understanding it entirely

Fair enough. :)

Comment threadsrc/librustc_mir/interpret/intern.rs Outdated
Comment threadsrc/librustc_mir/interpret/intern.rs Outdated
Comment threadsrc/librustc_mir/interpret/intern.rs Outdated
Comment threadsrc/librustc_mir/interpret/intern.rs Outdated
@bors

bors commented Jan 10, 2020

Copy link
Copy Markdown
Collaborator

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

@oli-obk
oli-obkforce-pushed the no_mut_static_ref_from_const branch from 1af201c to 5053f1bCompareJanuary 10, 2020 08:12
Comment threadsrc/librustc_mir/interpret/intern.rs Outdated
@bors

bors commented Jan 11, 2020

Copy link
Copy Markdown
Collaborator

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

@RalfJung

Copy link
Copy Markdown
Member

r=me with the if let Some(_) = ecx.tcx.alloc_map.lock().get(alloc_id) branch removed.

Comment threadsrc/librustc_mir/interpret/intern.rs Outdated
@oli-obk
oli-obkforce-pushed the no_mut_static_ref_from_const branch from e1479dd to 69ffe7bCompareJanuary 15, 2020 10:50
@oli-obk

Copy link
Copy Markdown
ContributorAuthor

@bors r=RalfJung

@bors

bors commented Jan 15, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit 69ffe7b has been approved by RalfJung

@borsbors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 15, 2020
@RalfJung

Copy link
Copy Markdown
Member

@bors p=1 (regression fix, and this has been sitting for a while)

@bors

bors commented Jan 15, 2020

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 69ffe7b with merge faf45c5...

bors added a commit that referenced this pull request Jan 15, 2020
Promoteds can contain raw pointers, but these must still only point to immutable allocations
fixes#67601
r? @RalfJung
cc @wesleywiser in order to not change behaviour in this PR, const prop uses the constant rules for interning, but at least there's an explicit mode for it now that we can think about this in the future
@bors

bors commented Jan 15, 2020

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-azure
Approved by: RalfJung
Pushing faf45c5 to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label Jan 15, 2020
@bors
bors merged commit 69ffe7b into rust-lang:masterJan 15, 2020
@rust-highfive

Copy link
Copy Markdown
Contributor

📣 Toolstate changed by #67603!

Tested on commit faf45c5.
Direct link to PR: #67603

💔 rls on linux: test-pass → test-fail (cc @Xanewok, @rust-lang/infra).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Jan 15, 2020
Tested on commit rust-lang/rust@faf45c5.
Direct link to PR: <rust-lang/rust#67603>
💔 rls on linux: test-pass → test-fail (cc @Xanewok, @rust-lang/infra).
@SimonSapin

Copy link
Copy Markdown
Contributor

Confirmed that this fixes #67601 for Servo. Thanks!

bors-servo pushed a commit to servo/servo that referenced this pull request Jan 16, 2020
Upgrade to rustc 1.42.0-nightly (3291ae339 2020-01-15)
This was unblocked by rust-lang/rust#67603 fixing rust-lang/rust#67601.
bors-servo pushed a commit to servo/servo that referenced this pull request Jan 16, 2020
Upgrade to rustc 1.42.0-nightly (3291ae339 2020-01-15)
This was unblocked by rust-lang/rust#67603 fixing rust-lang/rust#67601.
bors-servo pushed a commit to servo/servo that referenced this pull request Jan 16, 2020
Upgrade to rustc 1.42.0-nightly (3291ae339 2020-01-15)
This was unblocked by rust-lang/rust#67603 fixing rust-lang/rust#67601.
bors-servo pushed a commit to servo/servo that referenced this pull request Jan 16, 2020
Upgrade to rustc 1.42.0-nightly (3291ae339 2020-01-15)
This was unblocked by rust-lang/rust#67603 fixing rust-lang/rust#67601.
bors-servo pushed a commit to servo/servo that referenced this pull request Jan 16, 2020
Upgrade to rustc 1.42.0-nightly (3291ae339 2020-01-15)
This was unblocked by rust-lang/rust#67603 fixing rust-lang/rust#67601.
@oli-obk
oli-obk deleted the no_mut_static_ref_from_const branch March 16, 2021 12:13
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in Servo: "internal compiler error: mutable allocation in constant"

7 participants

@oli-obk@bors@SimonSapin@RalfJung@rust-highfive@wesleywiser@Centril