Add getIonDeserializer% and getIonSerializer% elaborators for generic Ion serialization#1095
Draft
keyboardDrummer-bot wants to merge 7 commits intomainfrom
Draft
Add getIonDeserializer% and getIonSerializer% elaborators for generic Ion serialization#1095keyboardDrummer-bot wants to merge 7 commits intomainfrom
getIonDeserializer% and getIonSerializer% elaborators for generic Ion serialization#1095keyboardDrummer-bot wants to merge 7 commits intomainfrom
Conversation
Implements a term-level elaborator that inspects Lean inductive and structure types at compile time and generates a ByteArray → Except Std.Format α deserializer. Encoding conventions: - Structures → Ion structs with field names as keys - Single-constructor inductives → Ion structs with _0, _1, … keys - Multi-constructor inductives → Ion sexps (CtorName arg1 arg2 …) - Supported leaf types: Nat, Int, String, Bool Closes #5
- Add readFloat runtime helper (accepts Ion float and int values) - Add Float as a supported leaf type in mkFieldRead and mkIndexRead - Support nested types: fields that are structures/inductives generate readers via let rec bindings in dependency order - Support recursive types: self-referencing types work when the enclosing definition is marked partial - Add tests for Float (Measurement), nested (Line with Point fields), and recursive (Tree) types
- Rewrite Strata/DDM/Integration/Java/Gen.lean to generate Java source
files from Lean types instead of DDM Dialect values
- New getIonSerializer% term elaborator inspects Lean inductive/structure
types at compile time and generates:
- Sealed interfaces for multi-constructor inductives
- Records for structures and single-constructor inductives
- Ion serialization matching getIonDeserializer% format:
- Structures → Ion struct with field name keys
- Single-ctor inductives → Ion struct with _0, _1, ... keys
- Multi-ctor inductives → Ion sexp (CtorName arg1 arg2 ...)
- Supported leaf types: Nat, Int, Float, String, Bool
- Nested and recursive types supported automatically
- Remove old javaGen CLI command from StrataMain.lean
- Rewrite tests to use Lean types (Point, Color, Shape, Person, Line, Tree)
- Add Java compilation test and Ion roundtrip test
(Java serializes → Lean deserializes → verify match)
# Conflicts: # StrataMain.lean # StrataTestExtra/DDM/Integration/Java/TestGen.lean # StrataTestExtra/DDM/Integration/Java/regenerate-testdata.sh
…rializer - Add readDecimal, readList, readOption runtime helpers to IonDeserializer - Extend getIonDeserializer% to handle List α, Option α, and Strata.Decimal - Extend getIonSerializer% to generate Java code for List (java.util.List), Option (nullable), and Decimal (java.math.BigDecimal) - Move old DDM-based Java generator to GenDDM.lean to preserve javaGen CLI - Remove support for MetaData, MetaDataElem, Core.Expression, and Array (no longer in Laurel AST) - Add tests for new types in StrataTest/Util/IonDeserializer.lean
The javac invocation was inside the HashMap iteration loop, causing it to compile partial sets of files. With non-deterministic HashMap ordering, this could fail when a file referencing another type was compiled before that type's source file was written. Also added the output directory to -cp so javac can find compiled classes from other files in the same package, and added cleanup at the end.
The CheckImports linter requires all modules under Strata/ to be transitively imported by Strata.lean. The new IonDeserializer module was missing from the import list, causing the lint step to fail in CI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5
Summary
Adds two term-level elaborators for generic Ion serialization/deserialization of Lean types:
getIonDeserializer%— generates a functionByteArray → Except Std.Format αthat deserializes Ion binary data into values of a given Lean type at compile time.getIonSerializer%— generates Java source files (records, sealed interfaces) withtoIonmethods that serialize to the same Ion format.Design
Since
Typeis erased at runtime in Lean, both elaborators inspect the type's constructors and fields in the Lean environment at elaboration time and produce syntax that is then type-checked normally.Ion encoding conventions
_0,_1, …(ConstructorName arg₁ arg₂ …)Supported leaf types
Nat,Int,Float,String,Bool,DecimalContainer types
List α→ Ion list /java.util.List<T>,Option α→ Ion null for none / nullableTNested and recursive types
Fields whose types are themselves structures or inductives are handled recursively. For recursive types (e.g.,
Tree), the generated code useslet recbindings — the enclosing definition must be markedpartial.Usage
Files
Strata/Util/IonDeserializer.lean— Runtime helpers and thegetIonDeserializer%elaboratorStrata/DDM/Integration/Java/Gen.lean— Rewritten to providegetIonSerializer%for Lean typesStrata/DDM/Integration/Java/GenDDM.lean— Original DDM-based Java generator (preserved forjavaGenCLI)StrataTest/Util/IonDeserializer.lean— Tests for the deserializerStrataTestExtra/DDM/Integration/Java/TestGen.lean— Rewritten tests for the serializerTesting
javacand produces Ion data thatgetIonDeserializer%can read back correctly.