Skip to content

Conversation

@nad
Copy link
Collaborator

@nad nad commented Dec 18, 2025

I added the option --no-occurrence-analysis, which turns off the occurrence analysis for functions. I have a mutual block that is 1762 lines long, and before I enabled the option I did not see Agda succeed in checking that block.

I also tried to enable the flag for the full development. I could type-check quite a lot of code before Agda complained. The speedup was something like 5%.

I placed the help text for the option in the section "Modalities". That is not a perfect fit. An alternative would be to add a new section. Any opinions?

In the documentation I connect the analysis to positivity checking and to the unused argument feature. Is the analysis used for something else that should be mentioned in the documentation?

Given that bugs in the positivity checker can lead to inconsistencies I suggest that someone checks that the implementation makes sense. The main change was to treat every function argument as "matched":

      -- Perform automated occurrence analysis for functions?
      performAnalysis <- optOccurrence <$> pragmaOptions
      if performAnalysis then
        Concat . zipWith (OccursAs . InClause) [0..] <$>
          mapM (getOccurrences []) cs
       else
        return $ case cs of
          []     -> __IMPOSSIBLE__
          cl : _ ->
            Concat
              [ OccursAs Matched (OccursHere (AnArg i []))
              | (i, _) <- zip [0..] (namedClausePats cl)
              ]

By the way, is the use of __IMPOSSIBLE__ above safe? The documentation of _funClauses does not state that a function must have at least one clause, but it seems as if functions without clauses are handled differently.

It might make sense to have a pragma as well, but I do not currently plan to implement that feature.

@martinescardo, the flag --no-occurrence-analysis turns off some Agda features that you might not want to rely on.

@nad nad added this to the 2.9.0 milestone Dec 18, 2025
@nad nad self-assigned this Dec 18, 2025
@nad nad added positivity Positivity checking for data-type definitions performance Slow type checking, interaction, compilation or execution of Agda programs labels Dec 18, 2025

.. versionadded:: 2.9.0

Enables automated occurrence analysis for functions. See
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads a bit ambiguously, as if occurrence analysis was added in 2.9.0.
Please expand a bit to rule out this misunderstanding.
E.g. "Enables" could be "Controls".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Slow type checking, interaction, compilation or execution of Agda programs positivity Positivity checking for data-type definitions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants