Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
749fca1
updated source code to the lasted CF
txiang61 Oct 16, 2019
151eb2d
remove unused code
txiang61 Oct 16, 2019
6776f55
eliminate override that only calls super
txiang61 Nov 8, 2019
85957f2
Use master branch of CF
wmdietl Nov 11, 2019
7641f19
remove polyall
txiang61 Nov 12, 2019
24477fe
Merge branch 'master' of https://github.com/txiang61/units-inference
txiang61 Nov 12, 2019
a4ac623
add classpath and remove polyall
txiang61 Nov 14, 2019
e74afc8
update gradle
txiang61 Nov 15, 2019
d82b53e
remove pollyall
txiang61 Nov 16, 2019
c90b70a
fix tests
txiang61 Nov 17, 2019
e5afb5a
update unit inference atf to fix benchmark exceptions
txiang61 Jan 8, 2020
9f7cf93
added view point adaption for receiver dependent units
txiang61 Mar 9, 2020
4de729d
added view point adaption for receiver dependent units
txiang61 Mar 9, 2020
e68e197
Merge branch 'rdu' of https://github.com/txiang61/units-inference int…
txiang61 Mar 11, 2020
6692f58
Merge branch 'rdu' of https://github.com/txiang61/units-inference int…
txiang61 Mar 11, 2020
c49375a
Add view point adaption inference constraints
txiang61 Mar 17, 2020
aea6e17
Add view point adaption inference constraints
txiang61 Mar 17, 2020
753a843
Merge branch 'rdu' of https://github.com/txiang61/units-inference int…
txiang61 Mar 25, 2020
340deae
add tests for rdu
txiang61 Mar 27, 2020
dc06314
fixed all failed test with the new added rdu
txiang61 Mar 28, 2020
6e152c5
comments and edges cases
txiang61 Mar 30, 2020
d0c5308
added more test on RDU
txiang61 Mar 30, 2020
941c11d
default Object class to UnitsBottom
txiang61 Apr 13, 2020
cefde96
modify constraints
txiang61 Apr 14, 2020
37f1efb
added astub file for java awt library
txiang61 Apr 14, 2020
7f495f3
Merge branch 'rdu' of https://github.com/txiang61/units-inference int…
txiang61 Apr 14, 2020
483bec3
corrected tests file
txiang61 Apr 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<classpathentry kind="src" output="build/classes/java/test" path="tests"/>
<classpathentry kind="src" path="/checker"/>
<classpathentry kind="src" path="/checker-framework-inference"/>
<classpathentry kind="lib" path="/checker-framework-inference/lib/com.microsoft.z3.jar"/>
<classpathentry kind="lib" path="/checker-framework-inference/lib/com.microsoft.z3.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="/checker-framework-inference/dist/checker-framework-inference.jar"/>
<classpathentry kind="output" path="build/classes/java"/>
</classpath>
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ manual-tests/annotated
manual-tests/inference
manual-tests/typecheck
manual-tests/insertionTest
annotated/
unsatConstraints.txt
statistics.txt
solutions.txt

# temp files
manual-tests/unused*
5 changes: 5 additions & 0 deletions benchmarks/projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ projects:
build: mvn -B -DskipTests compile
clean: mvn -B clean

commons-math:
giturl: https://github.com/txiang61-benchmarks/commons-math.git
build: mvn install -Drat.numUnapprovedLicenses=100
clean: mvn -B clean

