Skip to content

Separate flags for "compatible with univalence" and "compatible with Cubical Agda" #6049

Description

@jespercockx

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?

Activity

  1. added
    type: discussion
    cubical
    not-in-changelog
    on Aug 23, 2022
  2. added this to the 2.6.3 milestone on Aug 23, 2022
  3. plt-amy commented on Aug 23, 2022

    @plt-amy
    Contributor

    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).

  4. nad commented on Aug 23, 2022

    @nad
    Collaborator

    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.

  5. plt-amy commented on Aug 23, 2022

    @plt-amy
    Contributor

    Without the flag, we'd skip:

    • Generating transpX for indexed families
    • 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.

  6. plt-amy commented on Aug 31, 2022

    @plt-amy
    Contributor

    Something to keep in mind: #5448

  7. andreasabel commented on Aug 31, 2022

    @andreasabel
    Member

    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.

  8. removed
    not-in-changelog
    on Aug 31, 2022
  9. plt-amy commented on Aug 31, 2022

    @plt-amy
    Contributor

    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:

    1. 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.

    2. 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.

    1. 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 B not 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.

  10. 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
  11. mikeshulman commented on Sep 1, 2022

    @mikeshulman
    Contributor

    To clarify, is the intent that:

    1. --without-K is ideally supposed to exclude all features that are incompatible with univalence (even if it doesn't successfully do that today), and
    2. 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.

  12. jespercockx commented on Sep 1, 2022

    @jespercockx
    MemberAuthor

    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).

  13. 72 remaining items

  14. nad commented on Nov 17, 2022

    @nad
    Collaborator

    I plan to do this just before the next release candidate, or just before the release.

  15. reopened this on Nov 17, 2022
  16. jespercockx commented on Nov 19, 2022

    @jespercockx
    MemberAuthor

    @nad If you still want to get this into the release I suggest you do it soon.

  17. nad commented on Nov 19, 2022

    @nad
    Collaborator

    Changes to the code can affect Agda's performance. I plan to do this once all such changes have landed.

  18. nad commented on Nov 28, 2022

    @nad
    Collaborator

    Now I got the following numbers:

    • 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
      
  19. JacquesCarette commented on Nov 28, 2022

    @JacquesCarette
    Collaborator

    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.

  20. added 2 commits that reference this issue on Nov 28, 2022
  21. nad commented on Nov 28, 2022

    @nad
    Collaborator

    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?

  22. linked a pull request that will close this issueEdited the changelog #6365on Nov 28, 2022
  23. martinescardo commented on Dec 2, 2022

    @martinescardo

    Here are some more statistics on time efficiency using time agda AllModules.lagda with https://github.com/martinescardo/TypeTopology

    In a 2020 MacBook Air M1:

    • With the current version of Agda: 8min
    • With the release candidate: 4min

    In a 2017 Dell Latitude laptop with a core i5 Intel processor:

    • With the current version of Agda: 13m35
    • With the candidate release version: 8m47s.

    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).

  24. JacquesCarette commented on Dec 3, 2022

    @JacquesCarette
    Collaborator

    Note that @martinescardo 's measurements use --without-K and not --cubical-compatible. Though how much is due to Agda and how much to GHC is unclear.

    Nevertheless, the speedup is quite remarkable.

  25. added a commit that references this issue on Dec 7, 2022
  26. added a commit that references this issue on Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

cubicaldocumented-in-changelogtype: discussion

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions