Repository navigation
Compare compile-to targets with alpha equivalence - #507
jespercockx wants to merge 3 commits into
Conversation
| eqName :: AlphaRenaming -> Name () -> Name () -> Bool | ||
| eqName ren x y = case lookup x ren of | ||
| Just y' -> y == y' | ||
| Nothing -> x == y && y `notElem` map snd ren |
There was a problem hiding this comment.
The current code does not consider shadowing
| eqName :: AlphaRenaming -> Name () -> Name () -> Bool | |
| eqName ren x y = case lookup x ren of | |
| Just y' -> y == y' | |
| Nothing -> x == y && y `notElem` map snd ren | |
| eqName :: AlphaRenaming -> Name () -> Name () -> Bool | |
| eqName ren x y = case find (\(x', y') -> x' == x || y' == y) ren of | |
| Just (x', y') -> x' == x && y' == y | |
| Nothing -> x == y |
There was a problem hiding this comment.
\a b -> a and \b b -> b are not alpha equivalent but eqName [(b, b), (a, b)] a b computes to True currently
| forM_ (zip args1 args2) $ \(b1, b2) -> | ||
| unless (b1 == b2) $ fail $ | ||
| unless (alphaEq b1 b2) $ fail $ |
There was a problem hiding this comment.
I believe alpha equivalence check here should be done under the identity renaming of type parameters, rather than the empty renaming.
There was a problem hiding this comment.
Testcase:
data Foo (a b : Type) : Type where
C : b → a → Foo a b
{-# COMPILE AGDA2HS Foo #-}
data Bar (a b : Type) : Type where
C : a → b → Bar a b -- swapped!
{-# COMPILE AGDA2HS Bar to Foo #-}| eqAlpha ren' mvs mvs2 | ||
| && eqAlpha ren' mctx mctx2 | ||
| && eqAlpha ren' ih ih2 | ||
| where ren' = zip (tyVarBinders mvs) (tyVarBinders mvs2) ++ ren |
There was a problem hiding this comment.
ren' does not contain implicitly forall-quantified variables. mvs only contains vars bound by foralls we explicitly generate (for module parameters, for example).
wasabi315
left a comment
There was a problem hiding this comment.
Thank you for the fix! I found some places where the check is too permissive.
|
Thank you for the review. I'm really sorry that this was such a sloppy PR. In the future, I will be more diligent to double-check the implementation myself before requesting a review. For now, I can definitely fix the issues you identified but I'm not very confident in the correctness of this implementation. So perhaps it is better to postpone this until after the release of 1.5. |
Succeed tests now run agda2hs with warnings enabled and fail if any are emitted, so warning-producing tests must live in the Warn directory. Fix the incidental warnings in the existing Succeed tests: remove a stale hiding clause and suppress the intentional unreachable-clause warnings in the indexed Vec instance tests.
The checks for a `to` pragma now compare the translated Haskell code up to alpha-equivalence, so the names of local variables (pattern variables, type variables, and lambda and do bound variables) and of auxiliary definitions from a where block may differ between the source and the target.
- `eqName` now accounts for shadowing by resolving both names to their innermost binder instead of only checking the left name. - The compile-to checks for datatypes compare the datatype parameters by identity rather than treating them as implicitly quantified, so swapped constructor argument types are rejected. - `eqInstRule` includes the implicitly quantified variables of the whole instance rule in the renaming, so they are renamed consistently across the context and the head. Add a regression test for each issue: a shadowing case in the function clause warning test, a swapped-parameter datatype in a new fail test, and an inconsistently reordered instance in the instance warning test.
cfbab07 to
3519960
Compare
This fixes #479 by comparing the compiled Haskell code up to alpha equivalence for both bound variables and names of local helper functions.
Incidentally, it also updates the test runner so Succeed tests cannot produce any warnings, only Warn tests are allowed to do so.