Skip to content

Commit e834a94

Browse files
committed
move over all other function definitions from sty.rs
1 parent 9b563d7 commit e834a94

16 files changed

Lines changed: 657 additions & 1083 deletions

File tree

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
538538

539539
match *in_elem.kind() {
540540
ty::RawPtr(p_ty, _) => {
541-
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
541+
let metadata = p_ty.ptr_metadata_ty(bx.tcx, &ObligationCause::dummy(), |ty| {
542542
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
543543
});
544544
require!(
@@ -552,7 +552,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
552552
}
553553
match *out_elem.kind() {
554554
ty::RawPtr(p_ty, _) => {
555-
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
555+
let metadata = p_ty.ptr_metadata_ty(bx.tcx, &ObligationCause::dummy(), |ty| {
556556
bx.tcx.normalize_erasing_regions(ty::TypingEnv::fully_monomorphized(), ty)
557557
});
558558
require!(

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_data_structures::assert_matches;
1616
use rustc_hir::def_id::LOCAL_CRATE;
1717
use rustc_hir::{self as hir};
1818
use rustc_middle::mir::BinOp;
19+
use rustc_middle::traits::ObligationCause;
1920
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, LayoutOf};
2021
use rustc_middle::ty::offload_meta::OffloadMetadata;
2122
use rustc_middle::ty::{self, GenericArgsRef, Instance, SimdAlign, Ty, TyCtxt, TypingEnv};
@@ -2558,7 +2559,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
25582559

25592560
match in_elem.kind() {
25602561
ty::RawPtr(p_ty, _) => {
2561-
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
2562+
let metadata = p_ty.ptr_metadata_ty(bx.tcx, &ObligationCause::dummy(), |ty| {
25622563
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
25632564
});
25642565
require!(
@@ -2572,7 +2573,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
25722573
}
25732574
match out_elem.kind() {
25742575
ty::RawPtr(p_ty, _) => {
2575-
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
2576+
let metadata = p_ty.ptr_metadata_ty(bx.tcx, &ObligationCause::dummy(), |ty| {
25762577
bx.tcx.normalize_erasing_regions(bx.typing_env(), ty)
25772578
});
25782579
require!(

compiler/rustc_const_eval/src/interpret/call.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_data_structures::assert_matches;
99
use rustc_errors::msg;
1010
use rustc_hir::def_id::DefId;
1111
use rustc_hir::find_attr;
12+
use rustc_infer::traits::ObligationCause;
1213
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
1314
use rustc_middle::ty::{self, AdtDef, Instance, Ty, VariantDef};
1415
use rustc_middle::{bug, mir, span_bug};
@@ -221,7 +222,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
221222
// to fields, which can yield non-normalized types. So we need to provide a
222223
// normalization function.
223224
let normalize = |ty| self.tcx.normalize_erasing_regions(self.typing_env, ty);
224-
ty.ptr_metadata_ty(*self.tcx, normalize)
225+
ty.ptr_metadata_ty(*self.tcx, &ObligationCause::dummy(), normalize)
225226
};
226227
return interp_ok(meta_ty(caller) == meta_ty(callee));
227228
}

compiler/rustc_lint/src/gpukernel_abi.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::iter;
22

33
use rustc_abi::ExternAbi;
44
use rustc_hir::{self as hir, find_attr};
5+
use rustc_infer::traits::ObligationCause;
56
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable};
67
use rustc_session::{declare_lint, declare_lint_pass};
78
use rustc_span::Span;
@@ -109,7 +110,10 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for CheckGpuKernelTypes<'tcx> {
109110
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) => {}
110111
// Thin pointers are allowed but fat pointers with metadata are not
111112
ty::RawPtr(_, _) => {
112-
if !ty.pointee_metadata_ty_or_projection(self.tcx).is_unit() {
113+
if !ty
114+
.pointee_metadata_ty_or_projection(&ObligationCause::dummy(), self.tcx)
115+
.is_unit()
116+
{
113117
self.has_invalid = true;
114118
}
115119
}

compiler/rustc_middle/src/middle/lang_items.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir::def_id::DefId;
1212
use rustc_span::Span;
1313
use rustc_target::spec::PanicStrategy;
1414

15-
use crate::ty::{self, TyCtxt};
15+
use crate::ty::{self, AdtDef, TyCtxt};
1616

1717
impl<'tcx> TyCtxt<'tcx> {
1818
/// Returns the `DefId` for a given `LangItem`.
@@ -27,6 +27,10 @@ impl<'tcx> TyCtxt<'tcx> {
2727
self.lang_items().get(lang_item) == Some(def_id)
2828
}
2929

30+
pub fn is_c_void(self, adt: AdtDef) -> bool {
31+
self.is_lang_item(adt.did(), LangItem::CVoid)
32+
}
33+
3034
pub fn as_lang_item(self, def_id: DefId) -> Option<LangItem> {
3135
self.lang_items().from_def_id(def_id)
3236
}

compiler/rustc_middle/src/mir/statement.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use tracing::{debug, instrument};
66

77
use super::interpret::GlobalAlloc;
88
use super::*;
9+
use crate::traits::ObligationCause;
910
use crate::ty::CoroutineArgsExt;
1011

1112
///////////////////////////////////////////////////////////////////////////
@@ -870,7 +871,9 @@ impl<'tcx> UnOp {
870871
pub fn ty(&self, tcx: TyCtxt<'tcx>, arg_ty: Ty<'tcx>) -> Ty<'tcx> {
871872
match self {
872873
UnOp::Not | UnOp::Neg => arg_ty,
873-
UnOp::PtrMetadata => arg_ty.pointee_metadata_ty_or_projection(tcx),
874+
UnOp::PtrMetadata => {
875+
arg_ty.pointee_metadata_ty_or_projection(&ObligationCause::dummy(), tcx)
876+
}
874877
}
875878
}
876879
}

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,18 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
288288
None
289289
}
290290
}
291+
292+
fn discriminant_for_variant(self, tcx: TyCtxt<'tcx>, variant_index: VariantIdx) -> Discr<'tcx> {
293+
self.discriminant_for_variant(tcx, variant_index)
294+
}
295+
296+
fn variant_range(self) -> Range<VariantIdx> {
297+
self.variant_range()
298+
}
299+
300+
fn repr_discr_type_to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
301+
self.repr().discr_type().to_ty(tcx)
302+
}
291303
}
292304

293305
#[derive(Copy, Clone, Debug, Eq, PartialEq, HashStable, TyEncodable, TyDecodable)]

compiler/rustc_middle/src/ty/context/impl_interner.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ use rustc_type_ir::{CollectAndApply, Interner, TypeFoldable, search_graph};
1818
use crate::dep_graph::{DepKind, DepNodeIndex};
1919
use crate::infer::canonical::CanonicalVarKinds;
2020
use crate::query::IntoQueryParam;
21+
use crate::traits::ObligationCause;
2122
use crate::traits::cache::WithDepNode;
2223
use crate::traits::solve::{
2324
self, CanonicalInput, ExternalConstraints, ExternalConstraintsData, QueryResult, inspect,
2425
};
26+
use crate::ty::util::Discr;
2527
use crate::ty::{
2628
self, AdtDef, Clause, Const, List, ParamTy, Pattern, PolyExistentialPredicate, Predicate,
2729
Region, Ty, TyCtxt, VariantDef,
@@ -50,6 +52,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
5052
type Interned<T: Copy + Clone + std::fmt::Debug + std::hash::Hash + Eq + PartialEq> =
5153
Interned<'tcx, T>;
5254
type VariantIdx = VariantIdx;
55+
type Discr = Discr;
56+
type ObligationCause = ObligationCause;
5357

5458
type GenericArgs = ty::GenericArgsRef<'tcx>;
5559

@@ -471,6 +475,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
471475
self.is_lang_item(def_id, solver_lang_item_to_lang_item(lang_item))
472476
}
473477

478+
pub fn is_c_void(self, adt: AdtDef) -> bool {
479+
self.is_c_void(adt)
480+
}
481+
474482
fn is_trait_lang_item(self, def_id: DefId, lang_item: SolverTraitLangItem) -> bool {
475483
self.is_lang_item(def_id, solver_trait_lang_item_to_lang_item(lang_item))
476484
}
@@ -743,10 +751,36 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
743751
})
744752
}
745753

754+
#[inline]
755+
fn i8_type(self) -> Ty<'tcx> {
756+
self.types.i8
757+
}
758+
759+
#[inline]
760+
fn i16_type(self) -> Ty<'tcx> {
761+
self.types.i16
762+
}
763+
764+
#[inline]
765+
fn i32_type(self) -> Ty<'tcx> {
766+
self.types.i32
767+
}
768+
769+
#[inline]
746770
fn u8_type(self) -> Ty<'tcx> {
747771
self.types.u8
748772
}
749773

774+
#[inline]
775+
fn usize_type(self) -> Ty<'tcx> {
776+
self.types.usize
777+
}
778+
779+
#[inline]
780+
fn unit_type(self) -> Ty<'tcx> {
781+
self.types.unit
782+
}
783+
750784
fn is_async_drop_in_place_coroutine(self, def_id: DefId) -> bool {
751785
self.is_lang_item(self.parent(def_id), LangItem::AsyncDropInPlace)
752786
}
@@ -759,6 +793,16 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
759793
) -> Range<VariantIdx> {
760794
self.coroutine_variant_range(def_id, coroutine_args)
761795
}
796+
797+
fn struct_tail_raw(
798+
self,
799+
mut ty: Ty<'tcx>,
800+
cause: &ObligationCause<'tcx>,
801+
mut normalize: impl FnMut(Ty<'tcx>) -> Ty<'tcx>,
802+
mut f: impl FnMut() -> (),
803+
) -> Ty<'tcx> {
804+
self.struct_tail_raw(ty, cause, normalize, f)
805+
}
762806
}
763807

