Skip to content

Commit abf2358

Browse files
committed
oh lord
1 parent 5eda8ed commit abf2358

File tree

66 files changed

+651
-600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+651
-600
lines changed

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
376376
let instance = if let ty::FnDef(def_id, fn_args) = *func.layout().ty.kind() {
377377
let instance = ty::Instance::expect_resolve(
378378
fx.tcx,
379-
ty::TypingMode::PostAnalysis,
380-
ty::ParamEnv::reveal_all(),
379+
ty::TypingEnv::fully_monomorphized(),
381380
def_id,
382381
fn_args,
383382
source_info.span,

compiler/rustc_codegen_cranelift/src/unsize.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ pub(crate) fn unsized_info<'tcx>(
2222
target: Ty<'tcx>,
2323
old_info: Option<Value>,
2424
) -> Value {
25-
let (source, target) =
26-
fx.tcx.struct_lockstep_tails_for_codegen(source, target, ParamEnv::reveal_all());
25+
let (source, target) = fx.tcx.struct_lockstep_tails_for_codegen(
26+
source,
27+
target,
28+
ty::TypingEnv::fully_monomorphized(),
29+
);
2730
match (&source.kind(), &target.kind()) {
2831
(&ty::Array(_, len), &ty::Slice(_)) => fx.bcx.ins().iconst(
2932
fx.pointer_type,

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_data_structures::fx::FxHashSet;
2424
use rustc_middle::bug;
2525
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
2626
use rustc_middle::ty::layout::{
27-
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, LayoutOfHelpers,
27+
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError, LayoutOfHelpers,
2828
};
2929
use rustc_middle::ty::{Instance, ParamEnv, Ty, TyCtxt};
3030
use rustc_span::Span;
@@ -2319,7 +2319,7 @@ impl<'a, 'gcc, 'tcx> StaticBuilderMethods for Builder<'a, 'gcc, 'tcx> {
23192319
}
23202320
}
23212321

2322-
impl<'tcx> HasParamEnv<'tcx> for Builder<'_, '_, 'tcx> {
2322+
impl<'tcx> HasTypingEnv<'tcx> for Builder<'_, '_, 'tcx> {
23232323
fn param_env(&self) -> ParamEnv<'tcx> {
23242324
self.cx.param_env()
23252325
}

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1111
use rustc_middle::mir::mono::CodegenUnit;
1212
use rustc_middle::span_bug;
1313
use rustc_middle::ty::layout::{
14-
FnAbiError, FnAbiOf, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError,
14+
FnAbiError, FnAbiOf, FnAbiOfHelpers, FnAbiRequest, HasTyCtxt, HasTypingEnv, LayoutError,
1515
LayoutOfHelpers,
1616
};
1717
use rustc_middle::ty::{self, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt};
@@ -584,7 +584,7 @@ impl<'gcc, 'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
584584
}
585585
}
586586

587-
impl<'tcx, 'gcc> HasParamEnv<'tcx> for CodegenCx<'gcc, 'tcx> {
587+
impl<'tcx, 'gcc> HasTypingEnv<'tcx> for CodegenCx<'gcc, 'tcx> {
588588
fn param_env(&self) -> ParamEnv<'tcx> {
589589
ParamEnv::reveal_all()
590590
}

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_data_structures::small_c_str::SmallCStr;
1414
use rustc_hir::def_id::DefId;
1515
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
1616
use rustc_middle::ty::layout::{
17-
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, LayoutError, LayoutOfHelpers,
17+
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTypingEnv, LayoutError, LayoutOfHelpers,
1818
TyAndLayout,
1919
};
2020
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_hir::def_id::DefId;
1313
use rustc_middle::middle::codegen_fn_attrs::PatchableFunctionEntry;
1414
use rustc_middle::mir::mono::CodegenUnit;
1515
use rustc_middle::ty::layout::{
16-
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, LayoutError, LayoutOfHelpers,
16+
FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTypingEnv, LayoutError, LayoutOfHelpers,
1717
};
1818
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
1919
use rustc_middle::{bug, span_bug};
@@ -1147,7 +1147,7 @@ impl<'tcx> ty::layout::HasTyCtxt<'tcx> for CodegenCx<'_, 'tcx> {
11471147
}
11481148
}
11491149

