Skip to content

ValidLineRange static check for diffToLineRanges - #34

Merged
ninioArtillero merged 1 commit into
masterfrom
xg/output-checks
Jul 31, 2026
Merged

ValidLineRange static check for diffToLineRanges#34
ninioArtillero merged 1 commit into
masterfrom
xg/output-checks

Conversation

@ninioArtillero

@ninioArtillero ninioArtillero commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

This PR adds a LiquidHaskell static check to diffToLineRanges in the DiffOutput module, implemented using:

  • LineDiff, a refinement type alias for the Diff values with non-empty [String] arguments. This property was an implicit precondition of diffToLineRanges.
  • ValidLineRange, a refinement type alias of LineRange that requires lrNumbers to be an ordered pair where its lrContents must fit, is used for its postcondition.

A stronger alternative to ValidLineRange would be to directly refine the data declation, like so:

{-@
data LineRange = LineRange { lrNumbers :: {range : (Nat, Nat) | fst range <= snd range}
                           , lrContents :: {contents : [String] | snd lrNumbers - fst lrNumbers = len contents - 1}
@-}

Which would check the corresponding predicates wherever a LineRange is inferred by the compiler. Nevertheless, this route was not taken as parsePrettyDiffs implementation is too permissive for the invariants to hold without an extensive refactoring or the introduction of ad-hoc source checks enforcing them.

Comment thread src/Data/Algorithm/DiffOutput.hs Outdated
Comment thread src/Data/Algorithm/DiffOutput.hs Outdated
Comment thread src/Data/Algorithm/DiffOutput.hs Outdated
Comment thread src/Data/Algorithm/DiffOutput.hs Outdated
@facundominguez

Copy link
Copy Markdown
Contributor

It is looking to me like the changes of behavior need more of a justification, and they would be easier to spot if they were put in separate commits.

The refactoring of mkLineRange also deserves a separate commit.

@ninioArtillero
ninioArtillero force-pushed the xg/output-checks branch 5 times, most recently from 483117c to b8bb207 Compare July 29, 2026 23:05
@ninioArtillero ninioArtillero changed the title LineRange and StringDiff invariants static checks ValidLineRange and StringDiff invariant static checks for diffToLineRanges Jul 29, 2026
Comment thread src/Data/Algorithm/DiffOutput.hs Outdated
Comment thread src/Data/Algorithm/Diff/Refinement.hs Outdated
Comment thread src/Data/Algorithm/Diff/Refinement.hs Outdated
Comment thread src/Data/Algorithm/DiffOutput.hs Outdated
Comment thread src/Data/Algorithm/DiffOutput.hs Outdated
Comment thread src/Data/Algorithm/Diff/Refinement.hs Outdated
@ninioArtillero
ninioArtillero force-pushed the xg/output-checks branch 2 times, most recently from 8e48a46 to 5cc89a7 Compare July 30, 2026 20:27
@ninioArtillero ninioArtillero changed the title ValidLineRange and StringDiff invariant static checks for diffToLineRanges ValidLineRange static check for diffToLineRanges Jul 30, 2026
Comment thread src/Data/Algorithm/DiffOutput.hs
The `LineRange`s constructed in `diffToLineRanges` assume non-emptiness
of `Diff`'s values; this is checked using the `NonEmtpy` type alias.
Also, `Nat1` is introduced to account for the fact that line numbers start from 1.
Both conditions are required in order to check that `ValidLinaRange`s are
constructed.
@ninioArtillero
ninioArtillero merged commit 231b1bb into master Jul 31, 2026
13 checks passed
@ninioArtillero
ninioArtillero deleted the xg/output-checks branch July 31, 2026 15:27
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.

2 participants