Skip to content

Better dot rendering of PatternMatch#118

Open
acl-cqc wants to merge 6 commits intomainfrom
acl/dot_patterns
Open

Better dot rendering of PatternMatch#118
acl-cqc wants to merge 6 commits intomainfrom
acl/dot_patterns

Conversation

@acl-cqc
Copy link
Copy Markdown
Collaborator

@acl-cqc acl-cqc commented May 1, 2026

Similar to #117:

  • add edges from PatternMatch to each Box node it mentions
  • remove the now-redundant info in the label (OK this also removes detail of what tests are applied - are we happy?)
  • Include Boxes owned by a PatternMatch node as siblings of the latter. (The Source+Target and rest will thus be a subcluster)

Also reinstate closures.dot accidentally smashed by #117 :-(

closures.brat f is now:
f

which I think is an improvement

And g:
g

Note the "_lhs...._setup" boxes that are not in the hierarchy of the rest of the graph, created here:

brat/brat/Brat/Checker.hs

Lines 738 to 758 in 88e8617

-- First, we check the patterns on the LHS. This requires some overs,
-- so we make a box, however this box will be skipped during compilation.
(sol, match, rhsCty, defs) <- suppressHoles . fmap snd $
let ?my = my in ("$lhs" -!) $ makeBox (clauseName ++ "_setup") cty $
\(overs, unders) -> do
-- Make a problem to solve based on the lhs and the overs
problem <- argProblems (fst <$> overs) (unWC $ lhs clause) []
(tests, sol) <- localFC (fcOf (lhs clause)) $ solve my problem
(sol, defs) :: ([(String, (Src, BinderType m))], [((String, TypeKind), Val Z)]) <- case my of
Braty -> postProcessSolAndOuts sol unders
Kerny -> pure (sol, [])
-- The solution gives us the variables bound by the patterns.
-- We turn them into a row
mkArgRo my S0 ((\(n, (src, ty)) -> (NamedPort (toEnd src) n, ty)) <$> sol) >>= \case
-- Also make a row for the refined outputs (shifted by the pattern environment)
Some (patEz :* patRo) -> mkArgRo my patEz (first (fmap toEnd) <$> unders) >>= \case
Some (_ :* outRo) -> do
let testOuts = snd <$> sol
let match = TestMatchData my (MatchSequence overs tests testOuts)
trackM $ "[[[[[[TestMatchData\n" ++ show match ++ "\n]]]]]]"
pure (sol, match, patRo :->> outRo, fmap (Some . (patEz :*) . abstractEndz patEz) <$> defs)

Base automatically changed from acl/dot_closures to main May 4, 2026 07:50
@acl-cqc acl-cqc force-pushed the acl/dot_patterns branch from 8feeddb to 7bd9b9a Compare May 4, 2026 07:53
@acl-cqc acl-cqc changed the title Acl/dot patterns Better dot rendering of PatternMatch May 4, 2026
@acl-cqc
Copy link
Copy Markdown
Collaborator Author

acl-cqc commented May 4, 2026

Prior to the last commit, I also tried putting all the Boxes owned by a PatternMatch in a subcluster - so you'd have subcluster as a sibling of PatternMatch and the Boxes as nieces/nephews rather than siblings, thus there is an extra level of nesting per PatternMatch. Here's f with that approach:
f1

And here's g:
g1

I think the nesting is getting too hard here? But might it be good if there were several sibling PatternMatches?

@acl-cqc acl-cqc requested a review from croyzor May 4, 2026 08:42
Comment thread brat/Brat/Compiler.hs
writeDot :: [FilePath] -> String -> String -> IO ()
writeDot libDirs file out = do
env <- runExceptT $ loadFilename root libDirs file
-- Discard captureSets; perhaps we could incorporate into the graph
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This should have been removed in #117 too!

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