Skip to content

Commit 17410a7

Browse files
committed
use TypingEnv when no infcx is available
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
1 parent 21056f8 commit 17410a7

File tree

7 files changed

+32
-28
lines changed

7 files changed

+32
-28
lines changed

src/builder.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ 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
};
29-
use rustc_middle::ty::{Instance, ParamEnv, Ty, TyCtxt};
29+
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
3030
use rustc_span::Span;
3131
use rustc_span::def_id::DefId;
3232
use rustc_target::abi::call::FnAbi;
@@ -2319,9 +2319,9 @@ impl<'a, 'gcc, 'tcx> StaticBuilderMethods for Builder<'a, 'gcc, 'tcx> {
23192319
}
23202320
}
23212321

2322-
impl<'tcx> HasParamEnv<'tcx> for Builder<'_, '_, 'tcx> {
2323-
fn param_env(&self) -> ParamEnv<'tcx> {
2324-
self.cx.param_env()
2322+
impl<'tcx> HasTypingEnv<'tcx> for Builder<'_, '_, 'tcx> {
2323+
fn typing_env(&self) -> ty::TypingEnv<'tcx> {
2324+
self.cx.typing_env()
23252325
}
23262326
}
23272327

src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
215215
let gcc_type = if nested {
216216
self.type_i8()
217217
} else {
218-
let ty = instance.ty(self.tcx, ty::ParamEnv::reveal_all());
218+
let ty = instance.ty(self.tcx, ty::TypingEnv::fully_monomorphized());
219219
self.layout_of(ty).gcc_type(self)
220220
};
221221

src/context.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ 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
};
17-
use rustc_middle::ty::{self, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt};
17+
use rustc_middle::ty::{self, Instance, PolyExistentialTraitRef, Ty, TyCtxt};
1818
use rustc_session::Session;
1919
use rustc_span::source_map::respan;
2020
use rustc_span::{DUMMY_SP, Span};
@@ -144,7 +144,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
144144
supports_f128_type: bool,
145145
) -> Self {
146146
let create_type = |ctype, rust_type| {
147-
let layout = tcx.layout_of(ParamEnv::reveal_all().and(rust_type)).unwrap();
147+
let layout = tcx
148+
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(rust_type))
149+
.unwrap();
148150
let align = layout.align.abi.bytes();
149151
#[cfg(feature = "master")]
150152
{
@@ -459,7 +461,7 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
459461
Some(def_id) if !wants_msvc_seh(self.sess()) => {
460462
let instance = ty::Instance::expect_resolve(
461463
tcx,
462-
ty::ParamEnv::reveal_all(),
464+
self.typing_env(),
463465
def_id,
464466
ty::List::empty(),
465467
DUMMY_SP,
@@ -583,9 +585,9 @@ impl<'gcc, 'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
583585
}
584586
}
585587

586-
impl<'tcx, 'gcc> HasParamEnv<'tcx> for CodegenCx<'gcc, 'tcx> {
587-
fn param_env(&self) -> ParamEnv<'tcx> {
588-
ParamEnv::reveal_all()
588+
impl<'tcx, 'gcc> HasTypingEnv<'tcx> for CodegenCx<'gcc, 'tcx> {
589+
fn typing_env(&self) -> ty::TypingEnv<'tcx> {
590+
ty::TypingEnv::fully_monomorphized()
589591
}
590592
}
591593

src/int.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use gccjit::{BinaryOp, ComparisonOp, FunctionType, Location, RValue, ToRValue, Type, UnaryOp};
66
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
77
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeCodegenMethods, BuilderMethods, OverflowOp};
8-
use rustc_middle::ty::{ParamEnv, Ty};
8+
use rustc_middle::ty::{self, Ty};
99
use rustc_target::abi::Endian;
1010
use rustc_target::abi::call::{ArgAbi, ArgAttributes, Conv, FnAbi, PassMode};
1111
use rustc_target::spec;
@@ -380,7 +380,10 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
380380
let overflow_field = self.context.new_field(self.location, self.bool_type, "overflow");
381381

382382
let ret_ty = Ty::new_tup(self.tcx, &[self.tcx.types.i128, self.tcx.types.bool]);
383-
let layout = self.tcx.layout_of(ParamEnv::reveal_all().and(ret_ty)).unwrap();
383+
let layout = self
384+
.tcx
385+
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ret_ty))
386+
.unwrap();
384387

385388
let arg_abi = ArgAbi { layout, mode: PassMode::Direct(ArgAttributes::new()) };
386389
let mut fn_abi = FnAbi {

src/intrinsic/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, MiscCodegenMethods};
2121
use rustc_middle::bug;
2222
use rustc_middle::ty::layout::LayoutOf;
2323
#[cfg(feature = "master")]
24-
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt};
24+
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv};
2525
use rustc_middle::ty::{self, Instance, Ty};
2626
use rustc_span::{Span, Symbol, sym};
2727
use rustc_target::abi::HasDataLayout;
@@ -107,15 +107,15 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
107107
span: Span,
108108
) -> Result<(), Instance<'tcx>> {
109109
let tcx = self.tcx;
110-
let callee_ty = instance.ty(tcx, ty::ParamEnv::reveal_all());
110+
let callee_ty = instance.ty(tcx, self.typing_env());
111111

112112
let (def_id, fn_args) = match *callee_ty.kind() {
113113
ty::FnDef(def_id, fn_args) => (def_id, fn_args),
114114
_ => bug!("expected fn item type, found {}", callee_ty),
115115
};
116116

117117
let sig = callee_ty.fn_sig(tcx);
118-
let sig = tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), sig);
118+
let sig = tcx.normalize_erasing_late_bound_regions(self.typing_env(), sig);
119119
let arg_tys = sig.inputs();
120120
let ret_ty = sig.output();
121121
let name = tcx.item_name(def_id);

src/intrinsic/simd.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
5555
}
5656

5757
let tcx = bx.tcx();
58-
let sig =
59-
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), callee_ty.fn_sig(tcx));
58+
let sig = tcx.normalize_erasing_late_bound_regions(
59+
ty::TypingEnv::fully_monomorphized(),
60+
callee_ty.fn_sig(tcx),
61+
);
6062
let arg_tys = sig.inputs();
6163

6264
if name == sym::simd_select_bitmask {
@@ -478,7 +480,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
478480
match *in_elem.kind() {
479481
ty::RawPtr(p_ty, _) => {
480482
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
481-
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
483+
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
482484
});
483485
require!(metadata.is_unit(), InvalidMonomorphization::CastWidePointer {
484486
span,
@@ -493,7 +495,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
493495
match *out_elem.kind() {
494496
ty::RawPtr(p_ty, _) => {
495497
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
496-
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
498+
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
497499
});
498500
require!(metadata.is_unit(), InvalidMonomorphization::CastWidePointer {
499501
span,

src/mono_item.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE};
66
use rustc_middle::bug;
77
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
88
use rustc_middle::mir::mono::{Linkage, Visibility};
9-
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf};
9+
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv, LayoutOf};
1010
use rustc_middle::ty::{self, Instance, TypeVisitableExt};
1111

1212
use crate::context::CodegenCx;
@@ -27,11 +27,8 @@ impl<'gcc, 'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
2727
let DefKind::Static { nested, .. } = self.tcx.def_kind(def_id) else { bug!() };
2828
// Nested statics do not have a type, so pick a dummy type and let `codegen_static` figure out
2929
// the gcc type from the actual evaluated initializer.
30-
let ty = if nested {
31-
self.tcx.types.unit
32-
} else {
33-
instance.ty(self.tcx, ty::ParamEnv::reveal_all())
34-
};
30+
let ty =
31+
if nested { self.tcx.types.unit } else { instance.ty(self.tcx, self.typing_env()) };
3532
let gcc_type = self.layout_of(ty).gcc_type(self);
3633

3734
let is_tls = attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);

0 commit comments

Comments
 (0)