Skip to content

Commit

Permalink
Auto merge of #115762 - oli-obk:early_const_prop_lint2, r=<try>
Browse files Browse the repository at this point in the history
Avoid revealing in layout_of

r? `@compiler-errors`

I feel like `layout_of` is doing too many things at once, and I don't really know why. It could allow us to if callers could decide whether to reveal opaque types.
  • Loading branch information
bors committed Sep 11, 2023
2 parents 3ebb562 + 21e8d63 commit ec12977
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ build/
/src/tools/x/target
# Created by default with `src/ci/docker/run.sh`
/obj/
# Created on ICE during build
rustc-ice-*.txt

## Temporary files
*~
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
param_env: ty::ParamEnv<'tcx>,
) -> Result<SizeSkeleton<'tcx>, &'tcx LayoutError<'tcx>> {
debug_assert!(!ty.has_non_region_infer());
let param_env = param_env.with_reveal_all_normalized(tcx);

// First try computing a static layout.
let err = match tcx.layout_of(param_env.and(ty)) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_transform/src/const_prop_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
) -> ConstPropagator<'mir, 'tcx> {
let def_id = body.source.def_id();
let args = &GenericArgs::identity_for_item(tcx, def_id);
let param_env = tcx.param_env_reveal_all_normalized(def_id);
let param_env = tcx.param_env(def_id);

let can_const_prop = CanConstProp::check(tcx, param_env, body);
let mut ecx = InterpCx::new(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/layout_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub fn ensure_wf<'tcx>(
}

fn dump_layout_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribute) {
let param_env = tcx.param_env(item_def_id);
let param_env = tcx.param_env_reveal_all_normalized(item_def_id);
let ty = tcx.type_of(item_def_id).instantiate_identity();
let span = tcx.def_span(item_def_id.to_def_id());
if !ensure_wf(tcx, param_env, ty, item_def_id, span) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,10 @@ pub fn typeid_for_instance<'tcx>(
options: TypeIdOptions,
) -> String {
let fn_abi = tcx
.fn_abi_of_instance(tcx.param_env(instance.def_id()).and((*instance, ty::List::empty())))
.fn_abi_of_instance(
tcx.param_env_reveal_all_normalized(instance.def_id())
.and((*instance, ty::List::empty())),
)
.unwrap_or_else(|instance| {
bug!("typeid_for_instance: couldn't get fn_abi of instance {:?}", instance)
});
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ty_utils/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ fn layout_of<'tcx>(
let (param_env, ty) = query.into_parts();
debug!(?ty);

let param_env = param_env.with_reveal_all_normalized(tcx);
let unnormalized_ty = ty;

// FIXME: We might want to have two different versions of `layout_of`:
Expand Down
2 changes: 1 addition & 1 deletion src/etc/rust_analyzer_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"compiler/rustc_codegen_gcc/Cargo.toml"
],
"rust-analyzer.rustfmt.overrideCommand": [
"./build/host/rustfmt/bin/rustfmt",
"${workspaceFolder}/build/host/rustfmt/bin/rustfmt",
"--edition=2021"
],
"rust-analyzer.procMacro.server": "./build/host/stage0/libexec/rust-analyzer-proc-macro-srv",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ error[E0391]: cycle detected when elaborating drops for `<impl at $DIR/issue-249
LL | const BAR: u32 = IMPL_REF_BAR;
| ^^^^^^^^^^^^
|
note: ...which requires const-evaluating + checking `IMPL_REF_BAR`...
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:1
|
LL | const IMPL_REF_BAR: u32 = GlobalImplRef::BAR;
| ^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking `IMPL_REF_BAR`...
--> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:7:27
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ error[E0391]: cycle detected when elaborating drops for `FooDefault::BAR`
LL | const BAR: u32 = DEFAULT_REF_BAR;
| ^^^^^^^^^^^^^^^
|
note: ...which requires const-evaluating + checking `DEFAULT_REF_BAR`...
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:11:1
|
LL | const DEFAULT_REF_BAR: u32 = <GlobalDefaultRef>::BAR;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking `DEFAULT_REF_BAR`...
--> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:11:30
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ error[E0391]: cycle detected when elaborating drops for `<impl at $DIR/issue-249
LL | const BAR: u32 = TRAIT_REF_BAR;
| ^^^^^^^^^^^^^
|
note: ...which requires const-evaluating + checking `TRAIT_REF_BAR`...
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:1
|
LL | const TRAIT_REF_BAR: u32 = <GlobalTraitRef>::BAR;
| ^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires const-evaluating + checking `TRAIT_REF_BAR`...
--> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:7:28
|
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/recursion/issue-26548-recursion-via-normalize.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//~ ERROR cycle detected when computing layout of `core::option::Option<S>`
//~ ERROR cycle detected when computing layout of `core::option::Option<<S as Mirror>::It>`
//~| 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
//~| NOTE ...which requires computing layout of `S`...
//~| NOTE ...which requires computing layout of `core::option::Option<<S as Mirror>::It>`...
//~| NOTE ...which again requires computing layout of `core::option::Option<S>`, completing the cycle
//~| NOTE cycle used when computing layout of `core::option::Option<<S as Mirror>::It>`
//~| NOTE ...which again requires computing layout of `core::option::Option<<S as Mirror>::It>`, completing the cycle
//~| NOTE ...which requires computing layout of `core::option::Option<S>`...

trait Mirror {
//~^ NOTE: cycle used when checking deathness of variables in top-level module
type It: ?Sized;
}
impl<T: ?Sized> Mirror for T {
Expand Down
18 changes: 14 additions & 4 deletions tests/ui/recursion/issue-26548-recursion-via-normalize.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
error[E0391]: cycle detected when computing layout of `core::option::Option<S>`
error[E0391]: cycle detected when computing layout of `core::option::Option<<S as Mirror>::It>`
|
= note: ...which requires computing layout of `core::option::Option<S>`...
= note: ...which requires computing layout of `S`...
= note: ...which requires computing layout of `core::option::Option<<S as Mirror>::It>`...
= note: ...which again requires computing layout of `core::option::Option<S>`, completing the cycle
= note: cycle used when computing layout of `core::option::Option<<S as Mirror>::It>`
= note: ...which again requires computing layout of `core::option::Option<<S as Mirror>::It>`, completing the cycle
note: cycle used when checking deathness of variables in top-level module
--> $DIR/issue-26548-recursion-via-normalize.rs:7:1
|
LL | / trait Mirror {
LL | |
LL | | type It: ?Sized;
LL | | }
... |
LL | | let _s = S(None);
LL | | }
| |_^
= 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

error: aborting due to previous error
Expand Down

0 comments on commit ec12977

Please sign in to comment.