Search code examples
compiler-constructionagda

How does agda compiler figure out what to compile?


In Coq, it is explicit what is from the logical world (Prop) and what is from the computationnal world (Set). The proof world provides guarantees about the computationnal world, and is the only one that needs to be compiled.

In Agda, there is no such explicit difference so I was wondering:

How does the Agda compiler decide what needs to be compiled and what needs to be left behind?

Thank you.


Solution

  • UPDATE: I added documentation for irrelevance to the new user manual at readthedocs.io.

    In Agda, you can mark function arguments as irrelevant with a dot, which means that the argument will only be typechecked but never evaluated. For example, you can define sorted lists as follows (from the wiki):

      data SList (bound : ℕ) : Set where
        []    : SList bound
        scons : (head : ℕ) →
              .(head ≤ bound) →        -- note the dot!
              (tail : SList head) →
              SList bound
    

    The proof head ≤ bound has a dot in front, so it will be erased (both at compile time and at runtime).

    Aside from explicit irrelevance annotations, the Agda compiler also has a number of optimizations to erase unused arguments without any user intervention, such as the forcing optimization from this paper.