-
Notifications
You must be signed in to change notification settings - Fork 37
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
type-directed compilation #270
Conversation
afa75f8
to
222eed4
Compare
All the tests pass again, finally. Before merging this PR, there's still one caveat to fix: currently every test has the flag The following things are likely to break once I remove the flag:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! This is definitely a major improvement to the compilation process of agda2hs
. Going through the changes also made me realize that we're really not dealing with a small project here anymore. I have a couple of remarks and I think the projection-like functions should still be fixed. But overall I think this should be merged sooner rather than later.
Thanks for the review! My git skills are fairly limited but you're right that making another PR for purely cosmetic refactorings would be better. I'll see what I can do. |
Rebased on #277. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work Lucas!
One thing that slightly worries me is that I would expect this refactoring to reduce code size, but it in fact increases it substantially (c.f. +800/-500). Factoring out new tests and utilities we did not need before, it seems the main culprit is Compile.Term
; do you think the final polished version might be able to reduce LOC down a bit?
PS: Ping me when the projection-like optimization has been properly handled.
Implicit arguments with instance functions are still a compiler error, is this expected? i.e. test : {x : Nat} → Nat
test {x} = x
{-# COMPILE AGDA2HS test #-} will work but instance
test : {x : Nat} → Nat
test {x} = x
{-# COMPILE AGDA2HS test #-} will give
|
Hmm, to be fair the compilation of class instances is the part I'm the least happy with currently (the current implementation and what I did to make it typed). Though I fail to see when a compiled instance with hidden relevant arguments turning relevant would ever make sense. I will add a check that for instances specifically, no relevant arguments are ever hidden as I think this would do the trick. Thanks for the example! If you ever encounter an example where this would be useful behavior, hit me up! |
I came across this experimenting with adding runtime checks for e.g. erased preconditions. A deciding version of a precondition would ideally be written as instance so it can be found in instance search: instance
decLt : {x y : Nat} → Haskell.Extra.Dec.Dec (x Data.Nat.< y)
decLt {x} {y} = (x Haskell.Prelude.< y) ⟨ … ⟩
subtractFromGreater : (x y : Nat) → (@0 checkThis : x Data.Nat.< y) → Nat
subtractFromGreater x y lt = _-_ y x ⦃ … ⦄
{-# COMPILE AGDA2HS subtractFromGreater rtc checkThis #-} then |
@omelkonian: I fixed the compilation of projection-like functions and addressed all of your comments! You will see that one test still requires the
If you remove the flag, the code will still compile to correct Haskell, but the projection-like function If someone is really motivated, perhaps using projView could allow you to preserve the projection-like function application, but I think you'd still have to trigger inference at some point, which I don't want to do.
Hm, going into this implementation I had the same assumption, but quickly realized some more work was unavoidable (e.g Defs and projections cannot really be treated uniformly anymore). Hopefully things should be more easily maintainable too :)
But the instance itself shouldn't be compiled to agda2hs right? Or using some custom logic (that you'd have to implement yourself). I decided against adding the check I mentioned above, since the class compilation routine already doesn't enforce that, say, we don't pattern-match on parameters of instances, and they are silently dropped til we reach a (class) projection (See here). So something should be done alright, just not in this PR! |
Could you also add these unit tests, i.e. the ones without the flag where the generated code is further away from what the user wrote? Then, a subsequent PR that improves on that (e.g. using |
Done! (See |
A big refactoring as a first step to properly handle module parameters.
The most important change is the following: the compilation of terms if now completely type-directed. That is, we no longer rely on
ArgInfo
ofElims
to know whether they have to be preserved, but rather theirDom Type
only.What this means, concretely:
(a : Set)
) are dropped.{x : Nat}
) are made explicit.(This means we now officially support tactic arguments that are made explicit on the Haskell side.)
As a treat, we now properly erase types of sort
Prop
.Closes #217.
TODO list before opening the PR: