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

Treat constant values as mir::ConstantKind::Val #94059

Merged
merged 5 commits into from
Mar 10, 2022

Conversation

b-naber
Copy link
Contributor

@b-naber b-naber commented Feb 16, 2022

Another step that is necessary for the introduction of Valtrees: we don't want to treat ty::Const instances of kind ty::ConstKind::Value as mir::ConstantKind::Ty anymore.

r? @oli-obk

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 16, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 16, 2022
@rust-log-analyzer

This comment has been minimized.

@@ -570,6 +570,9 @@ impl<'tcx> Cx<'tcx> {

hir::ExprKind::ConstBlock(ref anon_const) => {
let anon_const_def_id = self.tcx.hir().local_def_id(anon_const.hir_id);

// FIXME Do we want to use `from_inline_const` once valtrees
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that function is only used from here? . If so, we can move it onto constantkind and turn inline consts always into mir constants

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this is only used from here. But changing from_inline_const would require some changes in how we process patterns during thir construction. The next PR will be about changing thir to use mir::Constant instead of ty::Const, so would also include the change to from_inline_const. I would prefer to leave this as is in this PR, unless you want this change right now.

@b-naber b-naber force-pushed the constantkind-val-transformation branch from b76a6d3 to a4feb9a Compare February 18, 2022 15:29
@b-naber
Copy link
Contributor Author

b-naber commented Feb 18, 2022

How can I make the 'inline_into_box_place' test not fail in CI? A new alloc value (the bd09 in alloc[bd09]) is created in each CI run.

- }
-
- bb2: {
+ // + span: $DIR/inline-into-box-place.rs:8:33: 8:43
+ // + user_ty: UserType(0)
+ // + literal: Const { ty: alloc::raw_vec::RawVec<u32>, val: Value(ByRef { alloc: Allocation { bytes: [4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [65535], len: Size { raw: 16 } }, align: Align { pow2: 3 }, mutability: Not, extra: () }, offset: Size { raw: 0 } }) }
+ // + literal: Const { ty: alloc::raw_vec::RawVec<u32>, val: Unevaluated(Unevaluated { def: WithOptConstParam { did: DefId(5:77 ~ alloc[bd09]::raw_vec::{impl#0}::NEW), const_param_did: None }, substs: [u32], promoted: None }) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Oof, yea that id is annoying. We should probably make the printing of unevaluted consts work in a more user-facing way. cc @lcnr

Copy link
Contributor

Choose a reason for hiding this comment

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

Afaict the issue here is that Debug for Unevaluated uses Debug for DefId which uses def_path_debug_str which prints the stable_crate_id. This ID is presumably not stable between targets so different CI runners disagree about what that ID should be.

It seems like - before this PR - all Unevaluated constants only referred to the currently compiled crate. The stabile_crate_id of which is probably stable for different targets.

Writing a potential fix rn.

Copy link
Member

Choose a reason for hiding this comment

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

This ID is presumably not stable between targets so different CI runners disagree about what that ID should be.

Indeed. Liballoc is compiled by cargo which afaik hashes the target into the value passed in using -Cmetadata. The -Cmetadata argumemts are one of the inputs to the stable crate id calculation.

constant.try_super_fold_with(self)
let constant_kind = match constant {
mir::ConstantKind::Ty(c) => {
let const_folded = c.try_super_fold_with(self)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems wrong, we should still normalize constants here, for now this should probably be

Suggested change
let const_folded = c.try_super_fold_with(self)?;
let const_folded = c.try_fold_with(self)?;

but with valtrees we have to avoid the conversion to valtrees here.

If you change this you should be able to avoid the CI issues for now

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 22, 2022
change `mir::Constant` in mir dumps

this removes duplicate information and avoids printing the `stable_crate_id` in mir dumps which broke CI in rust-lang#94059

r? `@oli-obk` cc `@b-naber`
@bors
Copy link
Contributor

bors commented Feb 22, 2022

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

@oli-obk oli-obk 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 Mar 2, 2022
@b-naber b-naber force-pushed the constantkind-val-transformation branch from a4feb9a to b6608af Compare March 8, 2022 19:43
@rust-log-analyzer

This comment has been minimized.

@b-naber b-naber force-pushed the constantkind-val-transformation branch from b6608af to 0a82066 Compare March 9, 2022 09:14
@b-naber b-naber force-pushed the constantkind-val-transformation branch 2 times, most recently from 0d58cd0 to 2fa5ed2 Compare March 9, 2022 11:57
@@ -16,6 +16,7 @@

#![allow(unconditional_panic)]


Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

@@ -25,10 +25,12 @@
_3 = &_4; // scope 0 at $DIR/issue-78442.rs:11:5: 11:15
StorageLive(_5); // scope 0 at $DIR/issue-78442.rs:11:5: 11:17
nop; // scope 0 at $DIR/issue-78442.rs:11:5: 11:17
_2 = <impl Fn() as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/issue-78442.rs:11:5: 11:17
- _2 = <impl Fn() as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/issue-78442.rs:11:5: 11:17
+ _2 = <fn() {foo} as Fn<()>>::call(move _3, move _5) -> [return: bb2, unwind: bb4]; // scope 0 at $DIR/issue-78442.rs:11:5: 11:17
Copy link
Contributor

Choose a reason for hiding this comment

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

bit surprised that this changed with your pr 🤔 but as its definitely a positive change, i don't necessarily care about why this changed 🤷

@lcnr
Copy link
Contributor

lcnr commented Mar 9, 2022

one last nit, then r=me

@lcnr
Copy link
Contributor

lcnr commented Mar 9, 2022

@bors delegate+

@bors
Copy link
Contributor

bors commented Mar 9, 2022

✌️ @b-naber can now approve this pull request

@b-naber b-naber force-pushed the constantkind-val-transformation branch from 2fa5ed2 to 18bb2dd Compare March 9, 2022 12:41
@bors
Copy link
Contributor

bors commented Mar 9, 2022

📌 Commit 021c3b0 has been approved by lcnr

@bors
Copy link
Contributor

bors commented Mar 9, 2022

⌛ Testing commit 021c3b0 with merge 519de42530b84c9cfbd03e9a0354724ba4ab2a5f...

@bors
Copy link
Contributor

bors commented Mar 9, 2022

💔 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 Mar 9, 2022
@nikic
Copy link
Contributor

nikic commented Mar 9, 2022

@bors retry

@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 Mar 9, 2022
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
.......... (60/61)
.          (61/61)


/checkout/src/test/rustdoc-gui/jump-to-def-background.goml An exception occured: Failed to launch the browser process!
Inconsistency detected by ld.so: dl-tls.c: 493: _dl_allocate_tls_init: Assertion `listp->slotinfo[cnt].gen <= GL(dl_tls_generation)' failed!


TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/master/docs/troubleshooting.md
== STACKTRACE ==
Error
Error
    at innerRunTestCode (/node-v14.4.0-linux-x64/lib/node_modules/browser-ui-test/src/index.js:468:16)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
/checkout/src/test/rustdoc-gui/mobile.goml mobile... FAILED
[ERROR] (line 27) Error: Evaluation failed: assert didn't fail: for command `compare-elements-position-near-false: ("#preferred-light-theme .setting-name", "#preferred-light-theme .choice", {"y": 16})`
Build completed unsuccessfully in 0:00:17

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Mar 9, 2022
…tion, r=lcnr

Treat constant values as mir::ConstantKind::Val

Another step that is necessary for the introduction of Valtrees: we don't want to treat `ty::Const` instances of kind `ty::ConstKind::Value` as `mir::ConstantKind::Ty` anymore.

r? `@oli-obk`
@bors
Copy link
Contributor

bors commented Mar 10, 2022

⌛ Testing commit 021c3b0 with merge d7b282b...

@bors
Copy link
Contributor

bors commented Mar 10, 2022

☀️ Test successful - checks-actions
Approved by: lcnr
Pushing d7b282b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 10, 2022
@bors bors merged commit d7b282b into rust-lang:master Mar 10, 2022
@rustbot rustbot added this to the 1.61.0 milestone Mar 10, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d7b282b): comparison url.

Summary: This benchmark run shows 92 relevant improvements 🎉 but 6 relevant regressions 😿 to instruction counts.

  • Arithmetic mean of relevant regressions: 1.3%
  • Arithmetic mean of relevant improvements: -1.0%
  • Arithmetic mean of all relevant changes: -0.9%
  • Largest improvement in instruction counts: -6.6% on full builds of ctfe-stress-4 opt
  • Largest regression in instruction counts: 1.6% on full builds of keccak check

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

@rustbot rustbot added the perf-regression Performance regression. label Mar 10, 2022
@lcnr
Copy link
Contributor

lcnr commented Mar 10, 2022

ConstantKind::Val doesn't need interning and we have less indirection with that variant 🤷 while i didn't expect such an improvement, i guess that's fine 😆

@rylev
Copy link
Member

rylev commented Mar 15, 2022

Since the regressions are all in secondary benchmarks and relatively small, I think it's fine if we consider this to be an improvement rather than a mixed result.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Mar 15, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 13, 2022
…li-obk

Use mir constant in thir instead of ty::Const

This is blocked on rust-lang#94059 (does include its changes, the first two commits in this PR correspond to those changes) and rust-lang#93800 being reinstated (which had to be reverted). Mainly opening since `@lcnr` offered to give some feedback and maybe also for a perf-run (if necessary).

This currently contains a lot of duplication since some of the logic of `ty::Const` had to be copied to `mir::ConstantKind`, but with the introduction of valtrees a lot of that functionality will disappear from `ty::Const`.

Only the last commit contains changes that need to be reviewed here. Did leave some `FIXME` comments regarding future implementation decisions and some things that might be incorrectly implemented.

r? `@oli-obk`
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Apr 21, 2022
Use mir constant in thir instead of ty::Const

This is blocked on rust-lang/rust#94059 (does include its changes, the first two commits in this PR correspond to those changes) and rust-lang/rust#93800 being reinstated (which had to be reverted). Mainly opening since `@lcnr` offered to give some feedback and maybe also for a perf-run (if necessary).

This currently contains a lot of duplication since some of the logic of `ty::Const` had to be copied to `mir::ConstantKind`, but with the introduction of valtrees a lot of that functionality will disappear from `ty::Const`.

Only the last commit contains changes that need to be reviewed here. Did leave some `FIXME` comments regarding future implementation decisions and some things that might be incorrectly implemented.

r? `@oli-obk`
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. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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.