Skip to content

Commit 586bd1f

Browse files
committed
wip wip
1 parent 9ca1f3e commit 586bd1f

Some content is hidden

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

70 files changed

+405
-350
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,10 @@ pub(crate) fn linking_symbol_name_for_instance_in_crate<'tcx>(
595595

596596
let (conv, args) = instance
597597
.map(|i| {
598-
tcx.fn_abi_of_instance(ty::ParamEnv::reveal_all().and((i, ty::List::empty())))
599-
.unwrap_or_else(|_| bug!("fn_abi_of_instance({i:?}) failed"))
598+
tcx.fn_abi_of_instance(
599+
ty::TypingEnv::fully_monomorphized().as_query_input((i, ty::List::empty())),
600+
)
601+
.unwrap_or_else(|_| bug!("fn_abi_of_instance({i:?}) failed"))
600602
})
601603
.map(|fnabi| (fnabi.conv, &fnabi.args[..]))
602604
.unwrap_or((Conv::Rust, &[]));

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
467467
// regions must appear in the argument
468468
// listing.
469469
let main_ret_ty = cx.tcx().normalize_erasing_regions(
470-
ty::ParamEnv::reveal_all(),
470+
ty::TypingEnv::fully_monomorphized(),
471471
main_ret_ty.no_bound_vars().unwrap(),
472472
);
473473

@@ -495,8 +495,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
495495
let start_def_id = cx.tcx().require_lang_item(LangItem::Start, None);
496496
let start_instance = ty::Instance::expect_resolve(
497497
cx.tcx(),
498-
ty::TypingMode::PostAnalysis,
499-
ty::ParamEnv::reveal_all(),
498+
ty::TypingEnv::fully_monomorphized(),
500499
start_def_id,
501500
cx.tcx().mk_args(&[main_ret_ty.into()]),
502501
DUMMY_SP,

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathD
2020
use rustc_hir::{CoroutineDesugaring, CoroutineKind, CoroutineSource, Mutability};
2121
use rustc_middle::bug;
2222
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
23-
use rustc_middle::ty::{
24-
self, ExistentialProjection, GenericArgKind, GenericArgsRef, ParamEnv, Ty, TyCtxt,
25-
};
23+
use rustc_middle::ty::{self, ExistentialProjection, GenericArgKind, GenericArgsRef, Ty, TyCtxt};
2624
use rustc_target::abi::Integer;
2725
use smallvec::SmallVec;
2826

@@ -82,7 +80,7 @@ fn push_debuginfo_type_name<'tcx>(
8280
ty::Adt(def, args) => {
8381
// `layout_for_cpp_like_fallback` will be `Some` if we want to use the fallback encoding.
8482
let layout_for_cpp_like_fallback = if cpp_like_debuginfo && def.is_enum() {
85-
match tcx.layout_of(ParamEnv::reveal_all().and(t)) {
83+
match tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(t)) {
8684
Ok(layout) => {
8785
if !wants_c_like_enum_debuginfo(tcx, layout) {
8886
Some(layout)
@@ -248,8 +246,10 @@ fn push_debuginfo_type_name<'tcx>(
248246
};
249247

250248
if let Some(principal) = trait_data.principal() {
251-
let principal =
252-
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), principal);
249+
let principal = tcx.normalize_erasing_late_bound_regions(
250+
ty::TypingEnv::fully_monomorphized(),
251+
principal,
252+
);
253253
push_item_name(tcx, principal.def_id, qualified, output);
254254
let principal_has_generic_params =
255255
push_generic_params_internal(tcx, principal.args, output, visited);
@@ -350,8 +350,10 @@ fn push_debuginfo_type_name<'tcx>(
350350
return;
351351
}
352352

353-
let sig =
354-
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), t.fn_sig(tcx));
353+
let sig = tcx.normalize_erasing_late_bound_regions(
354+
ty::TypingEnv::fully_monomorphized(),
355+
t.fn_sig(tcx),
356+
);
355357

356358
if cpp_like_debuginfo {
357359
// Format as a C++ function pointer: return_type (*)(params...)
@@ -415,7 +417,8 @@ fn push_debuginfo_type_name<'tcx>(
415417
// In the case of cpp-like debuginfo, the name additionally gets wrapped inside of
416418
// an artificial `enum2$<>` type, as defined in msvc_enum_fallback().
417419
if cpp_like_debuginfo && t.is_coroutine() {
418-
let ty_and_layout = tcx.layout_of(ParamEnv::reveal_all().and(t)).unwrap();
420+
let ty_and_layout =
421+
tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(t)).unwrap();
419422
msvc_enum_fallback(
420423
tcx,
421424
ty_and_layout,
@@ -529,8 +532,8 @@ pub fn compute_debuginfo_vtable_name<'tcx>(
529532
}
530533

531534
if let Some(trait_ref) = trait_ref {
532-
let trait_ref =
533-
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), trait_ref);
535+
let trait_ref = tcx
536+
.normalize_erasing_late_bound_regions(ty::TypingEnv::fully_monomorphized(), trait_ref);
534537
push_item_name(tcx, trait_ref.def_id, true, &mut vtable_name);
535538
visited.clear();
536539
push_generic_params_internal(tcx, trait_ref.args, &mut vtable_name, &mut visited);
@@ -639,7 +642,7 @@ fn push_generic_params_internal<'tcx>(
639642
output: &mut String,
640643
visited: &mut FxHashSet<Ty<'tcx>>,
641644
) -> bool {
642-
assert_eq!(args, tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args));
645+
assert_eq!(args, tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), args));
643646
let mut args = args.non_erasable_generics().peekable();
644647
if args.peek().is_none() {
645648
return false;
@@ -678,14 +681,14 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
678681
// FIXME: directly extract the bits from a valtree instead of evaluating an
679682
// already evaluated `Const` in order to get the bits.
680683
let bits = ct
681-
.try_to_bits(tcx, ty::ParamEnv::reveal_all())
684+
.try_to_bits(tcx, ty::TypingEnv::fully_monomorphized())
682685
.expect("expected monomorphic const in codegen");
683686
let val = Integer::from_int_ty(&tcx, *ity).size().sign_extend(bits) as i128;
684687
write!(output, "{val}")
685688
}
686689
ty::Uint(_) => {
687690
let val = ct
688-
.try_to_bits(tcx, ty::ParamEnv::reveal_all())
691+
.try_to_bits(tcx, ty::TypingEnv::fully_monomorphized())
689692
.expect("expected monomorphic const in codegen");
690693
write!(output, "{val}")
691694
}

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
766766

767767
let do_panic = !bx
768768
.tcx()
769-
.check_validity_requirement((requirement, bx.param_env().and(ty)))
769+
.check_validity_requirement((requirement, bx.typing_env().as_query_input(ty)))
770770
.expect("expect to have layout during codegen");
771771

772772
let layout = bx.layout_of(ty);
@@ -839,8 +839,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
839839
Some(
840840
ty::Instance::expect_resolve(
841841
bx.tcx(),
842-
ty::TypingMode::PostAnalysis,
843-
ty::ParamEnv::reveal_all(),
842+
ty::TypingEnv::fully_monomorphized(),
844843
def_id,
845844
args,
846845
fn_span,
@@ -1181,8 +1180,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11811180
if let ty::FnDef(def_id, args) = *const_.ty().kind() {
11821181
let instance = ty::Instance::resolve_for_fn_ptr(
11831182
bx.tcx(),
1184-
ty::TypingMode::PostAnalysis,
1185-
ty::ParamEnv::reveal_all(),
1183+
ty::TypingEnv::fully_monomorphized(),
11861184
def_id,
11871185
args,
11881186
)

compiler/rustc_codegen_ssa/src/mir/constant.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2424
// `MirUsedCollector` visited all required_consts before codegen began, so if we got here
2525
// there can be no more constants that fail to evaluate.
2626
self.monomorphize(constant.const_)
27-
.eval(
28-
self.cx.tcx(),
29-
ty::TypingMode::PostAnalysis,
30-
ty::ParamEnv::reveal_all(),
31-
constant.span,
32-
)
27+
.eval(self.cx.tcx(), ty::TypingEnv::fully_monomorphized(), constant.span)
3328
.expect("erroneous constant missed by mono item collection")
3429
}
3530

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5959
llresult: Bx::Value,
6060
span: Span,
6161
) -> Result<(), ty::Instance<'tcx>> {
62-
let callee_ty = instance.ty(bx.tcx(), ty::ParamEnv::reveal_all());
62+
let callee_ty = instance.ty(bx.tcx(), ty::TypingEnv::fully_monomorphized());
6363

6464
let ty::FnDef(def_id, fn_args) = *callee_ty.kind() else {
6565
bug!("expected fn item type, found {}", callee_ty);
6666
};
6767

6868
let sig = callee_ty.fn_sig(bx.tcx());
69-
let sig = bx.tcx().normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig);
69+
let sig = bx
70+
.tcx()
71+
.normalize_erasing_late_bound_regions(ty::TypingEnv::fully_monomorphized(), sig);
7072
let arg_tys = sig.inputs();
7173
let ret_ty = sig.output();
7274
let name = bx.tcx().item_name(def_id);