# Converted to use units
# TODO: revert to unsat version
jblas:
Expand Down
2 changes: 1 addition & 1 deletion dependency-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo "------ Downloading everthing from REPO_SITE: $REPO_SITE ------"
if [ -d $JSR308/checker-framework-inference ] ; then
(cd $JSR308/checker-framework-inference && git pull)
else
BRANCH=upstream_update_mar_5_2019
BRANCH=master
echo "Cloning from branch" $BRANCH
(cd $JSR308 && git clone -b $BRANCH --depth 1 https://github.com/"$REPO_SITE"/checker-framework-inference.git)
fi
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5-bin.zip
3 changes: 3 additions & 0 deletions scripts/run-units-infer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export PATH=$AFU/scripts:$PATH
CHECKER=units.UnitsChecker

SOLVER=units.solvers.backend.UnitsSolverEngine
DEBUG_SOLVER=checkers.inference.solver.DebugSolver
# SOLVER="$DEBUG_SOLVER"

if [ -n "$1" ] && [ $1 = "GJE" ]; then
SOLVERARGS=solver=GJE,collectStatistics=true,writeSolutions=true,noAppend=true
elif [ -n "$1" ] && [ $1 = "true" ]; then
Expand Down
9 changes: 9 additions & 0 deletions src/units/JavaAWT.astub
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import units.qual.*;

package java.awt;

abstract class Graphics2D {
abstract void rotate(@rad double theta);
abstract void rotate(@rad double theta, double x, double y);
}

12 changes: 12 additions & 0 deletions src/units/JavaAWTGeom.astub
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import units.qual.*;

package java.awt.geom;

class AffineTransform implements Cloneable, Serializable {
static AffineTransform getRotateInstance(@rad double theta);
static AffineTransform getRotateInstance(@rad double theta, double anchorx, double anchory);
void rotate(@rad double theta);
void rotate(@rad double theta, double x, double y);
void setToRotation(@rad double theta);
void setToRotation(@rad double theta, double anchorx, double anchory);
}
12 changes: 12 additions & 0 deletions src/units/JavaLang.astub
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import units.qual.*;

package java.lang;

@UnitsBottom class Object{
}

class System {
static @ms long currentTimeMillis();
static @ns long nanoTime();
Expand All @@ -22,3 +25,12 @@ class String implements Serializable, Comparable<String>, CharSequence {
static String valueOf(@UnknownUnits float arg0);
static String valueOf(@UnknownUnits double arg0);
}

class StringBuilder implements Serializable, CharSequence {
StringBuilder append(@UnknownUnits int i);
StringBuilder append(@UnknownUnits long lng);
StringBuilder append(@UnknownUnits float f);
StringBuilder append(@UnknownUnits double b);
StringBuilder append(@UnknownUnits char c);
}

10 changes: 10 additions & 0 deletions src/units/JavaText.astub
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import units.qual.*;

package java.text;

class NumberFormat {
String format(@UnknownUnits long number);
abstract StrinBuffer format(@UnknownUnits long number, StringBuffer toAppendTo, FieldPosition pos);
String format(@UnknownUnits double number);
abstract StrinBuffer format(@UnknownUnits double number, StringBuffer toAppendTo, FieldPosition pos);
}
17 changes: 9 additions & 8 deletions src/units/JavaUtilConcurrent.astub
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import units.qual.*;

package java.util.concurrent;

@UnitsBottom
enum TimeUnit {
@ns NANOSECONDS,
@us MICROSECONDS,
Expand All @@ -14,23 +15,23 @@ enum TimeUnit {
// For example, to convert 10 minutes to milliseconds, use:
// TimeUnit.MILLISECONDS.convert(10L, TimeUnit.MINUTES)
// TODO: enforce source value and unit are equal
@PolyUnit long convert(@PolyUnit TimeUnit this, @UnknownUnits long sourceDuration,
@RDU long convert(@UnknownUnits TimeUnit this, @UnknownUnits long sourceDuration,
@UnknownUnits TimeUnit sourceUnit);

// TODO: add dimensional bound on duration to be a time value
@ns long toNanos(@UnknownUnits long duration);
@ns long toNanos(@UnknownUnits TimeUnit this, @RDU long duration);

@us long toMicros(@UnknownUnits long duration);
@us long toMicros(@UnknownUnits TimeUnit this, @RDU long duration);

@ms long toMillis(@UnknownUnits long duration);
@ms long toMillis(@UnknownUnits TimeUnit this, @RDU long duration);

@s long toSeconds(@UnknownUnits long duration);
@s long toSeconds(@UnknownUnits TimeUnit this, @RDU long duration);

long toMinutes(@UnknownUnits long duration);
long toMinutes(@UnknownUnits TimeUnit this, @RDU long duration);

long toHours(@UnknownUnits long duration);
long toHours(@UnknownUnits TimeUnit this, @RDU long duration);

long toDays(@UnknownUnits long duration);
long toDays(@UnknownUnits TimeUnit this, @RDU long duration);

// TODO: enforce "this" has same unit as "timeout"
void timedWait(@UnknownUnits TimeUnit this, Object obj, @UnknownUnits long timeout);
Expand Down
104 changes: 52 additions & 52 deletions src/units/UnitsAnnotatedTypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
import org.checkerframework.common.basetype.BaseTypeChecker;
import org.checkerframework.framework.qual.LiteralKind;
import org.checkerframework.framework.qual.TypeUseLocation;
import org.checkerframework.framework.type.AnnotatedTypeFactory;
import org.checkerframework.framework.type.AnnotatedTypeFormatter;
import org.checkerframework.framework.type.AnnotatedTypeMirror;
import org.checkerframework.framework.type.AnnotationClassLoader;
import org.checkerframework.framework.type.DefaultAnnotatedTypeFormatter;
import org.checkerframework.framework.type.QualifierHierarchy;
import org.checkerframework.framework.type.ViewpointAdapter;
import org.checkerframework.framework.type.treeannotator.ListTreeAnnotator;
import org.checkerframework.framework.type.treeannotator.LiteralTreeAnnotator;
import org.checkerframework.framework.type.treeannotator.PropagationTreeAnnotator;
import org.checkerframework.framework.type.treeannotator.TreeAnnotator;
import org.checkerframework.framework.type.typeannotator.DefaultForTypeAnnotator;
import org.checkerframework.framework.type.typeannotator.ListTypeAnnotator;
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.MultiGraphFactory;
Expand All @@ -43,11 +49,6 @@ public UnitsAnnotatedTypeFactory(BaseTypeChecker checker) {
super(checker, true);
unitsRepUtils = UnitsRepresentationUtils.getInstance(processingEnv, elements);
postInit();

// add implicits for exceptions
addTypeNameImplicit(java.lang.Exception.class, unitsRepUtils.DIMENSIONLESS);
addTypeNameImplicit(java.lang.Throwable.class, unitsRepUtils.DIMENSIONLESS);
addTypeNameImplicit(java.lang.Void.class, unitsRepUtils.BOTTOM);
}

@Override
Expand All @@ -56,15 +57,19 @@ protected AnnotationClassLoader createAnnotationClassLoader() {
return new UnitsAnnotationClassLoader(checker);
}

@Override
protected ViewpointAdapter createViewpointAdapter() {
return new UnitsViewpointAdapter(this);
}

@Override
protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() {
// get all the loaded annotations
Set<Class<? extends Annotation>> qualSet = new HashSet<Class<? extends Annotation>>();
qualSet.addAll(getBundledTypeQualifiersWithPolyAll());
qualSet.addAll(getBundledTypeQualifiers());

// // load all the external units
// loadAllExternalUnits();
//
// // copy all loaded external Units to qual set
// qualSet.addAll(externalQualsMap.values());

Expand Down Expand Up @@ -122,7 +127,7 @@ public boolean isSupportedQualifier(AnnotationMirror anno) {
if (AnnotationUtils.areSameByClass(anno, UnitsRep.class)) {
return unitsRepUtils.hasAllBaseUnits(anno);
}
// Anno is PolyAll, PolyUnit
// Anno is PolyUnit
return AnnotationUtils.containsSame(this.getQualifierHierarchy().getTypeQualifiers(), anno);
}

Expand All @@ -146,28 +151,6 @@ protected void addCheckedCodeDefaults(QualifierDefaults defs) {
defs.addCheckedCodeDefault(unitsRepUtils.TOP, TypeUseLocation.LOCAL_VARIABLE);
}

// Note: remember to use
// --cfArgs="-AuseDefaultsForUncheckedCode=source,bytecode" in cmd line option
// -AuseDefaultsForUncheckedCode=bytecode // uses those defaults in byte code
// -AuseDefaultsForUncheckedCode=source,bytecode // also uses those defaults in
// source code
@Override
protected void addUncheckedCodeDefaults(QualifierDefaults defs) {
super.addUncheckedCodeDefaults(defs);

// experiment with:
// This seems to have no effect thus far in the constraints generated in inference
// top param, receiver, bot return for inference, explain unsat
defs.addUncheckedCodeDefault(unitsRepUtils.TOP, TypeUseLocation.RECEIVER);
defs.addUncheckedCodeDefault(unitsRepUtils.TOP, TypeUseLocation.PARAMETER);
defs.addUncheckedCodeDefault(unitsRepUtils.BOTTOM, TypeUseLocation.RETURN);

// bot param, top return for tightest api restriction??

// dimensionless is default for all other locations
// defs.addUncheckedCodeDefault(unitsRepUtils.DIMENSIONLESS, TypeUseLocation.OTHERWISE);
}

@Override
public QualifierHierarchy createQualifierHierarchy(MultiGraphFactory factory) {
return new UnitsQualifierHierarchy(factory);
Expand Down Expand Up @@ -226,19 +209,6 @@ protected void finish(
}
}

// Set direct supertypes of PolyAll
// replace raw @UnitsRep with UnitsTop in super of PolyAll
for (Entry<AnnotationMirror, Set<AnnotationMirror>> e : supertypesMap.entrySet()) {
if (AnnotationUtils.areSame(e.getKey(), unitsRepUtils.POLYALL)) {
Set<AnnotationMirror> polyAllSupers = AnnotationUtils.createAnnotationSet();
polyAllSupers.addAll(e.getValue());
polyAllSupers.add(unitsRepUtils.TOP);
polyAllSupers.remove(unitsRepUtils.RAWUNITSREP);
supertypesMap.put(e.getKey(), polyAllSupers);
break;
}
}

// Set direct supertypes of PolyUnit
// replace raw @UnitsRep with UnitsTop in super of PolyUnit
for (Entry<AnnotationMirror, Set<AnnotationMirror>> e : supertypesMap.entrySet()) {
Expand Down Expand Up @@ -275,6 +245,7 @@ protected void finish(

// Update tops
tops.remove(unitsRepUtils.RAWUNITSREP);
tops.remove(unitsRepUtils.RECEIVER_DEPENDANT_UNIT);
tops.add(unitsRepUtils.TOP);

// System.err.println(" === Typecheck ATF ");
Expand Down Expand Up @@ -312,13 +283,19 @@ public boolean isSubtype(AnnotationMirror subAnno, AnnotationMirror superAnno) {
return true;
}

// Case: @PolyAll and @PolyUnit are treated as @UnknownUnits
if (AnnotationUtils.areSame(subAnno, unitsRepUtils.POLYALL)
|| AnnotationUtils.areSame(subAnno, unitsRepUtils.POLYUNIT)) {
// Case: @PolyUnit are treated as @UnknownUnits
if (AnnotationUtils.areSame(subAnno, unitsRepUtils.POLYUNIT)) {
return isSubtype(unitsRepUtils.TOP, superAnno);
}
if (AnnotationUtils.areSame(superAnno, unitsRepUtils.POLYALL)
|| AnnotationUtils.areSame(superAnno, unitsRepUtils.POLYUNIT)) {
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;
}

Expand Down Expand Up @@ -350,13 +327,18 @@ public boolean isSubtype(AnnotationMirror subAnno, AnnotationMirror superAnno) {
@Override
public TreeAnnotator createTreeAnnotator() {
return new ListTreeAnnotator(
new UnitsTypecheckImplicitsTreeAnnotator(), new UnitsPropagationTreeAnnotator());
new UnitsLiteralTreeAnnotator(this), new UnitsPropagationTreeAnnotator());
}

protected final class UnitsTypecheckImplicitsTreeAnnotator extends UnitsImplicitsTreeAnnotator {
protected final class UnitsLiteralTreeAnnotator extends LiteralTreeAnnotator {
// Programmatically set the qualifier implicits
public UnitsTypecheckImplicitsTreeAnnotator() {
super(UnitsAnnotatedTypeFactory.this);
public UnitsLiteralTreeAnnotator(AnnotatedTypeFactory atf) {
super(atf);
// set BOTTOM as the literal qualifier for null literals
addLiteralKind(LiteralKind.NULL, unitsRepUtils.BOTTOM);
addLiteralKind(LiteralKind.STRING, unitsRepUtils.DIMENSIONLESS);
addLiteralKind(LiteralKind.CHAR, unitsRepUtils.DIMENSIONLESS);
addLiteralKind(LiteralKind.BOOLEAN, unitsRepUtils.DIMENSIONLESS);
// in type checking mode, we also set dimensionless for the number literals
addLiteralKind(LiteralKind.INT, unitsRepUtils.DIMENSIONLESS);
addLiteralKind(LiteralKind.LONG, unitsRepUtils.DIMENSIONLESS);
Expand Down Expand Up @@ -434,6 +416,24 @@ public Void visitBinary(BinaryTree binaryTree, AnnotatedTypeMirror type) {
}
}

@Override
protected TypeAnnotator createTypeAnnotator() {
return new ListTypeAnnotator(
new UnitsDefaultForTypeAnnotator(this), super.createTypeAnnotator());
}

protected class UnitsDefaultForTypeAnnotator extends DefaultForTypeAnnotator {
// Programmatically set the qualifier
public UnitsDefaultForTypeAnnotator(AnnotatedTypeFactory atf) {
super(atf);

// add defaults for exceptions
addTypes(java.lang.Exception.class, unitsRepUtils.DIMENSIONLESS);
addTypes(java.lang.Throwable.class, unitsRepUtils.DIMENSIONLESS);
addTypes(java.lang.Void.class, unitsRepUtils.BOTTOM);
}
}

// for use in AnnotatedTypeMirror.toString()
@Override
protected AnnotatedTypeFormatter createAnnotatedTypeFormatter() {
Expand Down
4 changes: 3 additions & 1 deletion src/units/UnitsChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
"JavaMathTrig.astub",
"JavaThread.astub",
"JavaUtil.astub",
"JavaText.astub",
"JavaAWT.astub", // for josm
"JavaUtilConcurrent.astub", // for ode4j, not yet annotated for hombucha
"ExperimentsJavaAwtGeomAffineTransform.astub", // for imgscalr experiment
// "ExperimentsJavaAwtGeomAffineTransform.astub", // for imgscalr experiment
"ExperimentsSunMiscUnsafe.astub", // for JLargeArrays
})
public class UnitsChecker extends BaseInferrableChecker {
Expand Down
26 changes: 0 additions & 26 deletions src/units/UnitsImplicitsTreeAnnotator.java

This file was deleted.

Loading