Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 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
4b25c84
refactor previous
acl-cqc Dec 22, 2025
f053569
HugrGraph.rs: add splice
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
ddf06f4
WIP: Try to wire up when unifying In vs In
croyzor Dec 10, 2025
5d31870
tracing
acl-cqc Jan 2, 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
13 changes: 8 additions & 5 deletions brat/Brat/Checker/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ import Data.List (intercalate)
import qualified Data.Map as M
import qualified Data.Set as S

-- import Debug.Trace
import Debug.Trace

-- Used for messages about thread forking / spawning
thTrace = const id
--thTrace = trace

trackM :: Monad m => String -> m ()
trackM = const (pure ())
--trackM = traceM
--trackM = const (pure ())
trackM = traceM

track = const id
--track = trace
--track = const id
track = trace
trackShowId x = track (show x) x

-- Data for using a type alias. E.g.
Expand Down Expand Up @@ -120,6 +120,7 @@ data CheckingSig ty where
ANewDynamic :: InPort -> FC -> CheckingSig ()
AskDynamics :: CheckingSig (M.Map InPort FC)
AddCapture :: Name -> (QualName, [(Src, BinderType Brat)]) -> CheckingSig ()
WiresIn :: Name -> CheckingSig [Wire]

wrapper :: (forall a. CheckingSig a -> Checking (Maybe a)) -> Checking v -> Checking v
wrapper _ (Ret v) = Ret v
Expand Down Expand Up @@ -319,6 +320,8 @@ handler (Req s k) ctx g
AddCapture n (var, ends) ->
handler (k ()) ctx {captureSets=M.insertWith M.union n (M.singleton var ends) (captureSets ctx)} g

WiresIn n -> handler (k (wiresTo n g)) ctx g

handler (Define lbl end v k) ctx g = let st@Store{typeMap=tm, valueMap=vm} = store ctx in
case track ("Define(" ++ lbl ++ ")" ++ show end ++ " = " ++ show v) $ M.lookup end vm of
Just _ -> Left $ dumbErr (InternalError $ "Redefining " ++ show end)
Expand Down
46 changes: 38 additions & 8 deletions brat/Brat/Checker/SolveNumbers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import Brat.Naming
import Hasochism
import Control.Monad.Freer

-- import Debug.Trace
import Debug.Trace
import qualified Data.Set as S

trailM :: Applicative f => String -> f ()
trailM = const (pure ())
trail = const id
--trail = trace
--trailM = const (pure ())
trailM = traceM
--trail = const id
trail = trace

-- This is currently lifted from SolvePatterns, which still imports it.
-- It is also used in SolveHoles, where it does the right mathematics
Expand Down Expand Up @@ -90,15 +91,18 @@ unifyNum' mine (NumValue lup lgro) (NumValue rup rgro)
lhsFun00 (StrictMonoFun sm) num = lhsStrictMono sm num

flexFlex :: VVar Z -> VVar Z -> Checking ()
flexFlex v v' | trace ("flexFlex " ++ show v ++ " " ++ show v') False = undefined
flexFlex v v' = case compare v v' of
GT -> flexFlex v' v
EQ -> pure ()
GT | trace "GT" False -> undefined | otherwise -> flexFlex v' v
EQ | trace "EQ" False -> undefined | otherwise -> pure ()
LT -> case (v, v') of
(VPar e@(ExEnd p), VPar e'@(ExEnd p'))
| trace "ExEx" False -> undefined
| Just _ <- mine e -> defineSrc (NamedPort p "") (VNum (nVar v'))
| Just _ <- mine e' -> defineSrc (NamedPort p' "") (VNum (nVar v))
| otherwise -> typeErr $ "Can't force " ++ show v ++ " to be " ++ show v'
(VPar e@(InEnd p), VPar e'@(ExEnd dangling))
| trace "InEx" False -> undefined
| Just _ <- mine e -> do
req (Wire (dangling, TNat, p))
defineTgt' ("flex-flex In Ex") (NamedPort p "") (VNum (nVar v'))
Expand All @@ -107,10 +111,36 @@ unifyNum' mine (NumValue lup lgro) (NumValue rup rgro)
defineSrc' ("flex-flex In Ex") (NamedPort dangling "") (VNum (nVar v))
| otherwise -> mkYield "flexFlex" (S.singleton e) >> unifyNum mine (nVar v) (nVar v')
(VPar e@(InEnd p), VPar e'@(InEnd p'))
| Just _ <- mine e -> defineTgt' "flex-flex In In1" (NamedPort p "") (VNum (nVar v'))
| Just _ <- mine e' -> defineTgt' "flex-flex In In0"(NamedPort p' "") (VNum (nVar v))
| trace "InIn" False -> undefined
| Just _ <- mine e -> solveInIn p p'
| Just _ <- mine e' -> solveInIn p' p
| otherwise -> mkYield "flexFlex" (S.fromList [e, e']) >> unifyNum mine (nVar v) (nVar v')

-- INVARIANT: The first argument is ours to solve
solveInIn :: InPort -> InPort -> Checking ()
solveInIn e0@(In node0 _) e1@(In node1 _) = do
ws0 <- req $ WiresIn node0
ws1 <- req $ WiresIn node1
mine <- mineToSolve
me <- whoAmI
case (ws0, ws1) of
([], [(dangling, ty, _)]) -> do
req $ Wire (dangling, ty, e0)
defineTgt' "solveInIn" (NamedPort e0 "") (VNum (nVar (VPar (toEnd e1))))
([], [])
| Just _ <- mine (InEnd e1) -> do
(_, [(tgt,_)], [(src0, _), (src1, _)], _) <- anext "copyInIn" Copy (S0, Some (Zy :* S0)) (REx ("clonee", Nat) R0) (REx ("clone0", Nat) (REx ("clone1", Nat) R0))
defineTgt' "solveInInCopy" (NamedPort e0 "") (VNum (nVar (VPar (toEnd tgt))))
defineTgt' "solveInInCopy" (NamedPort e1 "") (VNum (nVar (VPar (toEnd tgt))))
req $ Wire (end src0, TNat, e0)
req $ Wire (end src1, TNat, e1)
| otherwise -> error $ "solveInIn: rhs not ours to solve: " ++ show e1 ++ "\n we are " ++ show me
(_, []) -> err (Unimplemented "solveInIn: ours defined; other not" [])
-- Both things already wired up; just do the statics
_ -> defineTgt' "solveInInStatic" (NamedPort e0 "") (VNum (nVar (VPar (toEnd e1))))



lhsStrictMono :: StrictMono (VVar Z) -> NumVal (VVar Z) -> Checking ()
lhsStrictMono (StrictMono 0 mono) num = lhsMono mono num
lhsStrictMono (StrictMono n mono) num = do
Expand Down
Loading