Core Expression metadata#1066
Draft
MikaelMayer wants to merge 175 commits into
Draft
Conversation
…1065) Change Core.ExpressionMetadata and CoreExprMetadata from Unit to Strata.SourceRange so that source locations can be preserved through the B3→Core→CoreSMT pipeline. Key changes: - Add defaultMetadata field to SyntaxMono.MkLExprParams (defaults to Unit.unit for generic params, overridden to SourceRange.none for Core) - Mark SourceRange.none as @[expose] for pattern matching - Update all Core expression construction sites to use SourceRange.none - Update Inhabited, DecidableEq, Repr, ToFormat, Traceable instances - Update factory axioms to use eb[] macro instead of esM[] - Update test expected outputs
This comment has been minimized.
This comment has been minimized.
MikaelMayer
commented
Apr 28, 2026
…re-expression-metadata-from-pr # Conflicts: # Strata/Languages/Boole/Verify.lean # Strata/Languages/Core/DDMTransform/Translate.lean # Strata/Languages/Core/ProcedureEval.lean # Strata/Languages/Core/SMTEncoder.lean # Strata/Languages/Core/StatementEval.lean # Strata/Languages/Laurel/LaurelToCoreTranslator.lean # Strata/Languages/Python/PythonToCore.lean # Strata/Transform/ProcBodyVerify.lean # Strata/Transform/ProcBodyVerifyCorrect.lean
MikaelMayer
commented
Apr 28, 2026
MikaelMayer
commented
Apr 28, 2026
MikaelMayer
commented
Apr 28, 2026
In Boole/Verify.lean and Core/DDMTransform/Translate.lean, replace Strata.SourceRange.none with the actual source range from the AST pattern matches. This preserves source location information through the translation pipeline for better error reporting and diagnostics.
…helper, improve docstring, use Core.true
…comparisons Expression equality was comparing SourceRange metadata, causing semantically identical expressions with different source positions to be considered unequal. This broke ITE/loop condition evaluation (where evaluated conditions were compared against HasBool.tt which uses SourceRange.none), procedure inlining alpha-equivalence checks, and Boole map extensionality tests. Replace the derived structural DecidableEq on SourceRange with a trivial equality axiom so that all SourceRange values are considered equal. This matches the intended semantics: source ranges are metadata that should not affect expression identity.
Merge origin/main into branch. The conflict in LaurelToCoreTranslator.lean arose because main removed the metadata field from Laurel AstNode (2-element tuples) while our branch changed Core expression metadata from Unit to SourceRange. Resolution keeps SourceRange.none for Core expressions and uses the simplified 2-element AstNode destructuring from main.
…rences - Translate.lean: Remove dead SourceRange.none defaults (callers always pass op.ann) - LaurelToCoreTranslator: Add sourceRangeOf helper, propagate source ranges from AST - All other files: Add comments explaining why SourceRange.none is appropriate (synthesized expressions, SMT terms, semantic definitions, transforms)
…data The ExpressionMetadata change from Unit to SourceRange shifts assert label byte offsets, so use a flexible regex for the line number in test_param_reassign_cross_module. Remove test_unsupported_config.expected because the richer metadata now lets the evaluator resolve the assert condition to a bool.
Add checkNoSourceRangeNone.sh script (modeled after checkNoPanic.sh) that flags net-new SourceRange.none occurrences without suppression markers. Suppression: per-line (-- sourcerange:ok) or per-file (-- sourcerange:file-ok). All 33 files with SourceRange.none now have file-ok markers with explanations.
…re-expression-metadata-from-pr
MikaelMayer
commented
Apr 28, 2026
…lanations Rename per-line marker from "sourcerange:ok" to "nosourcerange: <explanation>" and per-file marker from "sourcerange:file-ok" to "nosourcerange-file: <explanation>". The CI script now validates that explanations are non-empty and not just "ok".
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr # Conflicts: # Strata/Languages/Core/DDMTransform/Translate.lean
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr # Conflicts: # Strata/Languages/Core/DDMTransform/Translate.lean # Strata/Languages/Core/Expressions.lean # Strata/Languages/Core/Identifiers.lean # Strata/Languages/Laurel/LaurelToCoreTranslator.lean # StrataBoole/StrataBooleTest/FeatureRequests/map_extensionality.lean # StrataPython/StrataPython/PythonToCore.lean # StrataTest/DL/Imperative/FormatStmtTest.lean # StrataTest/Languages/Core/Examples/DDMAxiomsExtraction.lean # StrataTest/Languages/Core/Examples/SubstFvarsCaptureTests.lean # StrataTest/Languages/Core/Tests/ExprEvalTest.lean # StrataTest/Languages/Core/Tests/FunctionTests.lean # StrataTest/Languages/Core/Tests/GenericCallFallbackTest.lean # StrataTest/Languages/Core/Tests/OverflowCheckTest.lean # StrataTest/Languages/Core/Tests/ProgramEvalTests.lean # StrataTest/Languages/Core/Tests/SMTEncoderDatatypeTest.lean # StrataTest/Languages/Core/Tests/SMTEncoderTests.lean # StrataTest/Languages/Core/Tests/SarifOutputTests.lean # StrataTest/Languages/Core/Tests/TestASTtoCST.lean # StrataTest/Transform/ProcedureInlining.lean
- Replace Core.true with .boolConst default Bool.true in VCOutcomeTests and LoopElim tests (Core.true is not accessible via meta import all) - Restore DDMAxiomsExtraction.lean to correct structure (bad merge had replaced #eval command with raw AST content)
…ore-expression-metadata-from-pr
Replace Unit () with default (ExprSourceLoc) for LExpr constructor metadata in FunctionTypeTests and StatementTypeTests. The metadata type changed from Unit to ExprSourceLoc but these test definitions were not updated.
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr
…ore-expression-metadata-from-pr # Conflicts: # Strata/Languages/Core/ProcedureEval.lean # Strata/Languages/Laurel/LaurelToCoreTranslator.lean
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.
Summary
This PR changes
Core.ExpressionMetadata(previouslyUnit) toExprSourceLoc, a lightweight struct carrying an optional file URI, a byte-offsetSourceRange, and a list of related source locations. This enables Core expressions to track their source location and originating file through the verification pipeline, which is necessary for correct source attribution after cross-file inlining.Key design decisions
ExprSourceLochas fieldsuri : Option Uri,range : SourceRange, andrelatedLocs : List (Option Uri × SourceRange)ExprSourceLoc.synthesized "<origin>"(e.g."semantics","factory","test", etc.) — there is noExprSourceLoc.noneCoe SourceRange ExprSourceLoccoercion provides backward compatibility for translators that don't yet carry URI informationrelatedLocsaccumulates additional source locations during expression substitution, preserving both the original expression location and the substituted argument locationeqModuloMeta/eraseMetadatainstead of==Translators updated
InputContext.fileNameAstNode.sourcepyLocExprSourceLoc.synthesizedwith appropriate origin tagsTesting
All existing tests pass. Test fixtures updated to use
ExprSourceLoc.synthesized "test".