typetools / typetools/checker-framework

checkPurity gradle task doesn't check purity

Open
#3,661 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.1k
Forks
440
Avg merge
1d 12h
Merged PRs (30d)
134

Description

The checkPurity task doesn't check purity of methods at all because the -AcheckPurityAnnotations flag is not provided to it. The way purity verification works is that passing the PurityChecker as an annotation processor is not relevant unless -AcheckPurityAnnotations is provided, too. To actually run the purity checker on CF code, supply the -AcheckPurityAnnotations:

createCheckTypeTask(project.name, 'Purity', 'org.checkerframework.framework.util.PurityChecker', ['-AcheckPurityAnnotations'])

in file build.gradle.

As a result, there are many purity errors inside Checker Framework. For example, checker.formatter.qual.ConversionCategory.toString() method is annotated as @Pure, even though it is not deterministic (the first line of this method creates a new instance of StringBuilder). But most of these errors come from the fact that purity annotations are inherited. As an example, framework.util.DefaultAnnotationFormatter.formatAnnotationString is annotated as @SideEffectFree, while the method that overrides it in UnitsAnnotatedTypeFormatter is not annotated, leading to an error. As an observation, DefaultAnnotationFormatter.formatAnnotationString doesn't look @SideEffectFree because it calls StringBuilder.append(String), which is not @SideEffectFree.

The cause for this is the check:

if (!checker.hasOption("checkPurityAnnotations")) { return; }

in BaseTypeVisitor.checkPurity(). The method doesn't check anything if -AcheckPurityAnnotations is not provided.

To fix this, many Checker Framework files need to be annotated (along with some more JDK files, too), and remove the check mentioned above. (this wouldn't be possible until #3151 is finished)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in build.gradle at createCheckTypeTask and in BaseTypeVisitor.checkPurity(), then review the dependency on issue #3151. Run the checkPurity Gradle task to observe the missing purity checks and resulting errors. Done requires enabling the purity annotation check and addressing the Checker Framework and JDK annotations identified by the verification.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.