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

The reflection machinery does not treat the module telescope consistently #6200

Closed
nad opened this issue Oct 18, 2022 · 2 comments · Fixed by #5858
Closed

The reflection machinery does not treat the module telescope consistently #6200

nad opened this issue Oct 18, 2022 · 2 comments · Fixed by #5858
Assignees
Labels
reflection Elaborator reflection, macros, tactic arguments type: enhancement Issues and pull requests about possible improvements
Milestone

Comments

@nad
Copy link
Contributor

nad commented Oct 18, 2022

The reflection primitives getType and getDefinition return definitions that include the module telescope. However, the quoting machinery does not in general return definitions that have been lifted to the top-level. Here is one example:

{-# OPTIONS -vdbg:5 #-}

module Bad (A : Set) where

open import Agda.Builtin.Equality
open import Agda.Builtin.List
open import Agda.Builtin.Reflection
open import Agda.Builtin.Unit

f : A  A
f x = x

macro

  m : Term  TC ⊤
  m goal =
    bindTC (getType (quote f)) λ type 
    bindTC (debugPrint "dbg" 5
              (strErr "Type of f: " ∷ termErr type ∷ [])) λ _ 
    bindTC (inferType goal) λ type 
    bindTC (quoteTC type) λ type 
    bindTC (debugPrint "dbg" 5
              (strErr "Goal type: " ∷ termErr type ∷ [])) λ _ 
    unify goal (con (quote refl) [])

_ : f ≡ f
_ = m

Output:

Type of f: (A₁ : Set₀) (z : A₁) → A₁
Goal type: def (quote _≡_)
           (arg (arg-info hidden (modality relevant quantity-ω))
            (def (quote Agda.Primitive.lzero) [])
            ∷
            arg (arg-info hidden (modality relevant quantity-ω))
            (pi
             (arg (arg-info visible (modality relevant quantity-ω)) (var 0 []))
             (abs "_" (var 1 [])))
            ∷
            arg (arg-info visible (modality relevant quantity-ω))
            (def (quote f) [])
            ∷
            arg (arg-info visible (modality relevant quantity-ω))
            (def (quote f) [])
            ∷ [])

Note that the type of f includes the module parameter, but f is not applied to the module parameter in the quoted representation of the goal type.

I think that the reflection machinery should be consistent, and always treat the module telescope in the same way. Internally f is presumably already applied to the module parameter, so I guess an active decision was taken to remove module parameters when quoting terms:

n <- getDefFreeVars x
def !@! quoteName x
@@ list (drop n $ conOrProjPars ++ map (quoteArg quoteTerm) ts)

Can someone explain why the reflection machinery is set up in this way? Wouldn't it make more sense to always work on the top-level, like Agda does internally?

@nad nad added type: enhancement Issues and pull requests about possible improvements reflection Elaborator reflection, macros, tactic arguments labels Oct 18, 2022
@nad nad added this to the 2.6.3 milestone Oct 18, 2022
@jespercockx
Copy link
Member

Yes, this would be good to have a better semantics of reflection in parametrized modules. Since this is not really critical and has been a problem for a while already, I am bumping this to 2.6.4.

@andreasabel
Copy link
Member

Considered for 2.6.3 since we already have a PR dated March 2022 that adresses this:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reflection Elaborator reflection, macros, tactic arguments type: enhancement Issues and pull requests about possible improvements
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants