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

Change Thir to lazily create constants #94876

Merged
merged 7 commits into from Mar 24, 2022

Conversation

b-naber
Copy link
Contributor

@b-naber b-naber commented Mar 12, 2022

To allow AbstractConsts to work with the previous thir changes we made and those we want to make, i.e. to avoid problems due to ValTree and ConstValue conversions, we instead switch to a thir representation for constants that allows us to lazily create constants.

r? @oli-obk

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

This comment has been minimized.

@b-naber b-naber force-pushed the thir-abstract-const-changes branch from 73a22ab to 9e73a91 Compare March 12, 2022 09:26
@@ -70,7 +70,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
local_decl.local_info =
Some(Box::new(LocalInfo::StaticRef { def_id, is_thread_local: true }));
}
ExprKind::Literal { const_id: Some(def_id), .. } => {
ExprKind::NamedConst { def_id, .. } => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might be problematic. I'm not completely sure whether we need any other variants here. Also don't know what adding constants to local_info here does later in codegen.

Copy link
Contributor

Choose a reason for hiding this comment

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

we previously also did this for ExprKind::ConstParam, would have to figure out what it's used for myself 😆 think you can just keep the current behavior and add a FIXME for now

Suggested change
ExprKind::NamedConst { def_id, .. } => {
ExprKind::NamedConst { def_id, .. } | ExprKind::ConstParam { def_id, .. } => {

Copy link
Contributor

Choose a reason for hiding this comment

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

we also want this for ExprKind::ConstParam: please add this as a test:

#![feature(adt_const_params)]
#![allow(incomplete_features)]

#[derive(PartialEq, Eq)]
struct Yikes;

impl Yikes {
    fn mut_self(&mut self) {}
}

fn foo<const YIKES: Yikes>() {
    YIKES.mut_self()
}

fn main() {
    foo::<{ Yikes }>()
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=fd11458a9e567c54fbb2fb43c15c9f56

@rust-log-analyzer

This comment has been minimized.

@b-naber b-naber force-pushed the thir-abstract-const-changes branch from a2ef0d4 to f7ff7aa Compare March 15, 2022 11:24
@b-naber b-naber changed the title [WIP] Thir abstract const changes Change Thir to lazily create constants Mar 15, 2022
@b-naber b-naber force-pushed the thir-abstract-const-changes branch from f7ff7aa to 1f24795 Compare March 15, 2022 11:33
@b-naber
Copy link
Contributor Author

b-naber commented Mar 15, 2022

This is ready for review now. Shouldn't be reviewed commit by commit probably.

@oli-obk
Copy link
Contributor

oli-obk commented Mar 15, 2022

This is ready for review now. Shouldn't be reviewed commit by commit probably.

I guess squash the commits in that case?

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

a few nits

compiler/rustc_middle/src/thir/visit.rs Show resolved Hide resolved
compiler/rustc_mir_build/src/build/expr/as_constant.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/thir.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/thir/cx/expr.rs Outdated Show resolved Hide resolved
@@ -70,7 +70,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
local_decl.local_info =
Some(Box::new(LocalInfo::StaticRef { def_id, is_thread_local: true }));
}
ExprKind::Literal { const_id: Some(def_id), .. } => {
ExprKind::NamedConst { def_id, .. } => {
Copy link
Contributor

Choose a reason for hiding this comment

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

we previously also did this for ExprKind::ConstParam, would have to figure out what it's used for myself 😆 think you can just keep the current behavior and add a FIXME for now

Suggested change
ExprKind::NamedConst { def_id, .. } => {
ExprKind::NamedConst { def_id, .. } | ExprKind::ConstParam { def_id, .. } => {

@b-naber b-naber force-pushed the thir-abstract-const-changes branch from e13f6b6 to 07f5641 Compare March 15, 2022 15:22
@b-naber
Copy link
Contributor Author

b-naber commented Mar 15, 2022

Decided to keep the thir::Pat code as is for now.

@rust-log-analyzer

This comment has been minimized.

@b-naber b-naber force-pushed the thir-abstract-const-changes branch from e2e84c3 to c962c81 Compare March 15, 2022 15:44
@rust-log-analyzer

This comment has been minimized.

@b-naber b-naber force-pushed the thir-abstract-const-changes branch from c962c81 to 8e21280 Compare March 15, 2022 16:32
@rust-log-analyzer

This comment has been minimized.

@b-naber b-naber force-pushed the thir-abstract-const-changes branch from c98ec1a to b3d71d3 Compare March 16, 2022 08:55
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

Alright, am pretty happy with this PR now.

I do dislike ScalarLiteral, it feels like a pretty bad name 🤔 can't think of a better name myself, so please take 1-2 min to think of one and if not we can merge it as is 😆

@@ -70,7 +70,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
local_decl.local_info =
Some(Box::new(LocalInfo::StaticRef { def_id, is_thread_local: true }));
}
ExprKind::Literal { const_id: Some(def_id), .. } => {
ExprKind::NamedConst { def_id, .. } => {
Copy link
Contributor

Choose a reason for hiding this comment

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

we also want this for ExprKind::ConstParam: please add this as a test:

#![feature(adt_const_params)]
#![allow(incomplete_features)]

#[derive(PartialEq, Eq)]
struct Yikes;

impl Yikes {
    fn mut_self(&mut self) {}
}

fn foo<const YIKES: Yikes>() {
    YIKES.mut_self()
}

fn main() {
    foo::<{ Yikes }>()
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=fd11458a9e567c54fbb2fb43c15c9f56

@lcnr
Copy link
Contributor

lcnr commented Mar 22, 2022

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 22, 2022
@lcnr
Copy link
Contributor

lcnr commented Mar 23, 2022

interesting 🤔 I would be surprised if these changes mattered, even if keeping them would probably have been preferable.

let's try it again, maybe it was spurious in some way?

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 23, 2022
@bors
Copy link
Contributor

bors commented Mar 23, 2022

⌛ Trying commit 96050421395ae1c3a75dc0a883e0d9317f918195 with merge 7827037e4b0cf03a1f99c331fa9ef74dd062fbea...

@bors
Copy link
Contributor

bors commented Mar 23, 2022

☀️ Try build successful - checks-actions
Build commit: 7827037e4b0cf03a1f99c331fa9ef74dd062fbea (7827037e4b0cf03a1f99c331fa9ef74dd062fbea)

@rust-timer
Copy link
Collaborator

Queued 7827037e4b0cf03a1f99c331fa9ef74dd062fbea with parent cd2da4d, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (7827037e4b0cf03a1f99c331fa9ef74dd062fbea): comparison url.

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

  • Arithmetic mean of relevant regressions: 0.4%
  • Arithmetic mean of relevant improvements: -1.6%
  • Arithmetic mean of all relevant changes: -1.0%
  • Largest improvement in instruction counts: -2.8% on full builds of keccak check
  • Largest regression in instruction counts: 0.5% on incr-unchanged builds of deeply-nested-multi check

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

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf +perf-regression

@b-naber
Copy link
Contributor Author

b-naber commented Mar 23, 2022

hm this is very weird. How can it be that the number of calls of a query differ in perf runs? Is this a bug in rustc_perf? (cc @Mark-Simulacrum)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 23, 2022
@b-naber b-naber force-pushed the thir-abstract-const-changes branch from 9605042 to ccfbe52 Compare March 23, 2022 18:42
@rust-log-analyzer

This comment has been minimized.

@b-naber b-naber force-pushed the thir-abstract-const-changes branch from ccfbe52 to 19041d9 Compare March 23, 2022 19:18
@lcnr
Copy link
Contributor

lcnr commented Mar 24, 2022

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Mar 24, 2022

📌 Commit 19041d9 has been approved by lcnr

@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 24, 2022
@bors
Copy link
Contributor

bors commented Mar 24, 2022

⌛ Testing commit 19041d9 with merge 8d8135f...

@bors
Copy link
Contributor

bors commented Mar 24, 2022

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 24, 2022
@bors bors merged commit 8d8135f into rust-lang:master Mar 24, 2022
@bors
Copy link
Contributor

bors commented Mar 24, 2022

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

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8d8135f): comparison url.

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

  • Arithmetic mean of relevant regressions: 1.6%
  • Arithmetic mean of relevant improvements: -1.0%
  • Arithmetic mean of all relevant changes: -0.3%
  • Largest improvement in instruction counts: -2.8% on full builds of keccak check
  • Largest regression in instruction counts: 3.5% on full builds of tuple-stress 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

@pnkfelix
Copy link
Member

pnkfelix commented Mar 30, 2022

Visiting for weekly performance triage.

The changes to the primary benchmarks are almost universally green here.

The secondary benchmarks are more of a mixed bag, but I think we can accept a 3.5% regression on tuple-stress given the overall benefits.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Mar 30, 2022
@b-naber b-naber deleted the thir-abstract-const-changes branch August 3, 2022 09:11
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.

None yet

9 participants