Skip to content

Merge frontend improvements #1559

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

Open
wants to merge 60 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
6cee56a
Update rustc
Nadrieril Jul 1, 2025
1ca3abe
Don't overuse the `tcx` arena
Nadrieril Jul 1, 2025
7dac848
Add an explicit `Self: Trait` clause to trait assoc items
Nadrieril Jul 2, 2025
358c68c
Merge branch 'explicit-self-clause' into dev
Nadrieril Jul 2, 2025
6471ff2
Don't add `Drop` clauses to some more marker traits
Nadrieril Jul 3, 2025
ae0f212
Normalize projections before translating them
Nadrieril Jul 3, 2025
8c92b50
Resolve assoc ty predicates in builtin `ImplExpr`s
Nadrieril Jul 3, 2025
7382371
Merge branch 'fix-builtin-impl-exprs' into dev
Nadrieril Jul 3, 2025
407c121
Don't use `SInto` derive for `FullDefKind`
Nadrieril Jun 20, 2025
6ed2039
Don't add drop bounds for closure fake type params
Nadrieril Jul 7, 2025
904ed63
Make `Drop` bounds on traits be implied instead of required
Nadrieril Jul 7, 2025
55ef02f
Don't add `Drop` bounds to the `Tuple` marker trait
Nadrieril Jul 7, 2025
9981e4e
Provide resolved `ImplExpr`s for virtual trait impls
Nadrieril Jul 7, 2025
0d9d42a
Merge branch 'fix-drops' into dev
Nadrieril Jul 7, 2025
b955547
Update rustc again
Nadrieril Jul 9, 2025
6e6d25d
Merge branch 'update-rustc' into dev
Nadrieril Jul 9, 2025
c73c480
Add variance information to generic parameters
Nadrieril Jul 9, 2025
855ed3e
Merge branch 'variance' into dev
Nadrieril Jul 9, 2025
e2d69df
Cleanup the creation of `State` structs
Nadrieril Jul 8, 2025
8c3e3a7
Remove `HasXXXSetter` traits
Nadrieril Jul 8, 2025
78946d1
Reorder `State` fields
Nadrieril Jul 10, 2025
29ba2d6
Track the type of surrounding expression in THIR translation
Nadrieril Jul 10, 2025
ddae0ab
Add metadata information to unsize coercions
Nadrieril Jul 10, 2025
d6d523d
Merge branch 'unsize-metadata' into dev
Nadrieril Jul 10, 2025
88346de
Never construct `ItemRef`s by hand
Nadrieril Jul 10, 2025
25795fa
resolution: let `PredicateSearcher` index clauses itself
Nadrieril Jul 10, 2025
fac3d69
Resolve `dyn` projection predicates
Nadrieril Jul 10, 2025
d30960b
Merge branch 'resolve-dyn' into dev
Nadrieril Jul 11, 2025
3972a6c
Fix `import_thir` after the `dyn` PR
Nadrieril Jul 11, 2025
9641a29
full_def: inline `get_ctor_contents`
Nadrieril Jul 8, 2025
a6be3d1
full_def: merge the three ADT types
Nadrieril Jul 8, 2025
00f4cf2
full_def: merge `AdtDef` into `FullDefKind`
Nadrieril Jul 8, 2025
83cc3e4
full_def: merge the various kinds of constant items
Nadrieril Jul 8, 2025
d4762a3
full_def: remove `parent` fields
Nadrieril Jul 10, 2025
2d7e20f
full_def: move heavy rustc logic to `rustc_utils`
Nadrieril Jul 10, 2025
9d12de0
full_def: add helper
Nadrieril Jul 10, 2025
e91aedb
full_def: better way to translate type aliases
Nadrieril Jul 10, 2025
32a73b4
Merge branch 'fulldef-cleanup' into dev
Nadrieril Jul 17, 2025
e837a1a
full_def: provide virtual impl for `Drop`
Nadrieril Jul 18, 2025
f3a3e1c
Tweak the representation of special `ImplExpr`s for `Drop`
Nadrieril Jul 18, 2025
700932c
Merge branch 'improve-drop-impl' into dev
Nadrieril Jul 21, 2025
773fc14
Fix equality on `Ty`
Nadrieril Jul 19, 2025
0af2fc5
full_def: don't store entire `FullDef`s in assoc items
Nadrieril Jul 17, 2025
f98a7c8
Implement `SInto` for `AssocItem` manually
Nadrieril Jul 11, 2025
60d847f
Allow recovering the `ty::GenericArgs` from an `ItemRef`
Nadrieril Jul 10, 2025
7bfa499
full_def: allow instantiating `FullDef` with generics
Nadrieril Jul 11, 2025
040d9a9
full_def: store a self-reference in `FullDef`
Nadrieril Jul 18, 2025
7d1c872
full_def: track parent item with appropriate args
Nadrieril Jul 19, 2025
b2d6177
full_def: cache instantiated translation
Nadrieril Jul 18, 2025
edbffed
Translate arguments of implemented item in `AssocItem`
Nadrieril Jul 18, 2025
f46482c
Normalize after substituting
Nadrieril Jul 19, 2025
97c713f
ItemRef: add erasure capabilities
Nadrieril Jul 21, 2025
8eded27
Merge branch 'mono-fulldef' into dev
Nadrieril Jul 21, 2025
6776d63
Merge remote-tracking branch 'upstream/main' into upstream-pr
Nadrieril Jul 22, 2025
60c354f
Commit test outputs
Nadrieril Jul 22, 2025
2864c04
Merge remote-tracking branch 'origin/main' into nadrieril-upstream-pr
W95Psp Jul 28, 2025
b2a2a29
fix(rengine): respect env var `HAX_ENGINE_BINARY`
W95Psp Jul 28, 2025
4952add
chore: refresh tests
W95Psp Jul 28, 2025
f68b3ab
chore: update rustc-coverage-tests
W95Psp Jul 28, 2025
108105f
fix: typo
Nadrieril Jul 29, 2025
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
30 changes: 17 additions & 13 deletions engine/lib/import_thir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@ end) : EXPR = struct
{
item =
{
value = { def_id = id; generic_args; impl_exprs; in_trait };
value =
{ def_id = id; generic_args; impl_exprs; in_trait; _ };
_;
};
_;
Expand Down Expand Up @@ -1001,7 +1002,7 @@ end) : EXPR = struct
| ClosureFnPointer Safe | ReifyFnPointer ->
(* we have arrow types, we do not distinguish between top-level functions and closures *)
(c_expr source).e
| Unsize ->
| Unsize _ ->
(* https://doc.rust-lang.org/std/marker/trait.Unsize.html *)
(U.call Rust_primitives__unsize [ c_expr source ] span typ).e
(* let source = c_expr source in *)
Expand Down Expand Up @@ -1090,21 +1091,25 @@ end) : EXPR = struct
| Error ->
assertion_failure [ span ]
"got type `Error`: Rust compilation probably failed."
| Dynamic (predicates, _region, Dyn) -> (
| Dynamic (_, predicates, _region) -> (
let goals, non_traits =
List.partition_map
~f:(fun pred ->
match pred.value with
| Trait { args; def_id } ->
~f:(fun ((clause, _span) : Types.clause * _) ->
match clause.kind.value with
| Trait { trait_ref; _ } ->
let goal : dyn_trait_goal =
{
trait = Concrete_ident.of_def_id ~value:false def_id;
non_self_args = List.map ~f:(c_generic_value span) args;
trait =
Concrete_ident.of_def_id ~value:false
trait_ref.value.def_id;
non_self_args =
List.map ~f:(c_generic_value span)
(List.tl_exn trait_ref.value.generic_args);
}
in
First goal
| _ -> Second ())
predicates
predicates.predicates
in
match non_traits with
| [] -> TDyn { witness = W.dyn; goals }
Expand All @@ -1126,7 +1131,7 @@ end) : EXPR = struct

and c_impl_expr (span : Thir.span) (ie : Thir.impl_expr) : impl_expr =
let goal = c_trait_ref span ie.trait.value in
let impl = { kind = c_impl_expr_atom span ie.impl; goal } in
let impl = { kind = c_impl_expr_atom span ie.impl goal; goal } in
match ie.impl with
| Concrete { value = { impl_exprs = []; _ }; _ } -> impl
| Concrete { value = { impl_exprs; _ }; _ } ->
Expand All @@ -1139,7 +1144,7 @@ end) : EXPR = struct
let args = List.map ~f:(c_generic_value span) tr.value.generic_args in
{ trait; args }

and c_impl_expr_atom (span : Thir.span) (ie : Thir.impl_expr_atom) :
and c_impl_expr_atom (span : Thir.span) (ie : Thir.impl_expr_atom) goal :
impl_expr_kind =
let browse_path (item_kind : impl_expr_kind)
(chunk : Thir.impl_expr_path_chunk) =
Expand Down Expand Up @@ -1172,8 +1177,7 @@ end) : EXPR = struct
List.fold ~init ~f:browse_path path
| Dyn -> Dyn
| SelfImpl { path; _ } -> List.fold ~init:Self ~f:browse_path path
| Builtin { trait; _ } -> Builtin (c_trait_ref span trait.value)
| Drop _ -> failwith @@ "impl_expr_atom: Drop"
| Builtin _ -> Builtin goal
| Error str -> failwith @@ "impl_expr_atom: Error " ^ str