compiler/rustc_codegen_ssa/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
124124
debug!("monomorphize: self.instance={:?}", self.instance);
125125
self.instance.instantiate_mir_and_normalize_erasing_regions(
126126
self.cx.tcx(),
127-
ty::ParamEnv::reveal_all(),
127+
ty::TypingEnv::fully_monomorphized(),
128128
ty::EarlyBinder::bind(value),
129129
)
130130
}

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
474474
ty::FnDef(def_id, args) => {
475475
let instance = ty::Instance::resolve_for_fn_ptr(
476476
bx.tcx(),
477-
ty::TypingMode::PostAnalysis,
478-
ty::ParamEnv::reveal_all(),
477+
ty::TypingEnv::fully_monomorphized(),
479478
def_id,
480479
args,
481480
)
@@ -710,7 +709,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
710709
mir::NullOp::OffsetOf(fields) => {
711710
let val = bx
712711
.tcx()
713-
.offset_of_subfield(bx.param_env(), layout, fields.iter())
712+
.offset_of_subfield(bx.typing_env(), layout, fields.iter())
714713
.bytes();
715714
bx.cx().const_usize(val)
716715
}

compiler/rustc_codegen_ssa/src/traits/type_.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub trait DerivedTypeCodegenMethods<'tcx>:
7474
}
7575

7676
fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool {
77-
ty.needs_drop(self.tcx(), ty::ParamEnv::reveal_all())
77+
ty.needs_drop(self.tcx(), ty::TypingEnv::fully_monomorphized())
7878
}
7979

8080
fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
@@ -86,12 +86,12 @@ pub trait DerivedTypeCodegenMethods<'tcx>:
8686
}
8787

8888
fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
89-
let param_env = ty::ParamEnv::reveal_all();
90-
if ty.is_sized(self.tcx(), param_env) {
89+
let typing_env = ty::TypingEnv::fully_monomorphized();
90+
if ty.is_sized(self.tcx(), typing_env.param_env) {
9191
return false;
9292
}
9393

94-
let tail = self.tcx().struct_tail_for_codegen(ty, param_env);
94+
let tail = self.tcx().struct_tail_for_codegen(ty, typing_env);
9595
match tail.kind() {
9696
ty::Foreign(..) => false,
9797
ty::Str | ty::Slice(..) | ty::Dynamic(..) => true,

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,9 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
625625
// This skips the check below that ensures we only call `const fn`.
626626
is_trait = true;
627627

628-
if let Ok(Some(instance)) = Instance::try_resolve(
629-
tcx,
630-
infcx.typing_mode(param_env),
631-
param_env,
632-
callee,
633-
fn_args,
634-
) && let InstanceKind::Item(def) = instance.def
628+
if let Ok(Some(instance)) =
629+
Instance::try_resolve(tcx, infcx.typing_env(param_env), callee, fn_args)
630+
&& let InstanceKind::Item(def) = instance.def
635631
{
636632
// Resolve a trait method call to its concrete implementation, which may be in a
637633
// `const` trait impl. This is only used for the const stability check below, since

0 commit comments

Comments
 (0)