Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty printing of source code locations #131

Merged
merged 21 commits into from
Mar 6, 2024
Merged

Pretty printing of source code locations #131

merged 21 commits into from
Mar 6, 2024

Conversation

JustusAdam
Copy link
Collaborator

@JustusAdam JustusAdam commented Mar 2, 2024

What Changed?

Adds diagnostic facilities for printing the source code spans corresponding to nodes in the SPDG to paralegal-policy.

These facilities were mainly created by @MithiJ and @nharbiso. I made some minor changes to it:

  • Interned the source file information.
  • Removed CallSiteSpan because only the loc field seemed to be used
  • Removed SrcCodeInfo and the src_locs field and instead attached the spans directly as part of node weights.
  • Adapted the printing logic to correctly handle tab characters in the source files when measuring whitespace length.
  • Integrate with the Diagnostics mechanism and add a suite of builder methods
  • Highlights only the subspans of a given operator within an operation where possible
    This uses some trickery based from the subtle relationships between the spans of a local variable and that of an instruction. Specifically we record both the instruction span and the spans of the definition sites of local variables. In most cases the operators to an instruction, especially for function calls, are temporary local variables that are automatically generated by the rust compiler. The spans of their definition site is precisely the span of an argument. We exploit this "coincidence" by printing the entire span of the instruction, but highlight only the definition span of the local, which happens to be the area of the argument we care about. If the definition span does not lie within the span of the instruction we print only the instruction and highlight everything.

Why Does It Need To?

Improves the UI for users and policy developers.

Checklist

  • Above description has been filled out so that upon quash merge we have a
    good record of what changed.
  • New functions, methods, types are documented. Old documentation is updated
    if necessary
  • Documentation in Notion has been updated
  • Tests for new behaviors are provided
    • New test suites (if any) ave been added to the CI tests (in
      .github/workflows/rust.yml) either as compiler test or integration test.
      Or justification for their omission from CI has been provided in this PR
      description.

@JustusAdam JustusAdam marked this pull request as ready for review March 4, 2024 22:46
@JustusAdam JustusAdam merged commit 8d83984 into main Mar 6, 2024
4 checks passed
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.

1 participant