Skip to content
Open
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
5 changes: 3 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,8 +1085,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
}

// Build a new closure where the return type is an owned value, instead of a ref.
let fn_sig_kind =
FnSigKind::default().set_safe(true).set_c_variadic(liberated_sig.c_variadic());
let fn_sig_kind = FnSigKind::default()
.set_safety(hir::Safety::Safe)
.set_c_variadic(liberated_sig.c_variadic());
let closure_sig_as_fn_ptr_ty = Ty::new_fn_ptr(
tcx,
ty::Binder::dummy(tcx.mk_fn_sig(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3590,7 +3590,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {

let fn_sig_kind = FnSigKind::default()
.set_abi(abi)
.set_safe(safety.is_safe())
.set_safety(safety)
.set_c_variadic(decl.fn_decl_kind.c_variadic());
let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, fn_sig_kind);
let fn_ptr_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars);
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let bound_sig = expected_sig.sig.map_bound(|sig| {
let fn_sig_kind = FnSigKind::default()
.set_abi(ExternAbi::RustCall)
.set_safe(true)
.set_safety(hir::Safety::Safe)
.set_c_variadic(sig.c_variadic());
self.tcx.mk_fn_sig(sig.inputs().iter().cloned(), sig.output(), fn_sig_kind)
});
Expand Down Expand Up @@ -860,7 +860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let fn_sig_kind = FnSigKind::default()
.set_abi(ExternAbi::RustCall)
.set_safe(true)
.set_safety(hir::Safety::Safe)
.set_c_variadic(expected_sigs.liberated_sig.c_variadic());
expected_sigs.liberated_sig =
self.tcx.mk_fn_sig(inputs, supplied_output_ty, fn_sig_kind);
Expand Down Expand Up @@ -935,7 +935,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let fn_sig_kind = FnSigKind::default()
.set_abi(ExternAbi::RustCall)
.set_safe(true)
.set_safety(hir::Safety::Safe)
.set_c_variadic(decl.c_variadic());
let result = ty::Binder::bind_with_vars(
self.tcx.mk_fn_sig(supplied_arguments, supplied_return, fn_sig_kind),
Expand Down Expand Up @@ -1098,7 +1098,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let fn_sig_kind = FnSigKind::default()
.set_abi(ExternAbi::RustCall)
.set_safe(true)
.set_safety(hir::Safety::Safe)
.set_c_variadic(decl.c_variadic());
let result = ty::Binder::dummy(self.tcx.mk_fn_sig(supplied_arguments, err_ty, fn_sig_kind));

Expand Down
83 changes: 24 additions & 59 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId};
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
use rustc_type_ir::TyKind::*;
pub use rustc_type_ir::lift::Lift;
use rustc_type_ir::{
CollectAndApply, FnSigKind, TypeFlags, WithCachedTypeInfo, elaborate, search_graph,
};
use rustc_type_ir::{CollectAndApply, TypeFlags, WithCachedTypeInfo, elaborate, search_graph};
use tracing::{debug, instrument};

use crate::arena::Arena;
Expand All @@ -69,11 +67,11 @@ use crate::traits;
use crate::traits::solve::{ExternalConstraints, ExternalConstraintsData, PredefinedOpaques};
use crate::ty::predicate::ExistentialPredicateStableCmpExt as _;
use crate::ty::{
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, GenericArg, GenericArgs,
GenericArgsRef, GenericParamDefKind, List, ListWithCachedTypeInfo, ParamConst, Pattern,
PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, PredicatePolarity,
Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid, ValTree, ValTreeKind,
Visibility,
self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, FnSigKind, GenericArg,
GenericArgs, GenericArgsRef, GenericParamDefKind, List, ListWithCachedTypeInfo, ParamConst,
Pattern, PatternKind, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind,
PredicatePolarity, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVid,
ValTree, ValTreeKind, Visibility,
};

impl<'tcx> rustc_type_ir::inherent::DefId<TyCtxt<'tcx>> for DefId {
Expand All @@ -86,50 +84,6 @@ impl<'tcx> rustc_type_ir::inherent::DefId<TyCtxt<'tcx>> for DefId {
}
}

impl<'tcx> rustc_type_ir::inherent::FSigKind<TyCtxt<'tcx>> for FnSigKind {
fn fn_sig_kind(self) -> Self {
self
}

fn new(abi: ExternAbi, safety: hir::Safety, c_variadic: bool) -> Self {
FnSigKind::default().set_abi(abi).set_safe(safety.is_safe()).set_c_variadic(c_variadic)
}

fn abi(self) -> ExternAbi {
self.abi()
}

fn safety(self) -> hir::Safety {
if self.is_safe() { hir::Safety::Safe } else { hir::Safety::Unsafe }
}

fn c_variadic(self) -> bool {
self.c_variadic()
}
}

impl<'tcx> rustc_type_ir::inherent::Abi<TyCtxt<'tcx>> for ExternAbi {
fn abi(self) -> Self {
self
}

fn rust() -> Self {
ExternAbi::Rust
}

fn is_rust(self) -> bool {
matches!(self, ExternAbi::Rust)
}

fn pack_abi(self) -> u8 {
self.as_packed()
}

fn unpack_abi(abi_index: u8) -> Self {
Self::from_packed(abi_index)
}
}

impl<'tcx> rustc_type_ir::inherent::Safety<TyCtxt<'tcx>> for hir::Safety {
fn safe() -> Self {
hir::Safety::Safe
Expand Down Expand Up @@ -1374,7 +1328,7 @@ impl<'tcx> TyCtxt<'tcx> {
let caller_features = &self.body_codegen_attrs(caller).target_features;
if self.is_target_feature_call_safe(&fun_features, &caller_features) {
return Some(fun_sig.map_bound(|sig| ty::FnSig {
fn_sig_kind: fun_sig.fn_sig_kind().set_safe(true),
fn_sig_kind: fun_sig.fn_sig_kind().set_safety(hir::Safety::Safe),
..sig
}));
}
Expand Down Expand Up @@ -2143,7 +2097,10 @@ impl<'tcx> TyCtxt<'tcx> {
assert!(sig.safety().is_safe());
Ty::new_fn_ptr(
self,
sig.map_bound(|sig| ty::FnSig { fn_sig_kind: sig.fn_sig_kind.set_safe(false), ..sig }),
sig.map_bound(|sig| ty::FnSig {
fn_sig_kind: sig.fn_sig_kind.set_safety(hir::Safety::Unsafe),
..sig
}),
)
}

Expand All @@ -2152,7 +2109,10 @@ impl<'tcx> TyCtxt<'tcx> {
/// unsafe.
pub fn safe_to_unsafe_sig(self, sig: PolyFnSig<'tcx>) -> PolyFnSig<'tcx> {
assert!(sig.safety().is_safe());
sig.map_bound(|sig| ty::FnSig { fn_sig_kind: sig.fn_sig_kind.set_safe(false), ..sig })
sig.map_bound(|sig| ty::FnSig {
fn_sig_kind: sig.fn_sig_kind.set_safety(hir::Safety::Unsafe),
..sig
})
}

/// Given the def_id of a Trait `trait_def_id` and the name of an associated item `assoc_name`
Expand Down Expand Up @@ -2197,7 +2157,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.mk_fn_sig(
params,
s.output(),
s.fn_sig_kind.set_safe(safety.is_safe()).set_abi(ExternAbi::Rust),
s.fn_sig_kind.set_safety(safety).set_abi(ExternAbi::Rust),
)
})
}
Expand Down Expand Up @@ -2471,7 +2431,12 @@ impl<'tcx> TyCtxt<'tcx> {
// IntoIterator` instead of `I: Iterator`, and it doesn't have a slice
// variant, because of the need to combine `inputs` and `output`. This
// explains the lack of `_from_iter` suffix.
pub fn mk_fn_sig<I, T>(self, inputs: I, output: I::Item, fn_sig_kind: FnSigKind) -> T::Output
pub fn mk_fn_sig<I, T>(
self,
inputs: I,
output: I::Item,
fn_sig_kind: FnSigKind<'tcx>,
) -> T::Output
where
I: IntoIterator<Item = T>,
T: CollectAndApply<Ty<'tcx>, ty::FnSig<'tcx>>,
Expand All @@ -2493,7 +2458,7 @@ impl<'tcx> TyCtxt<'tcx> {
I: IntoIterator<Item = T>,
T: CollectAndApply<Ty<'tcx>, ty::FnSig<'tcx>>,
{
self.mk_fn_sig(inputs, output, FnSigKind::default().set_safe(safety.is_safe()))
self.mk_fn_sig(inputs, output, FnSigKind::default().set_safety(safety))
}

/// `mk_fn_sig`, but with a safe Rust ABI, and no C-variadic argument.
Expand All @@ -2502,7 +2467,7 @@ impl<'tcx> TyCtxt<'tcx> {
I: IntoIterator<Item = T>,
T: CollectAndApply<Ty<'tcx>, ty::FnSig<'tcx>>,
{
self.mk_fn_sig(inputs, output, FnSigKind::default().set_safe(true))
self.mk_fn_sig(inputs, output, FnSigKind::default().set_safety(hir::Safety::Safe))
}

pub fn mk_poly_existential_predicates_from_iter<I, T>(self, iter: I) -> T::Output
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_middle/src/ty/context/impl_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

use std::{debug_assert_matches, fmt};

use rustc_abi::ExternAbi;
use rustc_errors::ErrorGuaranteed;
use rustc_hir as hir;
use rustc_hir::def::{CtorKind, CtorOf, DefKind};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem;
use rustc_span::{DUMMY_SP, Span, Symbol};
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
use rustc_type_ir::{
CollectAndApply, FnSigKind, Interner, TypeFoldable, Unnormalized, search_graph,
};
use rustc_type_ir::{CollectAndApply, Interner, TypeFoldable, Unnormalized, search_graph};

use crate::dep_graph::{DepKind, DepNodeIndex};
use crate::infer::canonical::CanonicalVarKinds;
Expand Down Expand Up @@ -92,9 +89,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
type AllocId = crate::mir::interpret::AllocId;
type Pat = Pattern<'tcx>;
type PatList = &'tcx List<Pattern<'tcx>>;
type FSigKind = FnSigKind;
type Safety = hir::Safety;
type Abi = ExternAbi;
type Const = ty::Const<'tcx>;
type Consts = &'tcx List<Self::Const>;

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
if self.tcx().codegen_fn_attrs(def_id).safe_target_features {
write!(self, "#[target_features] ")?;
sig = sig.map_bound(|mut sig| {
sig.fn_sig_kind = sig.fn_sig_kind.set_safe(true);
sig.fn_sig_kind = sig.fn_sig_kind.set_safety(hir::Safety::Safe);
sig
});
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ TrivialLiftImpls! {
rustc_hir::Safety,
rustc_middle::mir::ConstValue,
rustc_type_ir::BoundConstness,
rustc_type_ir::FnSigKind,
rustc_type_ir::PredicatePolarity,
// tidy-alphabetical-end
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub type TypeAndMut<'tcx> = ir::TypeAndMut<TyCtxt<'tcx>>;
pub type AliasTy<'tcx> = ir::AliasTy<TyCtxt<'tcx>>;
pub type AliasTyKind<'tcx> = ir::AliasTyKind<TyCtxt<'tcx>>;
pub type FnSig<'tcx> = ir::FnSig<TyCtxt<'tcx>>;
pub type FnSigKind = ir::FnSigKind;
pub type FnSigKind<'tcx> = ir::FnSigKind<TyCtxt<'tcx>>;
pub type Binder<'tcx, T> = ir::Binder<TyCtxt<'tcx>, T>;
pub type EarlyBinder<'tcx, T> = ir::EarlyBinder<TyCtxt<'tcx>, T>;
pub type Unnormalized<'tcx, T> = ir::Unnormalized<TyCtxt<'tcx>, T>;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_public/src/unstable/convert/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ impl RustcInternal for FnSig {
) -> Self::T<'tcx> {
let fn_sig_kind = rustc_ty::FnSigKind::default()
.set_abi(self.abi.internal(tables, tcx))
.set_safe(self.safety == Safety::Safe)
.set_safety(self.safety.internal(tables, tcx))
.set_c_variadic(self.c_variadic);
tcx.lift(rustc_ty::FnSig {
inputs_and_output: tcx.mk_type_list(&self.inputs_and_output.internal(tables, tcx)),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_public/src/unstable/convert/stable/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ where

// This internal type isn't publicly exposed, because it is an implementation detail.
// But it's a public field of FnSig (which has a public mirror type), so allow conversions.
impl<'tcx> Stable<'tcx> for ty::FnSigKind {
impl<'tcx> Stable<'tcx> for ty::FnSigKind<'tcx> {
type T = (bool /*c_variadic*/, crate::mir::Safety, crate::ty::Abi);
fn stable<'cx>(
&self,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_type_ir/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use derive_where::derive_where;
use rustc_abi::ExternAbi;
use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic};

use crate::solve::NoSolution;
Expand All @@ -25,7 +26,7 @@ pub enum TypeError<I: Interner> {
Mismatch,
PolarityMismatch(#[type_visitable(ignore)] ExpectedFound<ty::PredicatePolarity>),
SafetyMismatch(#[type_visitable(ignore)] ExpectedFound<I::Safety>),
AbiMismatch(#[type_visitable(ignore)] ExpectedFound<I::Abi>),
AbiMismatch(#[type_visitable(ignore)] ExpectedFound<ExternAbi>),
Mutability,
ArgumentMutability(usize),
TupleSize(ExpectedFound<usize>),
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_type_ir/src/generic_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use rustc_index::{Idx, IndexVec};
use smallvec::SmallVec;
use thin_vec::ThinVec;

use crate::Interner;

/// This trait is implemented for every type that can be visited,
/// providing the skeleton of the traversal.
///
Expand Down Expand Up @@ -210,4 +212,9 @@ trivial_impls!(
rustc_hash::FxBuildHasher,
crate::TypeFlags,
crate::solve::GoalSource,
rustc_abi::ExternAbi,
);

impl<I: Interner, V> GenericTypeVisitable<V> for crate::FnSigKind<I> {
fn generic_visit_with(&self, _visitor: &mut V) {}
}
36 changes: 0 additions & 36 deletions compiler/rustc_type_ir/src/inherent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,42 +205,6 @@ pub trait Tys<I: Interner<Tys = Self>>:
fn output(self) -> I::Ty;
}

#[rust_analyzer::prefer_underscore_import]
pub trait FSigKind<I: Interner<FSigKind = Self>>: Copy + Debug + Hash + Eq {
/// The identity function.
fn fn_sig_kind(self) -> Self;

/// Create a new FnSigKind with the given ABI, safety, and C-style variadic flag.
fn new(abi: I::Abi, safety: I::Safety, c_variadic: bool) -> Self;

/// Returns the ABI.
fn abi(self) -> I::Abi;

/// Returns the safety mode.
fn safety(self) -> I::Safety;

/// Do the function arguments end with a C-style variadic argument?
fn c_variadic(self) -> bool;
}

#[rust_analyzer::prefer_underscore_import]
pub trait Abi<I: Interner<Abi = Self>>: Copy + Debug + Hash + Eq {
/// The identity function.
fn abi(self) -> Self;

/// The ABI `extern "Rust"`.
fn rust() -> I::Abi;

/// Whether this ABI is `extern "Rust"`.
fn is_rust(self) -> bool;

/// Pack the ABI into a small dense integer, so it can be stored as packed `FnSigKind` flags.
fn pack_abi(self) -> u8;

/// Unpack the ABI from packed `FnSigKind` flags.
fn unpack_abi(abi_index: u8) -> Self;
}

#[rust_analyzer::prefer_underscore_import]
pub trait Safety<I: Interner<Safety = Self>>: Copy + Debug + Hash + Eq {
/// The `safe` safety mode.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_type_ir/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ pub trait Interner:
+ Eq
+ TypeVisitable<Self>
+ SliceLike<Item = Self::Pat>;
type FSigKind: FSigKind<Self>;
type Safety: Safety<Self>;
type Abi: Abi<Self>;

// Kinds of consts
type Const: Const<Self>;
Expand Down
Loading
Loading