You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letflag=ctor.get_bool(1, 8); // bool at scalar offset 8
135
+
```
136
+
137
+
## Notes
138
+
139
+
### Rust panic behavior
140
+
141
+
By default, Rust uses stack unwinding for panics. If a panic occurs in a Lean-to-Rust FFI function, the unwinding will try to cross the FFI boundary back into Lean. This is [undefined behavior](https://doc.rust-lang.org/stable/reference/panic.html#unwinding-across-ffi-boundaries). To avoid this, configure Rust to abort on panic in `Cargo.toml`:
142
+
143
+
```toml
144
+
[profile.release]
145
+
panic = "abort"
146
+
```
69
147
70
148
### Enum FFI convention
71
149
72
150
Lean passes simple enums (inductives where all constructors have zero fields,
73
151
e.g. `DefKind`, `QuotKind`) as **raw unboxed tag values** (`0`, `1`, `2`, ...)
74
-
across the FFI boundary, not as `lean_box(tag)`. To decode, use
75
-
`obj.as_ptr() as usize`; to build, use `LeanObject::from_raw(tag as *const c_void)`.
76
-
Do **not** use `box_usize`/`unbox_usize` for these — doing so will silently
77
-
corrupt the value.
78
-
79
-
### Reference counting for reused objects
80
-
81
-
When building a new Lean object, if you construct all fields from scratch (e.g.
82
-
`LeanString::new(...)`, `LeanByteArray::from_bytes(...)`), ownership is
83
-
straightforward — the freshly allocated objects start with rc=1 and Lean manages
84
-
them from there.
85
-
86
-
However, if you take a Lean object received as a **borrowed** argument (`@&` in
87
-
Lean, `b_lean_obj_arg` in C) and store it directly into a new object via
88
-
`.set()`, you must call `.inc_ref()` on it first. Otherwise Lean will free the
89
-
original while the new object still references it. If you only read/decode the
90
-
argument into Rust types and then build fresh Lean objects, this does not apply.
152
+
across the FFI boundary, not as `lean_box(tag)`. Use `LeanOwned::from_enum_tag()`
153
+
and `LeanRef::as_enum_tag()` for these.
154
+
155
+
### Persistent objects
156
+
157
+
Module-level Lean definitions and objects in compact regions are persistent
158
+
(`m_rc == 0`). Both `lean_inc_ref` and `lean_dec_ref` are no-ops for persistent
159
+
objects, so `LeanOwned`, `LeanBorrowed`, `Clone`, and `Drop` all work correctly
0 commit comments