Skip to content

Commit 73a3c08

Browse files
wmdietlnetdpb
andcommitted
Use EISOP CF sources (#118)
Co-authored-by: David P. Baker <[email protected]>
1 parent fae43cf commit 73a3c08

File tree

11 files changed

+208
-328
lines changed

11 files changed

+208
-328
lines changed

initialize-project

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# Set SHALLOW=1 to clone sibling projects at depth 1.
1212
#
1313
# This script automatically tries to download your fork of
14-
# jspecify/checker-framework, jspecify/jspecify, or jspecify/jdk, if they exist.
14+
# eisop/checker-framework, jspecify/jspecify, or jspecify/jdk, if they exist.
1515
# It uses the URL of the origin remote (the default remote created when cloning
1616
# a repo) to determine that.
1717
#
@@ -55,12 +55,17 @@ git_clone() {
5555

5656
local forking_org
5757
forking_org="$(forking_org)"
58-
if [[ -n "${forking_org}" ]]; then
58+
if [[ -n "${forking_org}" ]] && [[ "${forking_org}" != "https://github.com/jspecify" ]]; then
5959
if run "${git[@]}" "${forking_org}/${repo}.git" "../${repo}"; then
6060
return
6161
fi
6262
fi
63-
run "${git[@]}" "https://github.com/jspecify/${repo}.git" "../${repo}"
63+
if [[ "${repo}" == checker-framework ]]; then
64+
forking_org=https://github.com/eisop
65+
else
66+
forking_org=https://github.com/jspecify
67+
fi
68+
run "${git[@]}" "${forking_org}/${repo}.git" "../${repo}"
6469
}
6570

6671
git_clone jdk --depth 1 --single-branch

settings.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ includeBuild("../checker-framework")
1515
dependencyResolutionManagement {
1616
versionCatalogs {
1717
libs {
18-
version("checkerFramework", "3.21.5-SNAPSHOT")
18+
version("checkerFramework", "3.42.0-eisop2-SNAPSHOT")
1919

20-
library("checkerFramework-checker", "org.checkerframework", "checker").versionRef("checkerFramework")
21-
library("checkerFramework-checker-qual", "org.checkerframework", "checker-qual").versionRef("checkerFramework")
22-
library("checkerFramework-framework", "org.checkerframework", "framework").versionRef("checkerFramework")
23-
library("checkerFramework-framework-test", "org.checkerframework", "framework-test").versionRef("checkerFramework")
24-
library("checkerFramework-javacutil", "org.checkerframework", "javacutil").versionRef("checkerFramework")
20+
library("checkerFramework-checker", "io.github.eisop", "checker").versionRef("checkerFramework")
21+
library("checkerFramework-checker-qual", "io.github.eisop", "checker-qual").versionRef("checkerFramework")
22+
library("checkerFramework-framework", "io.github.eisop", "framework").versionRef("checkerFramework")
23+
library("checkerFramework-framework-test", "io.github.eisop", "framework-test").versionRef("checkerFramework")
24+
library("checkerFramework-javacutil", "io.github.eisop", "javacutil").versionRef("checkerFramework")
2525
library("errorProne-core", "com.google.errorprone:error_prone_core:2.18.0")
2626
library("errorProne-javac", "com.google.errorprone:javac:9+181-r4173-1")
2727
library("guava", "com.google.guava:guava:31.1-jre")

src/main/java/com/google/jspecify/nullness/NullSpecAnalysis.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414

1515
package com.google.jspecify.nullness;
1616

17-
import java.util.Set;
18-
import javax.lang.model.element.AnnotationMirror;
1917
import javax.lang.model.type.TypeMirror;
2018
import org.checkerframework.common.basetype.BaseTypeChecker;
2119
import org.checkerframework.framework.flow.CFAbstractAnalysis;
2220
import org.checkerframework.framework.flow.CFValue;
21+
import org.checkerframework.javacutil.AnnotationMirrorSet;
2322

2423
final class NullSpecAnalysis extends CFAbstractAnalysis<CFValue, NullSpecStore, NullSpecTransfer> {
2524
NullSpecAnalysis(BaseTypeChecker checker, NullSpecAnnotatedTypeFactory factory) {
@@ -37,7 +36,7 @@ public NullSpecStore createCopiedStore(NullSpecStore other) {
3736
}
3837

3938
@Override
40-
public CFValue createAbstractValue(Set<AnnotationMirror> annotations, TypeMirror underlyingType) {
39+
public CFValue createAbstractValue(AnnotationMirrorSet annotations, TypeMirror underlyingType) {
4140
return defaultCreateAbstractValue(this, annotations, underlyingType);
4241
}
4342
}

src/main/java/com/google/jspecify/nullness/NullSpecAnnotatedTypeFactory.java

Lines changed: 139 additions & 268 deletions
Large diffs are not rendered by default.

src/main/java/com/google/jspecify/nullness/NullSpecChecker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.sun.source.util.TreePath;
2424
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
2525
import com.sun.tools.javac.util.Log;
26-
import java.util.SortedSet;
26+
import java.util.NavigableSet;
2727
import java.util.TreeSet;
2828
import javax.lang.model.element.TypeElement;
2929
import org.checkerframework.common.basetype.BaseTypeChecker;
@@ -62,8 +62,8 @@ public final class NullSpecChecker extends BaseTypeChecker {
6262
public NullSpecChecker() {}
6363

6464
@Override
65-
public SortedSet<String> getSuppressWarningsPrefixes() {
66-
SortedSet<String> prefixes = new TreeSet<>();
65+
public NavigableSet<String> getSuppressWarningsPrefixes() {
66+
TreeSet<String> prefixes = new TreeSet<>();
6767
prefixes.add("nullness");
6868
return prefixes;
6969
}

src/main/java/com/google/jspecify/nullness/NullSpecTransfer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static com.sun.source.tree.Tree.Kind.NULL_LITERAL;
1919
import static java.util.Arrays.asList;
2020
import static java.util.Collections.emptyList;
21-
import static java.util.Collections.singleton;
2221
import static java.util.Collections.unmodifiableSet;
2322
import static java.util.stream.Collectors.toList;
2423
import static org.checkerframework.dataflow.expression.JavaExpression.fromNode;
@@ -71,6 +70,7 @@
7170
import org.checkerframework.framework.flow.CFValue;
7271
import org.checkerframework.framework.type.AnnotatedTypeMirror;
7372
import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType;
73+
import org.checkerframework.javacutil.AnnotationMirrorSet;
7474

7575
final class NullSpecTransfer extends CFAbstractTransfer<CFValue, NullSpecStore, NullSpecTransfer> {
7676
private final Util util;
@@ -1019,7 +1019,8 @@ private boolean valueIsAtLeastAsSpecificAs(CFValue value, CFValue targetDataflow
10191019
if (target == null) {
10201020
return false;
10211021
}
1022-
return atypeFactory.getQualifierHierarchy().greatestLowerBound(existing, target) == existing;
1022+
return atypeFactory.getQualifierHierarchy().greatestLowerBoundQualifiersOnly(existing, target)
1023+
== existing;
10231024
}
10241025

10251026
private static boolean isNullLiteral(Node node) {
@@ -1052,7 +1053,8 @@ private void setResultValue(
10521053
* if (clazz.cast(foo) != null) { return class.cast(foo); }
10531054
*/
10541055
result.setResultValue(
1055-
analysis.createAbstractValue(singleton(qual), result.getResultValue().getUnderlyingType()));
1056+
analysis.createAbstractValue(
1057+
AnnotationMirrorSet.singleton(qual), result.getResultValue().getUnderlyingType()));
10561058
}
10571059

10581060
private JavaExpression expressionToStoreFor(Node node) {

src/main/java/com/google/jspecify/nullness/NullSpecVisitor.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
import com.sun.source.tree.TypeParameterTree;
6262
import com.sun.source.tree.VariableTree;
6363
import java.util.ArrayList;
64-
import java.util.HashSet;
6564
import java.util.List;
6665
import java.util.Set;
6766
import javax.lang.model.element.AnnotationMirror;
@@ -76,6 +75,7 @@
7675
import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType;
7776
import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType;
7877
import org.checkerframework.javacutil.AnnotationBuilder;
78+
import org.checkerframework.javacutil.AnnotationMirrorSet;
7979

8080
final class NullSpecVisitor extends BaseTypeVisitor<NullSpecAnnotatedTypeFactory> {
8181
private final boolean checkImpl;
@@ -101,9 +101,11 @@ private void ensureNonNull(Tree tree, String messageKey) {
101101
}
102102
}
103103

104+
/* TODO: implement feature to add extra args to return type errors.
105+
*
104106
@Override
105107
protected String extraArgForReturnTypeError(Tree tree) {
106-
/*
108+
/
107109
* We call originStringIfTernary, not originString:
108110
*
109111
* If the statement is `return foo.bar()`, then the problem is obvious, so we don't want our
@@ -116,10 +118,11 @@ protected String extraArgForReturnTypeError(Tree tree) {
116118
* the possibly null value (possibly both!). However, this gets tricky: If the branches return
117119
* `Foo?` and `Foo*`, then we ideally want to emphasize the `Foo?` branch *but*, at least in
118120
* "strict mode," not altogether ignore the `Foo*` branch.
119-
*/
121+
/
120122
String origin = originStringIfTernary(tree);
121123
return origin.isEmpty() ? "" : (origin + "\n");
122124
}
125+
*/
123126

124127
private String originString(Tree tree) {
125128
while (tree instanceof ParenthesizedTree) {
@@ -628,8 +631,8 @@ private boolean isClassCastAppliedToNonNullableType(MemberReferenceTree tree) {
628631
}
629632

630633
@Override
631-
protected Set<? extends AnnotationMirror> getExceptionParameterLowerBoundAnnotations() {
632-
return new HashSet<>(asList(AnnotationBuilder.fromClass(elements, MinusNull.class)));
634+
protected AnnotationMirrorSet getExceptionParameterLowerBoundAnnotations() {
635+
return new AnnotationMirrorSet(asList(AnnotationBuilder.fromClass(elements, MinusNull.class)));
633636
}
634637

635638
@Override

src/test/java/tests/ConformanceTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ static final class DetailMessageReportedFact extends ReportedFact {
155155

156156
private static final ImmutableSet<String> CANNOT_CONVERT_KEYS =
157157
ImmutableSet.of(
158-
"argument",
159-
"assignment",
158+
"argument.type.incompatible",
159+
"assignment.type.incompatible",
160160
"atomicreference.must.include.null",
161161
"cast.unsafe",
162162
"lambda.param",
@@ -165,9 +165,9 @@ static final class DetailMessageReportedFact extends ReportedFact {
165165
"methodref.return",
166166
"override.param",
167167
"override.return",
168-
"return",
168+
"return.type.incompatible",
169169
"threadlocal.must.include.null",
170-
"type.argument");
170+
"type.argument.type.incompatible");
171171

172172
private static final ImmutableSet<String> IRRELEVANT_ANNOTATION_KEYS =
173173
ImmutableSet.of(

src/test/java/tests/NullSpecTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,20 @@ private boolean corresponds(TestDiagnostic missing, DetailMessage unexpected) {
156156
|| missing.getMessage().contains("jspecify_nullness_mismatch")
157157
|| missing.getMessage().contains("test:cannot-convert")) {
158158
switch (unexpected.messageKey) {
159-
case "argument":
160-
case "assignment":
159+
case "argument.type.incompatible":
160+
case "assignment.type.incompatible":
161161
case "atomicreference.must.include.null":
162162
case "cast.unsafe":
163163
case "dereference":
164-
case "lambda.param":
165-
case "methodref.receiver.bound":
166-
case "methodref.receiver":
167-
case "methodref.return":
168-
case "override.param":
169-
case "override.return":
170-
case "return":
164+
case "lambda.param.type.incompatible":
165+
case "methodref.receiver.bound.invalid":
166+
case "methodref.receiver.invalid":
167+
case "methodref.return.invalid":
168+
case "override.param.invalid":
169+
case "override.return.invalid":
170+
case "return.type.incompatible":
171171
case "threadlocal.must.include.null":
172-
case "type.argument":
172+
case "type.argument.type.incompatible":
173173
return true;
174174
default:
175175
return false;
@@ -196,7 +196,7 @@ private boolean corresponds(TestDiagnostic missing, DetailMessage unexpected) {
196196
* custom `*.annotated` error. This test probably doesn't confirm that second thing
197197
* anymore, but I did manually confirm that it is true as of this writing.
198198
*/
199-
case "bound":
199+
case "bound.type.incompatible":
200200
case "local.variable.annotated":
201201
case "type.parameter.annotated":
202202
case "wildcard.annotated":

tests/ConformanceTest-report.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# 90 pass; 24 fail; 114 total; 78.9% score
2-
PASS: Basic.java:28:test:expression-type:Object?:nullable
3-
PASS: Basic.java:28:test:sink-type:Object!:return
1+
# 84 pass; 30 fail; 114 total; 73.7% score
2+
FAIL: Basic.java:28:test:expression-type:Object?:nullable
3+
FAIL: Basic.java:28:test:sink-type:Object!:return
44
PASS: Basic.java:28:test:cannot-convert:Object? to Object!
5-
PASS: Basic.java:34:test:expression-type:Object!:nonNull
6-
PASS: Basic.java:34:test:sink-type:Object?:return
7-
PASS: Basic.java:41:test:sink-type:Object?:nullableObject
8-
PASS: Basic.java:43:test:sink-type:String!:testSinkType#nonNullString
5+
FAIL: Basic.java:34:test:expression-type:Object!:nonNull
6+
FAIL: Basic.java:34:test:sink-type:Object?:return
7+
FAIL: Basic.java:41:test:sink-type:Object?:nullableObject
8+
FAIL: Basic.java:43:test:sink-type:String!:testSinkType#nonNullString
99
FAIL: Basic.java:49:test:expression-type:List!<capture of ? extends String?>:nullableStrings
1010
PASS: Basic.java: no unexpected facts
1111
PASS: Irrelevant.java:28:test:irrelevant-annotation:Nullable

0 commit comments

Comments
 (0)