Skip to content
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

feat: Allow writing holes which are solved by BRAT #59

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open

Conversation

croyzor
Copy link
Collaborator

@croyzor croyzor commented Nov 27, 2024

Closes #28 and #30

Copy link
Collaborator

@acl-cqc acl-cqc left a comment

Choose a reason for hiding this comment

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

Ok, so

  • The number of comments suggests you've managed to break out a good sized chunk of code that is not too overwhelming :-), which is an achievement in itself - well done and thank you :-) 😁 👍
  • There's a lot of hard stuff in the nat-inversion-building that I really haven't followed through the logic - I can only say that it looks plausible. However really I would prefer to do one of
    • Add tests that cover all the cases and at least compile them down to Hugr. Then when we are able to execute them we suddenly gain a massive amount of assurance that we are actually building something sensible ;-) ;-)
    • If these functions are not covered by tests, then leave them error "TODO" here, and move the logic into another PR which can remain WIP until we do have tests (or at least, more time to think about them)
    • If the tests are only writable once we have Fork, lets leave them todo and move the code into Multi-threaded type inference #41 (they are quite localized - no change to APIs - so there shouldn't be much fallout from leaving them out of this PR)

@@ -724,7 +731,7 @@ checkBody fnName body cty = do
NoLhs tm -> pure (tm, (fcOf tm, fcOf tm))
Clauses (c :| cs) -> do
fc <- req AskFC
pure $ (WC fc (Lambda c cs), (bimap fcOf fcOf c))
pure (WC fc (Lambda c cs), bimap fcOf fcOf c)
Copy link
Collaborator

Choose a reason for hiding this comment

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

A few drive-bys here. Not sure if these come from linting! Feel free to punt out into a separate trivial PR that I can just trivially hit approve...

brat/Brat/Checker/Helpers.hs Outdated Show resolved Hide resolved
brat/Brat/Checker/Monad.hs Outdated Show resolved Hide resolved
brat/Brat/Checker/Monad.hs Show resolved Hide resolved
brat/Brat/Checker/Monad.hs Outdated Show resolved Hide resolved
@@ -799,7 +806,7 @@ kindCheck ((hungry, k@(TypeFor m [])):unders) (Con c arg) = req (TLup (m, c)) >>
-- the thing we *do* define kindOut as

(_, argUnders, [(kindOut,_)], (_ :<< _va, _)) <-
next "" Hypo (S0, Some (Zy :* S0)) aliasArgs (REx ("type",Star []) R0)
next "aliasargs" Hypo (S0, Some (Zy :* S0)) aliasArgs (REx ("type",Star []) R0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe call this "kc_alias" and the other "load_alias" or something like that?


-- Both targets, we need to create the thing that they both derive from
(InEnd bigTgt, [VPar (InEnd weeTgt)]) -> do
(_, [(idTgt, _)], [(idSrc, _)], _) <- anext "numval id" Id (S0, Some (Zy :* S0))
Copy link
Collaborator

Choose a reason for hiding this comment

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

(This case has no test coverage)

@@ -266,9 +279,23 @@ unifyNum (NumValue lup lgro) (NumValue rup rgro)
-- 2^k * x
-- = 2^k * (y + 1)
-- = 2^k + 2^k * y
demandSucc (StrictMono k (Linear (VPar (ExEnd out)))) = do
y <- mkPred out
demandSucc _sm@(StrictMono _k (Linear (VPar (ExEnd _x)))) = error "Todo..." {-do
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the whole of demandSucc has no test coverage

halfTgt <- buildNatVal (NumValue 0 (StrictMonoFun (StrictMono 1 (Linear (VPar (toEnd tgt))))))
let half = nVar (VPar (toEnd halfTgt))
solveNumMeta (InEnd tgt) (n2PowTimes 1 half)
pure (StrictMonoFun (StrictMono 0 (Linear (VPar (toEnd halfTgt)))))
Full sm -> StrictMonoFun sm <$ demand0 (NumValue 0 (StrictMonoFun sm))
evenGro (StrictMonoFun (StrictMono n mono)) = pure (StrictMonoFun (StrictMono (n - 1) mono))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the only line of evenGro that has test coverage

Full sm -> StrictMonoFun sm <$ demand0 (NumValue 0 (StrictMonoFun sm))
evenGro (StrictMonoFun (StrictMono n mono)) = pure (StrictMonoFun (StrictMono (n - 1) mono))

-- Check a numval is odd, and return its rounded down half
oddGro :: Fun00 (VVar Z) -> Checking (NumVal (VVar Z))
oddGro (StrictMonoFun (StrictMono 0 mono)) = case mono of
Linear (VPar (ExEnd out)) -> mkPred out >>= demandEven
Linear _ -> err . UnificationError $ "Can't force " ++ show n ++ " to be even"
-- TODO: Why aren't we using `out`??
Copy link
Collaborator

Choose a reason for hiding this comment

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

None of oddGro has test coverage

croyzor added a commit that referenced this pull request Dec 3, 2024
And other drive-by fixes pulled out from #59

---------

Co-authored-by: Alan Lawrence <[email protected]>
@acl-cqc acl-cqc mentioned this pull request Dec 9, 2024
3 tasks
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.

feat: Let BRAT fill in holes
2 participants