lean4-htt/stage0/stdlib/Lean
Henrik Böving 52b1b342ab
feat: zero cost BaseIO (#10625)
This PR implements zero cost `BaseIO` by erasing the `IO.RealWorld`
parameter from argument lists and structures. This is a **major breaking
change for FFI**.

Concretely:
- `BaseIO` is defined in terms of `ST IO.RealWorld`
- `EIO` (and thus `IO`) is defined in terms of `EST IO.RealWorld`
- The opaque `Void` type is introduced and the trivial structure
optimization updated to account for it. Furthermore, arguments of type
`Void s` are removed from the argument lists of the C functions.
- `ST` is redefined as `Void s -> ST.Out s a` where `ST.Out` is a pair
of `Void s` and `a`

This together has the following major effects on our generated code:
- Functions that return `BaseIO`/`ST`/`EIO`/`IO`/`EST` now do not take
the dummy world parameter anymore. To account for this FFI code needs to
delete the dummy world parameter from the argument lists.
- Functions that return `BaseIO`/`ST` now return their wrapped value
directly. In particular `BaseIO UInt32` now returns a `uint32_t` instead
of a `lean_object*`. To account for this FFI code might have to change
the return type and does not need to call `lean_io_result_mk_ok` anymore
but can instead just `return` values right away (same with extracting
values from `BaseIO` computations.
- Functions that return `EIO`/`IO`/`EST` now only return the equivalent
of an `Except` node which reduces the allocation size. The
`lean_io_result_mk_ok`/`lean_io_result_mk_error` functions were updated
to account for this already so no change is required.

Besides improving performance by dropping allocation (sizes) we can now
also do fun new things such as:
```lean
@[extern "malloc"]
opaque malloc (size : USize) : BaseIO USize
```
2025-10-22 10:55:12 +02:00
..
Compiler feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Data feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
DocString feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Elab feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
ErrorExplanations chore: update stage0 2025-09-29 14:24:13 +00:00
Language feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Linter feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Meta feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Parser feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
ParserCompiler feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
PremiseSelection feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
PrettyPrinter feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Server feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Util feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Widget feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
AddDecl.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Attributes.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
AuxRecursor.c chore: update stage0 2025-09-29 14:24:13 +00:00
BuiltinDocAttr.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Class.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Compiler.c chore: update stage0 2025-09-29 14:24:13 +00:00
CoreM.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Data.c chore: update stage0 2025-09-29 14:24:13 +00:00
Declaration.c chore: update stage0 2025-10-01 12:32:50 +00:00
DeclarationRange.c chore: update stage0 2025-10-19 23:45:51 +00:00
DefEqAttrib.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
DocString.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Elab.c chore: update stage0 2025-09-29 14:24:13 +00:00
EnvExtension.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Environment.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
ErrorExplanation.c chore: update stage0 2025-10-19 23:45:51 +00:00
ErrorExplanations.c chore: update stage0 2025-09-29 14:24:13 +00:00
Exception.c chore: update stage0 2025-10-19 23:45:51 +00:00
Expr.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
ExtraModUses.c chore: update stage0 2025-09-29 14:24:13 +00:00
HeadIndex.c chore: update stage0 2025-09-29 14:24:13 +00:00
Hygiene.c chore: update stage0 2025-10-19 23:45:51 +00:00
ImportingFlag.c chore: update stage0 2025-09-29 14:24:13 +00:00
InternalExceptionId.c chore: update stage0 2025-09-29 14:24:13 +00:00
KeyedDeclsAttribute.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
LabelAttribute.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Level.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Linter.c chore: update stage0 2025-09-29 14:24:13 +00:00
LoadDynlib.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
LocalContext.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Log.c chore: update stage0 2025-10-19 23:45:51 +00:00
Message.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Meta.c chore: update stage0 2025-09-29 14:24:13 +00:00
MetavarContext.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Modifiers.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
MonadEnv.c chore: update stage0 2025-10-19 23:45:51 +00:00
Namespace.c chore: update stage0 2025-09-29 14:24:13 +00:00
Parser.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
ParserCompiler.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
PremiseSelection.c chore: update stage0 2025-09-29 14:24:13 +00:00
PrettyPrinter.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
PrivateName.c chore: update stage0 2025-09-29 14:24:13 +00:00
ProjFns.c chore: update stage0 2025-09-29 14:24:13 +00:00
ReducibilityAttrs.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Replay.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
ReservedNameAction.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
ResolveName.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Runtime.c chore: update stage0 2025-09-29 14:24:13 +00:00
ScopedEnvExtension.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Server.c chore: update stage0 2025-09-29 14:24:13 +00:00
Setup.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Shell.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
Structure.c chore: update stage0 2025-10-19 23:45:51 +00:00
SubExpr.c chore: update stage0 2025-10-19 23:45:51 +00:00
Syntax.c feat: zero cost BaseIO (#10625) 2025-10-22 10:55:12 +02:00
ToExpr.c chore: update stage0 2025-10-19 23:45:51 +00:00
ToLevel.c chore: update stage0 2025-09-29 14:24:13 +00:00
Util.c chore: update stage0 2025-09-29 14:24:13 +00:00
Widget.c chore: update stage0 2025-09-29 14:24:13 +00:00