feat: introduce Provenance type and migrate metadata from FileRange#1140
Conversation
Introduce a Provenance inductive type that distinguishes between real source locations (Provenance.loc) and synthesized nodes (Provenance.synthesized). Changes: - Add Strata.Util.Provenance module with the Provenance type and helpers - Add provenance variant to MetaDataElem.Value in the Imperative dialect - Add Provenance-annotated DDM AST abbreviations (ArgProv, OperationProv, etc.) - Add conversion helpers (ArgF.toProv, OperationF.toProv) - Add MetaData.synthesized constructor for programmatic AST creation - Add getProvenance helper that checks both provenance and legacy fileRange - Update DDM→dialect translators (Core, C_Simp, Laurel, Boole, Python) to emit provenance metadata alongside the existing fileRange metadata - Update MetaData.toDiagnostic to use provenance when available - Update GOTO backend metadata conversion to preserve provenance
…Range helper Extract the common pattern of creating metadata with both fileRange and provenance elements into a shared MetaData.ofSourceRange helper. All translators now use this single helper instead of duplicating the logic. Also adds provenance to PythonToLaurel which was previously missing it.
|
All the follow-ups you filed up, do them now in this PR, and remove them from the PR description. Also, update the PR title. A PR is not an issue. |
…e-none-and-filerange-unknown-h # Conflicts: # Strata/DDM/AST.lean # Strata/DL/Imperative/MetaData.lean # Strata/Languages/Laurel/Grammar/ConcreteToAbstractTreeTranslator.lean # Strata/Languages/Python/PythonToLaurel.lean
|
🤖 Done. Completed the follow-ups in this PR:
The DDM abbreviation rename ( PR title and description updated. |
SourceRange.none and FileRange.unknown hide where statements are created…ileRange.unknown elimination
…ng MetaData.empty
When setCallSiteFileRange encounters a check with no file range but an existing synthesized provenance, it must erase the old provenance before pushing the call site's provenance. Otherwise findElem returns the stale synthesized entry, causing 'unknown location' in verification output for synthesized __init__ preconditions.
…e exclusively The .fileRange variant is removed from MetaDataElem.Value. All source locations in metadata are now stored via .provenance (Provenance.ofFileRange ...). This makes Provenance.loc the canonical replacement for standalone FileRange in metadata values.
MikaelMayer
left a comment
There was a problem hiding this comment.
🤖 Clean migration from FileRange to Provenance as the canonical metadata value. The Provenance type is well-designed with clear semantics. The SMT translator cleanup (replacing repeated let srnone := SourceRange.none with a single abbrev ann) is a nice improvement. A few items below.
…y, simplify getNameFromMd
0571c6a to
c2f9fe1
Compare
|
🤖 The original issue is addressed by replacing all |
I think my question deserves a deeper answer. Either something in this PR or a claim that the issue was not well informed. We see clearly in the PR diff that we eliminated FileRange and replaced it with Provenance that just adds a synthesized case. There is no mention of making sure that the dialect that use SourceRange as metadata (if any?) now use Provenance. |
|
🤖 To clarify the scope: the DDM grammar ASTs (B3, Boole, Python, SMT response parsing) still use The issue was specifically about the imperative metadata layer (
The DDM grammar annotations don't need this treatment because they don't suffer from the "SourceRange without file" problem — the file is always known at parse time and gets combined with the SourceRange when constructing metadata (via |
Better answer thanks. The B3 AST SHOULD use Provenance, otherwise we wouldn't be able to translate anything to it. |
|
🤖 Added a follow-up section to the PR description about migrating B3, Boole, and Python grammar ASTs from |
…e-none-and-filerange-unknown-h
joehendrix
left a comment
There was a problem hiding this comment.
One question, and I'd recommend auditing all uses of getFileRange, but I'm not sure if this should be blocking.
…e-none-and-filerange-unknown-h
…e-none-and-filerange-unknown-h
…e-none-and-filerange-unknown-h
Conflicts: - Strata/Transform/StructuredToUnstructured.lean: keep branch's loop-contract metadata (specLoopInvariant/specDecreases pushed to the transfer) and exit metadata propagation, while adopting main's String-only exit label and synthesizedMd-tagged synthesized commands. - Strata/Transform/ProcBodyVerifyCorrect.lean: adopt main's new Config.block (Option String × σ_parent × inner) shape, but keep the branch's destructured `ss : List Statement` (from procToVerifyStmt_is_structured) instead of `proc.body : Procedure.Body`. Follow-on fixes: - ProcBodyVerifyCorrect.lean lines 856/859/862: replace `proc.body` with `ss` so the new wf-preservation lemmas (core_wfVar_preserved, core_wfCong_preserved, core_wfExprCongr_preserved) typecheck. - Loops.lean / Exit.lean snapshots: replace `[fileRange]` tag with `[provenance]` and update shifted byte offsets to match the new Provenance metadata format introduced by #1140.
Fixes #1139
Introduces a
Provenancetype that fully replacesFileRangeandSourceRangeas the canonical way to store source locations in metadata. This structurally eliminates the "SourceRange without file name" problem.The
Provenancetype has two constructors:Provenance.loc uri range— a real source location (always requires both URI and range)Provenance.synthesized origin— a node created programmatically, with aSynthesizedOrigininductive typeA
SynthesizedOrigininductive enforces that only canonical origins are used (smtEncode,nondetIte,laurelParse,laurel,laurelToCore,structuredToUnstructured), preventing typos and duplicates at the type level.Key changes:
.fileRangevariant is removed fromMetaDataElem.Value— all metadata values now use.provenanceexclusivelyMetaData.ofSourceRangeemits only a provenance elementgetProvenanceis the single source of truth for reading source locations from metadatasetCallSiteFileRangeworks directly withProvenanceinstead of roundtripping throughFileRangegetFileRangedelegates togetProvenancefor extractionFileRange.unknownandSourceRange.noneeliminated from metadata constructionsmtAnncombinator to reduce annotation boilerplategetFileRange(which reads provenance)FileRangeremains as a utility struct for extraction and formatting (e.g., inDiagnosticModel), but is no longer a metadata value type.Existing tests pass unchanged.
Follow-up
SourceRangeas their annotation type parameter toProvenance. This would allow combining multiple files at the AST level and enable proper provenance tracking through translation passes.