Skip to content

Commit

Permalink
Merge pull request #687 from Nadrieril/update-rustc
Browse files Browse the repository at this point in the history
Bump rustc version
  • Loading branch information
W95Psp authored May 22, 2024
2 parents 19d23b2 + 7bdba90 commit bdd1233
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 165 deletions.
3 changes: 2 additions & 1 deletion cli/driver/src/callbacks_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ impl<'a> Callbacks for CallbacksWrapper<'a> {
}
fn after_analysis<'tcx>(
&mut self,
early_handler: &rustc_session::EarlyErrorHandler,
compiler: &interface::Compiler,
queries: &'tcx Queries<'tcx>,
) -> Compilation {
self.sub.after_analysis(compiler, queries)
self.sub.after_analysis(early_handler, compiler, queries)
}
}
2 changes: 1 addition & 1 deletion engine/hax-engine.opam
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ build: [
dev-repo: "git+https://github.com/hacspec/hax.git"
depexts: [
["nodejs"] {}
]
]
4 changes: 2 additions & 2 deletions engine/lib/import_thir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ end) : EXPR = struct
(U.call Rust_primitives__hax__never_to_any [ c_expr source ] span typ)
.e
(* TODO: this is incorrect (NeverToAny) *)
| Pointer { cast; source } -> c_pointer e typ span cast source
| PointerCoercion { cast; source } -> c_pointer e typ span cast source
| Loop { body } ->
let body = c_expr body in
Loop
Expand Down Expand Up @@ -907,7 +907,7 @@ end) : EXPR = struct
(* ^ [%show: expr] source)) *)
| _ ->
unimplemented [ e.span ]
("Pointer, with [cast] being " ^ [%show: Thir.pointer_cast] cast)
("Pointer, with [cast] being " ^ [%show: Thir.pointer_coercion] cast)

and c_ty (span : Thir.span) (ty : Thir.ty) : ty =
match ty with
Expand Down
51 changes: 16 additions & 35 deletions frontend/exporter/src/constant_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,14 @@ pub(crate) fn is_anon_const<'tcx>(
fn trait_const_to_constant_expr_kind<'tcx, S: BaseState<'tcx> + HasOwnerId>(
s: &S,
_const_def_id: rustc_hir::def_id::DefId,
substs: rustc_middle::ty::SubstsRef<'tcx>,
generics: rustc_middle::ty::GenericArgsRef<'tcx>,
assoc: &rustc_middle::ty::AssocItem,
) -> ConstantExprKind {
assert!(assoc.trait_item_def_id.is_some());
let name = assoc.name.to_string();

// Retrieve the trait information
let impl_expr = get_trait_info(s, substs, assoc);
let impl_expr = get_trait_info(s, generics, assoc);

ConstantExprKind::TraitConst { impl_expr, name }
}
Expand Down Expand Up @@ -356,19 +356,18 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug {
let cv = if let Some(assoc) = s.base().tcx.opt_associated_item(ucv.def) {
if assoc.trait_item_def_id.is_some() {
// This must be a trait declaration constant
trait_const_to_constant_expr_kind(s, ucv.def, ucv.substs, &assoc)
trait_const_to_constant_expr_kind(s, ucv.def, ucv.args, &assoc)
} else {
// Constant appearing in an inherent impl block.

// Solve the trait obligations
let parent_def_id = tcx.parent(ucv.def);
let param_env = s.param_env();
let trait_refs =
solve_item_traits(s, param_env, parent_def_id, ucv.substs, None);
let trait_refs = solve_item_traits(s, param_env, parent_def_id, ucv.args, None);

// Convert
let id = ucv.def.sinto(s);
let generics = ucv.substs.sinto(s);
let generics = ucv.args.sinto(s);
ConstantExprKind::GlobalName {
id,
generics,
Expand All @@ -377,7 +376,7 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug {
}
} else {
// Top-level constant.
assert!(ucv.substs.is_empty(), "top-level constant has generics?");
assert!(ucv.args.is_empty(), "top-level constant has generics?");
let id = ucv.def.sinto(s);
ConstantExprKind::GlobalName {
id,
Expand Down Expand Up @@ -449,7 +448,7 @@ pub(crate) fn valtree_to_constant_expr<'tcx, S: UnderOwnerState<'tcx>>(
(ty::ValTree::Branch(_), ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) => {
let contents: rustc_middle::ty::DestructuredConst = s
.base().tcx
.destructure_const(s.base().tcx.mk_const(valtree, ty));
.destructure_const(ty::Const::new_value(s.base().tcx, valtree, ty));
let fields = contents.fields.iter().copied();
match ty.kind() {
ty::Array(_, _) => ConstantExprKind::Array {
Expand Down Expand Up @@ -499,23 +498,10 @@ pub(crate) fn const_value_reference_to_constant_expr<'tcx, S: UnderOwnerState<'t
val: rustc_middle::mir::interpret::ConstValue<'tcx>,
span: rustc_span::Span,
) -> ConstantExpr {
use rustc_middle::mir::interpret;
use rustc_middle::ty;

let tcx = s.base().tcx;

// We use [try_destructure_mir_constant] to destructure the constant
let param_env = s.param_env();
// We have to clone some values: it is a bit annoying, but I don't
// manage to get the lifetimes working otherwise...
let cvalue = rustc_middle::mir::ConstantKind::Val(val, ty);
let param_env_and_const = rustc_middle::ty::ParamEnvAnd {
param_env,
value: cvalue,
};

let dc = tcx
.try_destructure_mir_constant(param_env_and_const)
.try_destructure_mir_constant_for_diagnostics((val, ty))
.s_unwrap(s);

// Iterate over the fields, which should be values
Expand All @@ -530,19 +516,14 @@ pub(crate) fn const_value_reference_to_constant_expr<'tcx, S: UnderOwnerState<'t
}
};

// The fields should be of the variant: [ConstantKind::Value]
let fields: Vec<(ty::Ty, interpret::ConstValue)> = dc
.fields
.iter()
.map(|f| (f.ty(), f.try_to_value(tcx).s_unwrap(s)))
.collect();

// Below: we are mutually recursive with [const_value_to_constant_expr],
// which takes a [ConstantKind] as input (see `cvalue` above), but it should be
// which takes a [ConstantKind] as input, but it should be
// ok because we call it on a strictly smaller value.
let fields: Vec<ConstantExpr> = fields
.into_iter()
.map(|(ty, f)| const_value_to_constant_expr(s, ty, f, span))
let fields: Vec<ConstantExpr> = dc
.fields
.iter()
.copied()
.map(|(val, ty)| const_value_to_constant_expr(s, ty, val, span))
.collect();
(ConstantExprKind::Tuple { fields }).decorate(hax_ty, span.sinto(s))
}
Expand Down Expand Up @@ -577,9 +558,9 @@ pub fn const_value_to_constant_expr<'tcx, S: UnderOwnerState<'tcx>>(
let cv = match &hty {
Ty::Tuple(tys) if tys.is_empty() => ConstantExprKind::Tuple { fields: Vec::new() },
Ty::Arrow(_) => match ty.kind() {
rustc_middle::ty::TyKind::FnDef(def_id, substs) => {
rustc_middle::ty::TyKind::FnDef(def_id, args) => {
let (def_id, generics, generics_impls, method_impl) =
get_function_from_def_id_and_substs(s, *def_id, substs);
get_function_from_def_id_and_generics(s, *def_id, args);

ConstantExprKind::FnPtr {
def_id,
Expand Down
8 changes: 4 additions & 4 deletions frontend/exporter/src/rustc_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ impl<'tcx, T: ty::TypeFoldable<ty::TyCtxt<'tcx>>> ty::Binder<'tcx, T> {
fn subst(
self,
tcx: ty::TyCtxt<'tcx>,
substs: &[ty::subst::GenericArg<'tcx>],
generics: &[ty::GenericArg<'tcx>],
) -> ty::Binder<'tcx, T> {
self.rebind(ty::EarlyBinder::bind(self.clone().skip_binder()).subst(tcx, substs))
self.rebind(ty::EarlyBinder::bind(self.clone().skip_binder()).instantiate(tcx, generics))
}
}

Expand Down Expand Up @@ -95,11 +95,11 @@ impl<'tcx> ty::TyCtxt<'tcx> {
pub fn poly_trait_ref<'tcx, S: UnderOwnerState<'tcx>>(
s: &S,
assoc: &ty::AssocItem,
substs: ty::SubstsRef<'tcx>,
generics: ty::GenericArgsRef<'tcx>,
) -> Option<ty::PolyTraitRef<'tcx>> {
let tcx = s.base().tcx;
let r#trait = tcx.trait_of_item(assoc.def_id)?;
Some(ty::Binder::dummy(ty::TraitRef::new(tcx, r#trait, substs)))
Some(ty::Binder::dummy(ty::TraitRef::new(tcx, r#trait, generics)))
}

#[tracing::instrument(skip(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 @@ -248,7 +248,7 @@ impl ImplInfos {

Self {
generics: tcx.generics_of(did).sinto(s),
typ: tcx.type_of(did).subst_identity().sinto(s),
typ: tcx.type_of(did).instantiate_identity().sinto(s),
trait_ref: tcx.impl_trait_ref(did).sinto(s),
clauses: tcx.predicates_defined_on(did).predicates.sinto(s),
}
Expand Down
26 changes: 11 additions & 15 deletions frontend/exporter/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ pub(crate) mod search_clause {
fn predicates_to_poly_trait_predicates<'tcx>(
tcx: TyCtxt<'tcx>,
predicates: impl Iterator<Item = Predicate<'tcx>>,
substs: subst::SubstsRef<'tcx>,
generics: GenericArgsRef<'tcx>,
) -> impl Iterator<Item = PolyTraitPredicate<'tcx>> {
predicates
.map(move |pred| pred.kind().subst(tcx, substs))
.map(move |pred| pred.kind().subst(tcx, generics))
.filter_map(|pred| pred.as_poly_trait_predicate())
}

Expand Down Expand Up @@ -160,20 +160,16 @@ pub(crate) mod search_clause {
.predicates_defined_on_or_above(self.def_id())
.into_iter()
.map(|apred| apred.predicate);
predicates_to_poly_trait_predicates(
tcx,
predicates,
self.skip_binder().trait_ref.substs,
)
.enumerate()
.collect()
predicates_to_poly_trait_predicates(tcx, predicates, self.skip_binder().trait_ref.args)
.enumerate()
.collect()
}
fn associated_items_trait_predicates(
self,
s: &S,
) -> Vec<(
AssocItem,
subst::EarlyBinder<Vec<(usize, PolyTraitPredicate<'tcx>)>>,
EarlyBinder<Vec<(usize, PolyTraitPredicate<'tcx>)>>,
)> {
let tcx = s.base().tcx;
tcx.associated_items(self.def_id())
Expand All @@ -185,7 +181,7 @@ pub(crate) mod search_clause {
predicates_to_poly_trait_predicates(
tcx,
clauses.into_iter().map(|clause| clause.as_predicate()),
self.skip_binder().trait_ref.substs,
self.skip_binder().trait_ref.args,
)
.enumerate()
.collect()
Expand Down Expand Up @@ -321,11 +317,11 @@ impl<'tcx> IntoImplExpr<'tcx> for rustc_middle::ty::PolyTraitRef<'tcx> {
match select_trait_candidate(s, param_env, *self) {
ImplSource::UserDefined(ImplSourceUserDefinedData {
impl_def_id,
substs,
args: generics,
nested,
}) => ImplExprAtom::Concrete {
id: impl_def_id.sinto(s),
generics: substs.sinto(s),
generics: generics.sinto(s),
}
.with_args(impl_exprs(s, &nested), trait_ref),
ImplSource::Param(nested, _constness) => {
Expand Down Expand Up @@ -398,7 +394,7 @@ pub fn super_clause_to_clause_and_impl_expr<'tcx, S: UnderOwnerState<'tcx>>(
let tcx = s.base().tcx;
let impl_trait_ref = tcx
.impl_trait_ref(impl_did)
.map(|binder| rustc_middle::ty::Binder::dummy(binder.subst_identity()))?;
.map(|binder| rustc_middle::ty::Binder::dummy(binder.instantiate_identity()))?;
let original_predicate_id = {
// We don't want the id of the substituted clause id, but the
// original clause id (with, i.e., `Self`)
Expand Down Expand Up @@ -470,7 +466,7 @@ pub mod copy_paste_from_rustc {
let obligation_cause = ObligationCause::dummy();
let obligation = Obligation::new(tcx, obligation_cause, param_env, trait_ref);

let selection = match selcx.select(&obligation) {
let selection = match selcx.poly_select(&obligation) {
Ok(Some(selection)) => selection,
Ok(None) => return Err(CodegenObligationError::Ambiguity),
Err(Unimplemented) => return Err(CodegenObligationError::Unimplemented),
Expand Down
Loading

0 comments on commit bdd1233

Please sign in to comment.