and c_generic_value (span : Thir.span) (ty : Thir.generic_arg) : generic_value
Expand Down
64 changes: 42 additions & 22 deletions frontend/exporter/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod module {
def_id::{DefId as RDefId, LocalDefId as RLocalDefId},
hir_id::OwnerId as ROwnerId,
};
use rustc_middle::ty;

mod store {
//! This module helps at store bodies to avoid stealing.
Expand Down Expand Up @@ -97,7 +98,7 @@ mod module {
}
pub use store::*;

pub fn get_thir<'tcx, S: UnderOwnerState<'tcx>>(
pub fn get_thir<'tcx, S: BaseState<'tcx>>(
did: RLocalDefId,
s: &S,
) -> (
Expand All @@ -122,7 +123,11 @@ mod module {
}

pub trait IsBody: Sized + std::fmt::Debug + Clone + 'static {
fn body<'tcx, S: UnderOwnerState<'tcx>>(did: RDefId, s: &S) -> Option<Self>;
fn body<'tcx, S: UnderOwnerState<'tcx>>(
s: &S,
did: RDefId,
instantiate: Option<ty::GenericArgsRef<'tcx>>,
) -> Option<Self>;

/// Reuse a MIR body we already got. Panic if that's impossible.
fn from_mir<'tcx, S: UnderOwnerState<'tcx>>(
Expand All @@ -133,7 +138,7 @@ mod module {
}
}

pub fn make_fn_def<'tcx, Body: IsBody, S: UnderOwnerState<'tcx>>(
pub fn make_fn_def<'tcx, Body: IsBody, S: BaseState<'tcx>>(
fn_sig: &rustc_hir::FnSig,
body_id: &rustc_hir::BodyId,
s: &S,
Expand All @@ -142,11 +147,11 @@ mod module {
let ldid = hir_id.owner.def_id;

let (thir, expr_entrypoint) = get_thir(ldid, s);
let s = &with_owner_id(s.base(), thir.clone(), (), ldid.to_def_id());
let s = &s.with_owner_id(ldid.to_def_id()).with_thir(thir.clone());
FnDef {
params: thir.params.raw.sinto(s),
ret: thir.exprs[expr_entrypoint].ty.sinto(s),
body: Body::body(ldid.to_def_id(), s).s_unwrap(s),
body: Body::body(s, ldid.to_def_id(), None).s_unwrap(s),
sig_span: fn_sig.span.sinto(s),
header: fn_sig.header.sinto(s),
}
Expand All @@ -161,13 +166,17 @@ mod module {
// be local. It is safe to do so, because if we have access to HIR objects,
// it necessarily means we are exploring a local item (we don't have
// access to the HIR of external objects, only their MIR).
Body::body(s.base().tcx.hir_body_owner_def_id(id).to_def_id(), s).s_unwrap(s)
Body::body(s, s.base().tcx.hir_body_owner_def_id(id).to_def_id(), None).s_unwrap(s)
}

mod implementations {
use super::*;
impl IsBody for () {
fn body<'tcx, S: UnderOwnerState<'tcx>>(_did: RDefId, _s: &S) -> Option<Self> {
fn body<'tcx, S: UnderOwnerState<'tcx>>(
_s: &S,
_did: RDefId,
_instantiate: Option<ty::GenericArgsRef<'tcx>>,
) -> Option<Self> {
Some(())
}
fn from_mir<'tcx, S: UnderOwnerState<'tcx>>(
Expand All @@ -178,9 +187,15 @@ mod module {
}
}
impl IsBody for ThirBody {
fn body<'tcx, S: UnderOwnerState<'tcx>>(did: RDefId, s: &S) -> Option<Self> {
fn body<'tcx, S: BaseState<'tcx>>(
s: &S,
did: RDefId,
instantiate: Option<ty::GenericArgsRef<'tcx>>,
) -> Option<Self> {
let did = did.as_local()?;
let (thir, expr) = get_thir(did, s);
assert!(instantiate.is_none(), "monomorphized thir isn't supported");
let s = &s.with_owner_id(did.to_def_id());
Some(if *CORE_EXTRACTION_MODE {
let expr = &thir.exprs[expr];
Decorated {
Expand All @@ -191,36 +206,41 @@ mod module {
span: expr.span.sinto(s),
}
} else {
expr.sinto(&with_owner_id(s.base(), thir, (), did.to_def_id()))
expr.sinto(&s.with_thir(thir))
})
}
}

impl<A: IsBody, B: IsBody> IsBody for (A, B) {
fn body<'tcx, S: UnderOwnerState<'tcx>>(did: RDefId, s: &S) -> Option<Self> {
Some((A::body(did, s)?, B::body(did, s)?))
fn body<'tcx, S: UnderOwnerState<'tcx>>(
s: &S,
did: RDefId,
instantiate: Option<ty::GenericArgsRef<'tcx>>,
) -> Option<Self> {
Some((A::body(s, did, instantiate)?, B::body(s, did, instantiate)?))
}
}

impl<MirKind: IsMirKind + Clone + 'static> IsBody for MirBody<MirKind> {
fn body<'tcx, S: UnderOwnerState<'tcx>>(did: RDefId, s: &S) -> Option<Self> {
MirKind::get_mir(s.base().tcx, did, |body| {
let body = Rc::new(body.clone());
body.sinto(&with_owner_id(s.base(), (), body.clone(), did))
fn body<'tcx, S: UnderOwnerState<'tcx>>(
s: &S,
did: RDefId,
instantiate: Option<ty::GenericArgsRef<'tcx>>,
) -> Option<Self> {
let tcx = s.base().tcx;
let typing_env = s.typing_env();
MirKind::get_mir(tcx, did, |body| {
let body = substitute(tcx, typing_env, instantiate, body.clone());
let body = Rc::new(body);
body.sinto(&s.with_mir(body.clone()))
})
}
fn from_mir<'tcx, S: UnderOwnerState<'tcx>>(
s: &S,
body: rustc_middle::mir::Body<'tcx>,
) -> Option<Self> {
let body = Rc::new(body.clone());
let s = &State {
base: s.base(),
owner_id: s.owner_id(),
mir: body.clone(),
binder: (),
thir: (),
};
let s = &s.with_mir(body.clone());
Some(body.sinto(s))
}
}
Expand Down
14 changes: 12 additions & 2 deletions frontend/exporter/src/id_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::{

/// Unique IDs in a ID table.
#[derive_group(Serializers)]
#[derive(Default, Clone, Debug, JsonSchema, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Default, Clone, Copy, Debug, JsonSchema, Hash, PartialEq, Eq, PartialOrd, Ord)]
#[serde(transparent)]
pub struct Id {
id: u32,
Expand Down Expand Up @@ -88,7 +88,7 @@ impl SupportedType<Value> for ItemRefContents {
}

/// A node is a bundle of an ID with a value.
#[derive(Deserialize, Serialize, Debug, JsonSchema, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Deserialize, Serialize, Debug, JsonSchema, PartialOrd, Ord)]
#[serde(into = "serde_repr::NodeRepr<T>")]
#[serde(try_from = "serde_repr::NodeRepr<T>")]
pub struct Node<T: 'static + SupportedType<Value>> {
Expand All @@ -111,6 +111,12 @@ impl<T: SupportedType<Value> + Hash> Hash for Node<T> {
self.value.as_ref().hash(state);
}
}
impl<T: SupportedType<Value> + Eq> Eq for Node<T> {}
impl<T: SupportedType<Value> + PartialEq> PartialEq for Node<T> {
fn eq(&self, other: &Self) -> bool {
self.value == other.value
}
}

/// Manual implementation of `Clone` that doesn't require a `Clone`
/// bound on `T`.
Expand Down Expand Up @@ -203,6 +209,10 @@ impl<T: Sync + Send + 'static + SupportedType<Value>> Node<T> {
pub fn inner(&self) -> &Arc<T> {
&self.value
}

pub fn id(&self) -> Id {
self.id
}
}

/// Wrapper for a type `T` that creates a bundle containing both a ID
Expand Down
Loading
Loading