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

make ConstEvaluatable more strict #74595

Merged
merged 7 commits into from
Sep 9, 2020

Conversation

lcnr
Copy link
Contributor

@lcnr lcnr commented Jul 21, 2020

relevant zulip discussion: https://rust-lang.zulipchat.com/#narrow/stream/146212-t-compiler.2Fconst-eval/topic/.60ConstEvaluatable.60.20generic.20functions/near/204125452

Let's see how much this impacts. Depending on how this goes this should probably be a future compat warning.

Short explanation: we currently forbid anonymous constants which depend on generic types, e.g. [0; std::mem::size_of::<T>] currently errors.

We previously checked this by evaluating the constant and returned an error if that failed. This however allows things like

const fn foo<T>() -> usize {
    if std::mem::size_of::<*mut T>() < 8 { // size of *mut T does not depend on T
        std::mem::size_of::<T>()
    } else {
        8
    }
}

fn test<T>() {
    let _ = [0; foo::<T>()];
}

which is a backwards compatibility hazard. This also has worrying interactions with mir optimizations (#74491 (comment)) and intrinsics (#74538).

r? @oli-obk @eddyb

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 21, 2020
@lcnr
Copy link
Contributor Author

lcnr commented Jul 21, 2020

@bors try

@bors
Copy link
Contributor

bors commented Jul 21, 2020

⌛ Trying commit 617f7ad0b02ca21994b4cf28d14634486163b166 with merge 536076e3df53cc305e0c3c5f38bdc73f6d9f08bb...

src/librustc_middle/mir/mod.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Jul 21, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 536076e3df53cc305e0c3c5f38bdc73f6d9f08bb (536076e3df53cc305e0c3c5f38bdc73f6d9f08bb)

@lcnr
Copy link
Contributor Author

lcnr commented Jul 21, 2020

It looks like the crater queue is fairly full. @Mark-Simulacrum do we currently have the capacity to do another check run?

I also did some small changes here, so once again @bors try

@bors
Copy link
Contributor

bors commented Jul 21, 2020

⌛ Trying commit 65395c0710061f8745bdfab3520256a178e92c9d with merge a5913924b14838b364c42230cae014cc2534331d...

@bors
Copy link
Contributor

bors commented Jul 21, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: a5913924b14838b364c42230cae014cc2534331d (a5913924b14838b364c42230cae014cc2534331d)

@lcnr
Copy link
Contributor Author

lcnr commented Jul 22, 2020

Well, will go ahead and add this PR into the crate queue. If we don't have the capacity for this we can just remove it again.

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-74595 created and queued.
🤖 Automatically detected try build a5913924b14838b364c42230cae014cc2534331d
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 22, 2020
@withoutboats withoutboats added I-nominated T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Jul 23, 2020
@craterbot
Copy link
Collaborator

🚧 Experiment pr-74595 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🚨 Experiment pr-74595 has encountered an error: command Command { std: "/workspace/cargo-home/bin/rustup-toolchain-install-master" "8ad7bc3f428300aee6764f6e23527e19eb235e81" "-c" "cargo", kill_on_drop: false } failed
🛠️ If the error is fixed use the retry command.

🆘 Can someone from the infra team check in on this? @rust-lang/infra
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@Mark-Simulacrum
Copy link
Member

@craterbot retry seems to have been spurious

@craterbot
Copy link
Collaborator

🚨 Error: failed to parse the command

🆘 If you have any trouble with Crater please ping @rust-lang/infra!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@lcnr
Copy link
Contributor Author

lcnr commented Jul 28, 2020

@craterbot retry

@craterbot
Copy link
Collaborator

🛠️ Experiment pr-74595 queued again.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@lcnr lcnr mentioned this pull request Jul 28, 2020
8 tasks
@lcnr
Copy link
Contributor Author

lcnr commented Jul 31, 2020

This behavior was introduced in #70452 which was merged on the 15.04.2020, meaning that this has been only stable for 2 stable versions. (since 1.43.0)

So hopefully there aren't many uses of this yet

@craterbot
Copy link
Collaborator

🚧 Experiment pr-74595 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🚨 Experiment pr-74595 has encountered an error: command Command { std: "/workspace/cargo-home/bin/rustup-toolchain-install-master" "8ad7bc3f428300aee6764f6e23527e19eb235e81" "-c" "cargo", kill_on_drop: false } failed
🛠️ If the error is fixed use the retry command.

🆘 Can someone from the infra team check in on this? @rust-lang/infra
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@Mark-Simulacrum
Copy link
Member

@craterbot retry

@craterbot
Copy link
Collaborator

🛠️ Experiment pr-74595 queued again.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🚧 Experiment pr-74595 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@lcnr lcnr force-pushed the ConstEvaluatable-fut-compat branch from 1a1c3dc to 1dd00e6 Compare September 8, 2020 14:44
@lcnr
Copy link
Contributor Author

lcnr commented Sep 8, 2020

I wasn't able to reproduce this locally, but added a #[warn(const_evaluatable_unchecked)] anyways.

@oli-obk
Copy link
Contributor

oli-obk commented Sep 8, 2020

r=me with CI passing

@lcnr
Copy link
Contributor Author

lcnr commented Sep 8, 2020

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Sep 8, 2020

📌 Commit 4226a17 has been approved by oli-obk

@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 Sep 8, 2020
@Aaron1011
Copy link
Member

@bors retry

@bors
Copy link
Contributor

bors commented Sep 8, 2020

⌛ Testing commit 4226a17 with merge 8d92815944e001c9703489b285f04a9eb6567699...

@bors
Copy link
Contributor

bors commented Sep 8, 2020

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 8, 2020
@lcnr
Copy link
Contributor Author

lcnr commented Sep 9, 2020

How can I reproduce this locally? I don't understand this error

@oli-obk
Copy link
Contributor

oli-obk commented Sep 9, 2020

The only thing I can come up with that could cause this difference is --target=i586-unknown-linux-gnu. You may be able to do a --pass=check test run of that specific test and check why it does this. I'm fine with just ignoring the test on that platform once we know why it's happening

@lcnr
Copy link
Contributor Author

lcnr commented Sep 9, 2020

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Sep 9, 2020

📌 Commit 74e0719 has been approved by oli-obk

@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 Sep 9, 2020
@bors
Copy link
Contributor

bors commented Sep 9, 2020

⌛ Testing commit 74e0719 with merge e2be5f5...

@bors
Copy link
Contributor

bors commented Sep 9, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: oli-obk
Pushing e2be5f5 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 9, 2020
@bors bors merged commit e2be5f5 into rust-lang:master Sep 9, 2020
@rustbot rustbot added this to the 1.48.0 milestone Sep 9, 2020
@lcnr lcnr deleted the ConstEvaluatable-fut-compat branch September 10, 2020 05:46
@Mark-Simulacrum
Copy link
Member

This was an improvement of up to 2% on wf-projection-stress. Presumably not an expected result?

@lcnr
Copy link
Contributor Author

lcnr commented Sep 16, 2020

We were afraid of causing a regression here and had similar results 🤔 Probably some inlining changes or something

but not really expected

edit: https://perf.rust-lang.org/compare.html?start=3cfc7fe78eccc754b16981704a098d7bd520e2fd&end=2ce316b2752e1543bc064357871d77fd4896ca27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.