1lab/mikan
13
52
Fork
You've already forked mikan
9

Lazier unSpineing of display forms for postfix projections #109

Open
opened 2026年05月19日 16:59:22 +02:00 by amyliao · 0 comments

Display form matching, including for projections, works on the head symbol of the term currently being reified. This means that display forms on projections can only match if the term is put in 'prefix form', i.e. unSpine. This means that the reification code shows all projections with display forms in prefix, even if none of the display forms match. A minimal reproducer is attached.

{-# OPTIONS --postfix-projections #-}module_ whereopenimportAgda.Builtin.EqualityrecordFoo:Set1wherefieldproj:SetopenFoopostulateAB:FooAp:Set{-# DISPLAY Foo.proj A = Ap #-}_:B.proj≡A.proj_=refl{-
The terms
 proj B
and
 Ap
are not equal at type Set
when checking that the expression refl has type proj B ≡ Ap
-}

We prefixize projections that have display forms before doing any case analysis on the term, and use the resulting head/spine to try display form matching. Display form matching receives only the head name and the eliminations.

case unSpine' prefixize v of
I.Def x es -> do
reportS "reify.def" 80 $ "reifying def" <+> pretty x
(x, es) <- reifyPathPConstAsPath x es
reifyDisplayForm x es $ reifyDef expandAnonDefs x es
-- | Find a matching display form for @q es@.
-- In essence this tries to rewrite @q es@ with any
-- display form @q ps --> dt@ and returns the instantiated
-- @dt@ if successful. First match wins.
displayForm :: MonadDisplayForm m => QName -> Elims -> m (Maybe DisplayTerm)

I think a better idea for the control flow in reifyTerm would instead weave unSpine and display form matching, and only continue to case analysis on the term if no display forms matched. Note that to preserve today's behaviour when display forms do match, the "nondeterminism" in unSpine has to be outside-in, i.e., for foo x .p1 y .p2, we should try (where $ f = Apply f, .pN = Proj pN in the spine):

displayForm p2 [$ p1 (foo x)]
displayForm p1 [$ foo x, $ y, .p2]
displayForm foo [$ x, .p1, $ y, .p2]
Display form matching, *including for projections,* works on the head symbol of the term currently being reified. This means that display forms on projections can only match if the term is put in 'prefix form', i.e. `unSpine`. This means that the reification code shows all projections with display forms in prefix, even if none of the display forms match. A minimal reproducer is attached. ```agda {-# OPTIONS --postfix-projections #-} module _ where open import Agda.Builtin.Equality record Foo : Set1 where field proj : Set open Foo postulate A B : Foo Ap : Set {-# DISPLAY Foo.proj A = Ap #-} _ : B .proj ≡ A .proj _ = refl {- The terms proj B and Ap are not equal at type Set when checking that the expression refl has type proj B ≡ Ap -} ``` --- We prefixize projections that have display forms before doing any case analysis on the term, and use the resulting head/spine to try display form matching. Display form matching receives only the head name and the eliminations. https://codeberg.org/1lab/mikan/src/commit/19cc63dc884dc7dc3e2d66c96c8bd19846785868/src/full/Mikan/Syntax/Translation/InternalToAbstract.hs#L511 https://codeberg.org/1lab/mikan/src/commit/19cc63dc884dc7dc3e2d66c96c8bd19846785868/src/full/Mikan/Syntax/Translation/InternalToAbstract.hs#L521-L524 https://codeberg.org/1lab/mikan/src/commit/19cc63dc884dc7dc3e2d66c96c8bd19846785868/src/full/Mikan/TypeChecking/DisplayForm.hs#L59-L63 I think a better idea for the control flow in `reifyTerm` would instead weave `unSpine` and display form matching, and only continue to case analysis on the term if no display forms matched. Note that to preserve today's behaviour when display forms *do* match, the "nondeterminism" in `unSpine` has to be outside-in, i.e., for `foo x .p1 y .p2`, we should try (where `$ f` = `Apply f`, `.pN` = `Proj pN` in the spine): ``` displayForm p2 [$ p1 (foo x)] displayForm p1 [$ foo x, $ y, .p2] displayForm foo [$ x, .p1, $ y, .p2] ```
Sign in to join this conversation.
No Branch/Tag specified
main
aliao/occurs-opt
aliao/rec-con
fix-license
aliao/oopsie
aliao/strengthen-iapply
No results found.
Labels
Clear labels
1 - scope
language
Backwards-compatible changes to the surface language, such as adding new features.
1 - scope
language change
Breaking changes to a documented part of the surface language. These should be documented and specifically called out in the changelog.
1 - scope
performance
Semantics-preserving performance work.
1 - scope
task
Changes that are not apparent to the user, e.g. developer documentation and refactors, which do not need to be documented.
A: dead-code
Dead code elimination and --save-metas.
A: errors
Reporting of error and warning messages.
A: highlighting
Highlighting during interaction & literate compilation
A: imports
Handling of imports and interface file de/serialization.
A: infra
Iinfrastructure (e.g. CI, developer documentation, the build system, or the repository itself)
A: instance
Instance declarations, arguments, and resolution
A: lhs
LHS checking, coverage checking, and clause compilation
A: modules
Declaration and instantiation of parametrised modules.
A: parallel
Parallel typechecking.
A: positivity
Positivity checking
A: printing
Pretty-printing, display forms, and the wording of diagnostic messages
A: records
Record declarations, record expressions and copattern matching
A: scoping
Scope checking (ConcreteToAbstract)
A: termination
Termination checking
0 - type
bug
Issues describing an incorrect behaviour in the project, typos in the documentation, etc.
0 - type
discussion
An issue raised to gather opinions on a proposed change, or a suggested language change.
0 - type
question
An issue raised to ask a question.
9 - status
duplicate
This issue or pull request already exists.
9 - status
info needed
More information is needed from the submitter to decide how to proceed with the issue report.
9 - status
invalid
The issue report or pull request does not describe an actual bug, or does otherwise does not meet the contributing guidelines.
good first issue
Interested in contributing? Get started here.
upstream
Related to an upstream repository, already reported there
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
1lab/mikan#109
Reference in a new issue
1lab/mikan
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?