Skip to content

Commit

Permalink
fix(dafny): Local Service Constructors MUST return concrete
Browse files Browse the repository at this point in the history
  • Loading branch information
texastony authored Mar 29, 2024
1 parent bd549c8 commit 64f72c1
Show file tree
Hide file tree
Showing 30 changed files with 788 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git b/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/Model/AwsCryptographyMaterialProvidersTypes.dfy a/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/Model/AwsCryptographyMaterialProvidersTypes.dfy
index 7fc594a1..7a5be522 100644
--- b/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/Model/AwsCryptographyMaterialProvidersTypes.dfy
+++ a/AwsCryptographicMaterialProviders/dafny/AwsCryptographicMaterialProviders/Model/AwsCryptographyMaterialProvidersTypes.dfy
@@ -1529,7 +1529,9 @@ abstract module AbstractAwsCryptographyMaterialProvidersService
import Operations : AbstractAwsCryptographyMaterialProvidersOperations
function method DefaultMaterialProvidersConfig(): MaterialProvidersConfig
method MaterialProviders(config: MaterialProvidersConfig := DefaultMaterialProvidersConfig())
- returns (res: Result<IAwsCryptographicMaterialProvidersClient, Error>)
+ // BEGIN MANUAL FIX
+ returns (res: Result<MaterialProvidersClient, Error>)
+ // END MANUAL FIX
ensures res.Success? ==>
&& fresh(res.value)
&& fresh(res.value.Modifies)
@@ -1537,10 +1539,14 @@ abstract module AbstractAwsCryptographyMaterialProvidersService
&& res.value.ValidState()

// Helper function for the benefit of native code to create a Success(client) without referring to Dafny internals
- function method CreateSuccessOfClient(client: IAwsCryptographicMaterialProvidersClient): Result<IAwsCryptographicMaterialProvidersClient, Error> {
+ // BEGIN MANUAL FIX
+ function method CreateSuccessOfClient(client: MaterialProvidersClient): Result<MaterialProvidersClient, Error> {
+ // END MANUAL FIX
Success(client)
} // Helper function for the benefit of native code to create a Failure(error) without referring to Dafny internals
- function method CreateFailureOfError(error: Error): Result<IAwsCryptographicMaterialProvidersClient, Error> {
+ // BEGIN MANUAL FIX
+ function method CreateFailureOfError(error: Error): Result<MaterialProvidersClient, Error> {
+ // END MANUAL FIX
Failure(error)
}
class MaterialProvidersClient extends IAwsCryptographicMaterialProvidersClient
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git b/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographicMaterialProviders/TypeConversion.cs a/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographicMaterialProviders/TypeConversion.cs
index b10e603c..89561181 100644
--- b/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographicMaterialProviders/TypeConversion.cs
+++ a/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographicMaterialProviders/TypeConversion.cs
@@ -3436,7 +3436,9 @@ namespace AWS.Cryptography.MaterialProviders
dafnyVal._ComAmazonawsDynamodb
);
case software.amazon.cryptography.materialproviders.internaldafny.types.Error_ComAmazonawsKms dafnyVal:
- return Com.Amazonaws.KMS.TypeConversion.FromDafny_CommonError(
+ // BEGIN MANUAL EDIT
+ return Com.Amazonaws.Kms.TypeConversion.FromDafny_CommonError(
+ // END MANUAL EDIT
dafnyVal._ComAmazonawsKms
);
case software.amazon.cryptography.materialproviders.internaldafny.types.Error_AwsCryptographicMaterialProvidersException dafnyVal:
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git b/AwsCryptographicMaterialProviders/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/materialproviders/MaterialProviders.java a/AwsCryptographicMaterialProviders/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/materialproviders/MaterialProviders.java
index ac695b97..290bcfc0 100644
--- b/AwsCryptographicMaterialProviders/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/materialproviders/MaterialProviders.java
+++ a/AwsCryptographicMaterialProviders/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/materialproviders/MaterialProviders.java
@@ -10,6 +10,9 @@ import java.lang.Byte;
import java.lang.IllegalArgumentException;
import java.nio.ByteBuffer;
import java.util.Objects;
+//BEGIN MANUAL FIX
+import software.amazon.cryptography.materialproviders.internaldafny.MaterialProvidersClient;
+//END MANUAL FIX
import software.amazon.cryptography.materialproviders.internaldafny.__default;
import software.amazon.cryptography.materialproviders.internaldafny.types.Error;
import software.amazon.cryptography.materialproviders.internaldafny.types.IAwsCryptographicMaterialProvidersClient;
@@ -49,7 +52,9 @@ public class MaterialProviders {
MaterialProvidersConfig input = builder.MaterialProvidersConfig();
software.amazon.cryptography.materialproviders.internaldafny.types.MaterialProvidersConfig dafnyValue =
ToDafny.MaterialProvidersConfig(input);
- Result<IAwsCryptographicMaterialProvidersClient, Error> result =
+ //BEGIN MANUAL FIX
+ Result<MaterialProvidersClient, Error> result =
+ //END MANUAL FIX
__default.MaterialProviders(dafnyValue);
if (result.is_Failure()) {
throw ToNative.Error(result.dtor_error());
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git b/AwsCryptographicMaterialProviders/dafny/AwsCryptographyKeyStore/Model/AwsCryptographyKeyStoreTypes.dfy a/AwsCryptographicMaterialProviders/dafny/AwsCryptographyKeyStore/Model/AwsCryptographyKeyStoreTypes.dfy
index 26600cfa..a3d5c6c9 100644
--- b/AwsCryptographicMaterialProviders/dafny/AwsCryptographyKeyStore/Model/AwsCryptographyKeyStoreTypes.dfy
+++ a/AwsCryptographicMaterialProviders/dafny/AwsCryptographyKeyStore/Model/AwsCryptographyKeyStoreTypes.dfy
@@ -285,7 +285,9 @@ abstract module AbstractAwsCryptographyKeyStoreService
import Operations : AbstractAwsCryptographyKeyStoreOperations
function method DefaultKeyStoreConfig(): KeyStoreConfig
method KeyStore(config: KeyStoreConfig := DefaultKeyStoreConfig())
- returns (res: Result<IKeyStoreClient, Error>)
+ // BEGIN MANUAL FIX
+ returns (res: Result<KeyStoreClient, Error>)
+ // END MANUAL FIX
requires config.ddbClient.Some? ==>
config.ddbClient.value.ValidState()
requires config.kmsClient.Some? ==>
@@ -314,10 +316,14 @@ abstract module AbstractAwsCryptographyKeyStoreService
config.kmsClient.value.ValidState()

// Helper function for the benefit of native code to create a Success(client) without referring to Dafny internals
- function method CreateSuccessOfClient(client: IKeyStoreClient): Result<IKeyStoreClient, Error> {
+ // BEGIN MANUAL FIX
+ function method CreateSuccessOfClient(client: KeyStoreClient): Result<KeyStoreClient, Error> {
+ // END MANUAL FIX
Success(client)
} // Helper function for the benefit of native code to create a Failure(error) without referring to Dafny internals
- function method CreateFailureOfError(error: Error): Result<IKeyStoreClient, Error> {
+ // BEGIN MANUAL FIX
+ function method CreateFailureOfError(error: Error): Result<KeyStoreClient, Error> {
+ // END MANUAL FIX
Failure(error)
}
class KeyStoreClient extends IKeyStoreClient
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git b/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographyKeyStore/TypeConversion.cs a/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographyKeyStore/TypeConversion.cs
index f5ef0458..f846a946 100644
--- b/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographyKeyStore/TypeConversion.cs
+++ a/AwsCryptographicMaterialProviders/runtimes/net/Generated/AwsCryptographyKeyStore/TypeConversion.cs
@@ -629,7 +629,9 @@ namespace AWS.Cryptography.KeyStore
dafnyVal._ComAmazonawsDynamodb
);
case software.amazon.cryptography.keystore.internaldafny.types.Error_ComAmazonawsKms dafnyVal:
- return Com.Amazonaws.KMS.TypeConversion.FromDafny_CommonError(
+ // BEGIN MANUAL EDIT
+ return Com.Amazonaws.Kms.TypeConversion.FromDafny_CommonError(
+ // END MANUAL EDIT
dafnyVal._ComAmazonawsKms
);
case software.amazon.cryptography.keystore.internaldafny.types.Error_KeyStoreException dafnyVal:
@@ -652,7 +654,9 @@ namespace AWS.Cryptography.KeyStore
{
case "Com.Amazonaws.KMS":
return software.amazon.cryptography.keystore.internaldafny.types.Error.create_ComAmazonawsKms(
- Com.Amazonaws.KMS.TypeConversion.ToDafny_CommonError(value)
+ // BEGIN MANUAL EDIT
+ Com.Amazonaws.Kms.TypeConversion.ToDafny_CommonError(value)
+ // END MANUAL EDIT
);
case "Com.Amazonaws.Dynamodb":
return software.amazon.cryptography.keystore.internaldafny.types.Error.create_ComAmazonawsDynamodb(
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
diff --git b/AwsCryptographicMaterialProviders/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/keystore/KeyStore.java a/AwsCryptographicMaterialProviders/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/keystore/KeyStore.java
index 68bf0666..7efec786 100644
--- b/AwsCryptographicMaterialProviders/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/keystore/KeyStore.java
+++ a/AwsCryptographicMaterialProviders/runtimes/java/src/main/smithy-generated/software/amazon/cryptography/keystore/KeyStore.java
@@ -6,6 +6,9 @@ package software.amazon.cryptography.keystore;
import Wrappers_Compile.Result;
import java.lang.IllegalArgumentException;
import java.util.Objects;
+// BEGIN MANUAL FIX
+import software.amazon.cryptography.keystore.internaldafny.KeyStoreClient;
+// END MANUAL FIX
import software.amazon.cryptography.keystore.internaldafny.__default;
import software.amazon.cryptography.keystore.internaldafny.types.Error;
import software.amazon.cryptography.keystore.internaldafny.types.IKeyStoreClient;
@@ -32,7 +35,9 @@ public class KeyStore {
KeyStoreConfig input = builder.KeyStoreConfig();
software.amazon.cryptography.keystore.internaldafny.types.KeyStoreConfig dafnyValue =
ToDafny.KeyStoreConfig(input);
- Result<IKeyStoreClient, Error> result = __default.KeyStore(dafnyValue);
+ // BEGIN MANUAL FIX
+ Result<KeyStoreClient, Error> result = __default.KeyStore(dafnyValue);
+ // END MANUAL FIX
if (result.is_Failure()) {
throw ToNative.Error(result.dtor_error());
}
Original file line number Diff line number Diff line change
Expand Up @@ -1529,18 +1529,24 @@ abstract module AbstractAwsCryptographyMaterialProvidersService
import Operations : AbstractAwsCryptographyMaterialProvidersOperations
function method DefaultMaterialProvidersConfig(): MaterialProvidersConfig
method MaterialProviders(config: MaterialProvidersConfig := DefaultMaterialProvidersConfig())
returns (res: Result<IAwsCryptographicMaterialProvidersClient, Error>)
// BEGIN MANUAL FIX
returns (res: Result<MaterialProvidersClient, Error>)
// END MANUAL FIX
ensures res.Success? ==>
&& fresh(res.value)
&& fresh(res.value.Modifies)
&& fresh(res.value.History)
&& res.value.ValidState()

// Helper function for the benefit of native code to create a Success(client) without referring to Dafny internals
function method CreateSuccessOfClient(client: IAwsCryptographicMaterialProvidersClient): Result<IAwsCryptographicMaterialProvidersClient, Error> {
// BEGIN MANUAL FIX
function method CreateSuccessOfClient(client: MaterialProvidersClient): Result<MaterialProvidersClient, Error> {
// END MANUAL FIX
Success(client)
} // Helper function for the benefit of native code to create a Failure(error) without referring to Dafny internals
function method CreateFailureOfError(error: Error): Result<IAwsCryptographicMaterialProvidersClient, Error> {
// BEGIN MANUAL FIX
function method CreateFailureOfError(error: Error): Result<MaterialProvidersClient, Error> {
// END MANUAL FIX
Failure(error)
}
class MaterialProvidersClient extends IAwsCryptographicMaterialProvidersClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module
}

method MaterialProviders(config: MaterialProvidersConfig)
returns (res: Result<IAwsCryptographicMaterialProvidersClient, Error>)
returns (res: Result<MaterialProvidersClient, Error>)
ensures res.Success? ==>
&& res.value is MaterialProvidersClient
{
Expand All @@ -29,7 +29,7 @@ module
var cryptoPrimitives := cryptoPrimitivesX as Primitives.AtomicPrimitivesClient;

var client := new MaterialProvidersClient(Operations.Config( crypto := cryptoPrimitives ));
return Success(client as IAwsCryptographicMaterialProvidersClient);
return Success(client);
}

class MaterialProvidersClient... {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ abstract module AbstractAwsCryptographyKeyStoreService
import Operations : AbstractAwsCryptographyKeyStoreOperations
function method DefaultKeyStoreConfig(): KeyStoreConfig
method KeyStore(config: KeyStoreConfig := DefaultKeyStoreConfig())
returns (res: Result<IKeyStoreClient, Error>)
// BEGIN MANUAL FIX
returns (res: Result<KeyStoreClient, Error>)
// END MANUAL FIX
requires config.ddbClient.Some? ==>
config.ddbClient.value.ValidState()
requires config.kmsClient.Some? ==>
Expand Down Expand Up @@ -314,10 +316,14 @@ abstract module AbstractAwsCryptographyKeyStoreService
config.kmsClient.value.ValidState()

// Helper function for the benefit of native code to create a Success(client) without referring to Dafny internals
function method CreateSuccessOfClient(client: IKeyStoreClient): Result<IKeyStoreClient, Error> {
// BEGIN MANUAL FIX
function method CreateSuccessOfClient(client: KeyStoreClient): Result<KeyStoreClient, Error> {
// END MANUAL FIX
Success(client)
} // Helper function for the benefit of native code to create a Failure(error) without referring to Dafny internals
function method CreateFailureOfError(error: Error): Result<IKeyStoreClient, Error> {
// BEGIN MANUAL FIX
function method CreateFailureOfError(error: Error): Result<KeyStoreClient, Error> {
// END MANUAL FIX
Failure(error)
}
class KeyStoreClient extends IKeyStoreClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module {:extern "software.amazon.cryptography.keystore.internaldafny"}
}

method KeyStore(config: KeyStoreConfig)
returns (res: Result<IKeyStoreClient, Error>)
returns (res: Result<KeyStoreClient, Error>)
ensures res.Success? ==>
&& res.value is KeyStoreClient
&& var rconfig := (res.value as KeyStoreClient).config;
Expand Down Expand Up @@ -123,7 +123,7 @@ module {:extern "software.amazon.cryptography.keystore.internaldafny"}
ddbClient := ddbClient
)
);
return Success(client as IKeyStoreClient);
return Success(client);
}

class KeyStoreClient... {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import Wrappers_Compile.Result;
import java.lang.IllegalArgumentException;
import java.util.Objects;
// BEGIN MANUAL FIX
import software.amazon.cryptography.keystore.internaldafny.KeyStoreClient;
// END MANUAL FIX
import software.amazon.cryptography.keystore.internaldafny.__default;
import software.amazon.cryptography.keystore.internaldafny.types.Error;
import software.amazon.cryptography.keystore.internaldafny.types.IKeyStoreClient;
Expand All @@ -32,7 +35,9 @@ protected KeyStore(BuilderImpl builder) {
KeyStoreConfig input = builder.KeyStoreConfig();
software.amazon.cryptography.keystore.internaldafny.types.KeyStoreConfig dafnyValue =
ToDafny.KeyStoreConfig(input);
Result<IKeyStoreClient, Error> result = __default.KeyStore(dafnyValue);
// BEGIN MANUAL FIX
Result<KeyStoreClient, Error> result = __default.KeyStore(dafnyValue);
// END MANUAL FIX
if (result.is_Failure()) {
throw ToNative.Error(result.dtor_error());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import java.lang.IllegalArgumentException;
import java.nio.ByteBuffer;
import java.util.Objects;
//BEGIN MANUAL FIX
import software.amazon.cryptography.materialproviders.internaldafny.MaterialProvidersClient;
//END MANUAL FIX
import software.amazon.cryptography.materialproviders.internaldafny.__default;
import software.amazon.cryptography.materialproviders.internaldafny.types.Error;
import software.amazon.cryptography.materialproviders.internaldafny.types.IAwsCryptographicMaterialProvidersClient;
Expand Down Expand Up @@ -49,7 +52,9 @@ protected MaterialProviders(BuilderImpl builder) {
MaterialProvidersConfig input = builder.MaterialProvidersConfig();
software.amazon.cryptography.materialproviders.internaldafny.types.MaterialProvidersConfig dafnyValue =
ToDafny.MaterialProvidersConfig(input);
Result<IAwsCryptographicMaterialProvidersClient, Error> result =
//BEGIN MANUAL FIX
Result<MaterialProvidersClient, Error> result =
//END MANUAL FIX
__default.MaterialProviders(dafnyValue);
if (result.is_Failure()) {
throw ToNative.Error(result.dtor_error());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,18 +519,24 @@ abstract module AbstractAwsCryptographyPrimitivesService
import Operations : AbstractAwsCryptographyPrimitivesOperations
function method DefaultCryptoConfig(): CryptoConfig
method AtomicPrimitives(config: CryptoConfig := DefaultCryptoConfig())
returns (res: Result<IAwsCryptographicPrimitivesClient, Error>)
// BEGIN MANUAL FIX
returns (res: Result<AtomicPrimitivesClient, Error>)
// END MANUAL FIX
ensures res.Success? ==>
&& fresh(res.value)
&& fresh(res.value.Modifies)
&& fresh(res.value.History)
&& res.value.ValidState()

// Helper function for the benefit of native code to create a Success(client) without referring to Dafny internals
function method CreateSuccessOfClient(client: IAwsCryptographicPrimitivesClient): Result<IAwsCryptographicPrimitivesClient, Error> {
// BEGIN MANUAL FIX
function method CreateSuccessOfClient(client: AtomicPrimitivesClient): Result<AtomicPrimitivesClient, Error> {
// END MANUAL FIX
Success(client)
} // Helper function for the benefit of native code to create a Failure(error) without referring to Dafny internals
function method CreateFailureOfError(error: Error): Result<IAwsCryptographicPrimitivesClient, Error> {
// BEGIN MANUAL FIX
function method CreateFailureOfError(error: Error): Result<AtomicPrimitivesClient, Error> {
// END MANUAL FIX
Failure(error)
}
class AtomicPrimitivesClient extends IAwsCryptographicPrimitivesClient
Expand Down
Loading

0 comments on commit 64f72c1

Please sign in to comment.