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

Introduce ConstAllocation. #94597

Merged
merged 1 commit into from
Mar 7, 2022
Merged

Conversation

nnethercote
Copy link
Contributor

Currently some Allocations are interned, some are not, and it's very
hard to tell at a use point which is which.

This commit introduces ConstAllocation for the known-interned ones,
which makes the division much clearer. ConstAllocation::inner() is
used to get the underlying Allocation.

In some places it's natural to use an Allocation, in some it's natural
to use a ConstAllocation, and in some places there's no clear choice.
I've tried to make things look as nice as possible, while generally
favouring ConstAllocation, which is the type that embodies more
information. This does require quite a few calls to inner().

The commit also tweaks how PartialOrd works for Interned. The
previous code was too clever by half, building on T: Ord to make the
code shorter. That caused problems with deriving PartialOrd and Ord
for ConstAllocation, so I changed it to build on T: PartialOrd,
which is slightly more verbose but much more standard and avoided the
problems.

r? @fee1-dead

@rust-highfive
Copy link
Collaborator

Some changes occured to rustc_codegen_gcc

cc @antoyo

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred in src/tools/clippy.

cc @rust-lang/clippy

Some changes occured to rustc_codegen_cranelift

cc @bjorn3

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

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

This is the next step after #93148.

@nnethercote
Copy link
Contributor Author

I don't expect this to have much effect on performance, but let's check.

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

bors commented Mar 4, 2022

⌛ Trying commit 904767d40562bb4e5775232d903c6a654f91cccd with merge 3cf02802d38ab3495d18e703694f862dd416f888...

@bors
Copy link
Contributor

bors commented Mar 4, 2022

☀️ Try build successful - checks-actions
Build commit: 3cf02802d38ab3495d18e703694f862dd416f888 (3cf02802d38ab3495d18e703694f862dd416f888)

@rust-timer
Copy link
Collaborator

Queued 3cf02802d38ab3495d18e703694f862dd416f888 with parent 8fa5d74, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (3cf02802d38ab3495d18e703694f862dd416f888): comparison url.

Summary: This benchmark run shows 15 relevant improvements 🎉 to instruction counts.

  • Arithmetic mean of relevant regressions: 0.3%
  • Arithmetic mean of relevant improvements: -0.9%
  • Arithmetic mean of all relevant changes: -0.7%
  • Largest improvement in instruction counts: -1.4% on full builds of keccak 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.

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 4, 2022
@RalfJung
Copy link
Member

RalfJung commented Mar 4, 2022

No objection from my side. I was at first a bit confused since it wasn't clear that ConstAllocation already is a reference (in contrast to Allocation which isn't), but I also do not have good ideas for how to avoid that confusion.

@Mark-Simulacrum
Copy link
Member

It seems like "const" might be referring to either somehow const-related allocations or constant allocations (i.e., immutable contents) -- I presume that it is the second, right? Maybe we should call it an InternedAllocation or ImmutableAllocation to try to head off some of this potential for confusion?

@RalfJung
Copy link
Member

RalfJung commented Mar 4, 2022

It's the first. Some of these allocations will be mutable at runtime, that is controlled by a flag inside Allocation.

@Mark-Simulacrum
Copy link
Member

Hm. I guess I don't fully understand the distinction, then. The comment on ConstAllocation says nothing about const, for example.

I would expect that runtime mutability is indeed distinct from immutability of the allocation at compile time -- do we only intern top-level allocations (for some definition of top-level, perhaps those associated with a DefId)?

