Skip to content

Inlining assertions should keep metadata#707

Draft
MikaelMayer wants to merge 5 commits intomainfrom
issue-706-inlining-assertions-should-keep-metadata
Draft

Inlining assertions should keep metadata#707
MikaelMayer wants to merge 5 commits intomainfrom
issue-706-inlining-assertions-should-keep-metadata

Conversation

@MikaelMayer
Copy link
Copy Markdown
Contributor

Fixes #706

During procedure inlining, assertions in the callee body now carry the call site metadata as the primary file range, with the original assertion location stored as a related file range. This allows error reporting to show the procedure call location first, with the original assertion as a related position.

  • Added relatedFileRange metadata field and setCallSiteFileRange helper to combine call site and original assertion metadata
  • Updated ProcedureInlining.inlineCallCmd to set call site metadata on inlined assertions, assumes, and covers
  • Display related positions in pyAnalyze and pyAnalyzeLaurel output
  • Added RelatedLocation to SARIF output for related positions
  • Updated SARIF test expected outputs for the new relatedLocations field

Tested: existing tests pass, SARIF test outputs updated.

…riginal location (#706)

During procedure inlining, assertions in the callee body now carry the call
site metadata as the primary file range, with the original assertion location
stored as a related file range. This allows error reporting to show the
procedure call location first, with the original assertion as a related
position.

Changes:
- Add relatedFileRange metadata field and setCallSiteFileRange helper
- Update ProcedureInlining to set call site metadata on inlined assertions
- Display related positions in pyAnalyze and pyAnalyzeLaurel output
- Add RelatedLocation to SARIF output for related positions
- Update SARIF test expected outputs for new relatedLocations field

/-- Metadata field for a related file range (e.g., the original assertion location
when the primary file range points to the call site after inlining). -/
def MetaData.relatedFileRange : MetaDataElem.Field P := .label "relatedFileRange"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be more than one inlining, so related file ranges should be ordered. For every inlining, the related file ranges should shift as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated setCallSiteFileRange to support multiple inlinings. It now collects existing related file ranges, clears them, prepends the current primary range as the first related range, then appends the previously existing related ranges. This preserves ordering: the most recent inlining's original location comes first, followed by earlier ones.

def MetaData.relatedFileRange : MetaDataElem.Field P := .label "relatedFileRange"

/-- Get the related file range from metadata, if present. -/
def getRelatedFileRange {P : PureExpr} [BEq P.Ident] (md: MetaData P) : Option FileRange := do
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be more than one related file range.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed getRelatedFileRange (returning Option FileRange) to getRelatedFileRanges (returning Array FileRange), which collects all metadata elements with the relatedFileRange field. Updated all callers: SARIF output now emits all related locations with sequential IDs, and the CLI output formats all related positions.

Strata.Sarif.toJsonString sarif

/-- info: "{\"runs\":[{\"results\":[{\"level\":\"error\",\"locations\":[],\"message\":{\"text\":\"Unknown (solver timeout or incomplete)\"},\"properties\":{\"propertyType\":\"assert\"},\"ruleId\":\"test_error\"}],\"tool\":{\"driver\":{\"informationUri\":\"https://github.com/strata-org/Strata\",\"name\":\"Strata\",\"version\":\"0.1.0\"}}}],\"schema\":\"https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json\",\"version\":\"2.1.0\"}" -/
/-- info: "{\"runs\":[{\"results\":[{\"level\":\"error\",\"locations\":[],\"message\":{\"text\":\"Unknown (solver timeout or incomplete)\"},\"properties\":{\"propertyType\":\"assert\"},\"relatedLocations\":[],\"ruleId\":\"test_error\"}],\"tool\":{\"driver\":{\"informationUri\":\"https://github.com/strata-org/Strata\",\"name\":\"Strata\",\"version\":\"0.1.0\"}}}],\"schema\":\"https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json\",\"version\":\"2.1.0\"}" -/
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to update this but I would like to see a test that displays related locations. Look into the python specification tests, there is a place where we inline a procedure. Look at StrataTest/Languages/Python/AnalyzeLaurelTest.lean and messages like Storage_Storage_put_item_assert(0)_9: ✔️ always true if reached (Required parameter 'Bucket' is missing).
First you should update the messages to include line and column number and remove the assertion names that are not human-readable. Then verify that with your approach, it indicates the assertion's line and column number to be at the call site.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a SARIF test that constructs metadata with setCallSiteFileRange (simulating inlining) and verifies the related location appears in the SARIF JSON output with the correct line/column.

Regarding the Python spec test updates (updating messages to include line/column, removing non-human-readable assertion names, and verifying call site location through the full pipeline) — this is a larger change that touches the Python pipeline output formatting. I can tackle that as a follow-up if you'd like, or address it in this PR with more guidance on the expected output format.

- Change getRelatedFileRange to getRelatedFileRanges returning Array FileRange
- Add MetaData.eraseAllElems to remove all elements with a given field
- Update setCallSiteFileRange to preserve existing related ranges on each inlining
- Update extractRelatedLocations in SARIF output to emit all related locations
- Update formatRelatedPositions in StrataMain to display all related locations
- Add SARIF test with related locations from inlining
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inlining assertions should keep metadata

1 participant