Skip to content

feat: Add nat hope solving #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f783923
Add hole solving but not for nats
croyzor Dec 18, 2024
d981a5b
feat: Add nat hope solving
croyzor Dec 18, 2024
6f9d28a
Merge branch 'main' into just-holes
croyzor Dec 23, 2024
889fb32
Merge remote-tracking branch 'origin/main' into HEAD
acl-cqc Jan 7, 2025
2bc84cf
Drop unnecessary 'derive Ord' for TypeKind
acl-cqc Jan 7, 2025
e32d0b9
Remove repeated export of DIRY in Syntax/Common.hs
acl-cqc Jan 7, 2025
3a60703
review comments
acl-cqc Jan 7, 2025
4965210
another comment
acl-cqc Jan 7, 2025
9b8a997
No need to filter hopes, but clarify with error
acl-cqc Jan 7, 2025
06c454e
Factor out getNumVar, use in typeEq'
acl-cqc Jan 7, 2025
6b05fb6
hlint
acl-cqc Jan 7, 2025
ce5c348
Merge remote-tracking branch 'origin/main' into just-holes
acl-cqc Jan 7, 2025
daf2443
Merge branch 'just-holes' into HEAD
acl-cqc Jan 7, 2025
98c74f8
Don't (re-)export buildNum from SolveHoles.hs
acl-cqc Jan 7, 2025
f5c0a20
and further reduce diff
acl-cqc Jan 7, 2025
8f83c77
Compute 2^constant at compile-time (#74)
acl-cqc Jan 7, 2025
6a94b85
Merge remote-tracking branch 'origin/main' into just-nat-solving
croyzor Apr 1, 2025
90a3ade
[ broken ] troublesome examples of nat solving
Apr 1, 2025
2d9fb1a
Fix demandEven
croyzor Apr 1, 2025
e4010b4
Fix recursive call in `hasfulllen`
croyzor Apr 1, 2025
783107c
[ minor fix ] hasfulllen needs a numeric input
Apr 1, 2025
aa0a509
Fix the other call site that calls `invertNatVal` with a Src
croyzor Apr 1, 2025
61dd235
[ progress ] factored out SolveNumbers; started numEq (to be nuked)
Apr 2, 2025
ae05f2e
[ progress ] unifyNum now used in solveHoles as well as solvePatterns…
Apr 2, 2025
b81186a
[ progress ] Fred vs Ginger now a thing.
Apr 2, 2025
09641ea
[ progress ] eatsfullbis.brat now typechecks; long way to go; messy
Apr 3, 2025
5b0c6a8
Skeleton for converting valPats to Valz
croyzor Apr 3, 2025
16ccb96
[wip] Bug hunting
croyzor Apr 4, 2025
4acf90c
[ fix ] makePred now defines the hole to be the succ
Apr 4, 2025
537346b
[ progress ] removed tracing
Apr 7, 2025
36b1a0d
[ progress ] no more Fred and Ginger
Apr 7, 2025
3930d3d
Fix redefinition in make{Half,Pred}
croyzor Apr 7, 2025
1cd750d
Keep track of which hopes are dynamic
croyzor Apr 7, 2025
ae3be34
Better handling of flex-flex case when unifying numbers
croyzor Apr 7, 2025
6724dbd
Accept new golden values, regress vector errors for now
croyzor Apr 7, 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
27 changes: 21 additions & 6 deletions brat/Brat/Checker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import Bwd
import Hasochism
import Util (zipSameLength)

-- import Debug.Trace

-- Put things into a standard form in a kind-directed manner, such that it is
-- meaningful to do case analysis on them
standardise :: TypeKind -> Val Z -> Checking (Val Z)
Expand Down Expand Up @@ -456,22 +458,35 @@ check' tm@(Con vcon vargs) ((), (hungry, ty):unders) = case (?my, ty) of
where
aux :: Modey m -> (QualName -> QualName -> Checking (CtorArgs m)) -> Val Z -> Checking ()
aux my lup ty = do
-- TODO: Use concurrency to avoid strictness - we don't have to work out that
-- this is a VCon immediately.
VCon tycon tyargs <- eval S0 ty
-- traceM $ "checking constructor of type: " ++ show tycon ++ " " ++ show tyargs
(CArgs pats nFree _ argTypeRo) <- lup vcon tycon
-- Look for vectors to produce better error messages for mismatched lengths
wrap <- detectVecErrors vcon tycon tyargs pats ty (Left tm)
Some (ny :* env) <- throwLeft $ valMatches tyargs pats
-- wrap <- detectVecErrors vcon tycon tyargs pats ty (Left tm)
-- Get the kinds of type args
let m = deModey my -- TODO: remember what this is
(_, ks) <- unzip <$> tlup (m, tycon)
-- Turn `pats` into values for unification
(varz, patVals) <- valPats2Val ks pats
-- traceM $ "problem: " ++ show tyargs ++ " =?= " ++ show patVals
-- Create a unification problem between tyargs and the value versions of pats
typeEq (show tycon) (TypeFor m []) (VCon tycon tyargs) (VCon tycon patVals)
-- traceM "Made it past unification"
Some (ny :* env) <- pure $ bwdStack varz
-- Make sure env is the correct length for args
Refl <- throwLeft $ natEqOrBust ny nFree
let topy = roTopM my ny argTypeRo
-- Weaken the scope of ty from Z to the top end of argTypeRo
-- in the kernel case the bottom and top of the row are the same
let ty' = weaken topy ty
env <- traverseStack (sem S0) env
-- traceM $ "Matchenv: " ++ show env
(_, argUnders, [(dangling, _)], _) <- anext (show vcon) (Constructor vcon)
(env, Some (Zy :* S0))
argTypeRo (RPr ("value", ty') R0)
(((), ()), ((), leftUnders)) <- wrapError wrap $ check vargs ((), argUnders)
(((), ()), ((), leftUnders)) <- {- wrapError wrap $ -} check vargs ((), argUnders)
ensureEmpty "con unders" leftUnders
wire (dangling, ty, hungry)

Expand Down Expand Up @@ -663,7 +678,7 @@ check' (Of n e) ((), unders) = case ?my of
check' Hope ((), (NamedPort hope _, ty):unders) = case (?my, ty) of
(Braty, Left _k) -> do
fc <- req AskFC
req (ANewHope hope fc)
req (ANewHope hope (HopeData (Just fc) True))
pure (((), ()), ((), unders))
(Braty, Right _ty) -> typeErr "Can only infer kinded things with !"
(Kerny, _) -> typeErr "Won't infer kernel typed !"
Expand Down Expand Up @@ -1146,11 +1161,11 @@ run ve initStore ns m = do
-- If the `hopes` set has any remaining holes with kind Nat, we need to abort.
-- Even though we didn't need them for typechecking problems, our runtime
-- behaviour depends on the values of the holes, which we can't account for.
case M.toList $ M.filterWithKey (\e _ -> isNatKinded tyMap (InEnd e)) (hopes ctx) of
case M.toList $ M.filterWithKey (\e hd -> isNatKinded tyMap (InEnd e) && hopeDynamic hd) (hopes ctx) of
[] -> pure (a, (holes, store ctx, graph))
-- Just use the FC of the first hole while we don't have the capacity to
-- show multiple error locations
hs@((_,fc):_) -> Left $ Err (Just fc) (RemainingNatHopes (show . fst <$> hs))
hs@((_,hd):_) -> Left $ Err (hopeFC hd) (RemainingNatHopes (show . fst <$> hs))
where
isNatKinded tyMap e = case tyMap M.! e of
EndType Braty (Left Nat) -> True
Expand Down
Loading
Loading