Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
53a8b4b
full_def: add some dyn-related information
Nadrieril Jul 24, 2025
1a06fb0
Merge branch 'more-dyn-data' into dev
Nadrieril Jul 25, 2025
56f639f
Add `RawConstantExpr::PtrNoProvenance`
N1ark Jul 26, 2025
ca0315e
Merge pull request #1 from N1ark/ptr-uneval
Nadrieril Aug 1, 2025
9471a9c
Add helper for trait assoc tys to `ItemRef`
Nadrieril Jul 31, 2025
79faad1
Merge branch 'dyn-assoc-tys' into dev
Nadrieril Aug 1, 2025
5050775
fix order problem
ssyram Aug 21, 2025
9eb48c9
improve translation of RerpOptions
firefighterduck Aug 21, 2025
f6ef814
Update frontend/exporter/src/rustc_utils.rs
ssyram Sep 4, 2025
24991a8
Merge pull request #2 from ssyram/main
protz Sep 4, 2025
0c44221
Add a flag to `ItemRef`
Nadrieril Sep 12, 2025
2c2cd79
re-add discriminant type to repr_options
firefighterduck Sep 12, 2025
b02ea22
Merge pull request #3 from firefighterduck/repr_options
Nadrieril Sep 12, 2025
182fa20
Merge remote-tracking branch 'cryspen/main' into dev
Nadrieril Sep 15, 2025
d03edae
Don't add explicit `Self` clause to GATs
Nadrieril Sep 12, 2025
5820a12
Merge branch 'gat' into dev
Nadrieril Sep 16, 2025
822f3e2
AssocFn with vtable_receiver
ssyram Sep 19, 2025
0b51ae9
vtable_receiver -> vtable_sig
ssyram Oct 2, 2025
8616f55
use truncate_to
ssyram Oct 2, 2025
ca11fbb
use `is_vtable_safe_method`
ssyram Oct 2, 2025
0ad425c
comments as suggested
ssyram Oct 2, 2025
589dad0
panic as suggested
ssyram Oct 2, 2025
bff544b
Merge pull request #4 from ssyram/main
Nadrieril Oct 2, 2025
a299767
Format
Nadrieril Oct 2, 2025
68c49ab
Rename
Nadrieril Oct 2, 2025
215c305
Fix
Nadrieril Oct 2, 2025
e7ea93f
Cleanup
Nadrieril Oct 2, 2025
193c439
Merge branch 'fix-vtable_sig' into dev
Nadrieril Oct 2, 2025
b1cfecc
Add a method
Nadrieril Oct 2, 2025
68926eb
Fix
Nadrieril Oct 2, 2025
24d033e
Rename `ty_alias_mode`
Nadrieril Oct 17, 2025
841323a
Let IDEs know about the rustfmt edition to use
Nadrieril Oct 7, 2025
d542692
Normalize `ItemRef`s pointing to implemented trait items
Nadrieril Nov 3, 2025
61fc9b4
Add some `T: Sized` clauses required for type well-formedness
Nadrieril Oct 7, 2025
3f1bd92
The empty tuple has a trivial drop
Nadrieril Nov 8, 2025
9f18c30
Generate fake defids for arrays, slices and tuples
Nadrieril Nov 7, 2025
614fed2
Merge branch 'array-drop' into dev
Nadrieril Nov 8, 2025
bab2a3a
Use `Destruct` instead of `Drop` to carry the `drop_in_place` data
Nadrieril Nov 8, 2025
bee75c6
Regroup built-in impl data handling a bit
Nadrieril Nov 8, 2025
bc9839c
drive-by: add helper
Nadrieril Nov 9, 2025
409de71
full_def: provide evaluated value for constants
Nadrieril Nov 9, 2025
4f2ebfc
Make constant evaluation more lenient
Nadrieril Nov 9, 2025
b7b7eda
Merge branch 'const-eval-tweaks' into dev
Nadrieril Nov 9, 2025
0706e47
Fix closure generics in `FullDef.this()``
Nadrieril Nov 10, 2025
aac4c57
Update rustc
Nadrieril Nov 9, 2025
118c476
Simplify const eval a tiny bit
Nadrieril Nov 9, 2025
d99327f
Update rustc
Nadrieril Nov 9, 2025
2fc82b1
Merge branch 'update-rustc' into dev
Nadrieril Nov 10, 2025
37e2962
Rename "fake builtins" to "synthetic items"
Nadrieril Nov 10, 2025
37baeaf
Merge branch 'main' into merge-upstream
W95Psp Nov 10, 2025
d0a7513
refactor(exporter): move and document `DefId::as_synthetic`
W95Psp Nov 12, 2025
b3e79b5
fix(exporter): sinto `DefId`: rename crate of synthetic items
W95Psp Nov 12, 2025
60ea816
misc(exporter): make `translate_def_id` private
W95Psp Nov 12, 2025
a335aa3
feat(exporter/hir): restore `safety` information
W95Psp Nov 12, 2025
17354ba
feat(exporter/def_id): implement `MacroKinds`
W95Psp Nov 12, 2025
323c116
refactor(exporter): do not use a `if let` guard in `full_def`
W95Psp Nov 12, 2025
c30d50d
feat(exporter): make `synthetic_items` visible without `feature = "ru…
W95Psp Nov 12, 2025
16e7e80
feat(exprter): add option `item_ref_use_concrete_impl`
W95Psp Nov 12, 2025
f97df0c
fix(oengine): fix rustc pin upgrade
W95Psp Nov 12, 2025
4d8589e
chore(rengine): regenerate names
W95Psp Nov 12, 2025
66d7d75
chore: update snapshots
W95Psp Nov 12, 2025
3cbb042
Merge pull request #1 from cryspen/merge-upstream-fixes
Nadrieril Nov 13, 2025
4df7fc3
chore: update rustc-coverage-tests snapshots
W95Psp Nov 13, 2025
334c478
Merge branch 'main' into merge-upstream
W95Psp Nov 13, 2025
a273432
chore: update snapshots
W95Psp Nov 17, 2025
9aa41a4
fix(oengine): tuples of size 1 in F*
W95Psp Nov 18, 2025
97df35a
chore(CHANGELOG)
W95Psp Nov 18, 2025
c4596e7
chore: snapshot updates
W95Psp Nov 18, 2025
c1aade9
Merge branch 'main' into merge-upstream
W95Psp Nov 18, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Changes to the Rust Engine:
lift monadic computations into values) (#1746)

Changes to the frontend:
- Update the pin of rustc (#1765)
- Miscellaneous changes related to Charon (#1765)

Change to cargo-hax:

Expand Down
3 changes: 2 additions & 1 deletion cli/driver/src/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ impl From<ExtractionCallbacks> for hax_frontend_exporter_options::Options {
hax_frontend_exporter_options::Options {
inline_anon_consts: true,
bounds_options: hax_frontend_exporter_options::BoundsOptions {
resolve_drop: false,
resolve_destruct: false,
prune_sized: true,
},
item_ref_use_concrete_impl: false,
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions engine/backends/fstar/fstar_backend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,12 @@ struct
]
in
F.term @@ F.AST.QExists (binders, ([], []), phi)
| App
{
f = { e = GlobalVar (`Projector (`TupleField (_, 1))) };
args = [ arg ];
} ->
pexpr arg
| App
{
f = { e = GlobalVar (`Projector (`TupleField (n, len))) };
Expand Down
15 changes: 11 additions & 4 deletions engine/lib/concrete_ident/thir_simple_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,29 @@ let to_string ~(namespace : View.ModPath.t) :
| Uint U128 -> Some "u128"
| Float F32 -> Some "f32"
| Float F64 -> Some "f64"
| Tuple [] -> Some "unit"
| Tuple { value = { generic_args = []; _ }; _ } -> Some "unit"
| Adt { value = { def_id; generic_args = []; _ }; _ } ->
Option.map ~f:escape (adt def_id)
| _ -> None
in
let apply left right = left ^ "_of_" ^ right in
let rec arity1 (ty : Types.node_for__ty_kind) =
match ty.value with
| Slice sub -> arity1 sub |> Option.map ~f:(apply "slice")
| Slice { value = { generic_args = [ Type sub ]; _ }; _ } ->
arity1 sub |> Option.map ~f:(apply "slice")
| Ref (_, sub, _) -> arity1 sub |> Option.map ~f:(apply "ref")
| Adt { value = { def_id; generic_args = [ Type arg ]; _ }; _ } ->
let* adt = adt def_id in
let* arg = arity1 arg in
Some (apply adt arg)
| Tuple l ->
let* l = List.map ~f:arity0 l |> Option.all in
| Tuple { value = { generic_args; _ }; _ } ->
let* l =
List.map
~f:(fun (arg : Types.generic_arg) ->
match arg with Type ty -> arity0 ty | _ -> None)
generic_args
|> Option.all
in
Some ("tuple_" ^ String.concat ~sep:"_" l)
| _ -> arity0 ty
in
Expand Down
49 changes: 40 additions & 9 deletions engine/lib/import_thir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ let c_borrow_kind span : Thir.borrow_kind -> borrow_kind = function

let c_binding_mode : Thir.by_ref -> binding_mode = function
| No -> ByValue
| Yes true -> ByRef (Mut W.mutable_reference, W.reference)
| Yes false -> ByRef (Shared, W.reference)
| Yes (_, true) -> ByRef (Mut W.mutable_reference, W.reference)
| Yes (_, false) -> ByRef (Shared, W.reference)

let unit_typ : ty = TApp { ident = `TupleType 0; args = [] }

Expand Down Expand Up @@ -663,11 +663,14 @@ end) : EXPR = struct
}
| TupleField { lhs; field } ->
(* TODO: refactor *)
let lhs = c_expr lhs in
let tuple_len =
0
(* todo, lookup type *)
match lhs.typ with
| TApp { ident = `TupleType len; _ } -> len
| _ ->
assertion_failure [ e.span ]
"LHS of tuple field projection is not typed as a tuple."
in
let lhs = c_expr lhs in
let projector =
GlobalVar
(`Projector (`TupleField (Int.of_string field, tuple_len)))
Expand Down Expand Up @@ -906,7 +909,7 @@ end) : EXPR = struct
"constant_lit_to_lit: TraitConst | FnPtr | RawBorrow | Cast | \
Memory"
| Todo _ -> assertion_failure [ span ] "ConstantExpr::Todo"
and constant_lit_to_lit (l : Thir.constant_literal) _span :
and constant_lit_to_lit (l : Thir.constant_literal) span :
Thir.lit_kind * bool =
match l with
| Bool v -> (Bool v, false)
Expand All @@ -922,6 +925,8 @@ end) : EXPR = struct
| None -> (Float (v, Suffixed ty), false))
| Str v -> (Str (v, Cooked), false)
| ByteStr v -> (ByteStr (v, Cooked), false)
| PtrNoProvenance _ ->
assertion_failure [ span ] "constant_lit_to_lit: PtrNoProvenance"
and constant_field_expr ({ field; value } : Thir.constant_field_expr) :
Thir.field_expr =
{ field; value = constant_expr_to_expr value }
Expand Down Expand Up @@ -1080,9 +1085,25 @@ end) : EXPR = struct
TApp { ident; args }
| Foreign _ -> unimplemented ~issue_id:928 [ span ] "Foreign"
| Str -> TStr
| Array (ty, len) ->
| Array item_ref ->
let ty, len =
match item_ref.value.generic_args with
| [ Type ty; Const len ] -> (ty, len)
| _ ->
assertion_failure [ span ]
"Wrong generics for array: expected a type and a constant. See \
synthetic_items in hax frontend."
in
TArray { typ = c_ty span ty; length = c_constant_expr len }
| Slice ty ->
| Slice item_ref ->
let ty =
match item_ref.value.generic_args with
| [ Type ty ] -> ty
| _ ->
assertion_failure [ span ]
"Wrong generics for slice: expected a type. See \
synthetic_items in hax frontend."
in
let ty = c_ty span ty in
TSlice { ty; witness = W.slice }
| RawPtr _ -> TRawPointer { witness = W.raw_pointer }
Expand All @@ -1091,7 +1112,17 @@ end) : EXPR = struct
let mut = c_mutability W.mutable_reference mut in
TRef { witness = W.reference; region = "todo"; typ; mut }
| Never -> U.never_typ
| Tuple types ->
| Tuple item_ref ->
let types =
List.map
~f:(function Types.Type ty -> Some ty | _ -> None)
item_ref.value.generic_args
|> Option.all
|> Option.value_or_thunk ~default:(fun _ ->
assertion_failure [ span ]
"Wrong generics for slice: expected a type. See \
synthetic_items in hax frontend.")
in
let types = List.map ~f:(fun ty -> GType (c_ty span ty)) types in
TApp { ident = `TupleType (List.length types); args = types }
| Alias { kind = Projection { assoc_item = _; impl_expr }; def_id; _ } ->
Expand Down
8 changes: 8 additions & 0 deletions engine/names/extract/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ fn def_path_item_to_str(path_item: DefPathItem) -> String {
DefPathItem::AnonAssocTy(..) => "AnonAssocTy".into(),
DefPathItem::SyntheticCoroutineBody => "SyntheticCoroutineBody".into(),
DefPathItem::NestedStatic => "NestedStatic".into(),
DefPathItem::LateAnonConst => "LateAnonConst".into(),
DefPathItem::DesugaredAnonymousLifetime => "DesugaredAnonymousLifetime".into(),
}
}

Expand Down Expand Up @@ -130,6 +132,11 @@ fn is_macro(did: &DefId) -> bool {
matches!(last.data, DefPathItem::MacroNs { .. })
}

/// Checks wether a def id refers to a syntactic item (see `syntactic_item.rs` in hax' exporter)
fn is_synthetic(did: &DefId) -> bool {
&did.contents.value.krate == hax_frontend_exporter_def_id::SYNTHETIC_CRATE_NAME
}

fn reader_to_str(s: String) -> String {
let json: Value = match serde_json::from_str(&s) {
Ok(v) => v,
Expand All @@ -141,6 +148,7 @@ fn reader_to_str(s: String) -> String {
let def_ids = def_ids
.into_iter()
.filter(|did| !is_macro(did))
.filter(|did| !is_synthetic(did))
.map(|did| {
let (json, krate_name) = def_id_to_str(&did);
(serde_json::to_string(&json).unwrap(), krate_name)
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.

8 changes: 5 additions & 3 deletions frontend/exporter/options/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,15 @@ pub struct Options {
pub inline_anon_consts: bool,
/// Options related to bounds.
pub bounds_options: BoundsOptions,
/// Resolve definition identifiers to their concrete impl counterpart when possible in `ItemRef::translate`.
pub item_ref_use_concrete_impl: bool,
}

#[derive(Debug, Clone, Copy)]
pub struct BoundsOptions {
/// Add `T: Drop` bounds to every type generic, so that we can build `ImplExpr`s to know what
/// code is run on drop.
pub resolve_drop: bool,
/// Add `T: Destruct` bounds to every type generic, so that we can build `ImplExpr`s to know
/// what code is run on drop.
pub resolve_destruct: bool,
/// Prune `T: Sized` and `T: MetaSized` predicates.
pub prune_sized: bool,
}
2 changes: 2 additions & 0 deletions frontend/exporter/src/constant_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum ConstantLiteral {
Char(char),
Float(String, FloatTy),
Int(ConstantInt),
PtrNoProvenance(u128),
Str(String),
ByteStr(Vec<u8>),
}
Expand Down Expand Up @@ -146,6 +147,7 @@ impl From<ConstantExpr> for Expr {
}
}
Float(f, ty) => LitKind::Float(f, LitFloatType::Suffixed(ty)),
PtrNoProvenance(p) => LitKind::Int(p, LitIntType::Unsigned(UintTy::Usize)),
ByteStr(raw) => LitKind::ByteStr(raw, StrStyle::Cooked),
Str(raw) => LitKind::Str(raw, StrStyle::Cooked),
};
Expand Down
61 changes: 45 additions & 16 deletions frontend/exporter/src/constant_utils/uneval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ pub fn translate_constant_reference<'tcx>(
.try_normalize_erasing_regions(typing_env, ty)
.unwrap_or(ty);
let kind = if let Some(assoc) = s.base().tcx.opt_associated_item(ucv.def)
&& (assoc.trait_item_def_id.is_some() || assoc.container == ty::AssocItemContainer::Trait)
{
&& matches!(
assoc.container,
ty::AssocContainer::Trait | ty::AssocContainer::TraitImpl(..)
) {
// This is an associated constant in a trait.
let name = assoc.name().to_string();
let impl_expr = self_clause_for_item(s, ucv.def, ucv.args).unwrap();
Expand All @@ -128,11 +130,22 @@ pub fn translate_constant_reference<'tcx>(
/// Evaluate a `ty::Const`.
pub fn eval_ty_constant<'tcx, S: UnderOwnerState<'tcx>>(
s: &S,
c: ty::Const<'tcx>,
uv: rustc_middle::ty::UnevaluatedConst<'tcx>,
) -> Option<ty::Const<'tcx>> {
use ty::TypeVisitableExt;
let tcx = s.base().tcx;
let evaluated = tcx.try_normalize_erasing_regions(s.typing_env(), c).ok()?;
(evaluated != c).then_some(evaluated)
let typing_env = s.typing_env();
if uv.has_non_region_param() {
return None;
}
let span = tcx.def_span(uv.def);
let erased_uv = tcx.erase_and_anonymize_regions(uv);
let val = tcx
.const_eval_resolve_for_typeck(typing_env, erased_uv, span)
.ok()?
.ok()?;
let ty = tcx.type_of(uv.def).instantiate(tcx, uv.args);
Some(ty::Const::new_value(tcx, val, ty))
}

/// Evaluate a `mir::Const`.
Expand Down Expand Up @@ -164,7 +177,7 @@ impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ConstantExpr> for ty::Const<'tcx>

ty::ConstKind::Unevaluated(ucv) => match translate_constant_reference(s, span, ucv) {
Some(val) => val,
None => match eval_ty_constant(s, *self) {
None => match eval_ty_constant(s, ucv) {
Some(val) => val.sinto(s),
// TODO: This is triggered when compiling using `generic_const_exprs`
None => supposely_unreachable_fatal!(s, "TranslateUneval"; {self, ucv}),
Expand All @@ -183,6 +196,13 @@ impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ConstantExpr> for ty::Const<'tcx>
}
}

impl<'tcx, S: UnderOwnerState<'tcx>> SInto<S, ConstantExpr> for ty::Value<'tcx> {
#[tracing::instrument(level = "trace", skip(s))]
fn sinto(&self, s: &S) -> ConstantExpr {
valtree_to_constant_expr(s, self.valtree, self.ty, rustc_span::DUMMY_SP)
}
}

#[tracing::instrument(level = "trace", skip(s))]
pub(crate) fn valtree_to_constant_expr<'tcx, S: UnderOwnerState<'tcx>>(
s: &S,
Expand Down Expand Up @@ -369,15 +389,24 @@ fn op_to_const<'tcx, S: UnderOwnerState<'tcx>>(
ConstantExprKind::FnPtr(item)
}
ty::RawPtr(..) | ty::Ref(..) => {
let op = ecx.deref_pointer(&op)?;
let val = op_to_const(s, span, ecx, op.into())?;
match ty.kind() {
ty::Ref(..) => ConstantExprKind::Borrow(val),
ty::RawPtr(.., mutability) => ConstantExprKind::RawBorrow {
arg: val,
mutability: mutability.sinto(s),
},
_ => unreachable!(),
if let Some(op) = ecx.deref_pointer(&op).discard_err() {
// Valid pointer case
let val = op_to_const(s, span, ecx, op.into())?;
match ty.kind() {
ty::Ref(..) => ConstantExprKind::Borrow(val),
ty::RawPtr(.., mutability) => ConstantExprKind::RawBorrow {
arg: val,
mutability: mutability.sinto(s),
},
_ => unreachable!(),
}
} else {
// Invalid pointer; try reading it as a raw address
let scalar = ecx.read_scalar(&op)?;
let scalar_int = scalar.try_to_scalar_int().unwrap();
let v = scalar_int.to_uint(scalar_int.size());
let lit = ConstantLiteral::PtrNoProvenance(v);
ConstantExprKind::Literal(lit)
}
}
ty::FnPtr(..)
Expand All @@ -402,7 +431,7 @@ fn op_to_const<'tcx, S: UnderOwnerState<'tcx>>(
pub fn const_value_to_constant_expr<'tcx, S: UnderOwnerState<'tcx>>(
s: &S,
ty: rustc_middle::ty::Ty<'tcx>,
val: mir::ConstValue<'tcx>,
val: mir::ConstValue,
span: rustc_span::Span,
) -> InterpResult<'tcx, ConstantExpr> {
let tcx = s.base().tcx;
Expand Down
1 change: 0 additions & 1 deletion frontend/exporter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ cfg_feature_rustc! {
extern crate rustc_abi;
extern crate rustc_ast;
extern crate rustc_ast_pretty;
extern crate rustc_attr_data_structures;
extern crate rustc_apfloat;
extern crate rustc_const_eval;
extern crate rustc_data_structures;
Expand Down
Loading
Loading