Add Hunk invariant static checks - #35
Merged
Merged
Conversation
ninioArtillero
force-pushed
the
xg/context-checks
branch
from
July 27, 2026 15:41
06d386d to
80fdf31
Compare
ninioArtillero
force-pushed
the
xg/context-checks
branch
3 times, most recently
from
July 27, 2026 22:35
1abbed5 to
197736d
Compare
ninioArtillero
marked this pull request as ready for review
July 27, 2026 22:35
ninioArtillero
force-pushed
the
xg/context-checks
branch
3 times, most recently
from
July 28, 2026 01:33
e34c8e4 to
7ae1361
Compare
ninioArtillero
force-pushed
the
xg/context-checks
branch
from
July 28, 2026 22:20
7ae1361 to
4b08596
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces Liquid Haskell static checks for the
ContextSizeto be a natural number and for the documentedtype Hunk c = [Diff [c]]invariant:Without introducing any semantic change.
The
Hunkinvariant is encoded using a refinement type alias of the same name with anoStutteringpredicate. Most notably, this is non-trivially checked ingetContextDiffNumberedpostcondition by specifying its local functionsdoPrefixanddoSuffixto transform an inputHunkinto an intermediate form{ds : [ValidListDiff c c] | noFFSS ds}thatsplitBothBothtransforms back into aHunk. The inputHunk(actually a stronger variant which also specifies the value contents to be non-empty) is produced bygetGroupedDiffBy.The changes within
getGroupedDiffByare just reformating (to better accomodate the Liquid Haskell specifications) and the following renamings to improve readability:NOTE: Refinement type aliases--such as
{-@ type Hunk c = { h : [ValidListDiff c c] | noStuttering h} @-}and{-@ type ContextDiff c = [Hunk c] @-}--override the corresponding type aliases--type Hunk c = [Diff [c]]andtype Hunk c = [Diff [c]respectively--in Liquid Haskell specifications.PolyDiffandDifftypes and instances are moved to a newData.Algorithm.Diff.Typemodule. This move is required to have functions defined solely for Liquid Haskell specifications in a separate module and avoid cyclic dependency; this helps prevent the cluther of implementation modules by (some of the) unused functions. Such functions reside inData.Algorithm.Diff.Refinement, together with refinement type aliases that use them and other helpers required for specifications.