Fix const normalization for generic const items with trait assoc consts#152278
Fix const normalization for generic const items with trait assoc consts#152278rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Conversation
| if res != term.to_term(tcx) | ||
| && (res.as_type().map_or(false, |t| t.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION)) | ||
| || term.kind(tcx) == ty::AliasTermKind::FreeTy) | ||
| && (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION) | ||
| || matches!( | ||
| term.kind(tcx), | ||
| ty::AliasTermKind::FreeTy | ty::AliasTermKind::FreeConst | ||
| )) |
There was a problem hiding this comment.
I would expect this to just be if term.has_aliases() and I don't understand why it isn't. Can you try changing it to that and see if anything breaks?
There was a problem hiding this comment.
I think term.has_aliases() is not a proper solution (though I didn't know that API). Actually it caused a SEGV during stage1 lib building:
output (extracted)
Building stage1 library artifacts (stage1 -> stage1, x86_64-unknown-linux-gnu)
Compiling compiler_builtins v0.1.160 (/home/lapla/repos/rust/library/compiler-builtins/compiler-builtins)
Compiling core v0.0.0 (/home/lapla/repos/rust/library/core)
Compiling libc v0.2.178
Compiling object v0.37.3
Compiling std v0.0.0 (/home/lapla/repos/rust/library/std)
Compiling test v0.0.0 (/home/lapla/repos/rust/library/test)
error: rustc interrupted by SIGSEGV, printing backtrace
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x93ee8c) [0x7bd87833ee8c]
/usr/lib/x86_64-linux-gnu/libc.so.6(+0x45f30) [0x7bd877645f30]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x313ad45) [0x7bd87ab3ad45]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x32f10d9) [0x7bd87acf10d9]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x335e113) [0x7bd87ad5e113]
### cycle encountered after 5 frames with period 6
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(_RNvXs_NtNtNtCsiiExf7IvESp_21rustc_trait_selection6traits5query9normalizeNtB4_15QueryNormalizerINtNtCs44sggCrMDsM_13rustc_type_ir4fold18FallibleTypeFolderNtNtNtCsforUfnDCdfO_12rustc_middle2ty7context6TyCtxtE11try_fold_ty+0x1ca) [0x7bd87ad71e1a]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x335e82e) [0x7bd87ad5e82e]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(_RNvXs_NtNtNtCsiiExf7IvESp_21rustc_trait_selection6traits5query9normalizeNtB4_15QueryNormalizerINtNtCs44sggCrMDsM_13rustc_type_ir4fold18FallibleTypeFolderNtNtNtCsforUfnDCdfO_12rustc_middle2ty7context6TyCtxtE11try_fold_ty+0x1ca) [0x7bd87ad71e1a]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x335e82e) [0x7bd87ad5e82e]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(_RNvXs_NtNtNtCsiiExf7IvESp_21rustc_trait_selection6traits5query9normalizeNtB4_15QueryNormalizerINtNtCs44sggCrMDsM_13rustc_type_ir4fold18FallibleTypeFolderNtNtNtCsforUfnDCdfO_12rustc_middle2ty7context6TyCtxtE11try_fold_ty+0x1ca) [0x7bd87ad71e1a]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x335e82e) [0x7bd87ad5e82e]
### recursed 41 times
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(_RNvXs_NtNtNtCsiiExf7IvESp_21rustc_trait_selection6traits5query9normalizeNtB4_15QueryNormalizerINtNtCs44sggCrMDsM_13rustc_type_ir4fold18FallibleTypeFolderNtNtNtCsforUfnDCdfO_12rustc_middle2ty7context6TyCtxtE11try_fold_ty+0x1ca) [0x7bd87ad71e1a]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x335e82e) [0x7bd87ad5e82e]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(_RNvXs_NtNtNtCsiiExf7IvESp_21rustc_trait_selection6traits5query9normalizeNtB4_15QueryNormalizerINtNtCs44sggCrMDsM_13rustc_type_ir4fold18FallibleTypeFolderNtNtNtCsforUfnDCdfO_12rustc_middle2ty7context6TyCtxtE11try_fold_ty+0x1ca) [0x7bd87ad71e1a]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(+0x335e82e) [0x7bd87ad5e82e]
/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1/lib/librustc_driver-2ff71906bfdf6a94.so(_RNvXs_NtNtNtCsiiExf7IvESp_21rustc_trait_selection6traits5query9normalizeNtB4_15QueryNormalizerINtNtCs44sggCrMDsM_13rustc_type_ir4fold18FallibleTypeFolderNtNtNtCsforUfnDCdfO_12rustc_middle2ty7context6TyCtxtE11try_fold_ty+0x1ca) [0x7bd87ad71e1a]
note: rustc unexpectedly overflowed its stack! this is a bug
note: maximum backtrace depth reached, frames may have been lost
note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
note: backtrace dumped due to SIGSEGV! resuming signal
rustc exited with signal: 11 (SIGSEGV) (core dumped)
error: could not compile `core` (lib)
Caused by:
process didn't exit successfully: `/home/lapla/repos/rust/build/bootstrap/debug/rustc /home/lapla/repos/rust/build/bootstrap/debug/rustc --crate-name core --edition=2024 library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=130 --crate-type lib --emit=dep-info,metadata,link -Z embed-metadata=no -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 --warn=unexpected_cfgs --check-cfg 'cfg(no_fp_fmt_parse)' --check-cfg 'cfg(feature, values(any()))' --check-cfg 'cfg(target_has_reliable_f16)' --check-cfg 'cfg(target_has_reliable_f16_math)' --check-cfg 'cfg(target_has_reliable_f128)' --check-cfg 'cfg(target_has_reliable_f128_math)' --check-cfg 'cfg(llvm_enzyme)' -Cembed-bitcode=yes -Zunstable-options -Cforce-frame-pointers=non-leaf --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values("debug_refcell", "llvm_enzyme", "optimize_for_size", "panic_immediate_abort"))' -C metadata=d728f96fea50222e -C extra-filename=-15fde4dd13344f6e --out-dir /home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/dist/deps --target x86_64-unknown-linux-gnu -C linker=clang -L dependency=/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/dist/deps -L dependency=/home/lapla/repos/rust/build/x86_64-unknown-linux-gnu/stage1-std/dist/deps -Zannotate-moves '--check-cfg=cfg(feature,values(any()))' -Zunstable-options -Zmacro-backtrace -Csplit-debuginfo=off -Cprefer-dynamic -Zinline-mir -Zinline-mir-preserve-debug -Zmir_strip_debuginfo=locals-in-tiny-functions -Clink-args=-Wl,-z,origin '-Clink-args=-Wl,-rpath,$ORIGIN/../lib' -Alinker-messages '-Zcrate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/")' -Z binary-dep-depinfo` (exit status: 254)
Build completed unsuccessfully in 0:04:56
HAS_ALIAS includes HAS_TY_OPAQUE, and opaque types are not normalized outside of TypingMode::PostAnalysis, so the res!=term.to_term(tcx) condition keeps passing and the recursion never terminates.
I also found needs_normalization(), which excludes HAS_TY_OPAQUE depending on the typing mode, but it still includes HAS_TY_PROJECTION and others, which similarly caused a stack overflow. Since projection types are already handled directly by try_fold_ty, the re-normalization here should only need HAS_CT_PROJECTION and the FreeTy/FreeConst cases (as normalize_canonicalized_free_alias() only unwraps one layer) I think.
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
|
@rustbot ready |
|
@bors r+ rollup |
…BoxyUwU Fix const normalization for generic const items with trait assoc consts In `try_fold_free_or_assoc`, the check for whether the normalization result needs further normalization only considered types, not constants. This caused generic const items marked with `#[type_const]` that reference trait associated consts to only partially normalize—the outer const would be expanded, but the inner associated const would remain unevaluated, resulting in an ICE in borrowck. close rust-lang#151647 r? BoxyUwU (Based on git blame)
cb84a82 to
55f56f2
Compare
|
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. |
|
Looks like #152324 is the cause. I've rebased. |
|
@bors r=BoxyUwU |
…BoxyUwU Fix const normalization for generic const items with trait assoc consts In `try_fold_free_or_assoc`, the check for whether the normalization result needs further normalization only considered types, not constants. This caused generic const items marked with `#[type_const]` that reference trait associated consts to only partially normalize—the outer const would be expanded, but the inner associated const would remain unevaluated, resulting in an ICE in borrowck. close rust-lang#151647 r? BoxyUwU (Based on git blame)
55f56f2 to
88f0ac3
Compare
|
|
|
@JonathanBrouwer Sorry, we still need to make some changes to pass CI. This should be fine now. |
|
I'll wait for CI to pass and then reapprove :P |
|
CI is now all green :) |
|
@bors r=BoxyUwU |
…BoxyUwU Fix const normalization for generic const items with trait assoc consts In `try_fold_free_or_assoc`, the check for whether the normalization result needs further normalization only considered types, not constants. This caused generic const items marked with `#[type_const]` that reference trait associated consts to only partially normalize—the outer const would be expanded, but the inner associated const would remain unevaluated, resulting in an ICE in borrowck. close rust-lang#151647 r? BoxyUwU (Based on git blame)
Rollup merge of #152278 - lapla-cogito:type_const_nested, r=BoxyUwU Fix const normalization for generic const items with trait assoc consts In `try_fold_free_or_assoc`, the check for whether the normalization result needs further normalization only considered types, not constants. This caused generic const items marked with `#[type_const]` that reference trait associated consts to only partially normalize—the outer const would be expanded, but the inner associated const would remain unevaluated, resulting in an ICE in borrowck. close #151647 r? BoxyUwU (Based on git blame)
In
try_fold_free_or_assoc, the check for whether the normalization result needs further normalization only considered types, not constants. This caused generic const items marked with#[type_const]that reference trait associated consts to only partially normalize—the outer const would be expanded, but the inner associated const would remain unevaluated, resulting in an ICE in borrowck.close #151647
r? BoxyUwU
(Based on git blame)