Skip to content

Commit

Permalink
Update rustc
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Jun 25, 2024
1 parent 34482ef commit ff74ed2
Show file tree
Hide file tree
Showing 16 changed files with 119 additions and 96 deletions.
23 changes: 17 additions & 6 deletions engine/lib/import_thir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ end) : EXPR = struct
| Ge -> Core__cmp__PartialOrd__ge
| Gt -> Core__cmp__PartialOrd__gt
| Eq -> Core__cmp__PartialEq__eq
| AddWithOverflow | SubWithOverflow | MulWithOverflow ->
assertion_failure (Span.to_thir span)
"Overflowing binary operators are not suppored"
| Cmp ->
assertion_failure (Span.to_thir span)
"`Cmp` binary operator is not suppored"
Expand All @@ -279,6 +282,9 @@ end) : EXPR = struct
| Ge -> Rust_primitives__u128__ge
| Gt -> Rust_primitives__u128__gt
| Eq -> Rust_primitives__u128__eq
| AddWithOverflow | SubWithOverflow | MulWithOverflow ->
assertion_failure (Span.to_thir span)
"Overflowing binary operators are not suppored"
| Cmp ->
assertion_failure (Span.to_thir span)
"`Cmp` binary operator is not suppored"
Expand Down Expand Up @@ -320,7 +326,9 @@ end) : EXPR = struct
let name = primitive_names_of_binop op in
let expected, f =
match op with
| Add | Sub | Mul | Div -> both int <|> both float
| Add | Sub | Mul | AddWithOverflow | SubWithOverflow
| MulWithOverflow | Div ->
both int <|> both float
| Rem | Cmp -> both int
| BitXor | BitAnd | BitOr -> both int <|> both bool
| Shl | Shr -> int <*> int
Expand Down Expand Up @@ -464,7 +472,10 @@ end) : EXPR = struct
(U.call
(match op with
| Not -> Core__ops__bit__Not__not
| Neg -> Core__ops__arith__Neg__neg)
| Neg -> Core__ops__arith__Neg__neg
| PtrMetadata ->
assertion_failure (Span.to_thir span)
"Unsupported unary operator: `PtrMetadata`")
[ c_expr arg ]
span typ)
.e
Expand Down Expand Up @@ -889,7 +900,7 @@ end) : EXPR = struct

and c_pointer e typ span cast source =
match cast with
| ClosureFnPointer Normal | ReifyFnPointer ->
| ClosureFnPointer Safe | ReifyFnPointer ->
(* we have arrow types, we do not distinguish between top-level functions and closures *)
(c_expr source).e
| Unsize ->
Expand Down Expand Up @@ -1443,7 +1454,7 @@ and c_item_unwrapped ~ident ~drop_body (item : Thir.item) : item list =
span = Span.of_thir span;
witness = W.macro;
}
| Trait (No, Normal, generics, _bounds, items) ->
| Trait (No, Safe, generics, _bounds, items) ->
let items =
List.filter
~f:(fun { attributes; _ } -> not (should_skip attributes))
Expand Down Expand Up @@ -1510,14 +1521,14 @@ and c_item_unwrapped ~ident ~drop_body (item : Thir.item) : item list =
let attrs = c_item_attrs item.attributes in
{ span = Span.of_thir item.span; v; ident; attrs })
items
| Impl { unsafety = Unsafe; _ } -> unsafe_block [ item.span ]
| Impl { safety = Unsafe; _ } -> unsafe_block [ item.span ]
| Impl
{
of_trait = Some of_trait;
generics;
self_ty;
items;
unsafety = Normal;
safety = Safe;
parent_bounds;
_;
} ->
Expand Down
3 changes: 3 additions & 0 deletions frontend/exporter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ tracing.workspace = true
paste = "1.0.11"
extension-traits = "1.0.1"
lazy_static = "1.4.0"

[features]
extract_names_mode = []
8 changes: 6 additions & 2 deletions frontend/exporter/src/sinto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,12 @@ impl<S, D, T: SInto<S, D>> SInto<S, Option<D>> for Option<T> {
}
impl<S, D, T: SInto<S, D>> SInto<S, D> for Box<T> {
fn sinto(&self, s: &S) -> D {
let box x = self;
x.sinto(s)
(**self).sinto(s)
}
}
impl<S, D, T: SInto<S, D>> SInto<S, D> for &T {
fn sinto(&self, s: &S) -> D {
(**self).sinto(s)
}
}
impl<S, D: Clone, T: SInto<S, D>> SInto<S, Vec<D>> for [T] {
Expand Down
15 changes: 5 additions & 10 deletions frontend/exporter/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub(crate) mod search_clause {
s: &S,
) -> Vec<(
AssocItem,
EarlyBinder<Vec<(usize, PolyTraitPredicate<'tcx>)>>,
EarlyBinder<'tcx, Vec<(usize, PolyTraitPredicate<'tcx>)>>,
)> {
let tcx = s.base().tcx;
tcx.associated_items(self.def_id())
Expand Down Expand Up @@ -201,12 +201,7 @@ pub(crate) mod search_clause {
param_env: rustc_middle::ty::ParamEnv<'tcx>,
) -> Option<Path<'tcx>> {
let tcx = s.base().tcx;
if predicate_equality(
self.to_predicate(tcx),
target.to_predicate(tcx),
param_env,
s,
) {
if predicate_equality(self.upcast(tcx), target.upcast(tcx), param_env, s) {
return Some(vec![]);
}

Expand Down Expand Up @@ -336,7 +331,7 @@ impl<'tcx> IntoImplExpr<'tcx> for rustc_middle::ty::PolyTraitRef<'tcx> {
let Some((apred, path)) = predicates.into_iter().find_map(|apred| {
apred
.predicate
.to_opt_poly_trait_pred()
.as_trait_clause()
.map(|poly_trait_predicate| poly_trait_predicate)
.and_then(|poly_trait_predicate| {
poly_trait_predicate.path_to(s, self.clone(), param_env)
Expand All @@ -350,7 +345,7 @@ impl<'tcx> IntoImplExpr<'tcx> for rustc_middle::ty::PolyTraitRef<'tcx> {
use rustc_middle::ty::ToPolyTraitRef;
let r#trait = apred
.predicate
.to_opt_poly_trait_pred()
.as_trait_clause()
.s_unwrap(s)
.to_poly_trait_ref()
.sinto(s);
Expand Down Expand Up @@ -406,7 +401,7 @@ pub fn super_clause_to_clause_and_impl_expr<'tcx, S: UnderOwnerState<'tcx>>(
let new_clause = clause.instantiate_supertrait(tcx, &impl_trait_ref);
let impl_expr = new_clause
.as_predicate()
.to_opt_poly_trait_pred()?
.as_trait_clause()?
.impl_expr(s, s.param_env());
let mut new_clause_no_binder = new_clause.sinto(s);
new_clause_no_binder.id = original_predicate_id;
Expand Down
65 changes: 39 additions & 26 deletions frontend/exporter/src/types/copied.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub struct Decorated<T> {
pub enum UnOp {
Not,
Neg,
PtrMetadata,
}

/// Reflects [`rustc_middle::mir::BinOp`]
Expand All @@ -143,6 +144,9 @@ pub enum BinOp {
rustc_middle::mir::BinOp::Mul | rustc_middle::mir::BinOp::MulUnchecked => BinOp::Mul,
)]
Mul,
AddWithOverflow,
SubWithOverflow,
MulWithOverflow,
Div,
Rem,
BitXor,
Expand Down Expand Up @@ -585,7 +589,6 @@ impl VariantDef {
)]
#[args(<'tcx, S: UnderOwnerState<'tcx>>, from: rustc_middle::ty::EarlyParamRegion, state: S as gstate)]
pub struct EarlyParamRegion {
pub def_id: DefId,
pub index: u32,
pub name: Symbol,
}
Expand Down Expand Up @@ -1536,6 +1539,7 @@ pub enum GenericParamDefKind {
pub struct TyGenerics {
pub parent: Option<DefId>,
pub parent_count: usize,
#[from(own_params)]
pub params: Vec<GenericParamDef>,
// pub param_def_id_to_index: FxHashMap<DefId, u32>,
pub has_self: bool,
Expand Down Expand Up @@ -1577,10 +1581,10 @@ impl Alias {
#[tracing::instrument(level = "trace", skip(s))]
fn from<'tcx, S: BaseState<'tcx> + HasOwnerId>(
s: &S,
alias_kind: &rustc_type_ir::AliasKind,
alias_kind: &rustc_type_ir::AliasTyKind,
alias_ty: &rustc_middle::ty::AliasTy<'tcx>,
) -> Self {
use rustc_type_ir::AliasKind as RustAliasKind;
use rustc_type_ir::AliasTyKind as RustAliasKind;
let kind = match alias_kind {
RustAliasKind::Projection => {
use rustc_middle::ty::{Binder, EarlyBinder, TypeVisitableExt};
Expand Down Expand Up @@ -1664,7 +1668,7 @@ pub enum Ty {
},
FROM_TYPE::Closure (_defid, generics) => {
let sig = generics.as_closure().sig();
let sig = state.base().tcx.signature_unclosure(sig, rustc_hir::Unsafety::Normal);
let sig = state.base().tcx.signature_unclosure(sig, rustc_hir::Safety::Safe);
arrow_of_sig(&sig, state)
},
)]
Expand Down Expand Up @@ -1985,15 +1989,15 @@ pub struct Arm {
attributes: Vec<Attribute>,
}

/// Reflects [`rustc_hir::Unsafety`]
/// Reflects [`rustc_hir::Safety`]
#[derive(AdtInto)]
#[args(<S>, from: rustc_hir::Unsafety, state: S as _s)]
#[args(<S>, from: rustc_hir::Safety, state: S as _s)]
#[derive(
Clone, Debug, Serialize, Deserialize, JsonSchema, Hash, PartialEq, Eq, PartialOrd, Ord,
)]
pub enum Unsafety {
pub enum Safety {
Unsafe,
Normal,
Safe,
}

/// Reflects [`rustc_middle::ty::adjustment::PointerCoercion`]
Expand All @@ -2003,7 +2007,7 @@ pub enum Unsafety {
pub enum PointerCoercion {
ReifyFnPointer,
UnsafeFnPointer,
ClosureFnPointer(Unsafety),
ClosureFnPointer(Safety),
MutToConstPointer,
ArrayToPointer,
Unsize,
Expand Down Expand Up @@ -2586,7 +2590,7 @@ pub struct TyFnSig {
#[value(self.output().sinto(s))]
pub output: Ty,
pub c_variadic: bool,
pub unsafety: Unsafety,
pub safety: Safety,
pub abi: Abi,
}

Expand Down Expand Up @@ -2627,7 +2631,7 @@ pub struct FnSig {
#[derive(AdtInto, Clone, Debug, Serialize, Deserialize, JsonSchema)]
#[args(<'tcx, S: UnderOwnerState<'tcx>>, from: rustc_hir::FnHeader, state: S as tcx)]
pub struct FnHeader {
pub unsafety: Unsafety,
pub safety: Safety,
pub constness: Constness,
pub asyncness: IsAsync,
pub abi: Abi,
Expand Down Expand Up @@ -2868,7 +2872,7 @@ impl<
S,
D: Clone,
T: SInto<S, D> + rustc_middle::ty::TypeFoldable<rustc_middle::ty::TyCtxt<'tcx>>,
> SInto<S, D> for rustc_middle::ty::EarlyBinder<T>
> SInto<S, D> for rustc_middle::ty::EarlyBinder<'tcx, T>
{
fn sinto(&self, s: &S) -> D {
self.clone().instantiate_identity().sinto(s)
Expand All @@ -2880,7 +2884,7 @@ impl<
#[args(<'tcx, S: UnderOwnerState<'tcx> >, from: rustc_hir::Impl<'tcx>, state: S as s)]
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct Impl<Body: IsBody> {
pub unsafety: Unsafety,
pub safety: Safety,
pub polarity: ImplPolarity,
pub defaultness: Defaultness,
pub defaultness_span: Option<Span>,
Expand Down Expand Up @@ -2940,6 +2944,15 @@ pub enum VariantData {
Unit(HirId, GlobalIdent),
}

impl<S> SInto<S, bool> for rustc_ast::ast::Recovered {
fn sinto(&self, _s: &S) -> bool {
match self {
Self::Yes(_) => true,
Self::No => false,
}
}
}

/// Reflects [`rustc_hir::FieldDef`]
#[derive(AdtInto)]
#[args(<'tcx, S: UnderOwnerState<'tcx> >, from: rustc_hir::FieldDef<'tcx>, state: S as s)]
Expand Down Expand Up @@ -3101,7 +3114,7 @@ pub enum ItemKind<Body: IsBody> {
Union(VariantData, Generics<Body>),
Trait(
IsAuto,
Unsafety,
Safety,
Generics<Body>,
GenericBounds,
Vec<TraitItem<Body>>,
Expand Down Expand Up @@ -3282,18 +3295,17 @@ pub struct TraitPredicate {
#[derive(
Clone, Debug, Serialize, Deserialize, JsonSchema, Hash, PartialEq, Eq, PartialOrd, Ord,
)]
pub struct OutlivesPredicate<A, B> {
pub lhs: A,
pub rhs: B,
pub struct OutlivesPredicate<T> {
pub lhs: T,
pub rhs: Region,
}

impl<'tcx, S: UnderOwnerState<'tcx>, A1, A2, B1, B2> SInto<S, OutlivesPredicate<A2, B2>>
for rustc_middle::ty::OutlivesPredicate<A1, B1>
impl<'tcx, S: UnderOwnerState<'tcx>, T, U> SInto<S, OutlivesPredicate<U>>
for rustc_middle::ty::OutlivesPredicate<'tcx, T>
where
A1: SInto<S, A2>,
B1: SInto<S, B2>,
T: SInto<S, U>,
{
fn sinto(&self, s: &S) -> OutlivesPredicate<A2, B2> where {
fn sinto(&self, s: &S) -> OutlivesPredicate<U> where {
OutlivesPredicate {
lhs: self.0.sinto(s),
rhs: self.1.sinto(s),
Expand All @@ -3302,9 +3314,9 @@ where
}

/// Reflects [`rustc_middle::ty::RegionOutlivesPredicate`]
pub type RegionOutlivesPredicate = OutlivesPredicate<Region, Region>;
pub type RegionOutlivesPredicate = OutlivesPredicate<Region>;
/// Reflects [`rustc_middle::ty::TypeOutlivesPredicate`]
pub type TypeOutlivesPredicate = OutlivesPredicate<Ty, Region>;
pub type TypeOutlivesPredicate = OutlivesPredicate<Ty>;

/// Reflects [`rustc_middle::ty::Term`]
#[derive(
Expand Down Expand Up @@ -3349,13 +3361,14 @@ impl<'tcx, S: BaseState<'tcx> + HasOwnerId> SInto<S, ProjectionPredicate>
for rustc_middle::ty::ProjectionPredicate<'tcx>
{
fn sinto(&self, s: &S) -> ProjectionPredicate {
let tcx = s.base().tcx;
let AliasKind::Projection {
impl_expr,
assoc_item,
} = Alias::from(
s,
&rustc_middle::ty::AliasKind::Projection,
&self.projection_ty,
&rustc_middle::ty::AliasTyKind::Projection,
&self.projection_term.expect_ty(tcx),
)
.kind
else {
Expand Down
5 changes: 2 additions & 3 deletions frontend/exporter/src/types/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ pub struct MirFnSig {
pub inputs: Vec<Ty>,
pub output: Ty,
pub c_variadic: bool,
pub unsafety: Unsafety,
pub safety: Safety,
pub abi: Abi,
}

Expand All @@ -816,7 +816,7 @@ impl<'tcx, S: BaseState<'tcx> + HasOwnerId> SInto<S, MirFnSig> for rustc_middle:
inputs,
output,
c_variadic: self.c_variadic,
unsafety: self.unsafety.sinto(s),
safety: self.safety.sinto(s),
abi: self.abi.sinto(s),
}
}
Expand Down Expand Up @@ -928,7 +928,6 @@ pub enum Rvalue {
Len(Place),
Cast(CastKind, Operand, Ty),
BinaryOp(BinOp, (Operand, Operand)),
CheckedBinaryOp(BinOp, (Operand, Operand)),
NullaryOp(NullOp, Ty),
UnaryOp(UnOp, Operand),
Discriminant(Place),
Expand Down
4 changes: 2 additions & 2 deletions frontend/exporter/src/types/mir_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ pub fn get_params_info<'tcx, S: BaseState<'tcx> + HasOwnerId>(
let mut num_trait_type_constraints = 0;

let generics = tcx.generics_of(def_id);
let num_generic_params = generics.params.len();
let num_generic_params = generics.own_params.len();
use rustc_middle::ty::GenericParamDefKind;
for param in &generics.params {
for param in &generics.own_params {
match param.kind {
GenericParamDefKind::Lifetime => num_region_params += 1,
GenericParamDefKind::Type { .. } => num_type_params += 1,
Expand Down
4 changes: 2 additions & 2 deletions frontend/exporter/src/types/new/predicate_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ impl<'tcx, S: UnderOwnerState<'tcx>> IntoPredicateId<'tcx, S> for ty::Predicate<

impl<'tcx, S: UnderOwnerState<'tcx>> IntoPredicateId<'tcx, S> for ty::PolyTraitPredicate<'tcx> {
fn predicate_id(&self, s: &S) -> PredicateId {
use ty::ToPredicate;
let predicate: ty::Predicate<'tcx> = (*self).to_predicate(s.base().tcx);
use ty::Upcast;
let predicate: ty::Predicate<'tcx> = (*self).upcast(s.base().tcx);
predicate.predicate_id(s)
}
}
Expand Down
Loading

0 comments on commit ff74ed2

Please sign in to comment.