(My opinions here aren't blockers or that strong, of course -- feel free to tell me that the name will be obvious for those working with this part of the compiler often).

@nnethercote
Copy link
Contributor Author

nnethercote commented Mar 4, 2022

It seems like "const" might be referring to either somehow const-related allocations or constant allocations (i.e., immutable contents) -- I presume that it is the second, right? Maybe we should call it an InternedAllocation or ImmutableAllocation to try to head off some of this potential for confusion?

These were already being called "const allocations" (e.g. pre-existing const_allocation, intern_const_alloc identifiers) so I just went with the existing names. And we generally avoid Interned as a prefix, e.g. types like Ty, Predicate, Region are all interned.

@nnethercote
Copy link
Contributor Author

nnethercote commented Mar 4, 2022

Nice to see this was a small instruction win for a few cases. Though cycles and wall-time didn't change in any significant way, so maybe it is perf-neutral in practice.

@Mark-Simulacrum
Copy link
Member

OK -- then since this is already being used elsewhere, seems OK to continue using it for now. We can consider a rename later down the line if it turns out that it is confusing for more than just me :)

Copy link
Member

@fee1-dead fee1-dead left a comment

Choose a reason for hiding this comment

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

r=me after nit

@@ -1434,7 +1435,7 @@ pub trait PrettyPrinter<'tcx>:
// The `inspect` here is okay since we checked the bounds, and there are no
// relocations (we have an active `str` reference here). We don't use this
// result to affect interpreter execution.
let slice = data.inspect_with_uninit_and_ptr_outside_interpreter(start..end);
let slice = data.0.inspect_with_uninit_and_ptr_outside_interpreter(start..end);
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps using inner like everywhere else would be more consistent here?

@fee1-dead
Copy link
Member

@bors delegate+

@bors
Copy link
Contributor

bors commented Mar 5, 2022

✌️ @nnethercote can now approve this pull request

@fee1-dead fee1-dead 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 6, 2022
Currently some `Allocation`s are interned, some are not, and it's very
hard to tell at a use point which is which.

This commit introduces `ConstAllocation` for the known-interned ones,
which makes the division much clearer. `ConstAllocation::inner()` is
used to get the underlying `Allocation`.

In some places it's natural to use an `Allocation`, in some it's natural
to use a `ConstAllocation`, and in some places there's no clear choice.
I've tried to make things look as nice as possible, while generally
favouring `ConstAllocation`, which is the type that embodies more
information. This does require quite a few calls to `inner()`.

The commit also tweaks how `PartialOrd` works for `Interned`. The
previous code was too clever by half, building on `T: Ord` to make the
code shorter. That caused problems with deriving `PartialOrd` and `Ord`
for `ConstAllocation`, so I changed it to build on `T: PartialOrd`,
which is slightly more verbose but much more standard and avoided the
problems.
@nnethercote
Copy link
Contributor Author

@bors r=fee1-dead

@bors
Copy link
Contributor

bors commented Mar 6, 2022

📌 Commit 4852291 has been approved by fee1-dead

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 6, 2022
@bors
Copy link
Contributor

bors commented Mar 6, 2022

⌛ Testing commit 4852291 with merge 8876ca3...

@bors
Copy link
Contributor

bors commented Mar 7, 2022

☀️ Test successful - checks-actions
Approved by: fee1-dead
Pushing 8876ca3 to master...

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

📣 Toolstate changed by #94597!

Tested on commit 8876ca3.
Direct link to PR: #94597

💔 miri on windows: test-pass → build-fail (cc @oli-obk @eddyb @RalfJung).
💔 miri on linux: test-pass → build-fail (cc @oli-obk @eddyb @RalfJung).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Mar 7, 2022
Tested on commit rust-lang/rust@8876ca3.
Direct link to PR: <rust-lang/rust#94597>

💔 miri on windows: test-pass → build-fail (cc @oli-obk @eddyb @RalfJung).
💔 miri on linux: test-pass → build-fail (cc @oli-obk @eddyb @RalfJung).
@nnethercote nnethercote deleted the ConstAllocation branch March 7, 2022 02:03
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8876ca3): comparison url.

Summary: This benchmark run shows 13 relevant improvements 🎉 to instruction counts.

  • Arithmetic mean of relevant improvements: -0.9%
  • Arithmetic mean of all relevant changes: -0.8%
  • Largest improvement in instruction counts: -1.4% on full builds of keccak check

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

@rustbot label: -perf-regression

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-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.

8 participants