Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade rustc #1036

Merged
merged 2 commits into from
Oct 24, 2024
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
1 change: 1 addition & 0 deletions cli/subcommands/src/cargo_hax.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(rustc_private)]
use annotate_snippets::{Level, Renderer};
use clap::Parser;
use colored::Colorize;
Expand Down
4 changes: 2 additions & 2 deletions engine/lib/import_thir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ end) : EXPR = struct
let e' = c_expr arg in
let kind = c_borrow_kind e.span kind in
Borrow { kind; e = e'; witness = W.reference }
| AddressOf { arg; mutability = mut } ->
| RawBorrow { arg; mutability = mut } ->
let e = c_expr arg in
AddressOf
{
Expand Down Expand Up @@ -1763,7 +1763,7 @@ and c_item_unwrapped ~ident ~drop_body (item : Thir.item) : item list =
| Union _ ->
unimplemented ~issue_id:998 [ item.span ] "Union types: not supported"
| ExternCrate _ | Static _ | Macro _ | Mod _ | ForeignMod _ | GlobalAsm _
| OpaqueTy _ | TraitAlias _ ->
| TraitAlias _ ->
mk NotImplementedYet

let import_item ~drop_body (item : Thir.item) :
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
};
default = pkgs.mkShell {
inherit packages inputsFrom LIBCLANG_PATH;
shellHook = ''echo "Commands available: $(ls ${utils}/bin | tr '\n' ' ')"'';
shellHook = ''echo "Commands available: $(ls ${utils}/bin | tr '\n' ' ')" 1>&2'';
};
};
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/exporter/src/constant_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ mod rustc {
borrow_kind: BorrowKind::Shared,
arg: e.into(),
},
MutPtr(e) => ExprKind::AddressOf {
MutPtr(e) => ExprKind::RawBorrow {
mutability: true,
arg: e.into(),
},
Expand Down Expand Up @@ -462,7 +462,7 @@ mod rustc {
impl<'tcx> ConstantExt<'tcx> for ty::Const<'tcx> {
fn eval_constant<S: UnderOwnerState<'tcx>>(&self, s: &S) -> Option<Self> {
let (ty, evaluated) = self
.eval(s.base().tcx, s.param_env(), rustc_span::DUMMY_SP)
.eval_valtree(s.base().tcx, s.param_env(), rustc_span::DUMMY_SP)
.ok()?;
let evaluated = ty::Const::new(s.base().tcx, ty::ConstKind::Value(ty, evaluated));
(&evaluated != self).then_some(evaluated)
Expand Down
8 changes: 0 additions & 8 deletions frontend/exporter/src/rustc_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ impl<'tcx, T: ty::TypeFoldable<ty::TyCtxt<'tcx>>> ty::Binder<'tcx, T> {
}
}

#[tracing::instrument(skip(s))]
pub(crate) fn arrow_of_sig<'tcx, S: UnderOwnerState<'tcx>>(
sig: &ty::PolyFnSig<'tcx>,
s: &S,
) -> TyKind {
TyKind::Arrow(Box::new(sig.sinto(s)))
}

