Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add type descriptors for data constructors in Java, when necessary #301

Merged
merged 53 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
461dd3d
Fix UTF8
robin-aws Oct 20, 2023
c31cee8
Temporarily try CI on 4.3
robin-aws Oct 20, 2023
45ee695
Merge branch 'main-1.x' into robin-aws/add-type-descriptors-for-java
robin-aws Oct 20, 2023
478c043
Get Resource test model working
robin-aws Oct 23, 2023
8f40bb7
Merge branch 'robin-aws/add-type-descriptors-for-java' of github.com:…
robin-aws Oct 23, 2023
fe5f975
Handle aggregate type descriptors in general
robin-aws Oct 23, 2023
ea48656
Fix KMS
robin-aws Oct 23, 2023
6ba962d
Fix a few more model tests
robin-aws Oct 23, 2023
e841a8a
Missing file
robin-aws Oct 23, 2023
213da2b
Missed one in DDB
robin-aws Oct 23, 2023
0a24bc8
Add dafnyVersion parameter, make type descriptors conditional
robin-aws Oct 28, 2023
6d8b292
Add —dafny-version to CLI
robin-aws Oct 29, 2023
180d29c
Test multiple Dafny versions in CI
robin-aws Oct 29, 2023
5c65aa7
Specify —dafny-version
robin-aws Oct 29, 2023
05327d8
Avoid conditional type descriptors in UTF8
robin-aws Oct 29, 2023
4d67a3d
Working around create_Success in test services
robin-aws Oct 29, 2023
ad4ac89
Fix KMS
robin-aws Oct 30, 2023
49c7de3
Fix test shim type descriptor
robin-aws Oct 30, 2023
ae8d542
public
robin-aws Oct 30, 2023
9e2cb47
Fix unit tests and local service
robin-aws Oct 30, 2023
33f74af
Fix DDB and Errors
robin-aws Oct 30, 2023
f0493fb
License headers, typos
robin-aws Oct 30, 2023
efed9b2
Shim.createFailureOfException -> Shim.createFailureOfError
robin-aws Oct 30, 2023
b6f4f09
Typo
robin-aws Oct 30, 2023
fb538e0
Typos, typos everywhere…
robin-aws Oct 30, 2023
c8f245e
Fix test
robin-aws Oct 30, 2023
8a1786b
Cleanup
robin-aws Oct 30, 2023
6e64b30
Refactor CI to handle nightly builds correctly
robin-aws Oct 31, 2023
538d872
Need full commit sha
robin-aws Oct 31, 2023
fb2d1e4
Use latest edition in sample
robin-aws Oct 31, 2023
eb785e0
Introduce proper DafnyVersion class
robin-aws Oct 31, 2023
82349d6
License headers
robin-aws Oct 31, 2023
60557cb
Move interop methods into Dafny (StandardLibrary and abstract server …
robin-aws Nov 2, 2023
7c693c9
Use the same helpers for test wrappers too
robin-aws Nov 2, 2023
f7c8069
Fix remaining TestModels
robin-aws Nov 2, 2023
e27cd3e
Fix unit tests
robin-aws Nov 2, 2023
ff32cc7
Document new StandardLibrary module
robin-aws Nov 2, 2023
93f39db
Miscellaneous fixes
robin-aws Nov 2, 2023
6ca9e79
Make sure CLi actually fails without —dafny-version, add it in CI eve…
robin-aws Nov 2, 2023
6c3ac1a
Upgrade setup-dafny-action to 1.7.0
robin-aws Nov 2, 2023
31595e5
Fix import statements for WrappersInterop
robin-aws Nov 2, 2023
9305206
Getting tired of only getting partial CI results
robin-aws Nov 2, 2023
f20738b
Using service client interface instead of concrete class in abstract …
robin-aws Nov 2, 2023
3d3e52f
Should be traitForServiceClient after all
robin-aws Nov 2, 2023
28adebb
Fix remaining models
robin-aws Nov 2, 2023
183b0fa
Fix Dependencies
robin-aws Nov 2, 2023
937bda6
I said, FIX DEPENDENCIES
robin-aws Nov 2, 2023
b0527ea
Skip Extendable model on 4.3
robin-aws Nov 21, 2023
3752aa6
Merge branch 'main-1.x' into robin-aws/add-type-descriptors-for-java
robin-aws Nov 22, 2023
6eed666
Remove dead code, more comments on the helper methods
robin-aws Nov 22, 2023
6f66074
Merge branch 'robin-aws/add-type-descriptors-for-java' of github.com:…
robin-aws Nov 22, 2023
0db5dec
Apply suggestions from code review
robin-aws Nov 27, 2023
855d329
PR feedback
robin-aws Nov 27, 2023
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
27 changes: 15 additions & 12 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,39 @@ on:
pull_request:

jobs:
pr-populate-dafny-versions:
runs-on: ubuntu-latest
steps:
- name: Populate Dafny versions list
id: populate-dafny-versions-list
run: echo "dafny-versions-list=['4.1.0', '4.3.0']" >> $GITHUB_OUTPUT
outputs:
dafny-version-list: ${{ steps.populate-dafny-versions-list.outputs.dafny-versions-list }}
texastony marked this conversation as resolved.
Show resolved Hide resolved

pr-ci-verification:
needs: pr-populate-dafny-versions
strategy:
fail-fast: false
matrix:
dafny-version: [
4.1.0,
4.3.0
]
dafny-version: ${{ fromJson(needs.pr-populate-dafny-versions.outputs.dafny-version-list) }}
uses: ./.github/workflows/test_models_dafny_verification.yml
with:
dafny: ${{ matrix.dafny-version }}
pr-ci-java:
needs: pr-populate-dafny-versions
strategy:
fail-fast: false
matrix:
dafny-version: [
4.1.0,
4.3.0
]
dafny-version: ${{ fromJson(needs.pr-populate-dafny-versions.outputs.dafny-version-list) }}
uses: ./.github/workflows/test_models_java_tests.yml
with:
dafny: ${{ matrix.dafny-version }}
pr-ci-net:
needs: pr-populate-dafny-versions
strategy:
fail-fast: false
matrix:
dafny-version: [
4.1.0,
4.3.0
]
dafny-version: ${{ fromJson(needs.pr-populate-dafny-versions.outputs.dafny-version-list) }}
uses: ./.github/workflows/test_models_net_tests.yml
with:
dafny: ${{ matrix.dafny-version }}
27 changes: 15 additions & 12 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,39 @@ on:
- main-1.x

jobs:
pr-populate-dafny-versions:
runs-on: ubuntu-latest
steps:
- name: Populate Dafny versions list
id: populate-dafny-versions-list
run: echo "dafny-versions-list=['4.1.0', '4.3.0']" >> $GITHUB_OUTPUT
outputs:
dafny-version-list: ${{ steps.populate-dafny-versions-list.outputs.dafny-versions-list }}

push-ci-verification:
needs: pr-populate-dafny-versions
strategy:
fail-fast: false
matrix:
dafny-version: [
4.1.0,
4.3.0
]
dafny-version: ${{ fromJson(needs.pr-populate-dafny-versions.outputs.dafny-version-list) }}
uses: ./.github/workflows/test_models_dafny_verification.yml
with:
dafny: ${{ matrix.dafny-version }}
push-ci-java:
needs: pr-populate-dafny-versions
strategy:
fail-fast: false
matrix:
dafny-version: [
4.1.0,
4.3.0
]
dafny-version: ${{ fromJson(needs.pr-populate-dafny-versions.outputs.dafny-version-list) }}
uses: ./.github/workflows/test_models_java_tests.yml
with:
dafny: ${{ matrix.dafny-version }}
push-ci-net:
needs: pr-populate-dafny-versions
strategy:
fail-fast: false
matrix:
dafny-version: [
4.1.0,
4.3.0
]
dafny-version: ${{ fromJson(needs.pr-populate-dafny-versions.outputs.dafny-version-list) }}
uses: ./.github/workflows/test_models_net_tests.yml
with:
dafny: ${{ matrix.dafny-version }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were imports added but not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just neglected to clean them up

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package software.amazon.polymorph.smithyjava.generator.library.shims;

import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.CodeBlock;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
Expand All @@ -19,12 +18,10 @@
import software.amazon.polymorph.smithyjava.BuilderSpecs;
import software.amazon.polymorph.smithyjava.generator.library.JavaLibrary;
import software.amazon.polymorph.smithyjava.modeled.Operation;
import software.amazon.polymorph.smithyjava.nameresolver.Dafny;
import software.amazon.smithy.model.shapes.ServiceShape;

import static javax.lang.model.element.Modifier.PROTECTED;
import static javax.lang.model.element.Modifier.PUBLIC;
import static javax.lang.model.element.Modifier.STATIC;

public class TestServiceShim extends ServiceShim {
/** The Service Shape this Shim Tests. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public static String datatypeConstructorCreate(String name, boolean isRecordType
// Dafnys greater than or equal to this will need Type Descriptors for constructing datatypes
private static final DafnyVersion NEEDS_TYPE_DESCRIPTORS_WHEN_CONSTRUCTING_DATATYPES = new DafnyVersion(4, 2, 0);
robin-aws marked this conversation as resolved.
Show resolved Hide resolved

/**
* @return Whether the given Dafny version requires type descriptor values when instantiating datatype constructors.
*/
public static boolean datatypeConstructorsNeedTypeDescriptors(DafnyVersion dafnyVersion) {
return dafnyVersion.compareTo(NEEDS_TYPE_DESCRIPTORS_WHEN_CONSTRUCTING_DATATYPES) >= 0;
}
Expand All @@ -108,6 +111,11 @@ private boolean datatypeConstructorsNeedTypeDescriptors() {
return datatypeConstructorsNeedTypeDescriptors(dafnyVersion);
}

/**
* Code to create an instance of the None constructor of Wrappers.Option<T>.
* @param typeDescriptor the code to create a TypeDescriptor for the type T,
* which is needed if datatypeConstructorsNeedTypeDescriptors()
*/
public CodeBlock createNone(CodeBlock typeDescriptor) {
if (datatypeConstructorsNeedTypeDescriptors()) {
return CodeBlock.of(
Expand All @@ -121,6 +129,11 @@ public CodeBlock createNone(CodeBlock typeDescriptor) {
}
}

/**
* Code to create an instance of the Some(value: T) constructor of Wrappers.Option<T>.
* @param typeDescriptor the code to create a TypeDescriptor for the type T,
* which is needed if datatypeConstructorsNeedTypeDescriptors()
*/
public CodeBlock createSome(CodeBlock typeDescriptor, CodeBlock value) {
if (datatypeConstructorsNeedTypeDescriptors()) {
return CodeBlock.of(
Expand All @@ -136,6 +149,11 @@ public CodeBlock createSome(CodeBlock typeDescriptor, CodeBlock value) {
}
}

/**
* Code to create an instance of the Success(value: T) constructor of Wrappers.Result<T, Error>.
* @param valueTypeDescriptor the code to create a TypeDescriptor for the type T,
* which is needed if datatypeConstructorsNeedTypeDescriptors()
*/
public CodeBlock createSuccess(CodeBlock valueTypeDescriptor, CodeBlock value) {
if (datatypeConstructorsNeedTypeDescriptors()) {
return CodeBlock.of(
Expand All @@ -151,12 +169,17 @@ public CodeBlock createSuccess(CodeBlock valueTypeDescriptor, CodeBlock value) {
}
}

public CodeBlock createFailure(CodeBlock typeDescriptor, CodeBlock error) {
/**
* Code to create an instance of the Failure(error: Error) constructor of Wrappers.Result<T, Error>.
* @param valueTypeDescriptor the code to create a TypeDescriptor for the type T,
* which is needed if datatypeConstructorsNeedTypeDescriptors()
*/
public CodeBlock createFailure(CodeBlock valueTypeDescriptor, CodeBlock error) {
if (datatypeConstructorsNeedTypeDescriptors()) {
return CodeBlock.of(
"$T.create_Failure($L, Error._typeDescriptor(), $L)",
Constants.DAFNY_RESULT_CLASS_NAME,
typeDescriptor,
valueTypeDescriptor,
error);
} else {
return CodeBlock.of(
Expand Down
Loading