-
Notifications
You must be signed in to change notification settings - Fork 338
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
Wrong de Bruijn indices for reflected variables inside an extended context #3831
Comments
Shouldn't |
The last argument to a macro does not get into the context, as If the last argument should be inside the context, then we shall open another issue for it. |
The arguments to the macro doesn't matter, it's the context of the call site that's relevant. So you'd expect:
|
Right, of course. |
I'd like to fix this myself. If I understand it correctly, I shall start from the following function, right? agda/src/full/Agda/TypeChecking/Unquote.hs Lines 635 to 636 in af3c1cf
|
Yes. |
Do you think this bug is related to the following issue? Here, we are extending the context with a Set, and then with an element of the set (i.e., var 0). But when we try to unquote the element (again, var 0), we get an error from de Bruijn indices. From our understanding, it seems that the elements in the context are not being lifted to acomodate to the new variable, is that correct? Macro: macro
fail : Term → TC ⊤
fail hole = do
st ← quoteTC Set
t ← extendContext (vArg st) (do
v ← unquoteTC {A = Set} $ var₀ zero
extendContext (vArg (var₀ zero)) (do
unquoteTC {A = v} $ var₀ zero
returnTC tt
)
)
u ← quoteTC {A = ⊤} t
unifyTC hole u When normalizing
|
Yes. If you observe the de Bruijn index for The problem is that the de Bruijn index is assigned and fixed when Agda transforms the reflected or abstract syntaxes to the internal syntax, and It is not obvious to me how this can be fixed without changing I will check contextual modal type theory as well ... |
Now that I think of it, wouldn't it suffice to just lift the indices of the continuation by 1? |
(@beta-ziliani talking here: I don't think CMTT is the answer...) |
Huh, that was what I thought initially. Hope I am wrong. Agda provides not only I am not familiar with semantics of type theory with elaborator reflection. If you know any reference on this, please let me know. |
Sorry, I'm missing the point about |
Okay, maybe a concrete macro. The question is what the intended behaviour of the following macro is. postulate
whatever : ∀ {a} {A : Set a} → A
macro
f : Term → TC ⊤
f hole = do
extendContext (vArg (quoteTerm ℕ)) do
x ← unquoteTC {A = ℕ} (var₀ 0)
inContext [] do
var₀ i ← quoteTC x -- what is `i` here?
where _ → whatever
typeError (strErr (show i) ∷ []) For now, Agda shows |
I would expect it to fail, but perhaps I'm missing some point here. @UlfNorell ? |
Alright, I overthought the problem. I will just increase the index inside agda/src/full/Agda/TypeChecking/Unquote.hs Lines 665 to 668 in af3c1cf
As for |
These days the interaction test case corresponding to this issue This does not appear to have been intended by the original commit and So I'm reopening this issue. |
Also, I am not sure why we have both |
It looks like this
As far as I understand, |
If the error comes from a user mistake when writing code on the reflected |
Agree! Make another PR to change the behaviour of |
I think the (now only) use of
So, the idea was that I intend to trigger a crash with a certain verbosity setting when this program point is reached. The idea was that I wanted to make sure that a certain test case does not reach a certain program location. |
Okay, so I will invent another kind of |
Do we really need a test case that refers to a specific line in the Agda source code? It changes with practically every major commit, which makes it very hard to avoid conflicts when people are working on multiple branches at the same time. |
Indeed it should not report the position. The correct fix is to check the debruijn indices explicitly (rather than strengthen blindly), and issue a proper type error if they're bad. |
No, we don't. Based on the discussion with @gallais and @andreasabel, the fix will be the one suggested by @UlfNorell. [ I just need to wait for my work laptop to arrive and work on it. I can't do this on my almost a decade old laptop. ] |
Consider the following macro.
If we execute the above code in Emacs by normalising
then we will get the following message
showing that the de Bruijn indices
i
andj
are both0
. However,i
should be1
.The text was updated successfully, but these errors were encountered: