Skip to content

Commit 94fd103

Browse files
authored
Changes related to a change to Agda's reflection machinery. (#1480)
* Changes related to a change to Agda's reflection machinery. The reflection machinery now supports erasure (in Arg), see agda/agda#5317. Note that the function showTerm does not print erasure annotations. However, it also does not print relevance annotations.
1 parent a2da970 commit 94fd103

12 files changed

+156
-31
lines changed

CHANGELOG.md

+19-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ Non-backwards compatible changes
2929

3030
#### Reflection
3131

32-
* The representation of reflected syntax in `Reflection.Term` and
33-
`Reflection.Pattern` has been updated to match the new
34-
representation used in Agda 2.6.2. Specifically, the following changes were made:
32+
* The representation of reflected syntax in `Reflection.Term`,
33+
`Reflection.Pattern`, `Reflection.Argument` and
34+
`Reflection.Argument.Information` has been updated to match the new
35+
representation used in Agda 2.6.2. Specifically, the following
36+
changes were made:
3537

3638
* The type of the `var` constructor of the `Pattern` datatype has
3739
been changed from `(x : String) → Pattern` to `(x : Int) →
@@ -48,6 +50,20 @@ Non-backwards compatible changes
4850
`prop : (t : Term) → Sort`, `propLit : (n : Nat) → Sort`, and
4951
`inf : (n : Nat) → Sort`.
5052

53+
* In `Reflection.Argument.Information` the function `relevance` was
54+
replaced by `modality`.
55+
56+
* The type of the `arg-info` constructor is now
57+
`(v : Visibility) (m : Modality) → ArgInfo`.
58+
59+
* In `Reflection.Argument` (as well as `Reflection`) there is a new
60+
pattern synonym `defaultModality`, and the pattern synonyms
61+
`vArg`, `hArg` and `iArg` have been changed.
62+
63+
* Two new modules have been added, `Reflection.Argument.Modality`
64+
and `Reflection.Argument.Quantity`. The constructors of the types
65+
`Modality` and `Quantity` are reexported from `Reflection`.
66+
5167
#### Other
5268

5369
* `Data.Maybe.Base` now re-exports the definition of `Maybe` given by

src/Reflection.agda

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Agda.Builtin.Reflection as Builtin
1616
open import Reflection.Abstraction as Abstraction public
1717
using (Abs; abs)
1818
open import Reflection.Argument as Argument public
19-
using (Arg; arg; Args; vArg; hArg; iArg)
19+
using (Arg; arg; Args; vArg; hArg; iArg; defaultModality)
2020
open import Reflection.Definition as Definition public
2121
using (Definition)
2222
open import Reflection.Meta as Meta public
@@ -30,13 +30,17 @@ open import Reflection.Pattern as Pattern public
3030
open import Reflection.Term as Term public
3131
using (Term; Type; Clause; Clauses; Sort)
3232

33+
import Reflection.Argument.Modality as Modality
34+
import Reflection.Argument.Quantity as Quantity
3335
import Reflection.Argument.Relevance as Relevance
3436
import Reflection.Argument.Visibility as Visibility
3537
import Reflection.Argument.Information as Information
3638

3739
open Definition.Definition public
3840
open Information.ArgInfo public
3941
open Literal.Literal public
42+
open Modality.Modality public
43+
open Quantity.Quantity public
4044
open Relevance.Relevance public
4145
open Term.Term public
4246
open Visibility.Visibility public
@@ -166,10 +170,10 @@ visibility = Information.visibility
166170
Please use Reflection.Argument.Information's visibility instead."
167171
#-}
168172

169-
relevance = Information.relevance
173+
relevance = Modality.relevance
170174
{-# WARNING_ON_USAGE relevance
171175
"Warning: relevance was deprecated in v1.3.
172-
Please use Reflection.Argument.Information's relevance instead."
176+
Please use Reflection.Argument.Modality's relevance instead."
173177
#-}
174178

175179
infix 4 _≟-AbsTerm_ _≟-AbsType_ _≟-ArgTerm_ _≟-ArgType_ _≟-Args_

src/Reflection/Argument.agda

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ open import Data.Product using (_×_; _,_; uncurry; <_,_>)
1313
open import Data.Nat using (ℕ)
1414
open import Reflection.Argument.Visibility
1515
open import Reflection.Argument.Relevance
16+
open import Reflection.Argument.Quantity
17+
open import Reflection.Argument.Modality
1618
open import Reflection.Argument.Information as Information
1719
open import Relation.Nullary
1820
import Relation.Nullary.Decidable as Dec
@@ -34,9 +36,11 @@ open Arg public
3436

3537
-- Pattern synonyms
3638

37-
pattern vArg ty = arg (arg-info visible relevant) ty
38-
pattern hArg ty = arg (arg-info hidden relevant) ty
39-
pattern iArg ty = arg (arg-info instance′ relevant) ty
39+
pattern defaultModality = modality relevant quantity-ω
40+
41+
pattern vArg ty = arg (arg-info visible defaultModality) ty
42+
pattern hArg ty = arg (arg-info hidden defaultModality) ty
43+
pattern iArg ty = arg (arg-info instance′ defaultModality) ty
4044

4145
------------------------------------------------------------------------
4246
-- Lists of arguments

src/Reflection/Argument/Information.agda

+17-12
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@
99
module Reflection.Argument.Information where
1010

1111
open import Data.Product
12-
open import Relation.Nullary
1312
import Relation.Nullary.Decidable as Dec
1413
open import Relation.Nullary.Product using (_×-dec_)
1514
open import Relation.Binary
1615
open import Relation.Binary.PropositionalEquality
1716

18-
open import Reflection.Argument.Relevance as Relevance using (Relevance)
17+
open import Reflection.Argument.Modality as Modality using (Modality)
1918
open import Reflection.Argument.Visibility as Visibility using (Visibility)
2019

20+
private
21+
variable
22+
v v′ : Visibility
23+
m m′ : Modality
24+
2125
------------------------------------------------------------------------
22-
-- Re-exporting the builtins publically
26+
-- Re-exporting the builtins publicly
2327

2428
open import Agda.Builtin.Reflection public using (ArgInfo)
2529
open ArgInfo public
@@ -30,23 +34,24 @@ open ArgInfo public
3034
visibility : ArgInfo Visibility
3135
visibility (arg-info v _) = v
3236

33-
relevance : ArgInfo Relevance
34-
relevance (arg-info _ r) = r
37+
modality : ArgInfo Modality
38+
modality (arg-info _ m) = m
3539

3640
------------------------------------------------------------------------
3741
-- Decidable equality
3842

39-
arg-info-injective₁ : {v r v′ r′} arg-info v r ≡ arg-info v′ r v ≡ v′
43+
arg-info-injective₁ : arg-info v m ≡ arg-info v′ m v ≡ v′
4044
arg-info-injective₁ refl = refl
4145

42-
arg-info-injective₂ : {v r v′ r′} arg-info v r ≡ arg-info v′ r rr
46+
arg-info-injective₂ : arg-info v m ≡ arg-info v′ m mm
4347
arg-info-injective₂ refl = refl
4448

45-
arg-info-injective : {v r v′ r′} arg-info v r ≡ arg-info v′ r v ≡ v′ × rr
49+
arg-info-injective : arg-info v m ≡ arg-info v′ m v ≡ v′ × mm
4650
arg-info-injective = < arg-info-injective₁ , arg-info-injective₂ >
4751

4852
_≟_ : DecidableEquality ArgInfo
49-
arg-info v r ≟ arg-info v′ r′ =
50-
Dec.map′ (uncurry (cong₂ arg-info))
51-
arg-info-injective
52-
(v Visibility.≟ v′ ×-dec r Relevance.≟ r′)
53+
arg-info v m ≟ arg-info v′ m′ =
54+
Dec.map′
55+
(uncurry (cong₂ arg-info))
56+
arg-info-injective
57+
(v Visibility.≟ v′ ×-dec m Modality.≟ m′)

src/Reflection/Argument/Modality.agda

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Modalities used in the reflection machinery
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K --safe #-}
8+
9+
module Reflection.Argument.Modality where
10+
11+
open import Data.Product
12+
import Relation.Nullary.Decidable as Dec
13+
open import Relation.Nullary.Product using (_×-dec_)
14+
open import Relation.Binary
15+
open import Relation.Binary.PropositionalEquality
16+
17+
open import Reflection.Argument.Relevance as Relevance using (Relevance)
18+
open import Reflection.Argument.Quantity as Quantity using (Quantity)
19+
20+
private
21+
variable
22+
r r′ : Relevance
23+
q q′ : Quantity
24+
25+
------------------------------------------------------------------------
26+
-- Re-exporting the builtins publicly
27+
28+
open import Agda.Builtin.Reflection public using (Modality)
29+
open Modality public
30+
31+
------------------------------------------------------------------------
32+
-- Operations
33+
34+
relevance : Modality Relevance
35+
relevance (modality r _) = r
36+
37+
quantity : Modality Quantity
38+
quantity (modality _ q) = q
39+
40+
------------------------------------------------------------------------
41+
-- Decidable equality
42+
43+
modality-injective₁ : modality r q ≡ modality r′ q′ r ≡ r′
44+
modality-injective₁ refl = refl
45+
46+
modality-injective₂ : modality r q ≡ modality r′ q′ q ≡ q′
47+
modality-injective₂ refl = refl
48+
49+
modality-injective : modality r q ≡ modality r′ q′ r ≡ r′ × q ≡ q′
50+
modality-injective = < modality-injective₁ , modality-injective₂ >
51+
52+
_≟_ : DecidableEquality Modality
53+
modality r q ≟ modality r′ q′ =
54+
Dec.map′
55+
(uncurry (cong₂ modality))
56+
modality-injective
57+
(r Relevance.≟ r′ ×-dec q Quantity.≟ q′)

src/Reflection/Argument/Quantity.agda

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Argument quantities used in the reflection machinery
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K --safe #-}
8+
9+
module Reflection.Argument.Quantity where
10+
11+
open import Relation.Nullary
12+
open import Relation.Binary
13+
open import Relation.Binary.PropositionalEquality
14+
15+
------------------------------------------------------------------------
16+
-- Re-exporting the builtins publicly
17+
18+
open import Agda.Builtin.Reflection public using (Quantity)
19+
open Quantity public
20+
21+
------------------------------------------------------------------------
22+
-- Decidable equality
23+
24+
_≟_ : DecidableEquality Quantity
25+
quantity-ω ≟ quantity-ω = yes refl
26+
quantity-0 ≟ quantity-0 = yes refl
27+
quantity-ω ≟ quantity-0 = no λ()
28+
quantity-0 ≟ quantity-ω = no λ()

src/Reflection/Argument/Relevance.agda

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ open import Relation.Binary
1313
open import Relation.Binary.PropositionalEquality
1414

1515
------------------------------------------------------------------------
16-
-- Re-exporting the builtins publically
16+
-- Re-exporting the builtins publicly
1717

1818
open import Agda.Builtin.Reflection public using (Relevance)
1919
open Relevance public

src/Reflection/Argument/Visibility.agda

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ open import Relation.Binary
1414
open import Relation.Binary.PropositionalEquality
1515

1616
------------------------------------------------------------------------
17-
-- Re-exporting the builtins publically
17+
-- Re-exporting the builtins publicly
1818

1919
open import Agda.Builtin.Reflection public using (Visibility)
2020
open Visibility public

src/Reflection/DeBruijn.agda

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ module _ where
5959

6060
private
6161
η : Visibility (Args Term Term) Args Term Term
62-
η h f args = lam h (abs "x" (f (weakenArgs 1 args ++ arg (arg-info h relevant) (var 0 []) ∷ [])))
62+
η h f args =
63+
lam h (abs "x" (f (weakenArgs 1 args ++
64+
arg (arg-info h defaultModality) (var 0 []) ∷
65+
[])))
6366

6467
η-expand : Visibility Term Term
6568
η-expand h (var x args) = η h (var (suc x)) args

src/Reflection/Show.agda

+10-4
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ open import Data.Product using (_×_; _,_)
2020
open import Data.String as String
2121
import Data.Word as Word
2222
open import Relation.Nullary using (yes; no)
23-
open import Function.Base using (_∘′_)
23+
open import Function.Base using (id; _∘′_; case_of_)
2424

2525
open import Reflection.Abstraction hiding (map)
2626
open import Reflection.Argument hiding (map)
2727
open import Reflection.Argument.Relevance
2828
open import Reflection.Argument.Visibility
29+
open import Reflection.Argument.Modality
2930
open import Reflection.Argument.Information
3031
open import Reflection.Definition
3132
open import Reflection.Literal
@@ -106,10 +107,15 @@ mutual
106107
showPatterns [] = ""
107108
showPatterns (a ∷ ps) = showArg a <+> showPatterns ps
108109
where
110+
-- Quantities are ignored.
109111
showArg : Arg Pattern String
110-
showArg (arg (arg-info visible r) p) = showRel r ++ showPattern p
111-
showArg (arg (arg-info hidden r) p) = braces (showRel r ++ showPattern p)
112-
showArg (arg (arg-info instance′ r) p) = braces (braces (showRel r ++ showPattern p))
112+
showArg (arg (arg-info h (modality r _)) p) =
113+
braces? (showRel r ++ showPattern p)
114+
where
115+
braces? = case h of λ where
116+
visible id
117+
hidden braces
118+
instance′ braces ∘′ braces
113119

114120
showPattern : Pattern String
115121
showPattern (con c []) = showName c

src/Reflection/Traversal.agda

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ module _ (actions : Actions) where
8080
traverseTerm Γ (var x args) = var <$> onVar Γ x ⊛ traverseArgs Γ args
8181
traverseTerm Γ (con c args) = con <$> onCon Γ c ⊛ traverseArgs Γ args
8282
traverseTerm Γ (def f args) = def <$> onDef Γ f ⊛ traverseArgs Γ args
83-
traverseTerm Γ (lam v t) = lam v <$> traverseAbs (arg (arg-info v relevant) unknown) Γ t
8483
traverseTerm Γ (pat-lam cs args) = pat-lam <$> traverseClauses Γ cs ⊛ traverseArgs Γ args
8584
traverseTerm Γ (pi a b) = pi <$> traverseArg Γ a ⊛ traverseAbs a Γ b
8685
traverseTerm Γ (agda-sort s) = agda-sort <$> traverseSort Γ s
8786
traverseTerm Γ (meta x args) = meta <$> onMeta Γ x ⊛ traverseArgs Γ args
8887
traverseTerm Γ t@(lit _) = pure t
8988
traverseTerm Γ t@unknown = pure t
89+
traverseTerm Γ (lam v t) = lam v <$> traverseAbs (arg (arg-info v m) unknown) Γ t
90+
where
91+
m = defaultModality
9092

9193
traverseArg Γ (arg i t) = arg i <$> traverseTerm Γ t
9294
traverseArgs Γ [] = pure []

src/Tactic/RingSolver/Core/ReflectionHelp.agda

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ vlams : ∀ {n} → Vec String n → Term → Term
3838
vlams vs xs = Vec.foldr (const Term) (λ v vs lam visible (abs v vs)) xs vs
3939

4040
getVisible : Arg Term Maybe Term
41-
getVisible (arg (arg-info visible relevant) x) = just x
42-
getVisible _ = nothing
41+
getVisible (arg (arg-info visible _) x) = just x
42+
getVisible _ = nothing
4343

4444
getArgs : n Term Maybe (Vec Term n)
4545
getArgs n (def _ xs) = Maybe.map Vec.reverse (List.foldl f c (List.mapMaybe getVisible xs) n)

0 commit comments

Comments
 (0)