diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 2af592d..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,11 +0,0 @@ -version: 2 -updates: -- package-ecosystem: gradle - directory: "/" - schedule: - interval: daily - open-pull-requests-limit: 10 - ignore: - - dependency-name: junit:junit - versions: - - 4.13.1 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/LICENSE b/LICENSE deleted file mode 100644 index d159169..0000000 --- a/LICENSE +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/build.gradle b/build.gradle index 27cae70..52b4818 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ /// Why doesn't this work on Travis under Java 7? /// The same text does in Randoop's build.gradle file. plugins { - id 'com.github.johnrengelman.shadow' version '6.1.0' + id 'com.github.johnrengelman.shadow' version '2.0.4' } apply plugin: 'java' @@ -37,15 +37,15 @@ dependencies { compile fileTree(dir: "${cf}/checker/dist", include: "checker.jar") compile fileTree(dir: "${cfi}/dist", include: "checker-framework-inference.jar") // sat4j solver dependency - compile 'org.ow2.sat4j:org.ow2.sat4j.core:2.3.6' - compile 'org.ow2.sat4j:org.ow2.sat4j.maxsat:2.3.6' + compile 'org.ow2.sat4j:org.ow2.sat4j.core:2.3.5' + compile 'org.ow2.sat4j:org.ow2.sat4j.maxsat:2.3.5' // z3 solver dependency compile fileTree(dir: "${cfi}/lib", include: "com.microsoft.z3.jar") // CF test lib dependency testCompile fileTree(dir: "${cf}/framework-test/build/libs", include: "framework-test-*.jar") testCompile fileTree(dir: "${cfi}/dist", include: "inference-framework-test-lib.jar") - testCompile 'junit:junit:4.13.2' + testCompile 'junit:junit:4.13' } sourceSets { @@ -180,7 +180,7 @@ task getCodeFormatScripts() { task pythonIsInstalled(type: Exec) { description "Check that the python executable is installed." - executable = "python" + executable = "python3" args "--version" } @@ -222,7 +222,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 @@ -239,7 +239,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 @@ -247,4 +247,8 @@ task reformat(type: Exec, dependsOn: [getCodeFormatScripts, pythonIsInstalled], } } -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/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 838e6bc..1b16c34 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists 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..eb6d609 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; @@ -26,6 +27,7 @@ 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; @@ -38,8 +40,6 @@ import units.util.UnitsTypecheckUtils; import java.lang.annotation.Annotation; -import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Map; @@ -48,7 +48,7 @@ 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; @@ -93,7 +93,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 @@ -124,11 +124,11 @@ public boolean isSupportedQualifier(AnnotationMirror anno) { * Top and Bottom. We need to check all other instances of @UnitsRep AMs that are * supported qualifiers here. */ - if (anno == null) { + if (!super.isSupportedQualifier(anno)) { return false; } if (AnnotationUtils.areSameByClass(anno, UnitsRep.class)) { - return true; + return unitsRepUtils.hasAllBaseUnits(anno); } if (AnnotationUtils.areSameByClass(anno, PolyUnit.class)) { return true; @@ -160,8 +160,17 @@ protected void addCheckedCodeDefaults(QualifierDefaults defs) { defs.addCheckedCodeDefault(unitsRepUtils.TOP, TypeUseLocation.LOCAL_VARIABLE); } + @SuppressWarnings("deprecation") + @Override + public QualifierHierarchy createQualifierHierarchy() { + return org.checkerframework.framework.util.MultiGraphQualifierHierarchy + .createMultiGraphQualifierHierarchy(this); + } + + @SuppressWarnings("deprecation") @Override - public QualifierHierarchy createQualifierHierarchy(MultiGraphFactory factory) { + public QualifierHierarchy createQualifierHierarchyWithMultiGraphFactory( + MultiGraphFactory factory) { return new UnitsQualifierHierarchy(factory); } @@ -170,82 +179,102 @@ public UnitsQualifierHierarchy(MultiGraphFactory mgf) { super(mgf, unitsRepUtils.BOTTOM); } - /** Programmatically set {@link UnitsRepresentationUtils#TOP} as the top */ - @Override - protected Set findTops( - Map> supertypes) { - Set tops = AnnotationUtils.createAnnotationSet(); - - tops.add(unitsRepUtils.TOP); - - // remove RAWUNITSREP in supertypes - assert supertypes.containsKey(unitsRepUtils.RAWUNITSREP); - supertypes.remove(unitsRepUtils.RAWUNITSREP); - // add TOP to supertypes - supertypes.put(unitsRepUtils.TOP, Collections.emptySet()); - - return tops; - } - - /** Programmatically set {@link UnitsRepresentationUtils#BOTTOM} as the bottom */ + // Programmatically set UnitsRepresentationUtils.BOTTOM as the bottom @Override protected Set findBottoms( Map> supertypes) { - Set bottoms = AnnotationUtils.createAnnotationSet(); - - bottoms.add(unitsRepUtils.BOTTOM); + Set newBottoms = super.findBottoms(supertypes); + newBottoms.remove(unitsRepUtils.RAWUNITSREP); + newBottoms.add(unitsRepUtils.BOTTOM); - // set direct supertypes of BOTTOM and add to supertypes - Set bottomSupers = new LinkedHashSet<>(); - bottomSupers.add(unitsRepUtils.POLYUNIT); - bottomSupers.add(unitsRepUtils.TOP); - supertypes.put(unitsRepUtils.BOTTOM, Collections.unmodifiableSet(bottomSupers)); + // set direct supertypes of bottom + Set supertypesOfBottom = new LinkedHashSet<>(); + supertypesOfBottom.add(unitsRepUtils.TOP); + supertypes.put(unitsRepUtils.BOTTOM, supertypesOfBottom); - return bottoms; + return newBottoms; } - /** - * Programmatically set {@link UnitsRepresentationUtils#POLYUNIT} as the polymorphic - * qualifiers - */ + // Programmatically set UnitsRepresentationUtils.TOP as the top @Override - protected void addPolyRelations( + protected void finish( QualifierHierarchy qualHierarchy, - Map> supertypes, + Map> supertypesMap, Map polyQualifiers, Set tops, - Set bottoms) { + Set bottoms, + Object... args) { + super.finish(qualHierarchy, supertypesMap, polyQualifiers, tops, bottoms, args); + + // System.err.println(" === ATF "); + // System.err.println(" supertypesMap {"); + // for (Entry e : supertypesMap.entrySet()) { + // System.err.println(" " + e.getKey() + " -> " + e.getValue()); + // } + // System.err.println(" }"); + // System.err.println(" polyQualifiers " + polyQualifiers); + // System.err.println(" tops " + tops); + // System.err.println(" bottoms " + bottoms); + + // swap every instance of RAWUNITSREP with TOP - // polyQualifiers {null=@PolyAll, @UnitsRep=@PolyUnit} - // replace RAWUNITSREP -> @PolyUnit with TOP -> @PolyUnit - // Build up a replacement map by looping through polyQualifiers as it is a simple hash - // map. The null key causes crashes if not handled correctly. - Map updatedPolyQualifiers = new HashMap<>(); + // Set direct supertypes of TOP + for (Entry> e : supertypesMap.entrySet()) { + if (AnnotationUtils.areSame(e.getKey(), unitsRepUtils.RAWUNITSREP)) { + supertypesMap.put(unitsRepUtils.TOP, e.getValue()); + supertypesMap.remove(e.getKey()); + break; + } + } + + // Set direct supertypes of PolyUnit + // replace raw @UnitsRep with UnitsTop in super of PolyUnit + for (Entry> e : supertypesMap.entrySet()) { + if (AnnotationUtils.areSame(e.getKey(), unitsRepUtils.POLYUNIT)) { + Set polyUnitSupers = AnnotationUtils.createAnnotationSet(); + polyUnitSupers.addAll(e.getValue()); + polyUnitSupers.add(unitsRepUtils.TOP); + polyUnitSupers.remove(unitsRepUtils.RAWUNITSREP); + supertypesMap.put(e.getKey(), polyUnitSupers); + break; + } + } + + // Set direct supertypes of BOTTOM + for (Entry> e : supertypesMap.entrySet()) { + if (AnnotationUtils.areSame(e.getKey(), unitsRepUtils.BOTTOM)) { + Set bottomSupers = AnnotationUtils.createAnnotationSet(); + bottomSupers.addAll(e.getValue()); + // bottom already has top in its super set + bottomSupers.remove(unitsRepUtils.RAWUNITSREP); + supertypesMap.put(e.getKey(), bottomSupers); + break; + } + } + + // Update polyQualifiers for (Entry e : polyQualifiers.entrySet()) { if (AnnotationUtils.areSame(e.getKey(), unitsRepUtils.RAWUNITSREP)) { - updatedPolyQualifiers.put(unitsRepUtils.TOP, e.getValue()); - } else { - updatedPolyQualifiers.put(e.getKey(), e.getValue()); + polyQualifiers.put(unitsRepUtils.TOP, e.getValue()); + polyQualifiers.remove(e.getKey()); + break; } } - polyQualifiers.clear(); - polyQualifiers.putAll(updatedPolyQualifiers); - // add @PolyUnit -> {TOP} to supertypes - Set polyUnitSupers = AnnotationUtils.createAnnotationSet(); - polyUnitSupers.add(unitsRepUtils.TOP); - supertypes.put(unitsRepUtils.POLYUNIT, Collections.unmodifiableSet(polyUnitSupers)); + // Update tops + tops.remove(unitsRepUtils.RAWUNITSREP); + tops.remove(unitsRepUtils.RECEIVER_DEPENDANT_UNIT); + tops.add(unitsRepUtils.TOP); - // System.err.println(" POST "); - // System.err.println(" supertypes {"); - // for (Entry e : supertypes.entrySet()) { + // System.err.println(" === Typecheck ATF "); + // System.err.println(" supertypesMap {"); + // for (Entry e : supertypesMap.entrySet()) { // System.err.println(" " + e.getKey() + " -> " + e.getValue()); // } // System.err.println(" }"); // System.err.println(" polyQualifiers " + polyQualifiers); // System.err.println(" tops " + tops); // System.err.println(" bottoms " + bottoms); - // System.err.println(); } @Override @@ -272,12 +301,27 @@ 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)) { - return AnnotationUtils.areSame(subAnno, superAnno); - // return UnitsTypecheckUtils.unitsEqual(subAnno, superAnno); + boolean result = UnitsTypecheckUtils.unitsEqual(subAnno, superAnno); // if (AnnotationUtils.areSame(superAnno, unitsRepUtils.METER)) { // System.err.println(" === checking SUBTYPE \n " @@ -286,10 +330,15 @@ public boolean isSubtype(AnnotationMirror subAnno, AnnotationMirror superAnno) { // + " result: " + result); // } - // return result; + 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..2f7e2f4 100644 --- a/src/units/UnitsChecker.java +++ b/src/units/UnitsChecker.java @@ -52,7 +52,7 @@ public UnitsVisitor createVisitor( } @Override - public UnitsAnnotatedTypeFactory createRealTypeFactory() { + public UnitsAnnotatedTypeFactory createRealTypeFactory(boolean infer) { return new UnitsAnnotatedTypeFactory(this); } diff --git a/src/units/UnitsInferenceAnnotatedTypeFactory.java b/src/units/UnitsInferenceAnnotatedTypeFactory.java index cb53306..c5bc894 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,7 @@ 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,119 +127,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<>(); @@ -287,12 +169,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,20 +203,20 @@ 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; } // insert varAnnot of the slot into the ATM AnnotationMirror resultAM = slotManager.getAnnotation(result); - atm.clearAnnotations(); + atm.clearPrimaryAnnotations(); atm.replaceAnnotation(resultAM); // 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 +296,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 +319,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 getQualifierHierarchy().isPolymorphicQualifier(constant); } return false; } @@ -534,13 +417,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 +445,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); @@ -596,7 +479,7 @@ private void replaceATM(AnnotatedTypeMirror atm, AnnotationMirror am) { AnnotationBuilder ab = new AnnotationBuilder(realTypeFactory.getProcessingEnv(), VarAnnot.class); ab.setValue("value", cs.getId()); - atm.clearAnnotations(); + atm.clearPrimaryAnnotations(); atm.replaceAnnotation(ab.build()); } } 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..3500029 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; @@ -24,10 +23,12 @@ import org.checkerframework.javacutil.TreeUtils; import units.representation.UnitsRepresentationUtils; +import units.util.UnitsTypecheckUtils; import java.util.Set; import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.ExecutableElement; public class UnitsVisitor extends InferenceVisitor { @@ -178,8 +179,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); @@ -268,11 +268,13 @@ public Void visitTypeCast(TypeCastTree node, Void p) { UnitsRepresentationUtils.getInstance().TOP); // If expression type is dimensionless, permit it to be casted to anything - if (AnnotationUtils.areSame( + if (UnitsTypecheckUtils.unitsEqual( 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 +357,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/representation/UnitsRepresentationUtils.java b/src/units/representation/UnitsRepresentationUtils.java index 4a5b73f..4712cd7 100644 --- a/src/units/representation/UnitsRepresentationUtils.java +++ b/src/units/representation/UnitsRepresentationUtils.java @@ -80,7 +80,7 @@ public class UnitsRepresentationUtils { * Instances of time units for use with various time APIs, used by {@link * UnitsAnnotatedTypeFactory#UnitsImplicitsTreeAnnotator} */ - // public AnnotationMirror SECOND, MILLISECOND, MICROSECOND, NANOSECOND; + public AnnotationMirror SECOND, MILLISECOND, MICROSECOND, NANOSECOND; // Comparator used to sort annotation classes by their simple class name private static Comparator> annoClassComparator = @@ -253,13 +253,13 @@ public void postInit() { SURFACE_TOP = AnnotationBuilder.fromClass(elements, UnknownUnits.class); SURFACE_BOTTOM = AnnotationBuilder.fromClass(elements, UnitsBottom.class); - // - // Map secondBaseMap = createZeroFilledBaseUnitsMap(); - // secondBaseMap.put("s", 1); - // SECOND = createInternalUnit(false, false, 0, secondBaseMap); - // MILLISECOND = createInternalUnit(false, false, -3, secondBaseMap); - // MICROSECOND = createInternalUnit(false, false, -6, secondBaseMap); - // NANOSECOND = createInternalUnit(false, false, -9, secondBaseMap); + + Map secondBaseMap = createZeroFilledBaseUnitsMap(); + secondBaseMap.put("s", 1); + SECOND = createInternalUnit(false, false, 0, secondBaseMap); + MILLISECOND = createInternalUnit(false, false, -3, secondBaseMap); + MICROSECOND = createInternalUnit(false, false, -6, secondBaseMap); + NANOSECOND = createInternalUnit(false, false, -9, secondBaseMap); // for (Entry entry : unitsAnnotationMirrorMap // .entrySet()) { 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/gje/encoder/UnitsGJEConstraintEncoderFactory.java b/src/units/solvers/backend/gje/encoder/UnitsGJEConstraintEncoderFactory.java index 02431ad..88c83ae 100644 --- a/src/units/solvers/backend/gje/encoder/UnitsGJEConstraintEncoderFactory.java +++ b/src/units/solvers/backend/gje/encoder/UnitsGJEConstraintEncoderFactory.java @@ -2,6 +2,7 @@ import checkers.inference.solver.backend.encoder.AbstractConstraintEncoderFactory; import checkers.inference.solver.backend.encoder.ArithmeticConstraintEncoder; +import checkers.inference.solver.backend.encoder.ComparisonConstraintEncoder; import checkers.inference.solver.backend.encoder.binary.ComparableConstraintEncoder; import checkers.inference.solver.backend.encoder.binary.EqualityConstraintEncoder; import checkers.inference.solver.backend.encoder.binary.InequalityConstraintEncoder; @@ -73,4 +74,9 @@ public ImplicationConstraintEncoder createImplicationConstraintE public ArithmeticConstraintEncoder createArithmeticConstraintEncoder() { return new UnitsGJEArithmeticConstraintEncoder(lattice, formatTranslator); } + + @Override + public ComparisonConstraintEncoder createComparisonConstraintEncoder() { + return null; + } } 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); diff --git a/src/units/solvers/backend/z3smt/encoder/UnitsZ3SmtConstraintEncoderFactory.java b/src/units/solvers/backend/z3smt/encoder/UnitsZ3SmtConstraintEncoderFactory.java index c333cc0..5c14b0c 100644 --- a/src/units/solvers/backend/z3smt/encoder/UnitsZ3SmtConstraintEncoderFactory.java +++ b/src/units/solvers/backend/z3smt/encoder/UnitsZ3SmtConstraintEncoderFactory.java @@ -4,6 +4,7 @@ import backend.z3smt.encoder.Z3SmtConstraintEncoderFactory; import checkers.inference.solver.backend.encoder.ArithmeticConstraintEncoder; +import checkers.inference.solver.backend.encoder.ComparisonConstraintEncoder; import checkers.inference.solver.backend.encoder.binary.ComparableConstraintEncoder; import checkers.inference.solver.backend.encoder.binary.EqualityConstraintEncoder; import checkers.inference.solver.backend.encoder.binary.InequalityConstraintEncoder; @@ -78,4 +79,9 @@ public ImplicationConstraintEncoder createImplicationConstraintEncoder public ArithmeticConstraintEncoder createArithmeticConstraintEncoder() { return new UnitsZ3SmtArithmeticConstraintEncoder(lattice, ctx, formatTranslator); } + + @Override + public ComparisonConstraintEncoder createComparisonConstraintEncoder() { + return null; + } } diff --git a/testing/inference/StaticFinalConstants.java b/testing/inference/StaticFinalConstants.java index 4d4d808..50c4aff 100644 --- a/testing/inference/StaticFinalConstants.java +++ b/testing/inference/StaticFinalConstants.java @@ -26,6 +26,7 @@ static class MyConstants { public static final @rad int HASUNIT = 20 * UnitsTools.rad; public MyConstants() {} + ; } void inferRadians2() {