Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
04c52ac
Add "hoping" variables
Aug 19, 2024
3a1d6fe
Expand Free monad with Define and Yield
Aug 19, 2024
bf6cfcf
Add Define/Yield cases to handler functions
Aug 20, 2024
a6f00dd
Handle Yield in toplevel handler
Aug 20, 2024
4204c50
Add bang parsing
mark-koch Aug 20, 2024
3b8fdc1
Turn on ApplicativeDo
Aug 20, 2024
8f904bc
Add some dummy code for typechecking !
Aug 20, 2024
8b852a2
Revert "Add "hoping" variables"
Aug 20, 2024
77b92fe
Some parallelisation
Aug 20, 2024
3a1288d
Add hope set to monad
Aug 20, 2024
b979c70
Move occur check logic to Eval
Aug 20, 2024
a197fb2
misc changes
Aug 20, 2024
b115f84
[broken] update eqworker
Aug 20, 2024
ce1d1cf
Revert "[broken] update eqworker"
Aug 20, 2024
c064466
Add !,! test
Aug 20, 2024
b33f100
Rewrite typeEq
mark-koch Aug 20, 2024
c093ced
feat: Solve numbers that are just variables
Aug 21, 2024
7986539
typeEqRow returns sub-problems
acl-cqc Aug 21, 2024
7afa2c4
sequence_ -> traverse_ id
acl-cqc Aug 21, 2024
265a5b6
[broken] Build things to wire into solved hopes
Aug 21, 2024
2a360b6
Don't hide that error
Aug 21, 2024
6be252b
Fix typechecking for infer example
Aug 22, 2024
646f6f9
feat: Complain when we have remaining Nat-kinded holes
Aug 22, 2024
c2c8bbe
Incude file context in hopeSet
Aug 22, 2024
3765a8a
Allow comparing VInx
Aug 22, 2024
a22531b
Rewrite dynamic num refinements to work on srcs and tgts
Aug 22, 2024
af75834
Fix demandEven logic
Aug 22, 2024
283ccae
Flip that hypo node back around
Aug 22, 2024
0da9554
Rewrite computeMeta to do definition as well
Aug 23, 2024
2139140
SolvePatterns build fixes; unified.brat+infer.brat fail with non-clos…
acl-cqc Sep 17, 2024
78cc87c
Step0. Yield in getThunks
acl-cqc Aug 21, 2024
fb99b1a
Drop already-commented-out Helpers.hs export list
acl-cqc Sep 20, 2024
07c17ed
WIP two-stage check
acl-cqc Aug 21, 2024
23853e5
Add infer_thunks(,2).brat example; ...2 works but map body not checked
acl-cqc Aug 21, 2024
75e9017
checkClause returns subproblem (oops) - BOTH infer_thunks(,2) failing…
acl-cqc Sep 20, 2024
0f21ce7
Revert "checkClause returns subproblem (oops) - BOTH infer_thunks(,2)…
acl-cqc Sep 20, 2024
3bebd4c
WIP debug (shows we stop at [to_float] and never check to_float)
acl-cqc Aug 21, 2024
dce7f0f
Try just using *> rather than returning subproblem (tests build, 59 f…
acl-cqc Sep 17, 2024
5764083
WIP add request to Fork, but TODO captureOuterLocals (tests build but…
acl-cqc Sep 17, 2024
a2ebfcf
Add captureSets, AddCapture
acl-cqc Sep 17, 2024
2e4b14e
Plumb captureSet into CompilationState (never read), various Load.hs …
acl-cqc Sep 17, 2024
85ff9c7
captureOuterLocals routes captures via AddCapture, so Box VEnv always…
acl-cqc Aug 23, 2024
c90845c
And remove VEnv from Box
acl-cqc Aug 23, 2024
115c0fa
wip debug
acl-cqc Aug 23, 2024
c24ca0d
new: Add `Lluf` operation to the BRAT hugr extension
Sep 25, 2024
672392c
checkpoint b4 I break eerything
Sep 25, 2024
9f3faa8
A couple of unit tests with Fork/Define/Yield (add assertCheckingFail)
acl-cqc Aug 23, 2024
e694a8d
Reduce change, revert checkInputs/Outputs back to Checking, also chec…
acl-cqc Sep 17, 2024
2b73543
Add string description to Fork
acl-cqc Oct 1, 2024
251455b
TEMP remove failure tests
acl-cqc Sep 13, 2024
47f4c31
Fork outside Req, with both child computations (44 fails)
acl-cqc Oct 1, 2024
9dc4b0e
WIP remove debug
acl-cqc Oct 1, 2024
554bae2
Fix compilation crashing on empty captureSet
acl-cqc Sep 18, 2024
0bfcc27
Add isSkolem func, use in typeEqEta - TODO for now True for any outport
acl-cqc Sep 18, 2024
a4115fb
simpleCheck is Checking, allow to define hopes (except nat/int?!) and…
acl-cqc Sep 18, 2024
3b76be2
typeMap stores skolem-ness (always False ATM); TypeOf returns (EndTyp…
acl-cqc Sep 17, 2024
2ebb941
Inline only use of declareSrc
acl-cqc Sep 17, 2024
e0c7997
Declare takes Bool param (still always False)
acl-cqc Oct 1, 2024
45751ac
anext' allows setting Sources to be skolem
acl-cqc Sep 17, 2024
87270bf
implement isSkolem using TypeOf
acl-cqc Sep 18, 2024
2fcdd48
Common up Checking wrappers via 'wrapper' and 'wrapper2'
acl-cqc Sep 25, 2024
75a5ac0
print hopeset when blocked
acl-cqc Oct 1, 2024
9f1c6ff
Use defineEnd more
acl-cqc Oct 1, 2024
0808dab
Add mkYield, use it
acl-cqc Oct 1, 2024
a83de68
Remove concurrency-blocking -!s in makeBox (27 -> 24 fails)
acl-cqc Oct 1, 2024
98a5671
Remove howStuck, just use Unstuck (30 -> 27 fails)
acl-cqc Oct 1, 2024
db83ba9
typeEqEta shouldWait for ends inside nums as well, assert -> unless
acl-cqc Oct 1, 2024
710c931
Redo invertNatVal
Oct 3, 2024
3b36023
Refactor typeEqEta
acl-cqc Oct 4, 2024
3e15acc
typeEqEta: fast-path without blocking for both ends the same
acl-cqc Oct 4, 2024
a900ac4
typeEqEta shouldWait for ends inside nums as well, assert -> unless
acl-cqc Oct 1, 2024
3bf4f0b
Refactor typeEqEta
acl-cqc Oct 4, 2024
2c8f26b
typeEqEta: fast-path without blocking for both ends the same
acl-cqc Oct 4, 2024
42ef6d3
Call eval after resumption in simpleCheck
acl-cqc Oct 4, 2024
5b13e9d
Merge remote-tracking branch 'origin/main' into inference-wip/fork
acl-cqc Oct 4, 2024
43bcaf8
Merge remote-tracking branch 'origin/inference-wip/fork' into new/inf…
Oct 7, 2024
62332cf
Merge remote-tracking branch 'origin/craig/inference-wip/fork-and-nat…
acl-cqc Oct 7, 2024
5517854
SolvePatterns build fixes
acl-cqc Oct 7, 2024
48cd1e2
Merge remote-tracking branch 'origin/main' into inference-wip/fork (c…
acl-cqc Oct 21, 2024
4f8099b
Comment out mapVec
acl-cqc Oct 21, 2024
9203cb6
Fix checking of infer.brat w/note, add more. Compilation fails on Pow ?!
acl-cqc Oct 21, 2024
95dad0f
Revert "TEMP remove failure tests"
acl-cqc Oct 21, 2024
352e9f8
Fix infer.brat, no need to multiply by 2^0
acl-cqc Nov 22, 2024
3c96393
Merge remote-tracking branch 'origin/main' into inference-wip/fork
acl-cqc Nov 22, 2024
7c20289
Fix bad merge, check against HopeSet before vectorise not after
acl-cqc Nov 22, 2024
03316af
fix some golden/graph tests, mostly internal variable names, plus an …
acl-cqc Apr 1, 2025
9f6f549
Merge remote-tracking branch 'origin/just-nat-solving' into inference…
acl-cqc Apr 1, 2025
d081457
Remove RemoveHope, Define does it automatically
acl-cqc Apr 1, 2025
2c44b1d
Replace Bool with IsSkolem = SkolemConst | Definable
acl-cqc Apr 2, 2025
a98f429
wip Merge remote-tracking branch 'origin/just-nat-solving' into infer…
croyzor Apr 7, 2025
0802411
Lots of debug printing
croyzor Apr 8, 2025
d95c95f
[ minor progress ] typeEqs forks
Apr 8, 2025
575fa2e
Drop needless call to abstractAll (transitively valMatch)
croyzor Apr 8, 2025
6cbd6f3
Add debug labels to test file
croyzor Apr 8, 2025
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
155 changes: 90 additions & 65 deletions brat/Brat/Checker.hs

Large diffs are not rendered by default.

177 changes: 95 additions & 82 deletions brat/Brat/Checker/Helpers.hs
Original file line number Diff line number Diff line change
@@ -1,33 +1,14 @@
{-# LANGUAGE AllowAmbiguousTypes #-}

module Brat.Checker.Helpers {-(pullPortsRow, pullPortsSig
,simpleCheck
,combineDisjointEnvs
,ensureEmpty, noUnders
,rowToSig
,showMode, getVec
,mkThunkTy
,wire
,next, knext, anext
,kindType, getThunks
,binderToValue, valueToBinder
,kConFields
,defineSrc, defineTgt
,declareSrc, declareTgt
,makeBox
,uncons
,evalBinder
,evalSrcRow, evalTgtRow
,solveHopeVal, solveHopeSem
)-} where

import Brat.Checker.Monad (Checking, CheckingSig(..), HopeData(..), captureOuterLocals, err, typeErr, kindArgRows, defineEnd, tlup)
module Brat.Checker.Helpers where

import Brat.Checker.Monad (Checking, CheckingSig(..), HopeData(..), captureOuterLocals, err, typeErr, kindArgRows, defineEnd, tlup, isSkolem, mkYield, throwLeft)
import Brat.Checker.Types
import Brat.Error (ErrorMsg(..))
import Brat.Eval (eval, EvMode(..), kindType, quote, doesntOccur)
import Brat.FC (FC)
import Brat.Graph (Node(..), NodeType(..))
import Brat.Naming (Name, FreshMonad(..))
import Brat.Naming (Name)
import Brat.Syntax.Common
import Brat.Syntax.Core (Term(..))
import Brat.Syntax.Simple
Expand All @@ -38,23 +19,45 @@ import Hasochism
import Util (log2)

import Control.Monad ((>=>))
import Control.Monad.Freer
import Control.Monad.State.Lazy (StateT(..), runStateT)
import Control.Monad.Freer (req)
import Data.Bifunctor
import Data.Foldable (foldrM)
import Data.List (partition)
import Data.Type.Equality (TestEquality(..), (:~:)(..))
import qualified Data.Map as M
import qualified Data.Set as S
import Prelude hiding (last)

-- import Debug.Trace

simpleCheck :: Modey m -> Val Z -> SimpleTerm -> Either ErrorMsg ()
simpleCheck Braty TNat (Num n) | n >= 0 = pure ()
simpleCheck Braty TInt (Num _) = pure ()
simpleCheck Braty TFloat (Float _) = pure ()
simpleCheck Braty TText (Text _) = pure ()
simpleCheck _ ty tm = Left $ TypeErr $ unwords
import Debug.Trace

simpleCheck :: Modey m -> Val Z -> SimpleTerm -> Checking ()
simpleCheck my ty tm = case (my, ty) of
(Braty, VApp (VPar e) _) -> do
hopes <- req AskHopes
let isHope = case e of
InEnd i -> M.member i hopes
ExEnd _ -> False
if isHope then
case tm of
Float _ -> defineEnd "simpleCheck" e TFloat
Text _ -> defineEnd "simpleCheck" e TText
Num n | n < 0 -> defineEnd "simpleCheck" e TInt
Num _ -> typeErr $ "Can't determine whether Int or Nat: " ++ show tm
else isSkolem e >>= \case
SkolemConst -> throwLeft $ helper Braty ty tm
Definable -> do
mkYield "simpleCheck" (S.singleton e)
ty <- eval S0 ty
simpleCheck Braty ty tm
_ -> throwLeft $ helper my ty tm
where
helper :: Modey m -> Val Z -> SimpleTerm -> Either ErrorMsg ()
helper Braty TNat (Num n) | n >= 0 = pure ()
helper Braty TInt (Num _) = pure ()
helper Braty TFloat (Float _) = pure ()
helper Braty TText (Text _) = pure ()
helper _ ty tm = Left $ TypeErr $ unwords
["Expected something of type"
,"`" ++ show ty ++ "`"
,"but got"
Expand Down Expand Up @@ -133,11 +136,6 @@ ensureEmpty :: Show ty => String -> [(NamedPort e, ty)] -> Checking ()
ensureEmpty _ [] = pure ()
ensureEmpty str xs = err $ InternalError $ "Expected empty " ++ str ++ ", got:\n " ++ showSig (rowToSig xs)

noUnders m = do
((outs, ()), (overs, unders)) <- m
ensureEmpty "unders" unders
pure (outs, overs)

rowToSig :: Traversable t => t (NamedPort e, ty) -> t (PortName, ty)
rowToSig = fmap $ first portName

Expand Down Expand Up @@ -170,26 +168,40 @@ anext :: forall m i j k
-> Ro m i j -- Inputs and Outputs use de Bruijn indices
-> Ro m j k
-> Checking (Name, Unders m Chk, Overs m UVerb, (Semz k, Some Endz))
anext str th vals0 ins outs = do
anext str th vals0 ins outs = anext' str th vals0 ins outs $ case th of
Source -> SkolemConst
_ -> Definable

anext' :: forall m i j k
. EvMode m
=> String
-> NodeType m
-> (Semz i, Some Endz)
-> Ro m i j -- Inputs and Outputs use de Bruijn indices
-> Ro m j k
-> IsSkolem -- inports are always Definable
-> Checking (Name, Unders m Chk, Overs m UVerb, (Semz k, Some Endz))
anext' str th vals0 ins outs skol = do
node <- req (Fresh str) -- Pick a name for the thunk
-- Use the new name to generate Ends with which to instantiate types
(unders, vals1) <- endPorts node InEnd In 0 vals0 ins
(overs, vals2) <- endPorts node ExEnd Ex 0 vals1 outs
() <- sequence_ $
[ declareTgt tgt (modey @m) ty | (tgt, ty) <- unders ] ++
[ declareSrc src (modey @m) ty | (src, ty) <- overs ]
[ req (Declare (ExEnd (end src)) (modey @m) ty skol) | (src, ty) <- overs ]

let inputs = [ (portName p, biType @m ty) | (p, ty) <- unders ]
let outputs = [ (portName p, biType @m ty) | (p, ty) <- overs ]

() <- req (AddNode node (mkNode (modey @m) th inputs outputs))
pure (node, unders, overs, vals2)
where
mkNode :: forall m. Modey m -> NodeType m
-> [(PortName, Val Z)]
-> [(PortName, Val Z)]
-> Node
mkNode Braty = BratNode
mkNode Kerny = KernelNode

mkNode :: forall m. Modey m -> NodeType m
-> [(PortName, Val Z)]
-> [(PortName, Val Z)]
-> Node
mkNode Braty = BratNode
mkNode Kerny = KernelNode

type Endz = Ny :* Stack Z End

Expand Down Expand Up @@ -248,14 +260,16 @@ getThunks :: Modey m
,Overs m UVerb
)
getThunks _ [] = pure ([], [], [])
getThunks Braty ((src, Right ty):rest) = do
ty <- eval S0 ty
(src, ss :->> ts) <- vectorise Braty (src, ty)
(node, unders, overs, _) <- let ?my = Braty in
anext "Eval" (Eval (end src)) (S0, Some (Zy :* S0)) ss ts
(nodes, unders', overs') <- getThunks Braty rest
pure (node:nodes, unders <> unders', overs <> overs')
getThunks Braty row@((src, Right ty):rest) = req AskHopes >>= \h -> eval S0 ty >>= \case
VApp (VPar e@(InEnd i)) _ | M.member i h -> mkYield "getThunks" (S.singleton e) >> getThunks Braty row
ty -> do
(src, ss :->> ts) <- vectorise Braty (src, ty)
(node, unders, overs, _) <- let ?my = Braty in
anext "Eval" (Eval (end src)) (S0, Some (Zy :* S0)) ss ts
(nodes, unders', overs') <- getThunks Braty rest
pure (node:nodes, unders <> unders', overs <> overs')
getThunks Kerny ((src, Right ty):rest) = do
-- TODO we probably want to check against the HopeSet here too, good to refactor+common-up somehow
ty <- eval S0 ty
(src, ss :->> ts) <- vectorise Kerny (src,ty)
(node, unders, overs, _) <- let ?my = Kerny in anext "Splice" (Splice (end src)) (S0, Some (Zy :* S0)) ss ts
Expand Down Expand Up @@ -297,7 +311,7 @@ vectorise my (src, ty) = do
next "MapFun" MapFun (S0, Some (Zy :* S0))
(REx ("len", Nat) (RPr ("value", weak1 ty) R0))
(RPr ("vector", weak1 vecFun) R0)
defineTgt lenTgt (VNum len)
defineTgt' "vectorise" lenTgt (VNum len)
wire (lenSrc, kindType Nat, lenTgt)
wire (valSrc, ty, valTgt)
let vecCTy = case (my,my',cty) of
Expand Down Expand Up @@ -334,16 +348,19 @@ valueToBinder Braty = Right
valueToBinder Kerny = id

defineSrc :: Src -> Val Z -> Checking ()
defineSrc src = defineEnd (ExEnd (end src))
defineSrc src = defineEnd "" (ExEnd (end src))

defineTgt :: Tgt -> Val Z -> Checking ()
defineTgt tgt = defineEnd (InEnd (end tgt))
defineTgt tgt = defineEnd "" (InEnd (end tgt))

defineSrc' :: String -> Src -> Val Z -> Checking ()
defineSrc' lbl src = defineEnd lbl (ExEnd (end src))

declareSrc :: Src -> Modey m -> BinderType m -> Checking ()
declareSrc src my ty = req (Declare (ExEnd (end src)) my ty)
defineTgt' :: String -> Tgt -> Val Z -> Checking ()
defineTgt' lbl tgt = defineEnd lbl (InEnd (end tgt))

declareTgt :: Tgt -> Modey m -> BinderType m -> Checking ()
declareTgt tgt my ty = req (Declare (InEnd (end tgt)) my ty)
declareTgt tgt my ty = req (Declare (InEnd (end tgt)) my ty Definable)

-- listToRow :: [(PortName, BinderType m)] -> Ro m Z i
-- listToRow [] = R0
Expand All @@ -360,14 +377,14 @@ makeBox name cty@(ss :->> ts) body = do
(tgt, unders, _, _) <- anext (name ++ "/out") Target ctx ts R0
case (?my, body) of
(Kerny, _) -> do
(_,_,[thunk],_) <- next (name ++ "_thunk") (Box M.empty src tgt) (S0, Some (Zy :* S0))
(_,_,[thunk],_) <- next (name ++ "_thunk") (Box src tgt) (S0, Some (Zy :* S0))
R0 (RPr ("thunk", VFun Kerny cty) R0)
bres <- name -! body (overs, unders)
bres <- body (overs, unders)
pure (thunk, bres)
(Braty, body) -> do
(bres, captures) <- name -! captureOuterLocals (body (overs, unders))
(_, [], [thunk], _) <- next (name ++ "_thunk") (Box captures src tgt) (S0, Some (Zy :* S0))
(node, [], [thunk], _) <- next (name ++ "_thunk") (Box src tgt) (S0, Some (Zy :* S0))
R0 (RPr ("thunk", VFun ?my cty) R0)
bres <- captureOuterLocals node (body (overs, unders))
pure (thunk, bres)

-- Evaluate either mode's BinderType
Expand Down Expand Up @@ -477,7 +494,7 @@ buildSub n = do
nDangling <- buildNum n
((lhs,rhs),out) <- buildArithOp Sub
req $ Wire (end nDangling, TNat, end rhs)
defineTgt lhs (VNum (nPlus n (nVar (VPar (toEnd out)))))
defineTgt' "Sub" lhs (VNum (nPlus n (nVar (VPar (toEnd out)))))
pure (lhs, out)

buildDoub :: Checking (Tgt, Src)
Expand All @@ -493,24 +510,22 @@ buildHalve = do
nDangling <- buildNum 2
((lhs,rhs),out) <- buildArithOp Div
req $ Wire (end nDangling, TNat, end rhs)
defineTgt lhs (VNum (n2PowTimes 1 (nVar (VPar (toEnd out)))))
defineTgt' "Helpers"lhs (VNum (n2PowTimes 1 (nVar (VPar (toEnd out)))))
pure (lhs, out)

replaceHope :: InPort -> InPort -> Checking ()
replaceHope old new = do
hs <- req AskHopes
case M.lookup old hs of
Nothing -> pure ()
Just hd -> do
req (RemoveHope old)
req (ANewHope new (HopeData Nothing (hopeDynamic hd)))
Just hd -> req (ANewHope new (HopeData Nothing (hopeDynamic hd)))

-- Return an End with the same polarity whose value is half that of the input End
makeHalf :: End -> Checking End
makeHalf (InEnd e) = do
(doubIn, doubOut) <- buildDoub
req (Wire (end doubOut, TNat, e))
defineTgt (NamedPort e "") (VNum (nVar (VPar (toEnd doubOut))))
defineTgt' "Helpers"(NamedPort e "") (VNum (nVar (VPar (toEnd doubOut))))
replaceHope e (end doubIn)
pure (InEnd (end doubIn))
makeHalf (ExEnd e) = do
Expand All @@ -523,7 +538,7 @@ makePred :: End -> Checking End
makePred (InEnd e) = do
(succIn, succOut) <- buildAdd 1
req (Wire (end succOut, TNat, e))
defineTgt (NamedPort e "") (VNum (nVar (VPar (toEnd succOut))))
defineTgt' "Helpers"(NamedPort e "") (VNum (nVar (VPar (toEnd succOut))))
replaceHope e (end succIn)
pure (toEnd succIn)
makePred (ExEnd e) = do
Expand All @@ -542,7 +557,8 @@ buildNatVal nv@(NumValue n gro) = case n of
(inn, out) <- buildAdd n
src <- buildGro gro
req $ Wire (end src, TNat, end inn)
defineTgt inn (VNum (nVar (VPar (toEnd src))))
traceM $ "buildNatVal " ++ show inn
defineTgt' "Helpers"inn (VNum (nVar (VPar (toEnd src))))
pure out
where
buildGro :: Fun00 (VVar Z) -> Checking Src
Expand Down Expand Up @@ -587,8 +603,8 @@ invertNatVal (NumValue up gro) = case up of
req $ Wire (end upSrc, TNat, end rhs)
tgt <- invertGro gro
req $ Wire (end out, TNat, end tgt)
defineTgt tgt (VNum (nVar (VPar (toEnd out))))
defineTgt lhs (VNum (nPlus up (nVar (VPar (toEnd tgt)))))
defineTgt' "Helpers"tgt (VNum (nVar (VPar (toEnd out))))
defineTgt' "Helpers"lhs (VNum (nPlus up (nVar (VPar (toEnd tgt)))))
pure lhs
where
invertGro Constant0 = error "Invariant violated: the numval arg to invertNatVal should contain a variable"
Expand All @@ -602,17 +618,17 @@ invertNatVal (NumValue up gro) = case up of
tgt <- invertMono mono
req $ Wire (end out, TNat, end tgt)
req $ Wire (end divisor, TNat, end rhs)
defineTgt tgt (VNum (nVar (VPar (toEnd out))))
defineTgt lhs (VNum (n2PowTimes k (nVar (VPar (toEnd tgt)))))
defineTgt' "Helpers"tgt (VNum (nVar (VPar (toEnd out))))
defineTgt' "Helpers"lhs (VNum (n2PowTimes k (nVar (VPar (toEnd tgt)))))
pure lhs

invertMono (Linear (VPar (InEnd e))) = pure (NamedPort e "numval")
invertMono (Full sm) = do
(_, [(llufTgt,_)], [(llufSrc,_)], _) <- next "luff" (Prim ("BRAT","lluf")) (S0, Some (Zy :* S0)) (REx ("n", Nat) R0) (REx ("n", Nat) R0)
tgt <- invertSM sm
req $ Wire (end llufSrc, TNat, end tgt)
defineTgt tgt (VNum (nVar (VPar (toEnd llufSrc))))
defineTgt llufTgt (VNum (nFull (nVar (VPar (toEnd tgt)))))
defineTgt' "Helpers"tgt (VNum (nVar (VPar (toEnd llufSrc))))
defineTgt' "Helpers"llufTgt (VNum (nFull (nVar (VPar (toEnd tgt)))))
pure llufTgt

-- This will update the `hopes`, potentially invalidating things that have
Expand All @@ -621,13 +637,12 @@ invertNatVal (NumValue up gro) = case up of
solveHopeVal :: TypeKind -> InPort -> Val Z -> Checking ()
solveHopeVal k hope v = case doesntOccur (InEnd hope) v of
Right () -> do
defineEnd (InEnd hope) v
defineEnd "solveHopeVal" (InEnd hope) v
dangling <- case (k, v) of
(Nat, VNum v) -> buildNatVal v
(Nat, _) -> err $ InternalError "Head of Nat wasn't a VNum"
_ -> buildConst Unit TUnit
req (Wire (end dangling, kindType k, hope))
req (RemoveHope hope)
Left msg -> case v of
VApp (VPar (InEnd end)) B0 | hope == end -> pure ()
-- TODO: Not all occurrences are toxic. The end could be in an argument
Expand Down Expand Up @@ -680,13 +695,11 @@ valPats2Val (k:ks) (v:vs) = do
valPats2Val [] [] = pure (B0, [])
valPats2Val _ _ = err $ InternalError "Type args didn't match expected - kindCheck should've sorted it"

{-
traceChecking :: (Show a, Show b) => String -> (a -> Checking b) -> (a -> Checking b)
traceChecking lbl m a = do
traceM ("Enter " ++ lbl ++ ": " ++ show a)
b <- m a
traceM ("Exit " ++ lbl ++ ": " ++ show b)
pure b
-}

traceChecking = const id
-- traceChecking = const id
Loading