You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Separate flags for "compatible with univalence" and "compatible with Cubical Agda" #6049
cubicalCubical Agda paraphernalia: Paths, Glue, partial elements, hcomp, transpdocumented-in-changelogIssues already documented in the CHANGELOGtype: discussionDiscussions about Agda's design and implementation
In #5897, @plt-amy suggested that perhaps we should hide the support for indexed inductive types with --cubical behind a flag, since the current implementation is not yet complete and will possibly change in future releases. I think this is a good idea. What would be a good name for this flag? --experimental-hcomp-for-indexed?
@Saizan@mortberg do you have an opinion on this? Is this feature already being used in the cubical library?
I think --experimental-transport-indices is a good name: not too technical, describes exactly what goes wrong otherwise (substituting an index by a path will get stuck).
Is the idea that inductive families would not be allowed unless this flag is used, or would the flag only affect the extra clauses? In the former case the flag should presumably also be required to use inductive families when --without-K is used.
Generating trX-trX clauses, trX-hcomp clauses, trX-con clauses when matching on indexed families
That is: without the flag, we have 2.6.2.2's status quo when it comes to indexed families in --cubical. They're allowed, but transport on them doesn't compute.
Nisse 2022-08-31: The flag should be coinfective and turned on in the builtin modules.
Amelia: --cubical and --safe should imply the flag.
Nisse: The flag should be enabled in the standard library.
Here's a summary of our discussion on this topic on 2022-08-31 (@jespercockx@andreasabel@nad@UlfNorell) to make sure we're all on the same page (and to get user feedback, of course).
First, background:
Agda should have a flag that makes it compatible with univalent type theory, without bringing in anything cubical. In version 2.6.2.2, this is called --without-K.
Cubical Agda is a thing that exists. More importantly, Cubical Agda needs to be able to sneakily invite itself to modules, because any Agda code that could in the future be loaded by one using --cubical needs to have cubical stuff to work.
Side note: I'm calling the generated bits of code "cubical stuff" for short since the actual details of what needs to be generated are not relevant and are basically internal implementation details.
It should be possible to write code that is compatible with, but not allowed to make use of, cubical features.
Originally we had a proposal (#5843) to stratify the flags like so:
without-K limits pattern matching, changes the termination checker, and changes how indices are counted towards the sorts of indexed types.
cubical-compatible implies without-K and additionally tells Agda to generate cubical stuff for this module.
cubical and erased-cubical are unchanged.
These flags got conflated because of the fix for #5448: When cubical clauses aren't generated, Agda accidentally allows you to generate code that is invalid wrt erasure. To be explicit, in
subst : (@0 P : A → Set p) → x ≡ y → P x → P y
subst _ refl p = p
the semantics of without-K should be that the use of a substitution derived from splitting on refl to under P should count as a use: the path p may have content, after all. When cubical stuff is generated, we get a literal use in one of the generated clauses, so that Agda correctly rejects this code:
subst {A} {P} {x} {y} (transpX (p : Path y' y) (r : x ≡ y')) z
= transp (\ i -> P (p i)) i0 (subst {A} {P} {x} {z} r z)
Proposal:
Let's split without-K and cubical-compatible again. These are the interactions, or at least the ones I can think of:
cubical-compatible should imply without-K.
cubical-compatible is coinfective. For onlookers this means that if A is cubical-compatible and A imports B, then it's an error for Bnot to be cubical-compatible.
As today, cubical is infective, but it is changed to imply the new the coinfective cubical-compatible.
Modules that are without-K can not be imported from cubical or cubical-compatible code, because from the perspective of cubical-compatible, those modules are incomplete (e.g. they are missing transpIx definitions, which are required in the client module for the coverage checker).
An immediate effect is that this re-breaks #5448, which will require a fix independent of cubical stuff.
Reacted by Tom de Jong, Szumi Xie, Carlo Angiuli and Andreas Abel
changed the title [-]Hide indexed inductives for cubical behind a flag[/-][+]Separate flags for "compatible with univalence" and "compatible with Cubical Agda"[/+]on Aug 31, 2022
--without-K is ideally supposed to exclude all features that are incompatible with univalence (even if it doesn't successfully do that today), and
Anyone writing code that might conceivably be imported by someone else's cubical code in the future must explicitly declare that using --cubical-compatible?
From this user's perspective, splitting --without-K and --cubical-compatible feels like exposing undesirable implementation details. As a user of univalent type theory who is not deeply versed in cubical type theory and doesn't use it regularly, it wouldn't have occurred to me at first that my definitions need to have "cubical stuff added" in order to be usable by someone doing cubical type theory. (After thinking about it, the reason is clear, but at an intuitive level one feels that definitions in Book HoTT should just "make sense" in cubical type theory without needing to be changed.)
Given this proposal, under what circumstances should I choose to use --without-K rather than --cubical-compatible? Is it because I might want to avoid the extra overhead of generating cubical stuff?
On the other side, if I'm using cubical agda and I want to import someone else's library who wrote it using --without-K, what do I have to do? If I just go change all the --without-K flags to --cubical-compatible, am I guaranteed that their library will still compile? Can I do that "globally" in some way without modifying their code?
I kind of feel like the ideal setup would be for Agda to check whenever importing a file from a --cubical file whether the file to be imported was compiled with cubical stuff, and if not, recompile it right then to add the cubical stuff needed. Then there wouldn't be a need for --cubical-compatible. I expect probably that is impossible, however.
On the other side, if I'm using cubical agda and I want to import someone else's library who wrote it using --without-K, what do I have to do? If I just go change all the --without-K flags to --cubical-compatible, am I guaranteed that their library will still compile? Can I do that "globally" in some way without modifying their code?
You can add the --cubical-compatible flag to the .agda-lib file of the library you want to use, so you'd only need to change a single file in the library. Ideally this would always succeed (but take a bit more time since it has to generate the cubical clauses), but this is not something we can guarantee at the moment. Also --cubical-compatible might generate error messages that mention the generated cubical clauses, which --without-K wouldn't (again, ideally you'd never see any errors in the generated clauses, but this is currently not something we can guarantee easily either).
Agda 2.6.3, compiled with GHC 9.4.3, with -fenable-clustering-counting and -foptimise-heavily enabled, for the standard library (commit c5f42e1fb86b964dfe2558e103f2f4f662e553b3 with --cubical-compatible enabled in most modules), the worst of two runs (the other one was about nine seconds faster):
776,232,581,760 bytes allocated in the heap
93,021,091,928 bytes copied during GC
1,509,595,560 bytes maximum residency (156 sample(s))
5,174,872 bytes maximum slop
2282 MiB total memory in use (0 MB lost due to fragmentation)
Tot time (elapsed) Avg pause Max pause
Gen 0 184608 colls, 0 par 74.649s 74.733s 0.0004s 0.0263s
Gen 1 156 colls, 0 par 10.780s 10.781s 0.0691s 0.6478s
TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)
SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)
INIT time 0.000s ( 0.000s elapsed)
MUT time 232.692s (231.408s elapsed)
GC time 85.430s ( 85.514s elapsed)
EXIT time 0.001s ( 0.008s elapsed)
Total time 318.123s (316.930s elapsed)
Alloc rate 3,335,884,664 bytes per MUT second
Productivity 73.1% of total user, 73.0% of total elapsed
Agda 2.6.3, compiled with GHC 9.4.3, with -fenable-clustering-counting and -foptimise-heavily enabled, for the standard library (commit e873a786a3cfe76367a5d0a1d9b2da3c0cdf6af1 without --cubical-compatible), the worst of two runs (the other one was similar):
581,486,402,304 bytes allocated in the heap
54,256,390,544 bytes copied during GC
1,174,244,880 bytes maximum residency (117 sample(s))
4,783,496 bytes maximum slop
1894 MiB total memory in use (0 MB lost due to fragmentation)
Tot time (elapsed) Avg pause Max pause
Gen 0 138162 colls, 0 par 48.831s 48.885s 0.0004s 0.0242s
Gen 1 117 colls, 0 par 4.643s 4.643s 0.0397s 0.1983s
TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)
SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)
INIT time 0.001s ( 0.000s elapsed)
MUT time 180.140s (179.008s elapsed)
GC time 53.474s ( 53.528s elapsed)
EXIT time 0.001s ( 0.004s elapsed)
Total time 233.616s (232.540s elapsed)
Alloc rate 3,227,963,050 bytes per MUT second
Productivity 77.1% of total user, 77.0% of total elapsed
Agda 2.6.2.2, compiled with GHC 9.4.3, with -fenable-clustering-counting and -foptimise-heavily enabled, for the standard library (commit 4b7e69b22ec698716f323fc24fc6bd1305ed47df), the best of two runs (the other one was similar):
815,837,786,360 bytes allocated in the heap
71,253,738,216 bytes copied during GC
1,136,954,952 bytes maximum residency (164 sample(s))
2,049,984 bytes maximum slop
1953 MiB total memory in use (0 MB lost due to fragmentation)
Tot time (elapsed) Avg pause Max pause
Gen 0 192219 colls, 0 par 81.075s 81.172s 0.0004s 0.0216s
Gen 1 164 colls, 0 par 6.892s 6.952s 0.0424s 0.2266s
TASKS: 4 (1 bound, 3 peak workers (3 total), using -N1)
SPARKS: 0 (0 converted, 0 overflowed, 0 dud, 0 GC'd, 0 fizzled)
INIT time 0.001s ( 0.003s elapsed)
MUT time 265.432s (264.177s elapsed)
GC time 87.968s ( 88.124s elapsed)
EXIT time 0.001s ( 0.007s elapsed)
Total time 353.402s (352.310s elapsed)
Alloc rate 3,073,618,868 bytes per MUT second
Productivity 75.1% of total user, 75.0% of total elapsed
The speedup in 2.6.3 is nice, but it's rather encouraging me to stick with --without-K in agda-categories rather than switching to --cubical-compatible.
The speedup in 2.6.3 is nice, but it's rather encouraging me to stick with --without-K in agda-categories rather than switching to --cubical-compatible.
That would mean that one cannot import the code from Cubical Agda. Could you use --without-K when developing new code, but switch to --cubical-compatible before releasing it?
cubicalCubical Agda paraphernalia: Paths, Glue, partial elements, hcomp, transpdocumented-in-changelogIssues already documented in the CHANGELOGtype: discussionDiscussions about Agda's design and implementation
Activity
plt-amy commentedon Aug 23, 2022
I think
--experimental-transport-indicesis a good name: not too technical, describes exactly what goes wrong otherwise (substituting an index by a path will get stuck).nad commentedon Aug 23, 2022
Is the idea that inductive families would not be allowed unless this flag is used, or would the flag only affect the extra clauses? In the former case the flag should presumably also be required to use inductive families when
--without-Kis used.plt-amy commentedon Aug 23, 2022
Without the flag, we'd skip:
transpXfor indexed familiestrX-trXclauses,trX-hcompclauses,trX-conclauses when matching on indexed familiesThat is: without the flag, we have 2.6.2.2's status quo when it comes to indexed families in
--cubical. They're allowed, but transport on them doesn't compute.plt-amy commentedon Aug 31, 2022
Something to keep in mind: #5448
andreasabel commentedon Aug 31, 2022
Nisse 2022-08-31: The flag should be coinfective and turned on in the builtin modules.
Amelia:
--cubicaland--safeshould imply the flag.Nisse: The flag should be enabled in the standard library.
plt-amy commentedon Aug 31, 2022
Here's a summary of our discussion on this topic on 2022-08-31 (@jespercockx @andreasabel @nad @UlfNorell) to make sure we're all on the same page (and to get user feedback, of course).
First, background:
Agda should have a flag that makes it compatible with univalent type theory, without bringing in anything cubical. In version 2.6.2.2, this is called
--without-K.Cubical Agda is a thing that exists. More importantly, Cubical Agda needs to be able to sneakily invite itself to modules, because any Agda code that could in the future be loaded by one using
--cubicalneeds to have cubical stuff to work.Side note: I'm calling the generated bits of code "cubical stuff" for short since the actual details of what needs to be generated are not relevant and are basically internal implementation details.
Originally we had a proposal (#5843) to stratify the flags like so:
without-Klimits pattern matching, changes the termination checker, and changes how indices are counted towards the sorts of indexed types.cubical-compatibleimplieswithout-Kand additionally tells Agda to generate cubical stuff for this module.cubicalanderased-cubicalare unchanged.These flags got conflated because of the fix for #5448: When cubical clauses aren't generated, Agda accidentally allows you to generate code that is invalid wrt erasure. To be explicit, in
the semantics of
without-Kshould be that the use of a substitution derived from splitting onreflto underPshould count as a use: the pathpmay have content, after all. When cubical stuff is generated, we get a literal use in one of the generated clauses, so that Agda correctly rejects this code:Proposal:
Let's split
without-Kandcubical-compatibleagain. These are the interactions, or at least the ones I can think of:cubical-compatibleshould implywithout-K.cubical-compatibleis coinfective. For onlookers this means that ifAiscubical-compatibleandAimportsB, then it's an error forBnot to becubical-compatible.As today,
cubicalis infective, but it is changed to imply the new the coinfectivecubical-compatible.Modules that are
without-Kcan not be imported fromcubicalorcubical-compatiblecode, because from the perspective ofcubical-compatible, those modules are incomplete (e.g. they are missingtranspIxdefinitions, which are required in the client module for the coverage checker).An immediate effect is that this re-breaks #5448, which will require a fix independent of cubical stuff.
[-]Hide indexed inductives for cubical behind a flag[/-][+]Separate flags for "compatible with univalence" and "compatible with Cubical Agda"[/+]mikeshulman commentedon Sep 1, 2022
To clarify, is the intent that:
--without-Kis ideally supposed to exclude all features that are incompatible with univalence (even if it doesn't successfully do that today), and--cubical-compatible?From this user's perspective, splitting
--without-Kand--cubical-compatiblefeels like exposing undesirable implementation details. As a user of univalent type theory who is not deeply versed in cubical type theory and doesn't use it regularly, it wouldn't have occurred to me at first that my definitions need to have "cubical stuff added" in order to be usable by someone doing cubical type theory. (After thinking about it, the reason is clear, but at an intuitive level one feels that definitions in Book HoTT should just "make sense" in cubical type theory without needing to be changed.)Given this proposal, under what circumstances should I choose to use
--without-Krather than--cubical-compatible? Is it because I might want to avoid the extra overhead of generating cubical stuff?On the other side, if I'm using cubical agda and I want to import someone else's library who wrote it using
--without-K, what do I have to do? If I just go change all the--without-Kflags to--cubical-compatible, am I guaranteed that their library will still compile? Can I do that "globally" in some way without modifying their code?I kind of feel like the ideal setup would be for Agda to check whenever importing a file from a
--cubicalfile whether the file to be imported was compiled with cubical stuff, and if not, recompile it right then to add the cubical stuff needed. Then there wouldn't be a need for--cubical-compatible. I expect probably that is impossible, however.jespercockx commentedon Sep 1, 2022
You can add the
--cubical-compatibleflag to the.agda-libfile of the library you want to use, so you'd only need to change a single file in the library. Ideally this would always succeed (but take a bit more time since it has to generate the cubical clauses), but this is not something we can guarantee at the moment. Also--cubical-compatiblemight generate error messages that mention the generated cubical clauses, which--without-Kwouldn't (again, ideally you'd never see any errors in the generated clauses, but this is currently not something we can guarantee easily either).72 remaining items
nad commentedon Nov 17, 2022
I plan to do this just before the next release candidate, or just before the release.
jespercockx commentedon Nov 19, 2022
@nad If you still want to get this into the release I suggest you do it soon.
nad commentedon Nov 19, 2022
Changes to the code can affect Agda's performance. I plan to do this once all such changes have landed.
nad commentedon Nov 28, 2022
Now I got the following numbers:
-fenable-clustering-countingand-foptimise-heavilyenabled, for the standard library (commit c5f42e1fb86b964dfe2558e103f2f4f662e553b3 with--cubical-compatibleenabled in most modules), the worst of two runs (the other one was about nine seconds faster):-fenable-clustering-countingand-foptimise-heavilyenabled, for the standard library (commit e873a786a3cfe76367a5d0a1d9b2da3c0cdf6af1 without--cubical-compatible), the worst of two runs (the other one was similar):-fenable-clustering-countingand-foptimise-heavilyenabled, for the standard library (commit 4b7e69b22ec698716f323fc24fc6bd1305ed47df), the best of two runs (the other one was similar):JacquesCarette commentedon Nov 28, 2022
The speedup in 2.6.3 is nice, but it's rather encouraging me to stick with
--without-Kin agda-categories rather than switching to--cubical-compatible.[ #6049 ] Edited the changelog.
[ #6049 ] Edited the changelog.
nad commentedon Nov 28, 2022
That would mean that one cannot import the code from Cubical Agda. Could you use
--without-Kwhen developing new code, but switch to--cubical-compatiblebefore releasing it?martinescardo commentedon Dec 2, 2022
Here are some more statistics on time efficiency using
time agda AllModules.lagdawith https://github.com/martinescardo/TypeTopologyIn a 2020 MacBook Air M1:
In a 2017 Dell Latitude laptop with a core i5 Intel processor:
For the release candidate we used ghc 9.4.3, and for the current version we used ghc 8.10.7, in both setups (for historical reasons).
JacquesCarette commentedon Dec 3, 2022
Note that @martinescardo 's measurements use
--without-Kand not--cubical-compatible. Though how much is due to Agda and how much to GHC is unclear.Nevertheless, the speedup is quite remarkable.
[ #6049 ] Edited the changelog.
[ #6049 ] Edited the changelog.