Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_abi::{CanonAbi, ExternAbi, X86Call};
use rustc_codegen_ssa::base::is_call_from_compiler_builtins_to_upstream_monomorphization;
use rustc_codegen_ssa::diagnostics::CompilerBuiltinsCannotCall;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::ty::layout::FnAbiOf;
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv as _};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{ShimKind, TypeVisitableExt};
use rustc_session::Session;
Expand Down Expand Up @@ -441,7 +441,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
let instance = if let ty::FnDef(def_id, fn_args) = *func.layout().ty.kind() {
let instance = ty::Instance::expect_resolve(
fx.tcx,
ty::TypingEnv::fully_monomorphized(),
fx.typing_env(),
def_id,
fn_args.no_bound_vars().unwrap(),
source_info.span,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
let func_ref = fx.get_function_ref(
Instance::resolve_for_fn_ptr(
fx.tcx,
ty::TypingEnv::fully_monomorphized(),
fx.typing_env(),
def_id,
args.no_bound_vars().unwrap(),
)
Expand Down Expand Up @@ -771,8 +771,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:

fn is_wide_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
ty.builtin_deref(true).is_some_and(|pointee_ty| {
fx.tcx
.type_has_metadata(pointee_ty, ty::TypingEnv::fully_monomorphized())
fx.tcx.type_has_metadata(pointee_ty, fx.typing_env())
})
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_cranelift/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use rustc_abi::{Float, Integer, Primitive};
use rustc_index::IndexVec;
use rustc_middle::ty::TypeFoldable;
use rustc_middle::ty::layout::{
self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers,
codegen_handle_fn_abi_err,
self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasTypingEnv as _, LayoutError,
LayoutOfHelpers, codegen_handle_fn_abi_err,
};
use rustc_span::Symbol;
use rustc_target::callconv::FnAbi;
Expand Down Expand Up @@ -350,7 +350,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
{
self.instance.instantiate_mir_and_normalize_erasing_regions(
self.tcx,
ty::TypingEnv::fully_monomorphized(),
self.typing_env(),
ty::EarlyBinder::bind(self.tcx, value),
)
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_cranelift/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::interpret::{
AllocId, GlobalAlloc, PointerArithmetic, Scalar, read_target_uint,
};
use rustc_middle::ty::layout::HasTypingEnv as _;
use rustc_middle::ty::{ExistentialTraitRef, ScalarInt};

use crate::prelude::*;
Expand Down Expand Up @@ -81,7 +82,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
let cv = fx.monomorphize(constant.const_);
// This cannot fail because we checked all required_consts in advance.
let val = cv
.eval(fx.tcx, ty::TypingEnv::fully_monomorphized(), constant.span)
.eval(fx.tcx, fx.typing_env(), constant.span)
.expect("erroneous constant missed by mono item collection");
(val, cv.ty())
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_cranelift/src/inline_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_abi::CanonAbi;
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_attr_ir::lang_items::LangItem;
use rustc_middle::mir::interpret::{GlobalAlloc, PointerArithmetic, Scalar as ConstScalar};
use rustc_middle::ty::layout::FnAbiOf;
use rustc_middle::ty::layout::{FnAbiOf, HasTypingEnv as _};
use rustc_span::sym;
use rustc_target::asm::*;
use rustc_target::spec::Arch;
Expand Down Expand Up @@ -175,7 +175,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
if let ty::FnDef(def_id, args) = *const_.ty().kind() {
let instance = ty::Instance::resolve_for_fn_ptr(
fx.tcx,
ty::TypingEnv::fully_monomorphized(),
fx.typing_env(),
def_id,
args.no_bound_vars().unwrap(),
)
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use cranelift_codegen::ir::{
};
use rustc_middle::ty;
use rustc_middle::ty::GenericArgsRef;
use rustc_middle::ty::layout::ValidityRequirement;
use rustc_middle::ty::layout::{HasTypingEnv as _, ValidityRequirement};
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
use rustc_span::{Spanned, Symbol, sym};
use rustc_target::spec::PanicStrategy;
Expand Down Expand Up @@ -729,10 +729,7 @@ fn codegen_regular_intrinsic_call<'tcx>(
if let Some(requirement) = requirement {
let do_panic = !fx
.tcx
.check_validity_requirement((
requirement,
ty::TypingEnv::fully_monomorphized().as_query_input(ty),
))
.check_validity_requirement((requirement, fx.typing_env().as_query_input(ty)))
.expect("expect to have layout during codegen");

if do_panic {
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_codegen_cranelift/src/num.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Various operations on integer and floating-point numbers

use rustc_middle::ty::layout::HasTypingEnv as _;

use crate::codegen_f16_f128;
use crate::prelude::*;

Expand Down Expand Up @@ -437,7 +439,7 @@ fn codegen_ptr_binop<'tcx>(
.layout()
.ty
.builtin_deref(true)
.map(|ty| !fx.tcx.type_has_metadata(ty, ty::TypingEnv::fully_monomorphized()))
.map(|ty| !fx.tcx.type_has_metadata(ty, fx.typing_env()))
.unwrap_or(true);

if is_thin_ptr {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_cranelift/src/value_and_place.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ impl<'tcx> CPlace<'tcx> {
};

let (field_ptr, field_layout) = codegen_field(fx, base, extra, layout, field);
if fx.tcx.type_has_metadata(field_layout.ty, ty::TypingEnv::fully_monomorphized()) {
if fx.tcx.type_has_metadata(field_layout.ty, fx.typing_env()) {
CPlace::for_ptr_with_extra(field_ptr, extra.unwrap(), field_layout)
} else {
CPlace::for_ptr(field_ptr, field_layout)
Expand Down Expand Up @@ -808,7 +808,7 @@ impl<'tcx> CPlace<'tcx> {

pub(crate) fn place_deref(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> CPlace<'tcx> {
let inner_layout = fx.layout_of(self.layout().ty.builtin_deref(true).unwrap());
if fx.tcx.type_has_metadata(inner_layout.ty, ty::TypingEnv::fully_monomorphized()) {
if fx.tcx.type_has_metadata(inner_layout.ty, fx.typing_env()) {
let (addr, extra) = self.to_cvalue(fx).load_scalar_pair(fx);
CPlace::for_ptr_with_extra(Pointer::new(addr), extra, inner_layout)
} else {
Expand All @@ -821,7 +821,7 @@ impl<'tcx> CPlace<'tcx> {
fx: &mut FunctionCx<'_, '_, 'tcx>,
layout: TyAndLayout<'tcx>,
) -> CValue<'tcx> {
if fx.tcx.type_has_metadata(self.layout().ty, ty::TypingEnv::fully_monomorphized()) {
if fx.tcx.type_has_metadata(self.layout().ty, fx.typing_env()) {
let (ptr, extra) = self.to_ptr_unsized();
CValue::by_val_pair(ptr.get_addr(fx), extra, layout)
} else {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_gcc/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use rustc_middle::mir::interpret::{
self, ConstAllocation, CtfeProvenance, ErrorHandled, Scalar as InterpScalar, read_target_uint,
};
use rustc_middle::mono::MonoItem;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self, Instance};
use rustc_middle::ty::Instance;
use rustc_middle::ty::layout::{HasTypingEnv as _, LayoutOf};
use rustc_span::def_id::DefId;
use rustc_span::{bug, span_bug};

Expand Down Expand Up @@ -251,7 +251,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
let gcc_type = if nested {
self.type_i8()
} else {
let ty = instance.ty(self.tcx, ty::TypingEnv::fully_monomorphized());
let ty = instance.ty(self.tcx, self.typing_env());
self.layout_of(ty).gcc_type(self)
};

Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_codegen_gcc/src/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use gccjit::{
use rustc_abi::{CanonAbi, Endian, ExternAbi};
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeCodegenMethods, BuilderMethods, OverflowOp};
use rustc_middle::ty::{self, Ty};
use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::HasTypingEnv as _;
use rustc_target::callconv::{ArgAbi, ArgAttributes, FnAbi, PassMode};
use rustc_type_ir::{Interner, TyKind};

Expand Down Expand Up @@ -387,10 +388,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
128 => self.tcx.types.i128,
_ => unreachable!("unexpected integer size"),
};
let layout = self
.tcx
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(res_ty))
.unwrap();
let layout = self.tcx.layout_of(self.cx.typing_env().as_query_input(res_ty)).unwrap();

let arg_abi = ArgAbi { layout, mode: PassMode::Direct(ArgAttributes::new()) };
let mut fn_abi = FnAbi {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_gcc/src/intrinsic/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, BuilderMethods, LayoutTy
use rustc_hir as hir;
use rustc_middle::mir::BinOp;
use rustc_middle::ty::consts::ConstExt;
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv as _, LayoutOf};
use rustc_middle::ty::{self, Ty};
use rustc_span::{ErrorGuaranteed, Span, Symbol, span_bug, sym};

Expand Down Expand Up @@ -540,7 +540,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
match *in_elem.kind() {
ty::RawPtr(p_ty, _) => {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
});
require!(
metadata.is_unit(),
Expand All @@ -554,7 +554,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
match *out_elem.kind() {
ty::RawPtr(p_ty, _) => {
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
});
require!(
metadata.is_unit(),
Expand Down
12 changes: 3 additions & 9 deletions compiler/rustc_codegen_llvm/src/builder/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_codegen_ssa::mir::place::PlaceValue;
use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, BuilderMethods, ReturnSlot};
use rustc_data_structures::thin_vec::ThinVec;
use rustc_middle::ty;
use rustc_middle::ty::{PseudoCanonicalInput, Ty, TyCtxt, TypingEnv};
use rustc_middle::ty::{Ty, TyCtxt, TypingEnv};
use rustc_span::bug;
use rustc_target::callconv::PassMode;
use tracing::debug;
Expand Down Expand Up @@ -50,12 +50,8 @@ pub(crate) fn adjust_activity_to_abi<'tcx>(
if let ty::Slice(element_ty) = tail_ty.kind() {
// Now we need to figure out the size of each slice element in memory to allow
// safety checks and usability improvements in the backend.
let pci = PseudoCanonicalInput {
typing_env: TypingEnv::fully_monomorphized(),
value: *element_ty,
};

let layout = tcx.layout_of(pci);
let layout = tcx.layout_of(typing_env.as_query_input(*element_ty));
let elem_size = match layout {
Ok(layout) => layout.size,
Err(_) => {
Expand Down Expand Up @@ -91,9 +87,7 @@ pub(crate) fn adjust_activity_to_abi<'tcx>(
}
}

let pci = PseudoCanonicalInput { typing_env: TypingEnv::fully_monomorphized(), value: *ty };

let layout = match tcx.layout_of(pci) {
let layout = match tcx.layout_of(typing_env.as_query_input(*ty)) {
Ok(layout) => layout.layout,
Err(_) => {
bug!("failed to compute layout for type {:?}", ty);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rustc_middle::mir::BinOp;
use rustc_middle::ty::consts::ConstExt;
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, LayoutOf};
use rustc_middle::ty::offload_meta::OffloadMetadata;
use rustc_middle::ty::{self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt, TypingEnv};
use rustc_middle::ty::{self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt};
use rustc_session::diagnostics::feature_err;
use rustc_span::{ErrorGuaranteed, Span, Symbol, bug, span_bug, sym};
use rustc_structures::CrateType;
Expand Down Expand Up @@ -1881,7 +1881,7 @@ fn codegen_autodiff<'ll, 'tcx>(
adjust_activity_to_abi(
tcx,
source_fn_ptr_ty,
TypingEnv::fully_monomorphized(),
bx.cx.typing_env(),
&mut diff_attrs.input_activity,
);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ where
let instance = match ty.kind() {
&ty::FnDef(def_id, args) => Instance::expect_resolve(
cx.tcx(),
ty::TypingEnv::fully_monomorphized(),
cx.typing_env(),
def_id,
args.no_bound_vars().unwrap(),
expr.span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
if tcx.features().ergonomic_clones() {
let monomorphized_mir = instance.instantiate_mir_and_normalize_erasing_regions(
tcx,
ty::TypingEnv::fully_monomorphized(),
cx.typing_env(),
ty::EarlyBinder::bind(tcx, mir.clone()),
);
mir = tcx.arena.alloc(optimize_use_clone::<Bx>(cx, monomorphized_mir));
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

// Helper to get a `-1` value of the appropriate type
fn neg_1_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> {
let typing_env = ty::TypingEnv::fully_monomorphized();
let typing_env = self.typing_env();
let size = self.tcx.layout_of(typing_env.as_query_input(ty)).unwrap().size;
let literal = Const::from_bits(self.tcx, size.unsigned_int_max(), typing_env, ty);

Expand All @@ -746,7 +746,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// Helper to get the minimum value of the appropriate type
fn minval_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> {
assert!(ty.is_signed());
let typing_env = ty::TypingEnv::fully_monomorphized();
let typing_env = self.typing_env();
let bits = self.tcx.layout_of(typing_env.as_query_input(ty)).unwrap().size.bits();
let n = 1 << (bits - 1);
let literal = Const::from_bits(self.tcx, n, typing_env, ty);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/builder/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! kind of thing.

use rustc_middle::mir::*;
use rustc_middle::ty::{self, Ty};
use rustc_middle::ty::Ty;
use rustc_span::Span;
use rustc_trait_selection::infer::InferCtxtExt;
use tracing::debug;
Expand Down Expand Up @@ -32,7 +32,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Returns a zero literal operand for the appropriate type, works for
/// bool, char and integers.
pub(crate) fn zero_literal(&mut self, span: Span, ty: Ty<'tcx>) -> Operand<'tcx> {
let literal = Const::from_bits(self.tcx, 0, ty::TypingEnv::fully_monomorphized(), ty);
let literal = Const::from_bits(self.tcx, 0, self.typing_env(), ty);

self.literal_operand(span, literal)
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_public_bridge/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_abi::{Size, TyAndLayout};
use rustc_middle::mir::interpret::{
AllocId, AllocInit, AllocRange, Allocation, ConstAllocation, Pointer, Scalar, alloc_range,
};
use rustc_middle::ty::layout::HasTypingEnv;
use rustc_middle::ty::{Ty, layout};

use super::{CompilerCtxt, Tables};
Expand All @@ -18,8 +19,7 @@ pub fn create_ty_and_layout<'tcx, B: Bridge>(
cx: &CompilerCtxt<'tcx, B>,
ty: Ty<'tcx>,
) -> Result<TyAndLayout<'tcx, Ty<'tcx>>, &'tcx layout::LayoutError<'tcx>> {
use crate::context::TypingEnvHelpers;
cx.tcx.layout_of(cx.fully_monomorphized().as_query_input(ty))
cx.tcx.layout_of(cx.typing_env().as_query_input(ty))
}

pub fn try_new_scalar<'tcx, B: Bridge>(
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_public_bridge/src/context/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
//! interface regardless of internal compiler changes.

use rustc_middle::mir::interpret::AllocRange;
use rustc_middle::ty;
use rustc_middle::ty::Ty;
use rustc_span::def_id::DefId;

pub trait TyHelpers<'tcx> {
fn new_foreign(&self, def_id: DefId) -> Ty<'tcx>;
}

pub trait TypingEnvHelpers<'tcx> {
fn fully_monomorphized(&self) -> ty::TypingEnv<'tcx>;
}

pub trait AllocRangeHelpers<'tcx> {
fn alloc_range(&self, offset: rustc_abi::Size, size: rustc_abi::Size) -> AllocRange;
}
Loading
Loading