diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..6fc4bb7 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,39 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + + workflow_dispatch: + +jobs: + build: + strategy: + fail-fast: false + matrix: + jdk: [ 8, 11 ] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK + uses: actions/setup-java@v1 + with: + java-version: ${{matrix.jdk}} + - name: Set up Python 3 + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install --user -r ./.travis-requirements.txt + - name: Github Environment Setup + run: | + owner=${{ github.repository_owner }} + echo "REPO_SITE=${owner}" >> $GITHUB_ENV + - name: Units Inference Dependency Setup & Build + run: ./dependency-setup.sh + - name: Units Inference Tests + run: ./test-units.sh diff --git a/build.gradle b/build.gradle index 56725a7..34dca54 100644 --- a/build.gradle +++ b/build.gradle @@ -90,12 +90,17 @@ afterEvaluate { group 'Verification' systemProperties 'path.afu.scripts': "${afu}/scripts", - 'path.inference.script': "${cfi}/scripts/inference", - JDK_JAR: "${cf}/checker/dist/jdk8.jar" + 'path.inference.script': "${cfi}/scripts/inference" + + if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + systemProperties += [JDK_JAR: "${cf}/checker/dist/jdk8.jar"] + } environment "external_checker_classpath", "${units}/build/classes/java/main:${units}/build/resources/main" - jvmArgs "-Xbootclasspath/p:${cfi}/dist/javac.jar" + if (JavaVersion.current() == JavaVersion.VERSION_1_8) { + jvmArgs "-Xbootclasspath/p:${cfi}/dist/javac.jar" + } testLogging { // Always run the tests @@ -179,7 +184,7 @@ task getCodeFormatScripts() { task pythonIsInstalled(type: Exec) { description "Check that the python executable is installed." - executable = "python" + executable = "python3" args "--version" } @@ -221,7 +226,7 @@ List getJavaFilesToFormat() { task checkFormat(type: Exec, dependsOn: [getCodeFormatScripts, pythonIsInstalled], group: 'Format') { description 'Check whether the source code is properly formatted' - executable 'python' + executable 'python3' doFirst { args += "${formatScripts}/check-google-java-format.py" args += "--aosp" // 4 space indentation @@ -238,7 +243,7 @@ task checkFormat(type: Exec, dependsOn: [getCodeFormatScripts, pythonIsInstalled task reformat(type: Exec, dependsOn: [getCodeFormatScripts, pythonIsInstalled], group: 'Format') { description 'Format the Java source code' // jdk8 and checker-qual have no source, so skip - executable 'python' + executable 'python3' doFirst { args += "${formatScripts}/run-google-java-format.py" args += "--aosp" // 4 space indentation @@ -246,4 +251,9 @@ task reformat(type: Exec, dependsOn: [getCodeFormatScripts, pythonIsInstalled], } } -tasks.test.dependsOn 'checkFormat' +//tasks.test.dependsOn 'checkFormat' +tasks.test { + if (JavaVersion.current() == JavaVersion.VERSION_11) { + dependsOn 'checkFormat' + } +} diff --git a/dependency-setup.sh b/dependency-setup.sh index 96d4a78..eb01107 100755 --- a/dependency-setup.sh +++ b/dependency-setup.sh @@ -33,7 +33,7 @@ else fi ## Build checker-framework-inference -(cd $JSR308/checker-framework-inference && ./.travis-build-without-test.sh) +(cd $JSR308/checker-framework-inference && ./.ci-build-without-test.sh) ## Build units-inference without testing (cd $JSR308/units-inference && ./gradlew build -x test) diff --git a/src/backend/z3smt/Z3SmtFormatTranslator.java b/src/backend/z3smt/Z3SmtFormatTranslator.java index 0d97f3c..0401bfc 100644 --- a/src/backend/z3smt/Z3SmtFormatTranslator.java +++ b/src/backend/z3smt/Z3SmtFormatTranslator.java @@ -1,11 +1,13 @@ package backend.z3smt; +import checkers.inference.model.ArithmeticVariableSlot; import checkers.inference.model.CombVariableSlot; import checkers.inference.model.ConstantSlot; import checkers.inference.model.ExistentialVariableSlot; import checkers.inference.model.LubVariableSlot; import checkers.inference.model.RefinementVariableSlot; import checkers.inference.model.Slot; +import checkers.inference.model.SourceVariableSlot; import checkers.inference.model.VariableSlot; import checkers.inference.solver.backend.AbstractFormatTranslator; import checkers.inference.solver.frontend.Lattice; @@ -40,13 +42,13 @@ public final void init(Context ctx) { finishInitializingEncoders(); } - protected abstract SlotEncodingT serializeVarSlot(VariableSlot slot); + protected abstract SlotEncodingT serializeVariableSlot(VariableSlot slot); protected abstract SlotEncodingT serializeConstantSlot(ConstantSlot slot); @Override - public SlotEncodingT serialize(VariableSlot slot) { - return serializeVarSlot(slot); + public SlotEncodingT serialize(SourceVariableSlot slot) { + return serializeVariableSlot(slot); } @Override @@ -56,22 +58,27 @@ public SlotEncodingT serialize(ConstantSlot slot) { @Override public SlotEncodingT serialize(ExistentialVariableSlot slot) { - return serializeVarSlot(slot); + return serializeVariableSlot(slot); } @Override public SlotEncodingT serialize(RefinementVariableSlot slot) { - return serializeVarSlot(slot); + return serializeVariableSlot(slot); } @Override public SlotEncodingT serialize(CombVariableSlot slot) { - return serializeVarSlot(slot); + return serializeVariableSlot(slot); } @Override public SlotEncodingT serialize(LubVariableSlot slot) { - return serializeVarSlot(slot); + return serializeVariableSlot(slot); + } + + @Override + public SlotEncodingT serialize(ArithmeticVariableSlot slot) { + return serializeVariableSlot(slot); } /** diff --git a/src/backend/z3smt/Z3SmtSolver.java b/src/backend/z3smt/Z3SmtSolver.java index 809f7f5..f26fec0 100644 --- a/src/backend/z3smt/Z3SmtSolver.java +++ b/src/backend/z3smt/Z3SmtSolver.java @@ -345,7 +345,7 @@ protected void encodeAllSlots() { // generate slot constraints for (Slot slot : slots) { - if (slot.isVariable()) { + if (slot instanceof VariableSlot) { VariableSlot varSlot = (VariableSlot) slot; BoolExpr wfConstraint = formatTranslator.encodeSlotWellformnessConstraint(varSlot); diff --git a/src/units/UnitsAnnotatedTypeFactory.java b/src/units/UnitsAnnotatedTypeFactory.java index 943c1a0..312349a 100644 --- a/src/units/UnitsAnnotatedTypeFactory.java +++ b/src/units/UnitsAnnotatedTypeFactory.java @@ -1,9 +1,10 @@ package units; +import checkers.inference.BaseInferenceRealTypeFactory; + import com.sun.source.tree.BinaryTree; import com.sun.source.tree.Tree.Kind; -import org.checkerframework.common.basetype.BaseAnnotatedTypeFactory; import org.checkerframework.common.basetype.BaseTypeChecker; import org.checkerframework.framework.qual.LiteralKind; import org.checkerframework.framework.qual.TypeUseLocation; @@ -23,9 +24,11 @@ import org.checkerframework.framework.type.typeannotator.TypeAnnotator; import org.checkerframework.framework.util.AnnotationFormatter; import org.checkerframework.framework.util.GraphQualifierHierarchy; +import org.checkerframework.framework.util.MultiGraphQualifierHierarchy; import org.checkerframework.framework.util.MultiGraphQualifierHierarchy.MultiGraphFactory; import org.checkerframework.framework.util.defaults.QualifierDefaults; import org.checkerframework.javacutil.AnnotationUtils; +import org.checkerframework.javacutil.BugInCF; import org.checkerframework.javacutil.TreeUtils; import org.checkerframework.javacutil.UserError; @@ -48,12 +51,12 @@ import javax.lang.model.element.AnnotationMirror; -public class UnitsAnnotatedTypeFactory extends BaseAnnotatedTypeFactory { +public class UnitsAnnotatedTypeFactory extends BaseInferenceRealTypeFactory { // static reference to the singleton instance protected static UnitsRepresentationUtils unitsRepUtils; - public UnitsAnnotatedTypeFactory(BaseTypeChecker checker) { - super(checker, true); + public UnitsAnnotatedTypeFactory(BaseTypeChecker checker, boolean isInfer) { + super(checker, isInfer); unitsRepUtils = UnitsRepresentationUtils.getInstance(processingEnv, elements); postInit(); } @@ -93,7 +96,7 @@ public AnnotationMirror canonicalAnnotation(AnnotationMirror anno) { // check to see if it is an internal units annotation if (AnnotationUtils.areSameByClass(anno, UnitsRep.class)) { // fill in missing base units - return anno; // unitsRepUtils.fillMissingBaseUnits(anno); + return unitsRepUtils.fillMissingBaseUnits(anno); } // check to see if it's a surface annotation such as @m or @UnknownUnits @@ -128,7 +131,7 @@ public boolean isSupportedQualifier(AnnotationMirror anno) { return false; } if (AnnotationUtils.areSameByClass(anno, UnitsRep.class)) { - return true; + return unitsRepUtils.hasAllBaseUnits(anno); } if (AnnotationUtils.areSameByClass(anno, PolyUnit.class)) { return true; @@ -161,7 +164,13 @@ protected void addCheckedCodeDefaults(QualifierDefaults defs) { } @Override - public QualifierHierarchy createQualifierHierarchy(MultiGraphFactory factory) { + public QualifierHierarchy createQualifierHierarchy() { + return MultiGraphQualifierHierarchy.createMultiGraphQualifierHierarchy(this); + } + + @Override + public QualifierHierarchy createQualifierHierarchyWithMultiGraphFactory( + MultiGraphFactory factory) { return new UnitsQualifierHierarchy(factory); } @@ -272,6 +281,22 @@ public boolean isSubtype(AnnotationMirror subAnno, AnnotationMirror superAnno) { return true; } + // Case: @PolyUnit are treated as @UnknownUnits + if (AnnotationUtils.areSame(subAnno, unitsRepUtils.POLYUNIT)) { + return isSubtype(unitsRepUtils.TOP, superAnno); + } + if (AnnotationUtils.areSame(superAnno, unitsRepUtils.POLYUNIT)) { + return true; + } + + // Case: @RDU shouldn't appear. throw error? + if (AnnotationUtils.areSame(subAnno, unitsRepUtils.RECEIVER_DEPENDANT_UNIT)) { + return isSubtype(unitsRepUtils.TOP, superAnno); + } + if (AnnotationUtils.areSame(superAnno, unitsRepUtils.RECEIVER_DEPENDANT_UNIT)) { + return true; + } + // Case: @UnitsRep(x) <: @UnitsRep(y) if (AnnotationUtils.areSameByClass(subAnno, UnitsRep.class) && AnnotationUtils.areSameByClass(superAnno, UnitsRep.class)) { @@ -289,7 +314,12 @@ public boolean isSubtype(AnnotationMirror subAnno, AnnotationMirror superAnno) { // return result; } - return true; + throw new BugInCF( + "Uncaught subtype check case:" + + "\n subtype: " + + getAnnotationFormatter().formatAnnotationMirror(subAnno) + + "\n supertype: " + + getAnnotationFormatter().formatAnnotationMirror(superAnno)); } } diff --git a/src/units/UnitsChecker.java b/src/units/UnitsChecker.java index 705528e..b620f3a 100644 --- a/src/units/UnitsChecker.java +++ b/src/units/UnitsChecker.java @@ -52,8 +52,8 @@ public UnitsVisitor createVisitor( } @Override - public UnitsAnnotatedTypeFactory createRealTypeFactory() { - return new UnitsAnnotatedTypeFactory(this); + public UnitsAnnotatedTypeFactory createRealTypeFactory(boolean infer) { + return new UnitsAnnotatedTypeFactory(this, infer); } @Override diff --git a/src/units/UnitsInferenceAnnotatedTypeFactory.java b/src/units/UnitsInferenceAnnotatedTypeFactory.java index cb53306..79ba9fb 100644 --- a/src/units/UnitsInferenceAnnotatedTypeFactory.java +++ b/src/units/UnitsInferenceAnnotatedTypeFactory.java @@ -2,8 +2,6 @@ import checkers.inference.InferenceAnnotatedTypeFactory; import checkers.inference.InferenceChecker; -import checkers.inference.InferenceMain; -import checkers.inference.InferenceQualifierHierarchy; import checkers.inference.InferenceTreeAnnotator; import checkers.inference.InferrableChecker; import checkers.inference.SlotManager; @@ -12,6 +10,7 @@ import checkers.inference.model.ConstantSlot; import checkers.inference.model.ConstraintManager; import checkers.inference.model.Slot; +import checkers.inference.model.SourceVariableSlot; import checkers.inference.model.VariableSlot; import checkers.inference.qual.VarAnnot; import checkers.inference.util.InferenceViewpointAdapter; @@ -32,12 +31,10 @@ import org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedExecutableType; import org.checkerframework.framework.type.AnnotationClassLoader; import org.checkerframework.framework.type.DefaultAnnotatedTypeFormatter; -import org.checkerframework.framework.type.QualifierHierarchy; import org.checkerframework.framework.type.treeannotator.ListTreeAnnotator; import org.checkerframework.framework.type.treeannotator.TreeAnnotator; import org.checkerframework.framework.util.AnnotatedTypes; import org.checkerframework.framework.util.AnnotationFormatter; -import org.checkerframework.framework.util.MultiGraphQualifierHierarchy.MultiGraphFactory; import org.checkerframework.javacutil.AnnotationBuilder; import org.checkerframework.javacutil.AnnotationUtils; import org.checkerframework.javacutil.ElementUtils; @@ -47,9 +44,6 @@ import units.representation.UnitsRepresentationUtils; -import java.util.Collection; -import java.util.HashSet; -import java.util.Map; import java.util.Set; import javax.lang.model.element.AnnotationMirror; @@ -132,126 +126,6 @@ public AnnotationMirror canonicalAnnotation(AnnotationMirror anno) { return result; } - @Override - public QualifierHierarchy createQualifierHierarchy(MultiGraphFactory factory) { - return new UnitsInferenceQualifierHierarchy(factory); - } - - private final class UnitsInferenceQualifierHierarchy extends InferenceQualifierHierarchy { - public UnitsInferenceQualifierHierarchy(MultiGraphFactory multiGraphFactory) { - super(multiGraphFactory); - } - - // In inference mode, the only bottom is VarAnnot - @Override - protected Set findBottoms( - Map> supertypes) { - Set newBottoms = super.findBottoms(supertypes); - newBottoms.remove(unitsRepUtils.RAWUNITSREP); - return newBottoms; - } - - // In inference mode, the only qualifier is VarAnnot. The poly qualifiers are - // PolyAll and any poly qual from the type system. - @Override - protected void finish( - QualifierHierarchy qualHierarchy, - Map> supertypesMap, - Map polyQualifiers, - Set tops, - Set bottoms, - Object... args) { - super.finish(qualHierarchy, supertypesMap, polyQualifiers, tops, bottoms, args); - - // TODO: this update, which is sensible to keep the inference qual hierarchy clean, - // causes crashes in creating constant slots for @PolyUnit - // disabling for now - - /* - * Map before update: - supertypesMap - @checkers.inference.qual.VarAnnot -> [@org.checkerframework.framework.qual.PolyAll] - @org.checkerframework.framework.qual.PolyAll -> [@checkers.inference.qual.VarAnnot, @units.qual.UnitsRep] - @units.qual.PolyUnit -> [@org.checkerframework.framework.qual.PolyAll, @units.qual.UnitsRep] - @units.qual.UnitsRep -> [] - polyQualifiers {null=@org.checkerframework.framework.qual.PolyAll, @units.qual.UnitsRep=@units.qual.PolyUnit} - tops [@checkers.inference.qual.VarAnnot] - bottoms [@checkers.inference.qual.VarAnnot] - */ - // - // // Remove @UnitsRep from super of PolyAll - // assert supertypesMap.containsKey(unitsRepUtils.POLYALL); - // Set polyAllSupers = AnnotationUtils.createAnnotationSet(); - // polyAllSupers.addAll(supertypesMap.get(unitsRepUtils.POLYALL)); - // polyAllSupers.remove(unitsRepUtils.RAWUNITSINTERNAL); - // supertypesMap.put(unitsRepUtils.POLYALL, - // Collections.unmodifiableSet(polyAllSupers)); - // - // // Remove @UnitsRep from super of PolyUnit - // assert supertypesMap.containsKey(unitsRepUtils.POLYUNIT); - // Set polyUnitSupers = AnnotationUtils.createAnnotationSet(); - // polyUnitSupers.addAll(supertypesMap.get(unitsRepUtils.POLYUNIT)); - // polyUnitSupers.remove(unitsRepUtils.RAWUNITSINTERNAL); - // supertypesMap.put(unitsRepUtils.POLYUNIT, - // Collections.unmodifiableSet(polyUnitSupers)); - // - // // Remove @UnitsRep from map - // supertypesMap.remove(unitsRepUtils.RAWUNITSINTERNAL); - // - // // Remove @UnitsRep from polyQualifiers - // assert polyQualifiers.containsKey(unitsRepUtils.RAWUNITSINTERNAL); - // polyQualifiers.remove(unitsRepUtils.RAWUNITSINTERNAL); - // - // System.err.println(" === Inference ATF "); - // System.err.println(" supertypesMap "); - // for (Entry e : supertypesMap.entrySet()) { - // System.err.println(" " + e.getKey() + " -> " + e.getValue()); - // } - // System.err.println(" polyQualifiers " + polyQualifiers); - // System.err.println(" tops " + tops); - // System.err.println(" bottoms " + bottoms); - - /* - * Map after update: - supertypesMap - @checkers.inference.qual.VarAnnot -> [@org.checkerframework.framework.qual.PolyAll] - @org.checkerframework.framework.qual.PolyAll -> [@checkers.inference.qual.VarAnnot] - @units.qual.PolyUnit -> [@org.checkerframework.framework.qual.PolyAll] - polyQualifiers {null=@org.checkerframework.framework.qual.PolyAll} - tops [@checkers.inference.qual.VarAnnot] - bottoms [@checkers.inference.qual.VarAnnot] - */ - } - - @Override - public Set leastUpperBounds( - Collection annos1, - Collection annos2) { - if (InferenceMain.isHackMode(annos1.size() != annos2.size())) { - Set result = AnnotationUtils.createAnnotationSet(); - for (AnnotationMirror a1 : annos1) { - for (AnnotationMirror a2 : annos2) { - AnnotationMirror lub = leastUpperBound(a1, a2); - if (lub != null) { - result.add(lub); - } - } - } - - return result; - } - - return super.leastUpperBounds(annos1, annos2); - } - } - - @Override - protected Set getDefaultTypeDeclarationBounds() { - Set top = new HashSet<>(); - top.add(unitsRepUtils.TOP); - return top; - } - @Override protected InferenceViewpointAdapter createViewpointAdapter() { return new UnitsInferenceViewpointAdapter(this); @@ -287,12 +161,12 @@ public void handleBinaryTree(AnnotatedTypeMirror atm, BinaryTree binaryTree) { inferenceTypeFactory.getAnnotatedType(binaryTree.getLeftOperand()); AnnotatedTypeMirror rhsATM = inferenceTypeFactory.getAnnotatedType(binaryTree.getRightOperand()); - VariableSlot lhs = slotManager.getVariableSlot(lhsATM); - VariableSlot rhs = slotManager.getVariableSlot(rhsATM); + Slot lhs = slotManager.getSlot(lhsATM); + Slot rhs = slotManager.getSlot(rhsATM); // create varslot for the result of the binary tree computation // note: constraints for binary ops are added in UnitsVisitor - VariableSlot result; + Slot result; switch (binaryTree.getKind()) { case PLUS: // if it is a string concatenation, result is dimensionless @@ -321,7 +195,7 @@ public void handleBinaryTree(AnnotatedTypeMirror atm, BinaryTree binaryTree) { result = slotManager.createConstantSlot(unitsRepUtils.DIMENSIONLESS); break; default: - result = slotManager.createLubVariableSlot(lhs, rhs); + result = slotManager.createLubMergeVariableSlot(lhs, rhs); break; } @@ -333,8 +207,8 @@ public void handleBinaryTree(AnnotatedTypeMirror atm, BinaryTree binaryTree) { // add to cache Set resultSet = AnnotationUtils.createAnnotationSet(); resultSet.add(resultAM); - final Pair> varATMPair = - Pair.of(slotManager.getVariableSlot(atm), resultSet); + final Pair> varATMPair = + Pair.of(slotManager.getSlot(atm), resultSet); treeToVarAnnoPair.put(binaryTree, varATMPair); } } @@ -414,16 +288,17 @@ private void generateVarSlotForStaticFinalConstants( // if member is from source code, it must be unannotated // if member is from byte code, it must not be annotated with a // non-dimensionless unit - if ((!fromByteCode && slot.isVariable()) + if ((!fromByteCode && slot instanceof VariableSlot) || (fromByteCode - && slot.isConstant() + && slot instanceof ConstantSlot && AnnotationUtils.areSame( ((ConstantSlot) slot).getValue(), unitsRepUtils.DIMENSIONLESS))) { // Generate a fresh variable for inference AnnotationLocation loc = VariableAnnotator.treeToLocation(atypeFactory, tree); - VariableSlot varSlot = slotManager.createVariableSlot(loc); + SourceVariableSlot varSlot = + slotManager.createSourceVariableSlot(loc, TreeUtils.typeOf(tree)); atm.replaceAnnotation(slotManager.getAnnotation(varSlot)); } } @@ -436,9 +311,9 @@ private void generateVarSlotForStaticFinalConstants( // @PolyAll private boolean isPolyAnnotation(AnnotationMirror annot) { Slot slot = slotManager.getSlot(annot); - if (slot.isConstant()) { + if (slot instanceof ConstantSlot) { AnnotationMirror constant = ((ConstantSlot) slot).getValue(); - return InferenceQualifierHierarchy.isPolymorphic(constant); + return qualHierarchy.isPolymorphicQualifier(constant); } return false; } @@ -534,13 +409,13 @@ public Void visitNewClass(NewClassTree newClassTree, AnnotatedTypeMirror atm) { // "@Poly Clazz(@Poly param)" we have the following annotations: // 1) the variable slot generated for the polymorphic declared return type - VariableSlot varSlotForPolyReturn = + SourceVariableSlot varSlotForPolyReturn = variableAnnotator.getOrCreatePolyVar(newClassTree); // disable insertion of polymorphic return variable slot varSlotForPolyReturn.setInsertable(false); // 2) the call site return type: "@m" in "new @m Clazz(...)" - VariableSlot callSiteReturnVarSlot = slotManager.getVariableSlot(atm); + Slot callSiteReturnVarSlot = slotManager.getSlot(atm); // Create a subtype constraint: callSiteReturnVarSlot <: varSlotForPolyReturn // since after annotation insertion, the varSlotForPolyReturn is conceptually a @@ -562,7 +437,7 @@ public Void visitMethodInvocation( super.visitMethodInvocation(methodInvocationTree, atm); if (isMethodDeclaredWithPolymorphicReturn(methodInvocationTree)) { - VariableSlot varSlotForPolyReturn = + SourceVariableSlot varSlotForPolyReturn = variableAnnotator.getOrCreatePolyVar(methodInvocationTree); // disable insertion of polymorphic return variable slot varSlotForPolyReturn.setInsertable(false); diff --git a/src/units/UnitsInferenceViewpointAdapter.java b/src/units/UnitsInferenceViewpointAdapter.java index 86624d7..13b12ad 100644 --- a/src/units/UnitsInferenceViewpointAdapter.java +++ b/src/units/UnitsInferenceViewpointAdapter.java @@ -36,7 +36,7 @@ protected AnnotationMirror combineAnnotationWithAnnotation( return unitsRepUtils.BOTTOM; } Slot declSlot = InferenceMain.getInstance().getSlotManager().getSlot(declaredAnnotation); - if (declSlot.isConstant()) { + if (declSlot instanceof ConstantSlot) { ConstantSlot cs = (ConstantSlot) declSlot; if (AnnotationUtils.areSame(cs.getValue(), unitsRepUtils.RECEIVER_DEPENDANT_UNIT)) { return super.combineAnnotationWithAnnotation( diff --git a/src/units/UnitsVisitor.java b/src/units/UnitsVisitor.java index 2439ff1..6721d5c 100644 --- a/src/units/UnitsVisitor.java +++ b/src/units/UnitsVisitor.java @@ -11,7 +11,6 @@ import checkers.inference.model.ConstantSlot; import checkers.inference.model.ConstraintManager; import checkers.inference.model.Slot; -import checkers.inference.model.VariableSlot; import com.sun.source.tree.BinaryTree; import com.sun.source.tree.Tree.Kind; @@ -28,6 +27,7 @@ import java.util.Set; import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.ExecutableElement; public class UnitsVisitor extends InferenceVisitor { @@ -178,8 +178,7 @@ public Void visitBinary(BinaryTree binaryTree, Void p) { break; default: // TODO: replace with LUBSlot pending mier's PR - VariableSlot lubSlot = - slotManager.getVariableSlot(atypeFactory.getAnnotatedType(binaryTree)); + Slot lubSlot = slotManager.getSlot(atypeFactory.getAnnotatedType(binaryTree)); // Create LUB constraint by default constraintManager.addSubtypeConstraint(lhs, lubSlot); constraintManager.addSubtypeConstraint(rhs, lubSlot); @@ -272,7 +271,9 @@ public Void visitTypeCast(TypeCastTree node, Void p) { exprType, UnitsRepresentationUtils.getInstance().DIMENSIONLESS)) { if (atypeFactory.getDependentTypesHelper() != null) { AnnotatedTypeMirror type = atypeFactory.getAnnotatedType(node); - atypeFactory.getDependentTypesHelper().checkType(type, node.getType()); + atypeFactory + .getDependentTypesHelper() + .checkTypeForErrorExpressions(type, node.getType()); } // perform scan and reduce as per super.super.visitTypeCast() @@ -355,4 +356,13 @@ protected Set getExceptionParameterLowerBoundAnnotat // Notes: // Slots created in ATF // Constraints created in Visitor + + /** + * Skip this test because a constructor produces either objects of a certain unit or + * dimensionless objects. + */ + @Override + protected void checkConstructorResult( + AnnotatedTypeMirror.AnnotatedExecutableType constructorType, + ExecutableElement constructorElement) {} } diff --git a/src/units/solvers/backend/gje/UnitsGJEFormatTranslator.java b/src/units/solvers/backend/gje/UnitsGJEFormatTranslator.java index 5691557..6805f1c 100644 --- a/src/units/solvers/backend/gje/UnitsGJEFormatTranslator.java +++ b/src/units/solvers/backend/gje/UnitsGJEFormatTranslator.java @@ -7,6 +7,7 @@ import checkers.inference.model.LubVariableSlot; import checkers.inference.model.RefinementVariableSlot; import checkers.inference.model.Slot; +import checkers.inference.model.SourceVariableSlot; import checkers.inference.model.VariableSlot; import checkers.inference.model.serialization.ToStringSerializer; import checkers.inference.solver.backend.AbstractFormatTranslator; @@ -67,7 +68,7 @@ protected int assignGJEVarIDs(Collection constraints) { constraint.serialize(slotsCollector); } - for (VariableSlot slot : slotsCollector.getSlots()) { + for (Slot slot : slotsCollector.getSlots()) { slotGJEtoCFIMap.put(gjeID, slot); slotCFItoGJEMap.put(slot, gjeID); System.err.println("ID: " + gjeID + " --> slot " + slot.serialize(toStringSerializer)); @@ -138,7 +139,7 @@ protected GJEInferenceUnit serializeConstantSlot(ConstantSlot slot) { } @Override - public GJEInferenceUnit serialize(VariableSlot slot) { + public GJEInferenceUnit serialize(SourceVariableSlot slot) { // System.err.println("Serializing vs " + slot); return serializeVarSlot(slot); } diff --git a/src/units/solvers/backend/z3smt/UnitsZ3SmtFormatTranslator.java b/src/units/solvers/backend/z3smt/UnitsZ3SmtFormatTranslator.java index 06e45b0..6b6d39a 100644 --- a/src/units/solvers/backend/z3smt/UnitsZ3SmtFormatTranslator.java +++ b/src/units/solvers/backend/z3smt/UnitsZ3SmtFormatTranslator.java @@ -60,7 +60,7 @@ protected ConstraintEncoderFactory createConstraintEncoderFactory() { @Override public String generateZ3SlotDeclaration(VariableSlot slot) { - Z3InferenceUnit encodedSlot = serializeVarSlot(slot); + Z3InferenceUnit encodedSlot = serializeVariableSlot(slot); List slotDeclaration = new ArrayList<>(); @@ -96,7 +96,7 @@ private String addZ3IntDefinition(IntExpr z3IntVariable) { } @Override - protected Z3InferenceUnit serializeVarSlot(VariableSlot slot) { + protected Z3InferenceUnit serializeVariableSlot(VariableSlot slot) { int slotID = slot.getId(); if (serializedSlots.containsKey(slotID)) { @@ -159,7 +159,7 @@ protected Z3InferenceUnit serializeConstantSlot(ConstantSlot slot) { public void preAnalyzeSlots(Collection slots) { Set constantSlots = new HashSet<>(); for (Slot slot : slots) { - if (slot.isConstant()) { + if (slot instanceof ConstantSlot) { constantSlots.add((ConstantSlot) slot); } } @@ -172,30 +172,12 @@ public void preAnalyzeSlots(Collection slots) { @Override public BoolExpr encodeSlotWellformnessConstraint(VariableSlot slot) { - if (slot instanceof ConstantSlot) { - ConstantSlot cs = (ConstantSlot) slot; - AnnotationMirror anno = cs.getValue(); - // encode PolyUnit as constant trues - if (AnnotationUtils.areSame(anno, unitsRepUtils.POLYUNIT)) { - return ctx.mkTrue(); - } - } - Z3InferenceUnit serializedSlot = slot.serialize(this); return UnitsZ3SmtEncoderUtils.slotWellformedness(ctx, serializedSlot); } @Override public BoolExpr encodeSlotPreferenceConstraint(VariableSlot slot) { - if (slot instanceof ConstantSlot) { - ConstantSlot cs = (ConstantSlot) slot; - AnnotationMirror anno = cs.getValue(); - // encode PolyUnit as constant trues - if (AnnotationUtils.areSame(anno, unitsRepUtils.POLYUNIT)) { - return ctx.mkTrue(); - } - } - Z3InferenceUnit serializedSlot = slot.serialize(this); return UnitsZ3SmtEncoderUtils.slotPreference(ctx, serializedSlot); } diff --git a/src/units/solvers/backend/z3smt/encoder/UnitsZ3SmtCombineConstraintEncoder.java b/src/units/solvers/backend/z3smt/encoder/UnitsZ3SmtCombineConstraintEncoder.java index afdf4ee..7473626 100644 --- a/src/units/solvers/backend/z3smt/encoder/UnitsZ3SmtCombineConstraintEncoder.java +++ b/src/units/solvers/backend/z3smt/encoder/UnitsZ3SmtCombineConstraintEncoder.java @@ -3,6 +3,7 @@ import backend.z3smt.Z3SmtFormatTranslator; import backend.z3smt.encoder.Z3SmtAbstractConstraintEncoder; +import checkers.inference.model.CombVariableSlot; import checkers.inference.model.ConstantSlot; import checkers.inference.model.VariableSlot; import checkers.inference.solver.backend.encoder.combine.CombineConstraintEncoder; @@ -33,7 +34,7 @@ public UnitsZ3SmtCombineConstraintEncoder( @Override public BoolExpr encodeVariable_Variable( - VariableSlot target, VariableSlot declared, VariableSlot result) { + VariableSlot target, VariableSlot declared, CombVariableSlot result) { Z3InferenceUnit decl = declared.serialize(z3SmtFormatTranslator); Z3InferenceUnit res = result.serialize(z3SmtFormatTranslator); return UnitsZ3SmtEncoderUtils.equality(ctx, decl, res); @@ -41,7 +42,7 @@ public BoolExpr encodeVariable_Variable( @Override public BoolExpr encodeVariable_Constant( - VariableSlot target, ConstantSlot declared, VariableSlot result) { + VariableSlot target, ConstantSlot declared, CombVariableSlot result) { Z3InferenceUnit tar = target.serialize(z3SmtFormatTranslator); Z3InferenceUnit decl = declared.serialize(z3SmtFormatTranslator); Z3InferenceUnit res = result.serialize(z3SmtFormatTranslator); @@ -53,7 +54,7 @@ public BoolExpr encodeVariable_Constant( @Override public BoolExpr encodeConstant_Variable( - ConstantSlot target, VariableSlot declared, VariableSlot result) { + ConstantSlot target, VariableSlot declared, CombVariableSlot result) { Z3InferenceUnit decl = declared.serialize(z3SmtFormatTranslator); Z3InferenceUnit res = result.serialize(z3SmtFormatTranslator); return UnitsZ3SmtEncoderUtils.equality(ctx, decl, res); @@ -61,7 +62,7 @@ public BoolExpr encodeConstant_Variable( @Override public BoolExpr encodeConstant_Constant( - ConstantSlot target, ConstantSlot declared, VariableSlot result) { + ConstantSlot target, ConstantSlot declared, CombVariableSlot result) { Z3InferenceUnit tar = target.serialize(z3SmtFormatTranslator); Z3InferenceUnit decl = declared.serialize(z3SmtFormatTranslator); Z3InferenceUnit res = result.serialize(z3SmtFormatTranslator);