#[tracing::instrument(skip(s))]
pub(crate) fn get_variant_information<'s, S: UnderOwnerState<'s>>(
adt_def: &ty::AdtDef<'s>,
Expand Down
2 changes: 1 addition & 1 deletion frontend/exporter/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ impl ImplInfos {
.impl_trait_ref(did)
.map(|trait_ref| trait_ref.instantiate_identity())
.sinto(s),
clauses: tcx.predicates_defined_on(did).predicates.sinto(s),
clauses: predicates_defined_on(tcx, did).predicates.sinto(s),
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion frontend/exporter/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ mod resolution;
#[cfg(feature = "rustc")]
mod utils;
#[cfg(feature = "rustc")]
pub use utils::{erase_and_norm, implied_predicates, required_predicates, self_predicate};
pub use utils::{
erase_and_norm, implied_predicates, predicates_defined_on, required_predicates, self_predicate,
};

#[cfg(feature = "rustc")]
pub use resolution::PredicateSearcher;
Expand Down
27 changes: 23 additions & 4 deletions frontend/exporter/src/traits/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ use rustc_hir::def::DefKind;
use rustc_middle::ty::*;
use rustc_span::def_id::DefId;

/// Returns a list of type predicates for the definition with ID `def_id`, including inferred
/// lifetime constraints. This is the basic list of predicates we use for essentially all items.
pub fn predicates_defined_on(tcx: TyCtxt<'_>, def_id: DefId) -> GenericPredicates<'_> {
let mut result = tcx.explicit_predicates_of(def_id);
let inferred_outlives = tcx.inferred_outlives_of(def_id);
if !inferred_outlives.is_empty() {
let inferred_outlives_iter = inferred_outlives
.iter()
.map(|(clause, span)| ((*clause).upcast(tcx), *span));
result.predicates = tcx.arena.alloc_from_iter(
result
.predicates
.into_iter()
.copied()
.chain(inferred_outlives_iter),
);
}
result
}

/// The predicates that must hold to mention this item.
pub fn required_predicates<'tcx>(
tcx: TyCtxt<'tcx>,
Expand All @@ -51,14 +71,14 @@ pub fn required_predicates<'tcx>(
| TraitAlias
| TyAlias
| Union => Some(
tcx.predicates_defined_on(def_id)
predicates_defined_on(tcx, def_id)
.predicates
.iter()
.map(|(clause, _span)| *clause),
),
// We consider all predicates on traits to be outputs
Trait => None,
// `predicates_defined_on ICEs on other def kinds.
// `predicates_defined_on` ICEs on other def kinds.
_ => None,
}
.into_iter()
Expand All @@ -85,8 +105,7 @@ pub fn implied_predicates<'tcx>(
use DefKind::*;
match tcx.def_kind(def_id) {
// We consider all predicates on traits to be outputs
Trait => tcx
.predicates_defined_on(def_id)
Trait => predicates_defined_on(tcx, def_id)
.predicates
.iter()
.map(|(clause, _span)| *clause)
Expand Down
28 changes: 14 additions & 14 deletions frontend/exporter/src/types/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,7 @@ pub struct Impl<Body: IsBody> {
let trait_did = tcx.trait_id_of_impl(owner_id);
if let Some(trait_did) = trait_did {
tcx.explicit_super_predicates_of(trait_did)
.predicates
.iter()
.copied()
.iter_identity_copied()
.filter_map(|(clause, span)| super_clause_to_clause_and_impl_expr(s, owner_id, clause, span))
.collect::<Vec<_>>()
} else {
Expand Down Expand Up @@ -665,7 +663,6 @@ pub enum ItemKind<Body: IsBody> {
Ty,
Generics<Body>,
),
OpaqueTy(OpaqueTy<Body>),
Enum(
EnumDef<Body>,
Generics<Body>,
Expand Down Expand Up @@ -768,7 +765,7 @@ impl<'a, 'tcx, S: UnderOwnerState<'tcx>, Body: IsBody> SInto<S, Vec<Item<Body>>>
#[derive(Clone, Debug, JsonSchema)]
#[derive_group(Serializers)]
pub enum ForeignItemKind<Body: IsBody> {
Fn(FnDecl, Vec<Ident>, Generics<Body>, Safety),
Fn(FnSig, Vec<Ident>, Generics<Body>),
Static(Ty, Mutability, Safety),
Type,
}
Expand Down Expand Up @@ -803,7 +800,6 @@ pub struct OpaqueTy<Body: IsBody> {
pub generics: Generics<Body>,
pub bounds: GenericBounds,
pub origin: OpaqueTyOrigin,
pub in_trait: bool,
}

/// Reflects [`hir::GenericBounds`]
Expand All @@ -825,10 +821,7 @@ fn region_bounds_at_current_owner<'tcx, S: UnderOwnerState<'tcx>>(s: &S) -> Gene
hir::Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Type(..),
..
}) | hir::Node::Item(hir::Item {
kind: hir::ItemKind::OpaqueTy(hir::OpaqueTy { .. }),
..
})
}) | hir::Node::OpaqueTy(..),
)
} else {
false
Expand All @@ -841,7 +834,7 @@ fn region_bounds_at_current_owner<'tcx, S: UnderOwnerState<'tcx>>(s: &S) -> Gene
.iter()
.collect()
} else {
tcx.predicates_defined_on(s.owner_id())
predicates_defined_on(tcx, s.owner_id())
.predicates
.iter()
.map(|(x, _span)| x)
Expand All @@ -864,9 +857,16 @@ impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, GenericBounds> for hir::GenericBou
#[derive(Clone, Debug, JsonSchema)]
#[derive_group(Serializers)]
pub enum OpaqueTyOrigin {
FnReturn(GlobalIdent),
AsyncFn(GlobalIdent),
TyAlias { in_assoc_ty: bool },
FnReturn {
parent: GlobalIdent,
},
AsyncFn {
parent: GlobalIdent,
},
TyAlias {
parent: GlobalIdent,
in_assoc_ty: bool,
},
}

/// Reflects [`rustc_ast::tokenstream::TokenStream`] as a plain
Expand Down
18 changes: 13 additions & 5 deletions frontend/exporter/src/types/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ fn get_function_from_operand<'tcx, S: UnderOwnerState<'tcx> + HasMir<'tcx>>(
trace!("type: {:?}", ty);
trace!("type kind: {:?}", ty.kind());
let sig = match ty.kind() {
rustc_middle::ty::TyKind::FnPtr(sig) => sig,
rustc_middle::ty::TyKind::FnPtr(sig, ..) => sig,
_ => unreachable!(),
};
trace!("FnPtr: {:?}", sig);
Expand Down Expand Up @@ -996,12 +996,11 @@ pub enum AggregateKind {

#[derive_group(Serializers)]
#[derive(AdtInto, Clone, Debug, JsonSchema)]
#[args(<'tcx, S: UnderOwnerState<'tcx> + HasMir<'tcx>>, from: rustc_middle::mir::CastKind, state: S as s)]
#[args(<'tcx, S>, from: rustc_middle::mir::CastKind, state: S as _s)]
pub enum CastKind {
PointerExposeProvenance,
PointerWithExposedProvenance,
PointerCoercion(PointerCoercion),
DynStar,
PointerCoercion(PointerCoercion, CoercionSource),
IntToInt,
FloatToInt,
FloatToFloat,
Expand All @@ -1011,6 +1010,14 @@ pub enum CastKind {
Transmute,
}

#[derive_group(Serializers)]
#[derive(AdtInto, Clone, Debug, JsonSchema)]
#[args(<'tcx, S>, from: rustc_middle::mir::CoercionSource, state: S as _s)]
pub enum CoercionSource {
AsCast,
Implicit,
}

#[derive_group(Serializers)]
#[derive(AdtInto, Clone, Debug, JsonSchema)]
#[args(<'tcx, S: UnderOwnerState<'tcx> + HasMir<'tcx>>, from: rustc_middle::mir::NullOp<'tcx>, state: S as s)]
Expand All @@ -1035,7 +1042,7 @@ pub enum Rvalue {
Repeat(Operand, ConstantExpr),
Ref(Region, BorrowKind, Place),
ThreadLocalRef(DefId),
AddressOf(Mutability, Place),
RawPtr(Mutability, Place),
Len(Place),
Cast(CastKind, Operand, Ty),
BinaryOp(BinOp, (Operand, Operand)),
Expand Down Expand Up @@ -1129,6 +1136,7 @@ pub enum ScopeData {
Arguments,
Destruction,
IfThen,
IfThenRescope,
Remainder(FirstStatementIndex),
}

Expand Down
7 changes: 5 additions & 2 deletions frontend/exporter/src/types/new/full_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ pub enum FullDefKind {
LifetimeParam,
/// A use of `global_asm!`.
GlobalAsm,
/// A synthetic coroutine body created by the lowering of a coroutine-closure, such as an async
/// closure.
SyntheticCoroutineBody,
}

impl FullDef {
Expand Down Expand Up @@ -425,6 +428,7 @@ fn get_def_visibility<'tcx>(tcx: ty::TyCtxt<'tcx>, def_id: RDefId) -> Option<boo
| InlineConst
| LifetimeParam
| OpaqueTy
| SyntheticCoroutineBody
| TyParam => None,
}
}
Expand Down Expand Up @@ -473,8 +477,7 @@ fn get_generic_predicates<'tcx, S: UnderOwnerState<'tcx>>(
s: &S,
def_id: RDefId,
) -> GenericPredicates {
// We use `predicates_defined_on` to skip the implied `Self` clause.
let predicates = s.base().tcx.predicates_defined_on(def_id);
let predicates = predicates_defined_on(s.base().tcx, def_id);
let pred_list = normalize_trait_clauses(s, predicates.predicates);
GenericPredicates {
parent: predicates.parent.sinto(s),
Expand Down
2 changes: 1 addition & 1 deletion frontend/exporter/src/types/thir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ pub enum ExprKind {
borrow_kind: BorrowKind,
arg: Expr,
},
AddressOf {
RawBorrow {
mutability: Mutability,
arg: Expr,
},
Expand Down
Loading
Loading