764808
/// Defines trivial conversion functions between the main [`LangItem`] enum,

compiler/rustc_middle/src/ty/generic_args.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::marker::PhantomData;
55
use std::num::NonZero;
66
use std::ptr::NonNull;
77

8+
use rustc_abi::VariantIdx;
89
use rustc_data_structures::intern::Interned;
910
use rustc_errors::{DiagArgValue, IntoDiagArg};
1011
use rustc_hir::def_id::DefId;
@@ -15,6 +16,7 @@ use rustc_type_ir::walk::TypeWalker;
1516
use smallvec::SmallVec;
1617

1718
use crate::ty::codec::{TyDecoder, TyEncoder};
19+
use crate::ty::util::Discr;
1820
use crate::ty::{
1921
self, ClosureArgs, CoroutineArgs, CoroutineClosureArgs, FallibleTypeFolder, InlineConstArgs,
2022
Lift, List, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor, VisitorResult,
@@ -122,6 +124,19 @@ impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArg
122124
_ => bug!("coroutine args missing synthetics"),
123125
}
124126
}
127+
128+
fn coroutine_discriminant_for_variant(
129+
self,
130+
def_id: DefId,
131+
tcx: TyCtxt<'tcx>,
132+
variant_index: VariantIdx,
133+
) -> Discr {
134+
self.as_coroutine().discriminant_for_variant(def_id, tcxt, variant_index)
135+
}
136+
137+
fn as_coroutine_discr_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
138+
self.as_coroutine().discr_ty(tcxt)
139+
}
125140
}
126141

127142
impl<'tcx> rustc_type_ir::inherent::IntoKind for GenericArg<'tcx> {

0 commit comments

Comments
 (0)