-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
rustdoc: correctly deal with self ty params when eliding default object lifetimes #115276
rustdoc: correctly deal with self ty params when eliding default object lifetimes #115276
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
f56bd1e
to
2fbc6a2
Compare
Ah, wait, the root issue is something else 😅 @rustbot author |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notwithstanding any eventual things missing here, I'd just like to point out that I have just built the documentation of both the reproducible project and the upstream dicom-parser
crate via this revision, and they both built successfully. 👍
Thank you very much for working on this!
It seemingly fixes the problem but it's not the correct fix. The actual issue is an off-by-one error: we should be looking at the type parameter It's a bit awkward to fix the off-by-one error but seeing that the priority of the issue has been ranked critical recently, I'm going to prioritize this PR now. |
2fbc6a2
to
4e71139
Compare
Since I've increased the size of a widely used function argument of a multi-parameter function, this might have a perf impact @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
⌛ Trying commit 4e71139142fb41322249a2f01c639aff6dae8136 with merge f79a93c17c4c06926817c89541e82597491cd6cf... |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to wait for the perf result before merging this PR.
This is ready for review, you can mostly ignore the FIXMEs (I'm gonna remove them later).
@rustbot ready
let offset = | ||
if !has_self && generics.parent.is_none() && generics.has_self { 1 } else { 0 }; | ||
let param = generics.params[index + offset].def_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This here is the most important part of the PR. It fixes the off-by-one error that leads to the ICE, see also #115276 (comment). Basically, if the container type is a trait object type (e.g. in dyn Container<dyn Content>
), the DefId
refers to the trait Container
whose generics contain the type parameter Self
but the args
never contain a substitution for the self type since it's dynamic for trait object types. In such case, we offset by one.
If the DefKind
of the container is Trait
, we don't necessarily have a trait object type, we might also have a trait bound like impl Container<dyn Content>
whose args
do contain the concrete self type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this explanation as a comment.
src/librustdoc/clean/mod.rs
Outdated
PathSegment { | ||
name: item.name, | ||
args: GenericArgs::AngleBracketed { | ||
args: ty_args_to_args( | ||
cx, | ||
ty.map_bound(|ty| &ty.args[generics.parent_count..]), | ||
false, | ||
None, | ||
// FIXME: Revert to `None`, CC #115379 | ||
Some(def_id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not relevant for fixing the ICE. I'm now just properly passing along the associated type as a container type. However, I've found out (#115379) that rustc itself doesn't handle associated type containers correctly (unless I'm mistaken), so theoretically, I can go back to None
without any repercussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to keep the correct value, so Some
in this case.
src/librustdoc/clean/mod.rs
Outdated
let default = tcx.object_lifetime_default(param); | ||
|
||
match default { | ||
rbv::ObjectLifetimeDefault::Param(lifetime) => { | ||
let index = generics.param_def_id_to_index[&lifetime]; | ||
let arg = args.skip_binder()[index as usize].expect_region(); | ||
let index = index as usize - generics.parent_count; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only relevant for associated type containers. The indices in param_def_id_to_index
are relative to the parent generics, thus we need to translate the index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, please add this as a comment. ;)
This comment has been minimized.
This comment has been minimized.
src/librustdoc/clean/mod.rs
Outdated
@@ -469,6 +469,7 @@ fn clean_projection<'tcx>( | |||
|
|||
let trait_ = | |||
clean_trait_ref_with_bindings(cx, ty.map_bound(|ty| ty.trait_ref(cx.tcx)), ThinVec::new()); | |||
// FIXME: Maybe add comment here why `None` is fine. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, please do. :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For posterity's sake, if/once we respect object lifetime defaults of GATs, None
would be fine here since Self
doesn't have a meaningful object lifetime default according to
rust/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs
Lines 1563 to 1564 in b30b535
// We may also get a `Trait` or `TraitAlias` because of how generics `Self` parameter | |
// works. Ignore it because it can't have a meaningful lifetime default. |
If #115379 (the 1000th time I'm mentioning it lol) is indeed a bug, then I will come back to this an add a comment :)
Code looks good to me. We'll see what perf checks say. Also please add the nice review comments you wrote into the code, will be useful for everyone. :) |
Thanks! @bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (35e4163): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 630.43s -> 630.838s (0.06%) |
…k-Simulacrum [beta] backport This PR backports: - rust-lang#115559: implied bounds: do not ICE on unconstrained region vars - rust-lang#115446: fix version for abi_thiscall to 1.73.0, which was forgotten to change when stabilized and (later) moved to beta - rust-lang#115276: rustdoc: correctly deal with self ty params when eliding default object lifetimes r? `@Mark-Simulacrum`
…Simulacrum [stable] 1.72.1 release This backports: * Remove assert that checks type equality rust-lang#115215 * implied bounds: do not ICE on unconstrained region vars rust-lang#115559 * rustdoc: correctly deal with self ty params when eliding default object lifetimes rust-lang#115276 * Stop emitting non-power-of-two vectors in (non-portable-SIMD) codegen rust-lang#115236 * Normalize before checking if local is freeze in deduced_param_attrs rust-lang#114948 Some cherry-picks required merge conflict resolution, we'll see if I got it right based on CI (rustdoc fix and LLVM codegen test). r? `@Mark-Simulacrum`
…Simulacrum [stable] 1.72.1 release This backports: * Remove assert that checks type equality rust-lang#115215 * implied bounds: do not ICE on unconstrained region vars rust-lang#115559 * rustdoc: correctly deal with self ty params when eliding default object lifetimes rust-lang#115276 * Stop emitting non-power-of-two vectors in (non-portable-SIMD) codegen rust-lang#115236 * Normalize before checking if local is freeze in deduced_param_attrs rust-lang#114948 Some cherry-picks required merge conflict resolution, we'll see if I got it right based on CI (rustdoc fix and LLVM codegen test). r? `@Mark-Simulacrum`
…Simulacrum [stable] 1.72.1 release This backports: * Remove assert that checks type equality rust-lang#115215 * implied bounds: do not ICE on unconstrained region vars rust-lang#115559 * rustdoc: correctly deal with self ty params when eliding default object lifetimes rust-lang#115276 * Stop emitting non-power-of-two vectors in (non-portable-SIMD) codegen rust-lang#115236 * Normalize before checking if local is freeze in deduced_param_attrs rust-lang#114948 Some cherry-picks required merge conflict resolution, we'll see if I got it right based on CI (rustdoc fix and LLVM codegen test). r? `@Mark-Simulacrum`
…Simulacrum [stable] 1.72.1 release This backports: * Remove assert that checks type equality rust-lang#115215 * implied bounds: do not ICE on unconstrained region vars rust-lang#115559 * rustdoc: correctly deal with self ty params when eliding default object lifetimes rust-lang#115276 * Stop emitting non-power-of-two vectors in (non-portable-SIMD) codegen rust-lang#115236 * Normalize before checking if local is freeze in deduced_param_attrs rust-lang#114948 Some cherry-picks required merge conflict resolution, we'll see if I got it right based on CI (rustdoc fix and LLVM codegen test). r? `@Mark-Simulacrum`
…Simulacrum [stable] 1.72.1 release This backports: * Remove assert that checks type equality rust-lang#115215 * implied bounds: do not ICE on unconstrained region vars rust-lang#115559 * rustdoc: correctly deal with self ty params when eliding default object lifetimes rust-lang#115276 * Stop emitting non-power-of-two vectors in (non-portable-SIMD) codegen rust-lang#115236 * Normalize before checking if local is freeze in deduced_param_attrs rust-lang#114948 Some cherry-picks required merge conflict resolution, we'll see if I got it right based on CI (rustdoc fix and LLVM codegen test). r? `@Mark-Simulacrum`
…Simulacrum [stable] 1.72.1 release This backports: * Remove assert that checks type equality rust-lang#115215 * implied bounds: do not ICE on unconstrained region vars rust-lang#115559 * rustdoc: correctly deal with self ty params when eliding default object lifetimes rust-lang#115276 * Stop emitting non-power-of-two vectors in (non-portable-SIMD) codegen rust-lang#115236 * Normalize before checking if local is freeze in deduced_param_attrs rust-lang#114948 Some cherry-picks required merge conflict resolution, we'll see if I got it right based on CI (rustdoc fix and LLVM codegen test). r? `@Mark-Simulacrum`
…Simulacrum [stable] 1.72.1 release This backports: * Remove assert that checks type equality rust-lang#115215 * implied bounds: do not ICE on unconstrained region vars rust-lang#115559 * rustdoc: correctly deal with self ty params when eliding default object lifetimes rust-lang#115276 * Stop emitting non-power-of-two vectors in (non-portable-SIMD) codegen rust-lang#115236 * Normalize before checking if local is freeze in deduced_param_attrs rust-lang#114948 Some cherry-picks required merge conflict resolution, we'll see if I got it right based on CI (rustdoc fix and LLVM codegen test). r? `@Mark-Simulacrum`
> 1.72.1 resolves a few regressions introduced in 1.72.0: > - [Partially revert codegen change, improving codegen](rust-lang/rust#115236) > - [rustdoc: Fix self ty params in objects with lifetimes](rust-lang/rust#115276) > - [Fix regression in compile times](rust-lang/rust#114948) > - Resolve some ICEs in the compiler: > - [#115215](rust-lang/rust#115215) > - [#115559](rust-lang/rust#115559)
Fixes #115179.