Skip to content

Core Expression metadata#1066

Draft
MikaelMayer wants to merge 175 commits into
main2from
issue-1065-extract-core-expression-metadata-from-pr
Draft

Core Expression metadata#1066
MikaelMayer wants to merge 175 commits into
main2from
issue-1065-extract-core-expression-metadata-from-pr

Conversation

@MikaelMayer

@MikaelMayer MikaelMayer commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR changes Core.ExpressionMetadata (previously Unit) to ExprSourceLoc, a lightweight struct carrying an optional file URI, a byte-offset SourceRange, 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

  • ExprSourceLoc has fields uri : Option Uri, range : SourceRange, and relatedLocs : List (Option Uri × SourceRange)
  • Every synthesized expression carries explicit provenance via ExprSourceLoc.synthesized "<origin>" (e.g. "semantics", "factory", "test", etc.) — there is no ExprSourceLoc.none
  • A Coe SourceRange ExprSourceLoc coercion provides backward compatibility for translators that don't yet carry URI information
  • relatedLocs accumulates additional source locations during expression substitution, preserving both the original expression location and the substituted argument location
  • Code that needs semantic equality (ANF encoder, scope merging, boolean checks) uses eqModuloMeta/eraseMetadata instead of ==

Translators updated

  • DDM-to-Core: propagates URI from InputContext.fileName
  • Laurel-to-Core: extracts URI and range from AstNode.source
  • Python-to-Core: propagates Python AST source positions via pyLoc
  • Boole, C_Simp: use ExprSourceLoc.synthesized with appropriate origin tags

Testing

All existing tests pass. Test fixtures updated to use ExprSourceLoc.synthesized "test".

…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
@MikaelMayer

This comment has been minimized.

Comment thread StrataTest/Languages/Core/Examples/DDMAxiomsExtraction.lean
…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
Comment thread Strata/Languages/Boole/Verify.lean Outdated
Comment thread Strata/Languages/C_Simp/Verify.lean Outdated
Comment thread Strata/Languages/Core/DDMTransform/Translate.lean Outdated
MikaelMayer

This comment was marked as resolved.

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.
…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.
@github-actions github-actions Bot added the github_actions Pull requests that update GitHub Actions code label Apr 28, 2026
Comment thread .github/scripts/checkNoSourceRangeNone.sh Outdated
…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".
@github-actions github-actions Bot removed the Python label Jun 3, 2026
…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
@github-actions github-actions Bot added the Python label Jun 4, 2026
- 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)
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

# Conflicts:
#	Strata/Languages/Core/ProcedureEval.lean
#	Strata/Languages/Laurel/LaurelToCoreTranslator.lean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants