Skip to content
Merged
Show file tree
Hide file tree
Changes from 152 commits
Commits
Show all changes
156 commits
Select commit Hold shift + click to select a range
e3e8260
Hugr: move parent pointer outside of node
acl-cqc Dec 16, 2025
8b26471
Make abstract datatype for Hugr
acl-cqc Dec 16, 2025
990e261
WIP inline the one -!, abandon FreshMonad
acl-cqc Dec 16, 2025
214333b
Fix Hugr on NodeId, move Namespace inside -> freshNodeWithParent
acl-cqc Dec 16, 2025
33a498c
WIP inline withIO
acl-cqc Dec 17, 2025
99a7416
refactor: lift compileNode up to top level
acl-cqc Dec 17, 2025
5ec4c67
Revert "refactor: lift compileNode up to top level"
acl-cqc Dec 17, 2025
b9be70d
Separate out compilation of Source - fails 3 tests
acl-cqc Dec 17, 2025
4f3d1ff
Fix Eval not respecting liftedOutPorts -> just 1 fail
acl-cqc Dec 17, 2025
5e4ee49
And splices should use getOutPort too
acl-cqc Dec 17, 2025
af49caf
xfail remaining failure in closures.brat
acl-cqc Dec 17, 2025
8b74892
fixup! Separate out
acl-cqc Dec 17, 2025
1e9e1f2
refactor out compileInEdges
acl-cqc Dec 17, 2025
33eb452
refactor in_edges to top-level
acl-cqc Dec 17, 2025
d42778d
Separate out compilation of Target
acl-cqc Dec 17, 2025
57c2df7
refactor: compileKernBox takes src+tgt (Name, Name)
acl-cqc Dec 17, 2025
41b913f
Rename: freshNodeWithParent -> freshNode
acl-cqc Dec 17, 2025
df8b4dd
makeCS takes Hugr
acl-cqc Dec 18, 2025
1cfebd1
compileBox takes Container = 3*NodeId, uses setOp; {freshNode,new}WithIO
acl-cqc Dec 18, 2025
57f2110
HugrGraph: separate out root
acl-cqc Dec 18, 2025
a791530
HugrGraph: add io_children (written not read)
acl-cqc Dec 18, 2025
e6cecd7
WIP use io_children to sort Hugr. Fails on Conditionals - cases in wr…
acl-cqc Dec 18, 2025
af23d7e
hack setFirstChildren to get Cases in order inside Conditional
acl-cqc Dec 18, 2025
5d0d815
Drop unused instance Ord, and index inside OpCase
acl-cqc Dec 18, 2025
d7ae859
Hugr->HugrGraph
acl-cqc Dec 19, 2025
c2cee45
Remove HugrGraph.freshNodeWithIO
acl-cqc Dec 19, 2025
cf5f705
Move Container from HugrGraph to Compile/Hugr
acl-cqc Dec 19, 2025
c50cbb7
new returns just HugrGraph, expose root accessor
acl-cqc Dec 19, 2025
3f3c06d
io_children->first_children stores any number
acl-cqc Dec 19, 2025
365dddc
ake HugrGraph ops in State HugrGraph, Compile use onHugr
acl-cqc Dec 20, 2025
cb31461
HugrGraph.hs: do not re-export PortId
acl-cqc Dec 22, 2025
b88878a
reduce imports from Naming
acl-cqc Dec 22, 2025
446d978
Move renameAndSort inside serialize
acl-cqc Dec 22, 2025
cac91fe
Honour first_children of root
acl-cqc Dec 22, 2025
f053569
HugrGraph.rs: add splice
acl-cqc Dec 22, 2025
4b25c84
refactor previous
acl-cqc Dec 22, 2025
109cbe2
Add test, and some debugging info
acl-cqc Dec 22, 2025
f0482a6
add isHole, test there are no holes in resHugr
acl-cqc Dec 24, 2025
0369fbf
Add inlineDFG
acl-cqc Dec 24, 2025
7c6c608
Parametrize test both with and without inlining
acl-cqc Dec 24, 2025
6b6ba8c
WIP add Machine.hs
acl-cqc Dec 9, 2025
72d8527
Evaluates constant 4
acl-cqc Dec 9, 2025
18a60e0
And simple arithmetic
acl-cqc Dec 9, 2025
c5a23d0
WIP Eval, Box with captureSets and ReturnTo
acl-cqc Dec 9, 2025
b953fe1
start pattern matching - works if no tests
acl-cqc Dec 9, 2025
33a8345
The test file I've been using
acl-cqc Dec 9, 2025
085ef76
Do tests for pattern matching
croyzor Dec 9, 2025
1e112fc
Tests for vector even/odd tests (example falls over)
croyzor Dec 10, 2025
b81c28e
tracing the machine
conormcb Dec 10, 2025
d3ba753
Eval constructors
croyzor Dec 10, 2025
5d23571
WIP remove Brat-specific compilation
acl-cqc Jan 2, 2026
5bcc324
And a bit more
acl-cqc Jan 2, 2026
d2676c8
Simplify: all decls require extra-call
acl-cqc Jan 2, 2026
c5e3036
WIP expose only compileKernel, fix holes. direct calls WTF??
acl-cqc Jan 2, 2026
8b937fe
Remove CaptureSets
acl-cqc Jan 2, 2026
34ed063
Ah - kernels were inside Value::Constants, so could never have called…
acl-cqc Jan 2, 2026
12c14c9
compile only kernel boxes, return map name -> bytes+[splice]; many in…
acl-cqc Jan 2, 2026
9b80320
compileKernel returns HugrGraph, dump_json->HG.to_json, tidy imports
acl-cqc Jan 2, 2026
7137722
Interpreter compileKernel+splice. Compiles but does it work!? TODO ch…
acl-cqc Jan 2, 2026
f181da4
Eval unification inputs in pattern matching; add dummy value for *; f…
croyzor Dec 10, 2025
b116c84
print json, + fixes: evalSplices Use->Finished, handle CQubit
acl-cqc Jan 9, 2026
a960fbb
Compile toplevel kernels only
acl-cqc Jan 9, 2026
5416be8
Review comment: M.alter in addToMap
acl-cqc Jan 10, 2026
36ae9d1
Review comment: check only single in-edges
acl-cqc Jan 10, 2026
a4523af
Review comments: state->modify, parent->defNode, foldl'
acl-cqc Jan 10, 2026
f691012
comments
acl-cqc Jan 10, 2026
d2e5473
WIP HugrGraph.hs separate Namespace
acl-cqc Jan 10, 2026
10e3abd
Move Namespace out of HugrGraph into Compile monad
acl-cqc Jan 10, 2026
673d664
Parametrize HugrGraph by nodeid for methods that don't use Namespace
acl-cqc Jan 10, 2026
1e34f29
hide HG.edgeList
acl-cqc Jan 10, 2026
00b4b16
comment issue 101
acl-cqc Jan 12, 2026
3404672
Merge remote-tracking branch 'origin/main' into refactor/hugr_graph
acl-cqc Jan 12, 2026
9d9bd68
Merge branch 'refactor/hugr_graph' into acl/splice_hugr
acl-cqc Jan 13, 2026
2b953b3
Comment what splice/inlineDFG do
acl-cqc Jan 16, 2026
d244141
Turn off tracing
croyzor Feb 23, 2026
ab928df
Renaming frames
croyzor Feb 25, 2026
3571256
rename union -> disjoint union, use more
acl-cqc Feb 25, 2026
ff54a49
Merge remote-tracking branch 'origin/main' into acl/splice_hugr
acl-cqc Feb 25, 2026
6e35999
Merge branch 'acl/splice_hugr' into acl/stack_machine2
acl-cqc Feb 25, 2026
8b21e2b
Fix input naming bug in makeIO
croyzor Feb 25, 2026
db17d09
Better `Show` instance for `Frame`
croyzor Feb 25, 2026
3694660
Fix bug in `addEdge` (`parents` contains all nodes; `nodes` doesn't!)
croyzor Feb 25, 2026
88b2a8f
Hack CR* gates into BRAT extension (for now!)
croyzor Feb 25, 2026
0385c65
Add hugr rotation helpers
croyzor Feb 25, 2026
b490ca1
Handle Prim ops in the machine
croyzor Feb 25, 2026
0fdacbc
Done TODO
acl-cqc Feb 27, 2026
5b55246
Merge remote-tracking branch 'origin/main' into acl/stack_machine2
acl-cqc Mar 6, 2026
646b3cc
Combine parsing tests into checking
acl-cqc Apr 14, 2026
bfef2e0
Calculate checking XFAILs from file header, but still have list for c…
acl-cqc Apr 14, 2026
b1478f6
Remove unused nonCompilingExamples, also invalidExamples mechanism
acl-cqc Apr 14, 2026
4245b0b
Two lists via struct, expect parsing to succeed for xfail-checking
acl-cqc Apr 14, 2026
a75ca1a
Integrate compile tests into checking (--!xfail-compilation)
acl-cqc Apr 14, 2026
fe91e5f
Remove old separate compilation tests
acl-cqc Apr 17, 2026
c54dd8e
Remove expected lists from haskell
acl-cqc Apr 14, 2026
ea17d12
Separate out Checking.hs from Examples.hs
acl-cqc Apr 17, 2026
ddb2af0
WIP Execution tests parsed out of file, reading func_name from next l…
acl-cqc Apr 15, 2026
abd49a1
runInterpreter returns ByteString, avoid capture/golden
acl-cqc Apr 17, 2026
5a014a9
more tests in examples/arith.brat (remove arith.brat)
acl-cqc Apr 17, 2026
5cbf449
Use Data.Aeson.Text encodeToLazyText
acl-cqc Apr 17, 2026
bba87c6
Update to tasty-1.5
croyzor Apr 17, 2026
3ea59a5
combine check+exec tests into sequentialTestGroup from tasty-1.5
acl-cqc Apr 17, 2026
3aea4e8
regroup parse+check+compile+exec under each example
acl-cqc Apr 17, 2026
3cf7052
simplify by allowing singleton group, but parallelize execution tests
acl-cqc Apr 17, 2026
3cbf05a
Re-enable warnings, fix
acl-cqc Apr 17, 2026
5af9f37
Remove the putStrLn 'Not an Id node', make 'not found in VEnv' an error
acl-cqc Apr 20, 2026
55e3929
Change --!test to --!exec w/option -xfail, add tests in app.brat
acl-cqc Apr 20, 2026
74a01a6
Add xfails (Suspend): brace-sections, batcher-merge-sort, cons, fanou…
acl-cqc Apr 20, 2026
f30f52b
infer{,2}.brat: remove repeated/commented-out-repeats, inc. of eatsfu…
acl-cqc Apr 20, 2026
977c695
infer.brat: add vector tests (passing w/ typechecking workaround)
acl-cqc Apr 20, 2026
501da84
infer2.brat: tests that work
acl-cqc Apr 20, 2026
2b055cb
infer2.brat: tests that produce wrong answer - suspect wrong graph
acl-cqc Apr 21, 2026
56fee11
Revert "infer2.brat: tests that produce wrong answer - suspect wrong …
acl-cqc Apr 21, 2026
31acde4
infer2.brat: test that fails with 'index too large' in Machine.hs
acl-cqc Apr 21, 2026
0c66214
Rm map.brat, included in infer.brat
acl-cqc Apr 21, 2026
eb88823
runInterpreter returns either Text or HugrGraph
acl-cqc Apr 21, 2026
070982f
HugrGraph: hide root, add getRoot/getNodes
acl-cqc Apr 21, 2026
6c82366
Test/Compile/Hugr.hs: add getSplices, compileToOutput checks they match
acl-cqc Apr 21, 2026
b2c624c
add --!exec-hugr that checks no splices, writes to test/examples/outp…
acl-cqc Apr 21, 2026
ba113a7
Fix bogus add def in examples
croyzor Apr 21, 2026
d6942bc
Machine: Add list constructors to pattern matching
croyzor Apr 21, 2026
83d27b2
xfail remaining tests
croyzor Apr 21, 2026
3407191
infer2.brat: xfailed tests that produce wrong answer - suspect wrong …
acl-cqc Apr 21, 2026
f267f4a
move examples output
acl-cqc Apr 22, 2026
3c0571a
Fix adder.brat test
croyzor Apr 22, 2026
91bfde2
Remove undercooked hea example
croyzor Apr 22, 2026
37f2209
Fix infer_thunks exec tests
croyzor Apr 22, 2026
2bf2238
Delete redundant karlheinz_alias test
croyzor Apr 22, 2026
b0457aa
Add missing extension to brat_extension
croyzor Apr 22, 2026
2a2b7c6
Merge branch 'main' into acl/stack_machine2
croyzor Apr 22, 2026
0f7679b
No point in CompilationResult returning OutPorts of lost Graph; getSp…
acl-cqc Apr 22, 2026
b81b2c6
clarify xfail comment
acl-cqc Apr 22, 2026
b82e277
add tiny hugr test in kernel.brat
acl-cqc Apr 22, 2026
289f19d
simplify some funcs in Compiler.hs
acl-cqc Apr 22, 2026
493e890
Get fanout test running
croyzor Apr 22, 2026
d17da8e
Expand link in comment
croyzor Apr 22, 2026
43bb48a
Add missing cases to Machine
croyzor Apr 22, 2026
febbf79
[WIP] bits and pieces for implementing MapFun in Machine
croyzor Apr 22, 2026
9a4a05e
implement MapFun, factor out runThunk
acl-cqc Apr 22, 2026
4997694
VectorisedFuncs (frame), plus runVectorisedThunks -> test passes
acl-cqc Apr 22, 2026
237b94e
More vectorise tests
croyzor Apr 22, 2026
4caa9dd
more batcher tests
acl-cqc Apr 22, 2026
fdb7aa1
refactor: rm runThunk
acl-cqc Apr 22, 2026
1952ed7
vector of Value not BratThunk, hopefully handles >1D
acl-cqc Apr 22, 2026
3e64526
Machine: Dig for appropriate vectorised function
croyzor Apr 22, 2026
7d3135e
StringV
croyzor Apr 22, 2026
a878b75
Remove VecThunkV, add BratThunk::VectorisedThunks
acl-cqc Apr 22, 2026
790f326
Merge commit 'a878b75e' into acl/stack_machine2
acl-cqc Apr 22, 2026
e6d10ea
dig inside getVecs
acl-cqc Apr 23, 2026
aafb9bb
use MapM in Maybe monad for getVecs+getThunks
acl-cqc Apr 23, 2026
70870c6
comment
acl-cqc Apr 23, 2026
faf03c4
cons.brat whitespace
acl-cqc Apr 24, 2026
b12abad
reinstate hea.brat
acl-cqc Apr 24, 2026
ffd0613
lookupOutport looks only in local BratValues
acl-cqc Apr 24, 2026
8f56da2
comments
acl-cqc Apr 24, 2026
1b61797
EvalPort -> evalPort
acl-cqc Apr 24, 2026
ae9b271
EvalNode -> evalNode
acl-cqc Apr 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion brat/Brat/Checker/Helpers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,10 @@ solveVal Nat it@(InEnd inn) v@(VNum nv) = do
dangling <- buildNatVal nv
req (Wire (end dangling, TNat, inn))
defineEnd "solveValNat" it v
solveVal _ it v = defineEnd "solveVal" it v
solveVal k@(TypeFor _ _) it@(InEnd inn) v = do
(_, _, [(dummySrc, _)], _) <- anext "" (Dummy k) (S0, Some (Zy :* S0)) R0 (REx ("dummy", k) R0)
req $ Wire (end dummySrc, kindType k, inn)
defineEnd "solveVal" it v
-- Do we also need dummy wiring here?

solveSem :: TypeKind -> End -> Sem -> Checking ()
Expand Down
386 changes: 49 additions & 337 deletions brat/Brat/Compile/Hugr.hs

Large diffs are not rendered by default.

48 changes: 40 additions & 8 deletions brat/Brat/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,30 @@ module Brat.Compiler (printAST
,writeDot
,compileFile
,compileAndPrintFile
,compileToGraph
,CompilingHoles(..)
) where

import Brat.Checker.Types (TypedHole)
import Brat.Checker.Types (TypedHole, Modey(Kerny), VEnv)
import Brat.Compile.Hugr
import Brat.Dot (toDotString)
import Brat.Elaborator
import Brat.Error
import Brat.Graph(Graph, Node(BratNode), NodeType(Box, Id))
import Brat.Load
import Brat.Naming (root, split)
import Brat.Naming (Namespace, root, split, Name)
import Brat.QualName (QualName)
import Brat.Syntax.Port (NamedPort(..), OutPort(..), InPort(..))
import Brat.Syntax.Value (Val(VFun))

import Control.Exception (evaluate)
import Control.Monad (forM, when)
import Control.Monad.Except
import Data.List (intercalate)
import qualified Data.Map as M
import qualified Data.ByteString.Lazy as BS
import Data.Foldable (for_)
import Data.HugrGraph (HugrGraph, NodeId, to_json)
import System.Exit (die)

printDeclsHoles :: [FilePath] -> String -> IO ()
Expand Down Expand Up @@ -74,18 +81,43 @@ instance Show CompilingHoles where
show (CompilingHoles hs) = unlines $
"Can't compile file with remaining holes": fmap ((" " ++) . show) hs

compileFile :: [FilePath] -> String -> IO (Either CompilingHoles BS.ByteString)
compileFile libDirs file = do
compileToGraph :: [FilePath] -> String -> IO (Namespace, VMod)
compileToGraph libDirs file = do
let (checkRoot, newRoot) = split "checking" root
env <- runExceptT $ loadFilename checkRoot libDirs file
(declEnv, holes, defs, outerGraph, capSets) <- eitherIO env
(newRoot,) <$> eitherIO env

-- Map from box name to (compiled hugr, list of hole nodes in it)
type CompilationResult = M.Map Name (HugrGraph NodeId, [NodeId])

compileFile :: [FilePath] -> String -> IO (Either CompilingHoles CompilationResult)
compileFile libDirs file = do
(newRoot, (declEnv, holes, st, outerGraph, _)) <- compileToGraph libDirs file
let venv = M.map fst declEnv
case holes of
[] -> Right <$> evaluate -- turns 'error' into IO 'die'
(compile defs newRoot outerGraph capSets venv)
[] -> let box_decls = (M.keys declEnv) >>= (findBoxes venv outerGraph)
in Right <$> (evaluate -- turns 'error' into IO 'die'
$ M.fromList [(n, let (hugr, holes) = compileKernel (newRoot, st, outerGraph) "root" n
in (hugr, map fst holes))
| n <- box_decls])
hs -> pure $ Left (CompilingHoles hs)
where
findBoxes :: VEnv -> Graph -> QualName -> [Name]
findBoxes venv (ns, es) name = case M.lookup name venv of
Nothing -> error $ (show name) ++ ".... not found in VEnv"
Just vals -> vals >>= \(NamedPort (Ex n _) _, _) -> case M.lookup n ns of
Just (BratNode Id _ _) ->
[src | (Ex src 0, _, In tgt _) <- es, tgt == n, isKernelBox src ns]
_ -> []
isKernelBox :: Name -> M.Map Name Node -> Bool
isKernelBox name ns
| Just (BratNode (Box _ _ ) [] [(_, VFun Kerny _cty)]) <- M.lookup name ns = True
| otherwise = False

compileAndPrintFile :: [FilePath] -> String -> IO ()
compileAndPrintFile libDirs file = compileFile libDirs file >>= \case
Right bs -> BS.putStr bs
Right hs -> for_ (M.toList hs) $ \(n, (hugr, splices)) -> do
putStrLn $ "Compiled box: " ++ show n
BS.putStr (to_json hugr)
putStrLn $ "With splices: " ++ show splices
Left err -> die (show err)
3 changes: 2 additions & 1 deletion brat/Brat/Constructors/Patterns.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ module Brat.Constructors.Patterns where

import Brat.QualName

pattern CSucc, CDoub, CNil, CCons, CSome, CNone, CTrue, CFalse, CZero, CSnoc,
pattern CSucc, CDoub, CFull, CNil, CCons, CSome, CNone, CTrue, CFalse, CZero, CSnoc,
CConcatEqEven, CConcatEqOdd, CRiffle :: QualName
pattern CSucc = PrefixName [] "succ"
pattern CDoub = PrefixName [] "doub"
pattern CFull = PrefixName [] "full"
pattern CNil = PrefixName [] "nil"
pattern CSome = PrefixName [] "some"
pattern CNone = PrefixName [] "none"
Expand Down
12 changes: 9 additions & 3 deletions brat/Brat/Graph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ data NodeType :: Mode -> Type where
ArithNode :: ArithOp -> NodeType Brat
Replicate :: NodeType Brat
MapFun :: NodeType a
-- The thing that gets plugged into type hopes when we solve them
Dummy :: TypeKind -> NodeType Brat

deriving instance Show (NodeType a)

Expand Down Expand Up @@ -110,9 +112,6 @@ toGraph (ns, ws) = G.graphFromEdges adj
)
| (name, node) <- M.toList ns]

wiresFrom :: Name -> Graph -> [Wire]
wiresFrom src (_, ws) = [ w | w@(Ex a _, _, _) <- ws, a == src ]

lookupNode :: Name -> Graph -> Maybe Node
lookupNode name (ns, _) = M.lookup name ns

Expand All @@ -121,3 +120,10 @@ wireStart (Ex x _, _, _) = x

wireEnd :: Wire -> Name
wireEnd (_, _, In x _) = x

-- These are horribly inefficient until we use a better structure for graph edges
wiresFrom :: Name -> Graph -> [Wire]
wiresFrom src (_, ws) = [ w | w@(Ex a _, _, _) <- ws, a == src ]

wiresTo :: Name -> Graph -> [Wire]
wiresTo tgt (_, ws) = [ w | w@(_, _, In a _) <- ws, a == tgt ]
1 change: 1 addition & 0 deletions brat/Brat/Load.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Brat.Load (loadFilename
,loadFiles
,parseFile
,desugarEnv
,VMod
) where

import Brat.Checker
Expand Down
Loading
Loading