Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
732db16
feat(rengine): intro interning
W95Psp Sep 16, 2025
d5be935
feat(rengine): intern `DefId` and `GlobalId`
W95Psp Sep 16, 2025
6e7b3c2
chore(rengine): regenerate names
W95Psp Sep 16, 2025
d054158
refactor(rengine): move `names` logic under `global_id`
W95Psp Sep 16, 2025
68c2598
refactor(rengine): make identifiers representation private
W95Psp Sep 16, 2025
e673c00
fix(rengine): no need for a reference here
W95Psp Sep 16, 2025
64bcac1
chore(changelog): update
W95Psp Sep 16, 2025
c119ffd
doc(rengine): document an invariant
W95Psp Sep 16, 2025
6bdbc58
fix(rengine): drop useless bounds
W95Psp Sep 18, 2025
b903042
refactor(rengine): merge `HasGlobal` and `InternExtTrait` as `Interna…
W95Psp Sep 18, 2025
807c3b9
fix(rengine): drop useless clone
W95Psp Sep 18, 2025
ebd774f
fix(rengine): `intern` -> `try_intern`
W95Psp Sep 18, 2025
5558a59
Update rust-engine/src/interning.rs
W95Psp Sep 22, 2025
7041009
doc(rengine): add comment on ExplicitClosure
W95Psp Sep 22, 2025
8bd565d
fix(rengine): drop useless `Any` bound
W95Psp Sep 22, 2025
20efeb6
feat(rengine): enforce abstraction on `GlobalId`s
W95Psp Sep 17, 2025
b0474a4
feat(rengine): represent tuple as a variant of `GlobalId`
W95Psp Sep 17, 2025
4718c79
feat(engine): patch exporter
W95Psp Sep 17, 2025
cd28edb
feat(rengine): make tuple-related names private
W95Psp Sep 17, 2025
c17dd6f
chore(rengine): refresh generated
W95Psp Sep 17, 2025
fb3c4aa
chore(changelog)
W95Psp Sep 17, 2025
2f530e3
misc(rengine): document panic
W95Psp Sep 18, 2025
8d29545
misc(rengine): better comment for `mod_only_closest_parent`
W95Psp Sep 18, 2025
41d6267
doc(rengine): global id
W95Psp Sep 18, 2025
3848d10
fix(engine): simplification
W95Psp Sep 18, 2025
c9f4ced
refactor(rengine): simplify `to_debug_string`
W95Psp Sep 18, 2025
4f71ab2
Merge pull request #1693 from cryspen/rengine-tuples
W95Psp Sep 22, 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
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Changes to the Rust Engine:
- Add support for enums and structs to the Lean backend (type definitions,
expressions, pattern-matching) (#1623)
- Update name rendering infrastructure in the Lean backend (#1623, #1624)
- Printers now emit proper diagnostics (PR #1669)
- Printers now emit proper diagnostics (PR #1669)
- Global identifiers are now interned (#1689)
- Global identifiers are encapsulated properly, and provide easy destructuring as tuple identifiers (#1693)

Changes to the frontend:
- Add an explicit `Self: Trait` clause to trait methods and consts (#1559)
Expand All @@ -29,7 +31,7 @@ Changes to the frontend:
- Fix a regression affecting projection predicates (#1678)

Changes to hax-lib:
- New behavior for`hax_lib::include`: it now forces inclusion when in contradiction with `-i` flag (#1685)
- New behavior for `hax_lib::include`: it now forces inclusion when in contradiction with `-i` flag.

Miscellaneous:
- A lean tutorial has been added to the hax website (#1626)
Expand Down
64 changes: 12 additions & 52 deletions engine/lib/export_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,6 @@ type missing_type = unit

module B = Rust_engine_types

module SpecialNames = struct
let rec map_strings (f : string -> string)
({ contents = { id; value } } : Types.def_id) =
let id = Int64.neg id in
let value =
match value with
| { index; is_local; kind; krate; parent; path } ->
let path =
List.map
~f:(fun { data; disambiguator } ->
let data =
match data with
| Types.CrateRoot { name } ->
Types.CrateRoot { name = f name }
| Types.TypeNs s -> Types.TypeNs (f s)
| Types.ValueNs s -> Types.ValueNs (f s)
| Types.MacroNs s -> Types.MacroNs (f s)
| Types.LifetimeNs s -> Types.LifetimeNs (f s)
| other -> other
in
Types.{ data; disambiguator })
path
in
let parent = Option.map ~f:(map_strings f) parent in
Types.{ index; is_local; kind; krate; parent; path }
in
let contents : Types.node_for__def_id_contents = { id; value } in
{ contents }

let mk value f =
Concrete_ident_generated.def_id_of >> map_strings f
>> Concrete_ident.of_def_id ~value

let f len nth = function
| "Tuple2" -> "Tuple" ^ Int.to_string len
| "1" -> "Tuple" ^ Int.to_string nth
| s -> s

let tuple_type len = mk false (f len 0) Rust_primitives__hax__Tuple2
let tuple_cons len = mk true (f len 0) Rust_primitives__hax__Tuple2__Ctor
let tuple_field len nth = mk false (f len nth) Rust_primitives__hax__Tuple2__1
end

module Make (FA : Features.T) = struct
open Ast
module A = Ast.Make (FA)
Expand Down Expand Up @@ -114,21 +71,24 @@ module Make (FA : Features.T) = struct
match fk with F16 -> F16 | F32 -> F32 | F64 -> F64 | F128 -> F128

and dglobal_ident (gi : global_ident) : B.global_id =
let concrete c : B.global_id = B.Concrete (Concrete_ident.to_rust_ast c) in
let concrete c : B.global_id =
Types.Newtypeglobal_id (B.Concrete (Concrete_ident.to_rust_ast c))
in
let of_name n = concrete (Concrete_ident.of_name ~value:true n) in
match gi with
| `Concrete c -> concrete c
| `TupleType len -> SpecialNames.tuple_type len |> concrete
| `TupleCons len -> SpecialNames.tuple_cons len |> concrete
| `TupleField (nth, len) -> SpecialNames.tuple_field len nth |> concrete
| `Concrete c | `Projector (`Concrete c) -> concrete c
| `TupleType length ->
Types.Newtypeglobal_id (Tuple (Type { length = Int.to_string length }))
| `TupleCons length ->
Types.Newtypeglobal_id
(Tuple (Constructor { length = Int.to_string length }))
| `Projector (`TupleField (field, length)) | `TupleField (field, length) ->
let field, length = (Int.to_string field, Int.to_string length) in
Types.Newtypeglobal_id (Tuple (Field { length; field }))
| `Primitive Deref -> of_name Rust_primitives__hax__deref_op
| `Primitive Cast -> of_name Rust_primitives__hax__cast_op
| `Primitive (LogicalOp And) -> of_name Rust_primitives__hax__logical_op_and
| `Primitive (LogicalOp Or) -> of_name Rust_primitives__hax__logical_op_or
| `Projector (`Concrete c) -> Projector (Concrete_ident.to_rust_ast c)
| `Projector (`TupleField (nth, len)) ->
let c = SpecialNames.tuple_field len nth in
Projector (Concrete_ident.to_rust_ast c)

and dlocal_ident (li : local_ident) : B.local_id =
Newtypelocal_id (Newtypesymbol li.name)
Expand Down
3 changes: 2 additions & 1 deletion engine/lib/rust_engine_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module Renamed = struct
type attribute_kind = Types.attribute_kind2
type binding_mode = Types.binding_mode2
type borrow_kind = Types.borrow_kind2
type def_id = Types.def_id2
type def_id = Types.def_id_inner
type global_id = Types.global_id
type expr_kind = Types.expr_kind2
type impl_expr = Types.impl_expr2
type param = Types.param2
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ expand *FLAGS:
# Regenerate names in the Rust engine. Writes to `rust-engine/src/names/generated.rs`.
regenerate-names:
#!/usr/bin/env bash
OUTPUT_FILE=rust-engine/src/names/generated.rs
OUTPUT_FILE=rust-engine/src/ast/identifiers/global_id/generated.rs
cargo hax -C --manifest-path engine/names/Cargo.toml \; into --output-dir $(dirname -- $OUTPUT_FILE) generate-rust-engine-names
rustfmt "$OUTPUT_FILE"

Expand Down
2 changes: 1 addition & 1 deletion rust-engine/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ pub enum ExprKind {
/// The body of the loop.
body: Expr,
/// The kind of loop (e.g. `while`, `loop`, `for`...).
kind: LoopKind,
kind: Box<LoopKind>,
/// An optional loop state, that makes explicit the state mutated by the
/// loop.
state: Option<LoopState>,
Expand Down
4 changes: 2 additions & 2 deletions rust-engine/src/ast/identifiers.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Identifier types used throughout the AST.
//!
//! This module defines:
//! This module provides two kinds of identifiers:
//! - `GlobalId`: fully-qualified paths like `std::mem::drop`
//! - `LocalId`: local variable identifiers
//! - `LocalId`: local identifiers

use crate::symbol::Symbol;
use hax_rust_engine_macros::*;
Expand Down
Loading
Loading