1150-
impl<'tcx, 'll> HasParamEnv<'tcx> for CodegenCx<'ll, 'tcx> {
1150+
impl<'tcx, 'll> HasTypingEnv<'tcx> for CodegenCx<'ll, 'tcx> {
11511151
fn param_env(&self) -> ty::ParamEnv<'tcx> {
11521152
ty::ParamEnv::reveal_all()
11531153
}

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ fn make_mir_scope<'ll, 'tcx>(
9494
// if this is moved to `rustc_codegen_ssa::mir::debuginfo`.
9595
let callee = cx.tcx.instantiate_and_normalize_erasing_regions(
9696
instance.args,
97-
ty::ParamEnv::reveal_all(),
97+
ty::TypingEnv::fully_monomorphized(),
9898
ty::EarlyBinder::bind(callee),
9999
);
100100
debug_context.inlined_function_scopes.entry(callee).or_insert_with(|| {

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
525525
if cx.tcx.trait_id_of_impl(impl_def_id).is_none() {
526526
let impl_self_ty = cx.tcx.instantiate_and_normalize_erasing_regions(
527527
instance.args,
528-
ty::ParamEnv::reveal_all(),
528+
ty::TypingEnv::fully_monomorphized(),
529529
cx.tcx.type_of(impl_def_id),
530530
);
531531

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
165165
) -> Bx::Value {
166166
let cx = bx.cx();
167167
let (source, target) =
168-
cx.tcx().struct_lockstep_tails_for_codegen(source, target, bx.param_env());
168+
cx.tcx().struct_lockstep_tails_for_codegen(source, target, bx.typing_env());
169169
match (source.kind(), target.kind()) {
170170
(&ty::Array(_, len), &ty::Slice(_)) => cx.const_usize(
171171
len.try_to_target_usize(cx.tcx()).expect("expected monomorphic const in codegen"),

compiler/rustc_codegen_ssa/src/mir/constant.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
6363
};
6464
let uv = self.monomorphize(uv);
6565
self.cx.tcx().const_eval_resolve_for_typeck(
66-
ty::TypingMode::PostAnalysis,
67-
ty::ParamEnv::reveal_all(),
66+
ty::TypingEnv::fully_monomorphized(),
6867
uv,
6968
constant.span,
7069
)

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
728728

729729
mir::Rvalue::ThreadLocalRef(def_id) => {
730730
assert!(bx.cx().tcx().is_static(def_id));
731-
let layout = bx.layout_of(bx.cx().tcx().static_ptr_ty(def_id));
731+
let layout = bx.layout_of(
732+
bx.cx().tcx().static_ptr_ty(def_id, ty::TypingEnv::fully_monomorphized()),
733+
);
732734
let static_ = if !def_id.is_local() && bx.cx().tcx().needs_thread_local_shim(def_id)
733735
{
734736
let instance = ty::Instance {

compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
385385
) -> InterpResult<'tcx> {
386386
// A<Struct> -> A<Trait> conversion
387387
let (src_pointee_ty, dest_pointee_ty) =
388-
self.tcx.struct_lockstep_tails_for_codegen(source_ty, cast_ty, self.param_env);
388+
self.tcx.struct_lockstep_tails_for_codegen(source_ty, cast_ty, self.typing_env());
389389

390390
match (src_pointee_ty.kind(), dest_pointee_ty.kind()) {
391391
(&ty::Array(_, length), &ty::Slice(_)) => {

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::ty::layout::{
1010
self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, TyAndLayout,
1111
};
1212
use rustc_middle::ty::{
13-
self, GenericArgsRef, ParamEnv, Ty, TyCtxt, TypeFoldable, TypingMode, Variance,
13+
self, GenericArgsRef, ParamEnv, Ty, TyCtxt, TypeFoldable, TypingEnv, TypingMode, Variance,
1414
};
1515
use rustc_middle::{mir, span_bug};
1616
use rustc_session::Limit;
@@ -116,16 +116,15 @@ impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> {
116116
/// This test should be symmetric, as it is primarily about layout compatibility.
117117
pub(super) fn mir_assign_valid_types<'tcx>(
118118
tcx: TyCtxt<'tcx>,
119-
typing_mode: TypingMode<'tcx>,
120-
param_env: ParamEnv<'tcx>,
119+
typing_env: TypingEnv<'tcx>,
121120
src: TyAndLayout<'tcx>,
122121
dest: TyAndLayout<'tcx>,
123122
) -> bool {
124123
// Type-changing assignments can happen when subtyping is used. While
125124
// all normal lifetimes are erased, higher-ranked types with their
126125
// late-bound lifetimes are still around and can lead to type
127126
// differences.
128-
if util::relate_types(tcx, typing_mode, param_env, Variance::Covariant, src.ty, dest.ty) {
127+
if util::relate_types(tcx, typing_env, Variance::Covariant, src.ty, dest.ty) {
129128
// Make sure the layout is equal, too -- just to be safe. Miri really
130129
// needs layout equality. For performance reason we skip this check when
131130
// the types are equal. Equal types *can* have different layouts when
@@ -145,8 +144,7 @@ pub(super) fn mir_assign_valid_types<'tcx>(
145144
#[cfg_attr(not(debug_assertions), inline(always))]
146145
pub(super) fn from_known_layout<'tcx>(
147146
tcx: TyCtxtAt<'tcx>,
148-
typing_mode: TypingMode<'tcx>,
149-
param_env: ParamEnv<'tcx>,
147+
typing_env: TypingEnv<'tcx>,
150148
known_layout: Option<TyAndLayout<'tcx>>,
151149
compute: impl FnOnce() -> InterpResult<'tcx, TyAndLayout<'tcx>>,
152150
) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
@@ -155,13 +153,7 @@ pub(super) fn from_known_layout<'tcx>(
155153
Some(known_layout) => {
156154
if cfg!(debug_assertions) {
157155
let check_layout = compute()?;
158-
if !mir_assign_valid_types(
159-
tcx.tcx,
160-
typing_mode,
161-
param_env,
162-
check_layout,
163-
known_layout,
164-
) {
156+
if !mir_assign_valid_types(tcx.tcx, typing_env, check_layout, known_layout) {
165157
span_bug!(
166158
tcx.span,
167159
"expected type differs from actual type.\nexpected: {}\nactual: {}",
@@ -216,6 +208,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
216208
TypingMode::PostAnalysis
217209
}
218210

211+
pub fn typing_env(&self) -> TypingEnv<'tcx> {
212+
TypingEnv { typing_mode: self.typing_mode(), param_env: self.param_env }
213+
}
214+
219215
/// Returns the span of the currently executed statement/terminator.
220216
/// This is the span typically used for error reporting.
221217
#[inline(always)]

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'tcx, Prov: Provenance> ImmTy<'tcx, Prov> {
341341

342342
#[inline]
343343
#[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
344-
pub fn to_pair(self, cx: &(impl HasTyCtxt<'tcx> + HasParamEnv<'tcx>)) -> (Self, Self) {
344+
pub fn to_pair(self, cx: &(impl HasTyCtxt<'tcx> + HasTypingEnv<'tcx>)) -> (Self, Self) {
345345
let layout = self.layout;
346346
let (val0, val1) = self.to_scalar_pair();
347347
(

compiler/rustc_const_eval/src/util/compare_types.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ use rustc_trait_selection::traits::ObligationCtxt;
1111
/// Returns whether `src` is a subtype of `dest`, i.e. `src <: dest`.
1212
pub fn sub_types<'tcx>(
1313
tcx: TyCtxt<'tcx>,
14-
typing_mode: TypingMode<'tcx>,
15-
param_env: ParamEnv<'tcx>,
14+
typing_env: TypingEnv<'tcx>,
1615
src: Ty<'tcx>,
1716
dest: Ty<'tcx>,
1817
) -> bool {
19-
relate_types(tcx, typing_mode, param_env, Variance::Covariant, src, dest)
18+
relate_types(tcx, typing_env, Variance::Covariant, src, dest)
2019
}
2120

2221
/// Returns whether `src` is a subtype of `dest`, i.e. `src <: dest`.
@@ -26,8 +25,7 @@ pub fn sub_types<'tcx>(
2625
/// because we want to check for type equality.
2726
pub fn relate_types<'tcx>(
2827
tcx: TyCtxt<'tcx>,
29-
typing_mode: TypingMode<'tcx>,
30-
param_env: ParamEnv<'tcx>,
28+
TypingEnv { typing_env }: TypingEnv<'tcx>,
3129
variance: Variance,
3230
src: Ty<'tcx>,
3331
dest: Ty<'tcx>,

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
3939
use rustc_middle::ty::{
4040
self, ConstVid, FloatVid, GenericArg, GenericArgKind, GenericArgs, GenericArgsRef,
4141
GenericParamDefKind, InferConst, IntVid, PseudoCanonicalInput, Ty, TyCtxt, TyVid,
42-
TypeVisitable, TypingMode,
42+
TypeVisitable, TypingEnv, TypingMode,
4343
};
4444
use rustc_middle::{bug, span_bug};
4545
use rustc_span::Span;
@@ -567,6 +567,13 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
567567
(infcx, value, args)
568568
}
569569

570+
pub fn build_with_typing_env<T>(
571+
mut self,
572+
TypingEnv { typing_mode, param_env }: TypingEnv<'tcx>,
573+
) -> (InferCtxt<'tcx>, ty::ParamEnv<'tcx>) {
574+
(self.build(typing_mode), param_env)
575+
}
576+
570577
pub fn build(&mut self, typing_mode: TypingMode<'tcx>) -> InferCtxt<'tcx> {
571578
let InferCtxtBuilder { tcx, considering_regions, skip_leak_check, next_trait_solver } =
572579
*self;
@@ -1295,7 +1302,8 @@ impl<'tcx> InferCtxt<'tcx> {
12951302
debug_assert!(!value.has_placeholders());
12961303
debug_assert!(!param_env.has_infer());
12971304
debug_assert!(!param_env.has_placeholders());
1298-
PseudoCanonicalInput { typing_mode: self.typing_mode(param_env), param_env, value }
1305+
let typing_env = ty::TypingEnv { typing_mode: self.typing_mode(param_env), param_env };
1306+
PseudoCanonicalInput { typing_env, value }
12991307
}
13001308

13011309
pub fn try_const_eval_resolve(
@@ -1367,9 +1375,10 @@ impl<'tcx> InferCtxt<'tcx> {
13671375
let param_env = tcx.erase_regions(param_env);
13681376
let args = tcx.erase_regions(args);
13691377
let unevaluated = ty::UnevaluatedConst { def: unevaluated.def, args };
1378+
let typing_env = TypingEnv { typing_mode: self.typing_mode(param_env), param_env };
13701379
// The return value is the evaluated value which doesn't contain any reference to inference
13711380
// variables, thus we don't need to instantiate back the original values.
1372-
tcx.const_eval_resolve_for_typeck(self.typing_mode(param_env), param_env, unevaluated, span)
1381+
tcx.const_eval_resolve_for_typeck(typing_env, unevaluated, span)
13731382
}
13741383

13751384
/// The returned function is used in a fast path. If it returns `true` the variable is

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_ast::CRATE_NODE_ID;
55
use rustc_attr as attr;
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_middle::query::LocalCrate;
8-
use rustc_middle::ty::{List, ParamEnv, ParamEnvAnd, Ty, TyCtxt};
8+
use rustc_middle::ty::{self, List, Ty, TyCtxt};
99
use rustc_session::Session;
1010
use rustc_session::config::CrateType;
1111
use rustc_session::cstore::{
@@ -613,7 +613,7 @@ impl<'tcx> Collector<'tcx> {
613613
.map(|ty| {
614614
let layout = self
615615
.tcx
616-
.layout_of(ParamEnvAnd { param_env: ParamEnv::empty(), value: ty })
616+
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty))
617617
.expect("layout")
618618
.layout;
619619
// In both stdcall and fastcall, we always round up the argument size to the

0 commit comments

Comments
 (0)