-
Notifications
You must be signed in to change notification settings - Fork 339
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
Failure of termination checking for reflection-generated code due to data projections #5922
Comments
Yes, by virtue of the hidden argument to F-to-N : {b : Nat} -> Fin b -> Nat
F-to-N {b} = \ { fz -> zero
; (fs {a} x) -> apply x (F-to-N {a}) \ { x -> suc x } } |
There is definitely something broken with the open import Agda.Builtin.Nat
open import Agda.Builtin.Reflection
open import Agda.Builtin.Unit
data Fin : Nat → Set where
fz : (b : Nat) → Fin (suc b)
fs : (b : Nat) → Fin b → Fin (suc b)
apply : {A B C : Set} (input : A) (f : A → B) (cont : B → C) → C
apply input f cont = cont (f input)
macro
id-macro : (b : Nat) → (Fin b → Nat) → Term → TC ⊤
id-macro b f hole =
bindTC (quoteTC f) λ f-term →
unify hole f-term
test : (b : Nat) → Fin b → Nat
test b = id-macro ? λ where
(fz _) → zero
(fs a x) → apply x (test a) suc But if the solution is put in (C-c C-s) and we reload (C-c C-l), we get the termination error:
Note the garbage |
Ok, this seems to be the "projection" from agda/src/full/Agda/TypeChecking/Rules/Data.hs Lines 317 to 319 in ca5fb2a
So, maybe |
I stumbled over the following issue when looking for uses of @Saizan wrote:
So this issue is new forcing translation redux (ping @UlfNorell), and my refactoring only brought the problem to the surface. Indeed, with option I read through the discussion at: I understood the following:
Yeah, just don't lean too far out of the window... |
Thanks for looking into it @andreasabel! For now I'll use |
2022-06-10 Discussion with Ulf: We could extend the termination checker to count projections from data as decrease. |
Q: Why are the projections not normalized against the constructors? Shouldn't this be just |
Irritated by the data projection redexes showing up in the termination error of issue #5922, I tried to get them reduced, which already fixed the instance given in the issue.
…nstructor Use @defApp f []@ instead of @def f@. There is no test case showing that this is necessary here, but it guarantees that there will be no projection redexes.
Submitted PR to the extent of reducing data projections. This already fixes the issue (at least the OP). |
Irritated by the data projection redexes showing up in the termination error of issue #5922, I tried to get them reduced, which already fixed the instance given in the issue.
…nstructor Use @defApp f []@ instead of @def f@. There is no test case showing that this is necessary here, but it guarantees that there will be no projection redexes.
Yes, my use case is fixed! Fantastic, thank you. |
In the following, the function
F-to-N
passes the termination checker:If we define a trivial macro which quotes and then unquotes the function, it still passes:
But if we explicitly pass the argument
b
to the macro, termination checking fails:gives the warning
Another way to cause (to me unexpected) termination checking failure is to check the type of
f-term
in the macro, i.e.I'm pretty new to Agda, so I don't 100% know what the intended behaviour is/should be here. Are we sure that the original
F-to-N
functon should pass termination checking?In my use-case I need to define functions with this structure in a macro, so I very much hope that this is supposed to work and can be fixed.
Thanks in advance for any help.
This issue may be related to/have the same underlying cause as #5747.
I'm using Agda version 2.6.2.2.
The text was updated successfully, but these errors were encountered: