-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Legacy datatype constructor compatibility in Java (#5558)
- Loading branch information
Showing
13 changed files
with
196 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...ests/TestFiles/LitTests/LitTest/comp/separate-compilation/fromDafny42/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
This code was created using Dafny 4.2 in order to capture the existing code that | ||
`--legacy-data-constructors` needs to still satisfy: | ||
|
||
``` | ||
dafny translate java --output=fromDafny42/usesTimesTwo --allow-warnings --library=Inputs/producer/timesTwo.dfy usesTimesTwo.dfy | ||
``` |
61 changes: 61 additions & 0 deletions
61
...est/comp/separate-compilation/fromDafny42/usesTimesTwo-java/ConsumerModule/__default.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Class __default | ||
// Dafny class __default compiled into Java | ||
package ConsumerModule; | ||
|
||
|
||
@SuppressWarnings({"unchecked", "deprecation"}) | ||
public class __default { | ||
public __default() { | ||
} | ||
public static void Main(dafny.DafnySequence<? extends dafny.DafnySequence<? extends dafny.CodePoint>> __noArgsParameter) | ||
{ | ||
java.math.BigInteger _0_n = java.math.BigInteger.ZERO; | ||
_0_n = java.math.BigInteger.valueOf(21L); | ||
java.math.BigInteger _1_TwoN = java.math.BigInteger.ZERO; | ||
_1_TwoN = LibraryModule.__default.TimesTwo(_0_n); | ||
System.out.print((dafny.DafnySequence.asUnicodeString("Two times ")).verbatimString()); | ||
System.out.print(java.lang.String.valueOf(_0_n)); | ||
System.out.print((dafny.DafnySequence.asUnicodeString(" is ")).verbatimString()); | ||
System.out.print(java.lang.String.valueOf(_1_TwoN)); | ||
System.out.print((dafny.DafnySequence.asUnicodeString("\n")).verbatimString()); | ||
java.math.BigInteger _2_aNat = java.math.BigInteger.ZERO; | ||
java.math.BigInteger _out0 = java.math.BigInteger.ZERO; | ||
_out0 = __default.PickANat(); | ||
_2_aNat = _out0; | ||
} | ||
public static void __Main(dafny.DafnySequence<? extends dafny.DafnySequence<? extends dafny.CodePoint>> args) { | ||
__default.Main(args); | ||
} | ||
public static java.math.BigInteger PickANat() | ||
{ | ||
java.math.BigInteger n = java.math.BigInteger.ZERO; | ||
if(true) { | ||
java.math.BigInteger _out1 = java.math.BigInteger.ZERO; | ||
_out1 = __default.<java.math.BigInteger>PickSomething(_System.nat._typeDescriptor()); | ||
n = _out1; | ||
} | ||
return n; | ||
} | ||
public static <__T> __T PickSomething(dafny.TypeDescriptor<__T> _td___T) | ||
{ | ||
@SuppressWarnings({"unchecked", "deprecation"}) | ||
__T t = _td___T.defaultValue(); | ||
if(true) { | ||
} | ||
return t; | ||
} | ||
public static void MakeAResult() | ||
{ | ||
LibraryModule.Result<java.math.BigInteger, dafny.DafnySequence<? extends dafny.CodePoint>> _3_r; | ||
_3_r = LibraryModule.Result.<java.math.BigInteger, dafny.DafnySequence<? extends dafny.CodePoint>>create_Success(java.math.BigInteger.valueOf(42L)); | ||
} | ||
public static void MakeAPair() | ||
{ | ||
LibraryModule.Pair<java.math.BigInteger, dafny.DafnySequence<? extends dafny.CodePoint>> _4_p; | ||
_4_p = LibraryModule.Pair.<java.math.BigInteger, dafny.DafnySequence<? extends dafny.CodePoint>>create(java.math.BigInteger.ONE, dafny.DafnySequence.asUnicodeString("partridge in a pair tree")); | ||
} | ||
@Override | ||
public java.lang.String toString() { | ||
return "ConsumerModule._default"; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...LitTests/LitTest/comp/separate-compilation/fromDafny42/usesTimesTwo-java/_System/nat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Class nat | ||
// Dafny class nat compiled into Java | ||
package _System; | ||
|
||
import ConsumerModule.*; | ||
|
||
@SuppressWarnings({"unchecked", "deprecation"}) | ||
public class nat { | ||
public nat() { | ||
} | ||
private static final dafny.TypeDescriptor<java.math.BigInteger> _TYPE = dafny.TypeDescriptor.<java.math.BigInteger>referenceWithInitializer(java.math.BigInteger.class, () -> java.math.BigInteger.ZERO); | ||
public static dafny.TypeDescriptor<java.math.BigInteger> _typeDescriptor() { | ||
return (dafny.TypeDescriptor<java.math.BigInteger>) (dafny.TypeDescriptor<?>) _TYPE; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...itTests/LitTest/comp/separate-compilation/fromDafny42/usesTimesTwo-java/usesTimesTwo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Dafny program the_program compiled into Java | ||
|
||
import ConsumerModule.*; | ||
import _System.*; | ||
|
||
|
||
|
||
|
||
public class usesTimesTwo { | ||
public static void main(String[] args) { | ||
dafny.Helpers.withHaltHandling(() -> { ConsumerModule.__default.__Main(dafny.Helpers.UnicodeFromMainArguments(args)); } ); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...stFiles/LitTests/LitTest/comp/separate-compilation/usesTimesTwo-oldDafnyCompatability.dfy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// NONUNIFORM: Highly target language specific | ||
|
||
// Alternate version of usesTimesTwo.dfy as a regression test for https://github.com/dafny-lang/dafny/issues/5555. | ||
// Relies on having checked in the compilation of the library using Dafny 4.2. | ||
|
||
// Java | ||
|
||
// RUN: %baredafny translate java --output=%S/Inputs/producer/timesTwo %S/Inputs/producer/timesTwo.dfy --legacy-data-constructors | ||
// RUN: javac -cp %binaryDir/DafnyRuntime.jar%{pathsep}%S/Inputs/producer/timesTwo-java %S/Inputs/producer/timesTwo-java/**/*.java | ||
|
||
// Already run using Dafny 4.2: %baredafny translate java --output=%S/fromDafny42/usesTimesTwo --allow-warnings --library=%S/Inputs/producer/timesTwo.dfy %S/usesTimesTwo.dfy | ||
// RUN: javac -cp %binaryDir/DafnyRuntime.jar%{pathsep}%S/Inputs/producer/timesTwo-java%{pathsep}%S/fromDafny42/usesTimesTwo-java %S/fromDafny42/usesTimesTwo-java/**/*.java | ||
|
||
// RUN: java -cp %binaryDir/DafnyRuntime.jar%{pathsep}%S/Inputs/producer/timesTwo-java%{pathsep}%S/fromDafny42/usesTimesTwo-java usesTimesTwo > "%t" | ||
|
||
// (Other languages could be added in the future too.) | ||
|
||
// Final output check for all runs | ||
|
||
// RUN: %diff "%s.expect" "%t" |
1 change: 1 addition & 0 deletions
1
.../LitTests/LitTest/comp/separate-compilation/usesTimesTwo-oldDafnyCompatability.dfy.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Two times 21 is 42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters