Skip to content

Commit 97bf25c

Browse files
committed
Auto merge of rust-lang#125179 - matthiaskrgr:rollup-wkdwoaj, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#124871 (Don't ICE because recomputing overflow goals during find_best_leaf_obligation causes inference side-effects) - rust-lang#125018 (Update linker-plugin-lto.md to include LLVM 18) - rust-lang#125130 (rustdoc-json-types: Document `Id`) - rust-lang#125170 (Uplift `FnSig` into `rustc_type_ir` (redux)) - rust-lang#125172 (Fix assertion when attempting to convert `f16` and `f128` with `as`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4a78c00 + e3864db commit 97bf25c

34 files changed

+725
-348
lines changed

compiler/rustc_codegen_ssa/src/traits/builder.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,10 @@ pub trait BuilderMethods<'a, 'tcx>:
247247
} else {
248248
(in_ty, dest_ty)
249249
};
250-
assert!(matches!(self.cx().type_kind(float_ty), TypeKind::Float | TypeKind::Double));
250+
assert!(matches!(
251+
self.cx().type_kind(float_ty),
252+
TypeKind::Half | TypeKind::Float | TypeKind::Double | TypeKind::FP128
253+
));
251254
assert_eq!(self.cx().type_kind(int_ty), TypeKind::Integer);
252255

253256
if let Some(false) = self.cx().sess().opts.unstable_opts.saturating_float_casts {

compiler/rustc_errors/src/diagnostic_impls.rs

+6
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::UnevaluatedConst
112112
}
113113
}
114114

115+
impl<I: rustc_type_ir::Interner> IntoDiagArg for rustc_type_ir::FnSig<I> {
116+
fn into_diag_arg(self) -> rustc_errors::DiagArgValue {
117+
format!("{self:?}").into_diag_arg()
118+
}
119+
}
120+
115121
into_diag_arg_for_number!(i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize);
116122

117123
impl IntoDiagArg for bool {

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3191,7 +3191,7 @@ pub enum Unsafety {
31913191
}
31923192

31933193
impl Unsafety {
3194-
pub fn prefix_str(&self) -> &'static str {
3194+
pub fn prefix_str(self) -> &'static str {
31953195
match self {
31963196
Self::Unsafe => "unsafe ",
31973197
Self::Normal => "",

compiler/rustc_middle/src/ty/context.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
9292
type DefiningOpaqueTypes = &'tcx ty::List<LocalDefId>;
9393
type AdtDef = ty::AdtDef<'tcx>;
9494
type GenericArgs = ty::GenericArgsRef<'tcx>;
95-
type GenericArgsSlice = &'tcx [ty::GenericArg<'tcx>];
95+
type OwnItemArgs = &'tcx [ty::GenericArg<'tcx>];
9696
type GenericArg = ty::GenericArg<'tcx>;
9797

9898
type Term = ty::Term<'tcx>;
@@ -103,6 +103,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
103103
type CanonicalVars = CanonicalVarInfos<'tcx>;
104104
type Ty = Ty<'tcx>;
105105
type Tys = &'tcx List<Ty<'tcx>>;
106+
type FnInputTys = &'tcx [Ty<'tcx>];
106107
type ParamTy = ParamTy;
107108
type BoundTy = ty::BoundTy;
108109
type PlaceholderTy = ty::PlaceholderType;
@@ -113,32 +114,37 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
113114
type AllocId = crate::mir::interpret::AllocId;
114115

115116
type Pat = Pattern<'tcx>;
117+
type Unsafety = hir::Unsafety;
118+
type Abi = abi::Abi;
119+
116120
type Const = ty::Const<'tcx>;
117121
type AliasConst = ty::UnevaluatedConst<'tcx>;
118122
type PlaceholderConst = ty::PlaceholderConst;
119123
type ParamConst = ty::ParamConst;
120124
type BoundConst = ty::BoundVar;
121125
type ValueConst = ty::ValTree<'tcx>;
122-
123126
type ExprConst = ty::Expr<'tcx>;
127+
124128
type Region = Region<'tcx>;
125129
type EarlyParamRegion = ty::EarlyParamRegion;
126130
type LateParamRegion = ty::LateParamRegion;
127131
type BoundRegion = ty::BoundRegion;
128132
type InferRegion = ty::RegionVid;
129-
130133
type PlaceholderRegion = ty::PlaceholderRegion;
134+
131135
type Predicate = Predicate<'tcx>;
132136
type TraitPredicate = ty::TraitPredicate<'tcx>;
133137
type RegionOutlivesPredicate = ty::RegionOutlivesPredicate<'tcx>;
134138
type TypeOutlivesPredicate = ty::TypeOutlivesPredicate<'tcx>;
135139
type ProjectionPredicate = ty::ProjectionPredicate<'tcx>;
136140
type NormalizesTo = ty::NormalizesTo<'tcx>;
137141
type SubtypePredicate = ty::SubtypePredicate<'tcx>;
142+
138143
type CoercePredicate = ty::CoercePredicate<'tcx>;
139144
type ClosureKind = ty::ClosureKind;
140145

141146
type Clauses = ty::Clauses<'tcx>;
147+
142148
fn mk_canonical_var_infos(self, infos: &[ty::CanonicalVarInfo<Self>]) -> Self::CanonicalVars {
143149
self.mk_canonical_var_infos(infos)
144150
}
@@ -191,7 +197,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
191197
self,
192198
def_id: Self::DefId,
193199
args: Self::GenericArgs,
194-
) -> (rustc_type_ir::TraitRef<Self>, Self::GenericArgsSlice) {
200+
) -> (rustc_type_ir::TraitRef<Self>, Self::OwnItemArgs) {
195201
assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst);
196202
let trait_def_id = self.parent(def_id);
197203
assert_matches!(self.def_kind(trait_def_id), DefKind::Trait);
@@ -223,6 +229,18 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
223229
}
224230
}
225231

232+
impl<'tcx> rustc_type_ir::inherent::Abi<TyCtxt<'tcx>> for abi::Abi {
233+
fn is_rust(self) -> bool {
234+
matches!(self, abi::Abi::Rust)
235+
}
236+
}
237+
238+
impl<'tcx> rustc_type_ir::inherent::Unsafety<TyCtxt<'tcx>> for hir::Unsafety {
239+
fn prefix_str(self) -> &'static str {
240+
self.prefix_str()
241+
}
242+
}
243+
226244
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
227245

228246
pub struct CtxtInterners<'tcx> {

compiler/rustc_middle/src/ty/print/pretty.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -3034,6 +3034,16 @@ forward_display_to_print! {
30343034
define_print! {
30353035
(self, cx):
30363036

3037+
ty::FnSig<'tcx> {
3038+
p!(write("{}", self.unsafety.prefix_str()));
3039+
3040+
if self.abi != Abi::Rust {
3041+
p!(write("extern {} ", self.abi));
3042+
}
3043+
3044+
p!("fn", pretty_fn_sig(self.inputs(), self.c_variadic, self.output()));
3045+
}
3046+
30373047
ty::TraitRef<'tcx> {
30383048
p!(write("<{} as {}>", self.self_ty(), self.print_only_trait_path()))
30393049
}
@@ -3169,16 +3179,6 @@ define_print_and_forward_display! {
31693179
p!("{{", comma_sep(self.iter()), "}}")
31703180
}
31713181

3172-
ty::FnSig<'tcx> {
3173-
p!(write("{}", self.unsafety.prefix_str()));
3174-
3175-
if self.abi != Abi::Rust {
3176-
p!(write("extern {} ", self.abi));
3177-
}
3178-
3179-
p!("fn", pretty_fn_sig(self.inputs(), self.c_variadic, self.output()));
3180-
}
3181-
31823182
TraitRefPrintOnlyTraitPath<'tcx> {
31833183
p!(print_def_path(self.0.def_id, self.0.args));
31843184
}

compiler/rustc_middle/src/ty/structural_impls.rs

-43
Original file line numberDiff line numberDiff line change
@@ -83,49 +83,6 @@ impl fmt::Debug for ty::LateParamRegion {
8383
}
8484
}
8585

86-
impl<'tcx> fmt::Debug for ty::FnSig<'tcx> {
87-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
88-
WithInfcx::with_no_infcx(self).fmt(f)
89-
}
90-
}
91-
impl<'tcx> DebugWithInfcx<TyCtxt<'tcx>> for ty::FnSig<'tcx> {
92-
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
93-
this: WithInfcx<'_, Infcx, &Self>,
94-
f: &mut core::fmt::Formatter<'_>,
95-
) -> core::fmt::Result {
96-
let sig = this.data;
97-
let ty::FnSig { inputs_and_output: _, c_variadic, unsafety, abi } = sig;
98-
99-
write!(f, "{}", unsafety.prefix_str())?;
100-
match abi {
101-
rustc_target::spec::abi::Abi::Rust => (),
102-
abi => write!(f, "extern \"{abi:?}\" ")?,
103-
};
104-
105-
write!(f, "fn(")?;
106-
let inputs = sig.inputs();
107-
match inputs.len() {
108-
0 if *c_variadic => write!(f, "...)")?,
109-
0 => write!(f, ")")?,
110-
_ => {
111-
for ty in &sig.inputs()[0..(sig.inputs().len() - 1)] {
112-
write!(f, "{:?}, ", &this.wrap(ty))?;
113-
}
114-
write!(f, "{:?}", &this.wrap(sig.inputs().last().unwrap()))?;
115-
if *c_variadic {
116-
write!(f, "...")?;
117-
}
118-
write!(f, ")")?;
119-
}
120-
}
121-
122-
match sig.output().kind() {
123-
ty::Tuple(list) if list.is_empty() => Ok(()),
124-
_ => write!(f, " -> {:?}", &this.wrap(sig.output())),
125-
}
126-
}
127-
}
128-
12986
impl<'tcx> ty::DebugWithInfcx<TyCtxt<'tcx>> for Ty<'tcx> {
13087
fn fmt<Infcx: InferCtxtLike<Interner = TyCtxt<'tcx>>>(
13188
this: WithInfcx<'_, Infcx, &Self>,

compiler/rustc_middle/src/ty/sty.rs

+21-52
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use super::GenericParamDefKind;
3939
pub type TyKind<'tcx> = ir::TyKind<TyCtxt<'tcx>>;
4040
pub type TypeAndMut<'tcx> = ir::TypeAndMut<TyCtxt<'tcx>>;
4141
pub type AliasTy<'tcx> = ir::AliasTy<TyCtxt<'tcx>>;
42+
pub type FnSig<'tcx> = ir::FnSig<TyCtxt<'tcx>>;
4243

4344
pub trait Article {
4445
fn article(&self) -> &'static str;
@@ -985,14 +986,6 @@ impl<'tcx, T> Binder<'tcx, T> {
985986
Binder { value: &self.value, bound_vars: self.bound_vars }
986987
}
987988

988-
pub fn map_bound_ref_unchecked<F, U>(&self, f: F) -> Binder<'tcx, U>
989-
where
990-
F: FnOnce(&T) -> U,
991-
{
992-
let value = f(&self.value);
993-
Binder { value, bound_vars: self.bound_vars }
994-
}
995-
996989
pub fn map_bound_ref<F, U: TypeVisitable<TyCtxt<'tcx>>>(&self, f: F) -> Binder<'tcx, U>
997990
where
998991
F: FnOnce(&T) -> U,
@@ -1109,73 +1102,37 @@ pub struct GenSig<'tcx> {
11091102
pub return_ty: Ty<'tcx>,
11101103
}
11111104

1112-
/// Signature of a function type, which we have arbitrarily
1113-
/// decided to use to refer to the input/output types.
1114-
///
1115-
/// - `inputs`: is the list of arguments and their modes.
1116-
/// - `output`: is the return type.
1117-
/// - `c_variadic`: indicates whether this is a C-variadic function.
1118-
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
1119-
#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)]
1120-
pub struct FnSig<'tcx> {
1121-
pub inputs_and_output: &'tcx List<Ty<'tcx>>,
1122-
pub c_variadic: bool,
1123-
pub unsafety: hir::Unsafety,
1124-
pub abi: abi::Abi,
1125-
}
1126-
1127-
impl<'tcx> FnSig<'tcx> {
1128-
pub fn inputs(&self) -> &'tcx [Ty<'tcx>] {
1129-
&self.inputs_and_output[..self.inputs_and_output.len() - 1]
1130-
}
1131-
1132-
pub fn output(&self) -> Ty<'tcx> {
1133-
self.inputs_and_output[self.inputs_and_output.len() - 1]
1134-
}
1135-
1136-
// Creates a minimal `FnSig` to be used when encountering a `TyKind::Error` in a fallible
1137-
// method.
1138-
fn fake() -> FnSig<'tcx> {
1139-
FnSig {
1140-
inputs_and_output: List::empty(),
1141-
c_variadic: false,
1142-
unsafety: hir::Unsafety::Normal,
1143-
abi: abi::Abi::Rust,
1144-
}
1145-
}
1146-
}
1147-
1148-
impl<'tcx> IntoDiagArg for FnSig<'tcx> {
1149-
fn into_diag_arg(self) -> DiagArgValue {
1150-
self.to_string().into_diag_arg()
1151-
}
1152-
}
1153-
11541105
pub type PolyFnSig<'tcx> = Binder<'tcx, FnSig<'tcx>>;
11551106

11561107
impl<'tcx> PolyFnSig<'tcx> {
11571108
#[inline]
11581109
pub fn inputs(&self) -> Binder<'tcx, &'tcx [Ty<'tcx>]> {
1159-
self.map_bound_ref_unchecked(|fn_sig| fn_sig.inputs())
1110+
self.map_bound_ref(|fn_sig| fn_sig.inputs())
11601111
}
1112+
11611113
#[inline]
11621114
#[track_caller]
11631115
pub fn input(&self, index: usize) -> ty::Binder<'tcx, Ty<'tcx>> {
11641116
self.map_bound_ref(|fn_sig| fn_sig.inputs()[index])
11651117
}
1118+
11661119
pub fn inputs_and_output(&self) -> ty::Binder<'tcx, &'tcx List<Ty<'tcx>>> {
11671120
self.map_bound_ref(|fn_sig| fn_sig.inputs_and_output)
11681121
}
1122+
11691123
#[inline]
11701124
pub fn output(&self) -> ty::Binder<'tcx, Ty<'tcx>> {
11711125
self.map_bound_ref(|fn_sig| fn_sig.output())
11721126
}
1127+
11731128
pub fn c_variadic(&self) -> bool {
11741129
self.skip_binder().c_variadic
11751130
}
1131+
11761132
pub fn unsafety(&self) -> hir::Unsafety {
11771133
self.skip_binder().unsafety
11781134
}
1135+
11791136
pub fn abi(&self) -> abi::Abi {
11801137
self.skip_binder().abi
11811138
}
@@ -2031,7 +1988,12 @@ impl<'tcx> Ty<'tcx> {
20311988
FnPtr(f) => *f,
20321989
Error(_) => {
20331990
// ignore errors (#54954)
2034-
ty::Binder::dummy(FnSig::fake())
1991+
ty::Binder::dummy(ty::FnSig {
1992+
inputs_and_output: ty::List::empty(),
1993+
c_variadic: false,
1994+
unsafety: hir::Unsafety::Normal,
1995+
abi: abi::Abi::Rust,
1996+
})
20351997
}
20361998
Closure(..) => bug!(
20371999
"to get the signature of a closure, use `args.as_closure().sig()` not `fn_sig()`",
@@ -2624,6 +2586,13 @@ impl<'tcx> Ty<'tcx> {
26242586
}
26252587
}
26262588

2589+
impl<'tcx> rustc_type_ir::inherent::Tys<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx>> {
2590+
fn split_inputs_and_output(self) -> (&'tcx [Ty<'tcx>], Ty<'tcx>) {
2591+
let (output, inputs) = self.split_last().unwrap();
2592+
(inputs, *output)
2593+
}
2594+
}
2595+
26272596
/// Extra information about why we ended up with a particular variance.
26282597
/// This is only used to add more information to error messages, and
26292598
/// has no effect on soundness. While choosing the 'wrong' `VarianceDiagInfo`

0 commit comments

Comments
 (0)