Skip to content

Commit 7ea1d3c

Browse files
committed
Auto merge of #115756 - oli-obk:early_const_prop_lint, r=<try>
WIP: move const prop lints before borrowck r? `@ghost` for this we need to stop revealing hidden types during const prop and for that I'm opening this WIP PR to do some perf runs
2 parents 55e5c9d + b241641 commit 7ea1d3c

File tree

14 files changed

+55
-38
lines changed

14 files changed

+55
-38
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ build/
5252
/src/tools/x/target
5353
# Created by default with `src/ci/docker/run.sh`
5454
/obj/
55+
# Created on ICE during build
56+
rustc-ice-*.txt
5557

5658
## Temporary files
5759
*~

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ rustc_queries! {
13981398

13991399
/// Computes the layout of a type. Note that this implicitly
14001400
/// executes in "reveal all" mode, and will normalize the input type.
1401-
query layout_of(
1401+
query layout_of_raw(
14021402
key: ty::ParamEnvAnd<'tcx, Ty<'tcx>>
14031403
) -> Result<ty::layout::TyAndLayout<'tcx>, &'tcx ty::layout::LayoutError<'tcx>> {
14041404
depth_limit

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,39 @@ pub trait LayoutOf<'tcx>: LayoutOfHelpers<'tcx> {
688688
}
689689
}
690690

691+
impl<'tcx> TyCtxt<'tcx> {
692+
pub fn layout_of(
693+
self,
694+
query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
695+
) -> Result<TyAndLayout<'tcx>, &'tcx LayoutError<'tcx>> {
696+
self.at(DUMMY_SP).layout_of(query)
697+
}
698+
}
699+
700+
impl<'tcx> TyCtxtAt<'tcx> {
701+
pub fn layout_of(
702+
self,
703+
query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
704+
) -> Result<TyAndLayout<'tcx>, &'tcx LayoutError<'tcx>> {
705+
let (param_env, ty) = query.into_parts();
706+
let param_env = param_env.with_reveal_all_normalized(self.tcx);
707+
708+
// FIXME: We might want to have two different versions of `layout_of`:
709+
// One that can be called after typecheck has completed and can use
710+
// `normalize_erasing_regions` here and another one that can be called
711+
// before typecheck has completed and uses `try_normalize_erasing_regions`.
712+
let ty = match self.try_normalize_erasing_regions(param_env, ty) {
713+
Ok(t) => t,
714+
Err(normalization_error) => {
715+
return Err(self
716+
.arena
717+
.alloc(LayoutError::NormalizationFailure(ty, normalization_error)));
718+
}
719+
};
720+
self.layout_of_raw(param_env.and(ty))
721+
}
722+
}
723+
691724
impl<'tcx, C: LayoutOfHelpers<'tcx>> LayoutOf<'tcx> for C {}
692725

693726
impl<'tcx> LayoutOfHelpers<'tcx> for LayoutCx<'tcx, TyCtxt<'tcx>> {

compiler/rustc_query_system/src/query/job.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl QueryJobId {
174174
while let Some(id) = current_id {
175175
let info = query_map.get(&id).unwrap();
176176
// FIXME: This string comparison should probably not be done.
177-
if format!("{:?}", info.query.dep_kind) == "layout_of" {
177+
if format!("{:?}", info.query.dep_kind) == "layout_of_raw" {
178178
depth += 1;
179179
last_layout = Some((info.clone(), depth));
180180
}

compiler/rustc_ty_utils/src/layout.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,17 @@ use crate::errors::{
2525
use crate::layout_sanity_check::sanity_check_layout;
2626

2727
pub fn provide(providers: &mut Providers) {
28-
*providers = Providers { layout_of, ..*providers };
28+
*providers = Providers { layout_of_raw, ..*providers };
2929
}
3030

3131
#[instrument(skip(tcx, query), level = "debug")]
32-
fn layout_of<'tcx>(
32+
fn layout_of_raw<'tcx>(
3333
tcx: TyCtxt<'tcx>,
3434
query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>,
3535
) -> Result<TyAndLayout<'tcx>, &'tcx LayoutError<'tcx>> {
3636
let (param_env, ty) = query.into_parts();
3737
debug!(?ty);
3838

39-
let param_env = param_env.with_reveal_all_normalized(tcx);
40-
let unnormalized_ty = ty;
41-
42-
// FIXME: We might want to have two different versions of `layout_of`:
43-
// One that can be called after typecheck has completed and can use
44-
// `normalize_erasing_regions` here and another one that can be called
45-
// before typecheck has completed and uses `try_normalize_erasing_regions`.
46-
let ty = match tcx.try_normalize_erasing_regions(param_env, ty) {
47-
Ok(t) => t,
48-
Err(normalization_error) => {
49-
return Err(tcx
50-
.arena
51-
.alloc(LayoutError::NormalizationFailure(ty, normalization_error)));
52-
}
53-
};
54-
55-
if ty != unnormalized_ty {
56-
// Ensure this layout is also cached for the normalized type.
57-
return tcx.layout_of(param_env.and(ty));
58-
}
59-
6039
let cx = LayoutCx { tcx, param_env };
6140

6241
let layout = layout_of_uncached(&cx, ty)?;

src/etc/rust_analyzer_settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"compiler/rustc_codegen_gcc/Cargo.toml"
1717
],
1818
"rust-analyzer.rustfmt.overrideCommand": [
19-
"./build/host/rustfmt/bin/rustfmt",
19+
"${workspaceFolder}/build/host/rustfmt/bin/rustfmt",
2020
"--edition=2021"
2121
],
2222
"rust-analyzer.procMacro.server": "./build/host/stage0/libexec/rust-analyzer-proc-macro-srv",

tests/ui/consts/const-size_of-cycle.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`..
1515
LL | bytes: [u8; std::mem::size_of::<Foo>()]
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1717
= note: ...which requires computing layout of `Foo`...
18-
= note: ...which requires computing layout of `[u8; std::mem::size_of::<Foo>()]`...
1918
= note: ...which requires normalizing `[u8; std::mem::size_of::<Foo>()]`...
2019
= note: ...which again requires evaluating type-level constant, completing the cycle
2120
note: cycle used when checking that `Foo` is well-formed

tests/ui/consts/issue-44415.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`..
1515
LL | bytes: [u8; unsafe { intrinsics::size_of::<Foo>() }],
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717
= note: ...which requires computing layout of `Foo`...
18-
= note: ...which requires computing layout of `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
1918
= note: ...which requires normalizing `[u8; unsafe { intrinsics::size_of::<Foo>() }]`...
2019
= note: ...which again requires evaluating type-level constant, completing the cycle
2120
note: cycle used when checking that `Foo` is well-formed

tests/ui/layout/layout-cycle.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
error[E0391]: cycle detected when computing layout of `S<S<()>>`
22
|
3-
= note: ...which requires computing layout of `<S<()> as Tr>::I`...
4-
= note: ...which again requires computing layout of `S<S<()>>`, completing the cycle
3+
= note: ...which immediately requires computing layout of `S<S<()>>` again
54
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
65

76
error: failed to get layout for S<S<()>>: a cycle occurred during layout computation

tests/ui/layout/valid_range_oob.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
error: the compiler unexpectedly panicked. this is a bug.
33

44
query stack during panic:
5-
#0 [layout_of] computing layout of `Foo`
5+
#0 [layout_of_raw] computing layout of `Foo`
66
#1 [eval_to_allocation_raw] const-evaluating + checking `FOO`
77
end of query stack

tests/ui/recursion/issue-26548-recursion-via-normalize.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
//~ ERROR cycle detected when computing layout of `core::option::Option<S>`
22
//~| NOTE see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
33
//~| NOTE ...which requires computing layout of `S`...
4-
//~| NOTE ...which requires computing layout of `core::option::Option<<S as Mirror>::It>`...
54
//~| NOTE ...which again requires computing layout of `core::option::Option<S>`, completing the cycle
6-
//~| NOTE cycle used when computing layout of `core::option::Option<<S as Mirror>::It>`
75

86
trait Mirror {
7+
//~^ NOTE: cycle used when checking deathness of variables in top-level module
98
type It: ?Sized;
109
}
1110
impl<T: ?Sized> Mirror for T {

tests/ui/recursion/issue-26548-recursion-via-normalize.stderr

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
error[E0391]: cycle detected when computing layout of `core::option::Option<S>`
22
|
33
= note: ...which requires computing layout of `S`...
4-
= note: ...which requires computing layout of `core::option::Option<<S as Mirror>::It>`...
54
= note: ...which again requires computing layout of `core::option::Option<S>`, completing the cycle
6-
= note: cycle used when computing layout of `core::option::Option<<S as Mirror>::It>`
5+
note: cycle used when checking deathness of variables in top-level module
6+
--> $DIR/issue-26548-recursion-via-normalize.rs:6:1
7+
|
8+
LL | / trait Mirror {
9+
LL | |
10+
LL | | type It: ?Sized;
11+
LL | | }
12+
... |
13+
LL | | let _s = S(None);
14+
LL | | }
15+
| |_^
716
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
817

918
error: aborting due to previous error

tests/ui/sized/recursive-type-2.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
error[E0391]: cycle detected when computing layout of `Foo<()>`
22
|
3-
= note: ...which requires computing layout of `<() as A>::Assoc`...
4-
= note: ...which again requires computing layout of `Foo<()>`, completing the cycle
3+
= note: ...which immediately requires computing layout of `Foo<()>` again
54
note: cycle used when elaborating drops for `main`
65
--> $DIR/recursive-type-2.rs:11:1
76
|

tests/ui/type-alias-impl-trait/issue-53092-2.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ note: ...which requires type-checking `CONST_BUG`...
1414
|
1515
LL | const CONST_BUG: Bug<u8, ()> = unsafe { std::mem::transmute(|_: u8| ()) };
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17-
= note: ...which requires computing layout of `Bug<u8, ()>`...
1817
= note: ...which requires normalizing `Bug<u8, ()>`...
1918
= note: ...which again requires computing type of `Bug::{opaque#0}`, completing the cycle
2019
note: cycle used when checking item types in top-level module

0 commit comments

Comments
 (0)