Skip to content

Remove OpaqueListContents#154399

Open
nnethercote wants to merge 3 commits intorust-lang:mainfrom
nnethercote:rm-OpaqueListContents
Open

Remove OpaqueListContents#154399
nnethercote wants to merge 3 commits intorust-lang:mainfrom
nnethercote:rm-OpaqueListContents

Conversation

@nnethercote
Copy link
Copy Markdown
Contributor

ty::List has an OpaqueListContents field that supposedly prevents &List from being a fat pointer but (a) it doesn't actually do that and (b) it causes other annoyances and complications. This PR removes it. Details in individual commits.

r? @cuviper

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

I don't expect this to have perf effects but it's a widely-used type so let's check.

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Mar 26, 2026
@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 26, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 26, 2026

☀️ Try build successful (CI)
Build commit: 7c5a6c1 (7c5a6c16c4a5d19afc9defe792d5c40dc6c3a35b, parent: 1174f784096deb8e4ba93f7e4b5ccb7bb4ba2c55)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (7c5a6c1): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

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

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.2% [-0.2%, -0.1%] 5
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.0%] 13
All ❌✅ (primary) -0.2% [-0.2%, -0.1%] 5

Max RSS (memory usage)

Results (secondary -4.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-4.3% [-4.3%, -4.3%] 1
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 483.566s -> 485.77s (0.46%)
Artifact size: 395.05 MiB -> 395.16 MiB (0.03%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 26, 2026
@rust-bors

This comment has been minimized.

@nnethercote nnethercote force-pushed the rm-OpaqueListContents branch from 69f7f82 to 4c8c82f Compare March 27, 2026 05:23
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@nnethercote nnethercote force-pushed the rm-OpaqueListContents branch from 4c8c82f to bf4d123 Compare March 27, 2026 11:23
@cuviper
Copy link
Copy Markdown
Member

cuviper commented Mar 29, 2026

ty::List has an OpaqueListContents field that supposedly prevents &List from being a fat pointer but (a) it doesn't actually do that [...] Details in individual commits.

Ok, so in the details you mention the "first part" which is actually lost here, that List is unsized. I'm not sure off-hand what that really hurts though, apart from size_of/size_of_val being misleading -- not accounting for the contents.

Comment on lines 226 to 229
// SAFETY: `data_ptr` has the same provenance as `self` and can therefore
// access the `self.skel.len` elements stored at `self.skel.data`.
// Note that we specifically don't reborrow `&self.skel.data`, because that
// would give us a pointer with provenance over 0 bytes.
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.

Does this provenance still work when the compiler thinks it does know the size? i.e. &self might have more limited range than when it was unsized.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't know much about provenance, so I don't even know how a change here would manifest in practice.

These will be augmented in the next commit.
`RawList::opaque` has type `OpaqueListContents`, which is commented
thusly:

> A dummy type used to force `List` to be unsized while not requiring
> references to it be wide pointers.

The first part is true: it does make `List` unsized. This is a little
annoying at times, requiring special handling.

The second part is false: `&List<T>` is a narrow pointer whether the
`opaque` field is present or not.

This commit removes `RawList::opaque` and `OpaqueListContents`.
Consequences:
- `List`/`RawList` are now sized and we can add size assertions.
- The `Erasable` impls for `&List`/`&ListWithCachedTypeInfo` are no longer
  necessary, because the impl for `&T` now covers them.
- The unsafe `DynSync` and `Aligned` impls can be removed.
- The `ptr_alignment_type` feature is no longer needed by `rustc_middle`.
They now have identical layout, so we don't need both.
@nnethercote nnethercote force-pushed the rm-OpaqueListContents branch from bf4d123 to 25f7a58 Compare March 29, 2026 23:51
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 29, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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.

5 participants