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 Positional Trait in Go codegen #7

Open
wants to merge 49 commits into
base: scchatur/GoCodegen
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
8662494
Add runtime (remove later)
rishav-karanjit Jul 31, 2024
2e05f73
Comment all test model for faster workflow run
rishav-karanjit Jul 31, 2024
ea8fd4a
Add runtime
rishav-karanjit Aug 1, 2024
eb466e3
Changes for the positional trait
rishav-karanjit Aug 5, 2024
fc3244a
Changes for positional trait
rishav-karanjit Aug 5, 2024
3a7264f
Remove redundant code
rishav-karanjit Aug 5, 2024
df3e00c
Add everything
rishav-karanjit Aug 7, 2024
2df4fd0
Revert the unwanted changes
rishav-karanjit Aug 7, 2024
662bb74
Changes for shim
rishav-karanjit Aug 7, 2024
9d3ea35
Update API client return type for interface
rishav-karanjit Aug 9, 2024
68f868f
maybe output to output
rishav-karanjit Aug 9, 2024
f5b9b36
get dafny type from DafnyNameResolver
rishav-karanjit Aug 9, 2024
fd66e38
remove print statement
rishav-karanjit Aug 10, 2024
fa80eb9
api client part where we return values
rishav-karanjit Aug 10, 2024
29f4a01
Uncomment so that CI runs
rishav-karanjit Aug 10, 2024
c6b27c1
Remove runtimes
rishav-karanjit Aug 10, 2024
e0e36d3
Add go.mod
rishav-karanjit Aug 10, 2024
4870e61
remove dafny codegen files
rishav-karanjit Aug 10, 2024
c4c346f
Update go mod
rishav-karanjit Aug 11, 2024
80eea0e
Fix symbolForPositional
rishav-karanjit Aug 11, 2024
fc2464a
Update to DafnyNameResolver
rishav-karanjit Aug 11, 2024
8338b42
Update getSmithyType
rishav-karanjit Aug 11, 2024
918c42e
Replace with isOptional
rishav-karanjit Aug 11, 2024
2f7f0cb
Replaced isOptional with isPointable
rishav-karanjit Aug 12, 2024
dec64c7
Update DafnyNameResolver
rishav-karanjit Aug 13, 2024
ffa8896
Update DafnyNameResolver
rishav-karanjit Aug 13, 2024
470f915
Copy GoPointableIndex from rishav-union
rishav-karanjit Aug 13, 2024
5e0dc6e
Merge with scchatur/GoCodegen
rishav-karanjit Aug 13, 2024
817d7a9
Put check for PositionalTrait outside outputshape check
rishav-karanjit Aug 22, 2024
eb8b0c0
Remove comments
rishav-karanjit Aug 22, 2024
e5c9ffd
Merge from scchatur/GoCodegen
rishav-karanjit Aug 29, 2024
d48e10f
Merge fix
rishav-karanjit Sep 2, 2024
bdd77e3
Merge branch 'scchatur/GoCodegen' into rishav-positional
rishav-karanjit Sep 2, 2024
8fde5f4
feat: Rust codegen for more SimpleTypes models (#542)
alex-chew Sep 2, 2024
dfca8d9
fix: bump Rust version to 1.80 (#553)
ajewellamz Sep 3, 2024
0a707a2
Remove unwanted whitespace
rishav-karanjit Sep 3, 2024
17425b1
chore(ci): make all pull.yml jobs required in branch protection autom…
robin-aws Sep 3, 2024
3c0a1ce
chore: add Dafny 4.8.0 (#522)
josecorella Sep 4, 2024
4a80456
fix: CI
ShubhamChaturvedi7 Sep 4, 2024
2c3f760
Merge branch 'main-1.x' into Golang/dev
ShubhamChaturvedi7 Sep 4, 2024
2cf84b3
fix: use gradle for CI
ShubhamChaturvedi7 Sep 4, 2024
f1504b5
fix: Add CI Tests
ShubhamChaturvedi7 Sep 4, 2024
61cc564
fix: Drop the removeDots script
ShubhamChaturvedi7 Sep 4, 2024
ac8a6a4
fix: prettify
ShubhamChaturvedi7 Sep 4, 2024
61d7284
Merge branch 'Golang/dev' into rishav-positional
rishav-karanjit Sep 5, 2024
ca4d375
Revert "Merge branch 'Golang/dev' into rishav-positional"
rishav-karanjit Sep 9, 2024
2072d44
Revert "Revert "Merge branch 'Golang/dev' into rishav-positional""
rishav-karanjit Sep 9, 2024
32f4f29
Merge fix structure generator
rishav-karanjit Sep 9, 2024
14ccc65
Format
rishav-karanjit Sep 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .github/workflows/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ jobs:
uses: ./.github/workflows/test_models_python_tests.yml
with:
dafny: ${{ inputs.dafny }}
manual-ci-go:
uses: ./.github/workflows/test_models_go_tests.yml
with:
dafny: ${{ inputs.dafny }}
1 change: 1 addition & 0 deletions .github/workflows/nightly_dafny.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
dafny-nightly-java,
dafny-nightly-net,
dafny-nightly-rust,
dafny-nightly-python,
]
if: ${{ always() && contains(needs.*.result, 'failure') }}
env:
Expand Down
29 changes: 27 additions & 2 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
steps:
- name: Populate Dafny versions list
id: populate-dafny-versions-list
run: echo "dafny-versions-list=['4.2.0', '4.4.0']" >> $GITHUB_OUTPUT
run: echo "dafny-versions-list=['4.2.0', '4.4.0', '4.8.0']" >> $GITHUB_OUTPUT
- name: Populate Dafny versions list for "only new versions" languages (Python)
id: populate-only-new-dafny-versions-list
run: echo "only-new-dafny-versions-list=['4.7.0']" >> $GITHUB_OUTPUT
run: echo "only-new-dafny-versions-list=['4.8.0']" >> $GITHUB_OUTPUT
outputs:
dafny-version-list: ${{ steps.populate-dafny-versions-list.outputs.dafny-versions-list }}
only-new-dafny-version-list: ${{ steps.populate-only-new-dafny-versions-list.outputs.only-new-dafny-versions-list }}
Expand Down Expand Up @@ -66,3 +66,28 @@ jobs:
uses: ./.github/workflows/test_models_python_tests.yml
with:
dafny: ${{ matrix.dafny-version }}
pr-ci-go:
needs: pr-populate-dafny-versions
strategy:
fail-fast: false
matrix:
dafny-version: ${{ fromJson(needs.pr-populate-dafny-versions.outputs.only-new-dafny-version-list) }}
uses: ./.github/workflows/test_models_go_tests.yml
with:
dafny: ${{ matrix.dafny-version }}

pr-ci-all-required:
if: always()
needs:
- pr-ci-verification
- pr-ci-java
- pr-ci-net
- pr-ci-rust
- pr-ci-python
- pr-ci-go
runs-on: ubuntu-latest
steps:
- name: Verify all required jobs passed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
13 changes: 11 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
steps:
- name: Populate Dafny versions list
id: populate-dafny-versions-list
run: echo "dafny-versions-list=['4.2.0', '4.4.0']" >> $GITHUB_OUTPUT
run: echo "dafny-versions-list=['4.2.0', '4.4.0', '4.8.0']" >> $GITHUB_OUTPUT
- name: Populate Dafny versions list for "only new versions" languages (Python)
id: populate-only-new-dafny-versions-list
run: echo "only-new-dafny-versions-list=['4.7.0']" >> $GITHUB_OUTPUT
run: echo "only-new-dafny-versions-list=['4.8.0']" >> $GITHUB_OUTPUT
outputs:
dafny-version-list: ${{ steps.populate-dafny-versions-list.outputs.dafny-versions-list }}
only-new-dafny-version-list: ${{ steps.populate-only-new-dafny-versions-list.outputs.only-new-dafny-versions-list }}
Expand Down Expand Up @@ -68,3 +68,12 @@ jobs:
uses: ./.github/workflows/test_models_python_tests.yml
with:
dafny: ${{ matrix.dafny-version }}
push-ci-go:
needs: pr-populate-dafny-versions
strategy:
fail-fast: false
matrix:
dafny-version: ${{ fromJson(needs.pr-populate-dafny-versions.outputs.only-new-dafny-version-list) }}
uses: ./.github/workflows/test_models_go_tests.yml
with:
dafny: ${{ matrix.dafny-version }}
160 changes: 74 additions & 86 deletions .github/workflows/test_models_go_tests.yml
Original file line number Diff line number Diff line change
@@ -1,79 +1,64 @@
name: Library Go tests

on: ["pull_request", "push"]
on:
workflow_call:
inputs:
dafny:
description: "The Dafny version to run"
required: true
type: string
num_shards:
required: false
type: number
default: 5

jobs:
test_go:
populate-matrix-dimensions:
runs-on: ubuntu-latest
steps:
- name: Populate shard list
id: populate-shard-list
run: echo "shard-list=[`seq -s , 1 ${{ inputs.num_shards }}`]" >> $GITHUB_OUTPUT
outputs:
shard-list: ${{ steps.populate-shard-list.outputs.shard-list }}
testGo:
needs: populate-matrix-dimensions
strategy:
fail-fast: false
fail-fast: false # at least for development; see all errors
matrix:
library: [
# TestModels/dafny-dependencies/StandardLibrary, # This stores current Polymorph dependencies that all TestModels depend on
TestModels/Aggregate,
# TestModels/AggregateReferences,
TestModels/CodegenPatches,
TestModels/Constraints,
TestModels/Constructor,
TestModels/Dependencies,
TestModels/Errors,
TestModels/Extendable,
TestModels/Extern,
# TestModels/LanguageSpecificLogic,
# TestModels/LocalService,
# TestModels/MultipleModels,
TestModels/Refinement,
TestModels/Resource,
# TestModels/SimpleTypes/BigDecimal,
# TestModels/SimpleTypes/BigInteger,
TestModels/SimpleTypes/SimpleBlob,
TestModels/SimpleTypes/SimpleBoolean,
# TestModels/SimpleTypes/SimpleByte,
TestModels/SimpleTypes/SimpleDouble,
TestModels/SimpleTypes/SimpleEnum,
# TestModels/SimpleTypes/SimpleEnumV2,
# TestModels/SimpleTypes/SimpleFloat,
TestModels/SimpleTypes/SimpleInteger,
TestModels/SimpleTypes/SimpleLong,
# TestModels/SimpleTypes/SimpleShort,
TestModels/SimpleTypes/SimpleString,
# TestModels/SimpleTypes/SimpleTimestamp,
TestModels/Union,
# TestModels/aws-sdks/ddb,
TestModels/aws-sdks/kms
]
runs-on: "macos-12"
shard: ${{ fromJson(needs.populate-matrix-dimensions.outputs.shard-list) }}
runs-on: "ubuntu-latest"
permissions:
id-token: write
contents: read
env:
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_NOLOGO: 1
steps:
- uses: actions/checkout@v2
- name: Support longpaths on Git checkout
run: |
git config --global core.longpaths true

# - name: Setup Dafny 4.5.0
# uses: dafny-lang/setup-dafny-action@v1.7.0
# with:
# dafny-version: 4.5.0
# TODO: Setup Dafny once its released
- name: Setup dotnet
uses: actions/setup-dotnet@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
dotnet-version: 6.0.x
aws-region: us-west-2
role-to-assume: arn:aws:iam::370957321024:role/GitHub-CI-PolymorphTestModels-Role-us-west-2
role-session-name: PythonTests

- name: Build Dafny from source
run: |
git clone https://github.com/dafny-lang/dafny.git --recurse-submodules
cd dafny
make exe

- name: Install Z3 version 4.12.1
run: |
cd $GITHUB_WORKSPACE/dafny
make z3-mac
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Add Dafny to PATH
run: |
echo "$GITHUB_WORKSPACE/dafny/Scripts" >> $GITHUB_PATH
- name: Setup Dafny
uses: dafny-lang/setup-dafny-action@v1.7.0
with:
dafny-version: ${{ inputs.dafny }}

- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '1.21'
go-version: "1.21"

- name: Install Go imports
run: |
Expand All @@ -82,33 +67,36 @@ jobs:
- name: Add go mod to Dafny Runtime Go
shell: bash
working-directory: ./DafnyRuntimeGo
run: |
run: |
go mod init github.com/dafny-lang/DafnyRuntimeGo
go mod tidy

- name: polymorph dafny dependencies
shell: bash
working-directory: ./TestModels/dafny-dependencies/StandardLibrary
run: |
export DAFNY_VERSION=4.6
make polymorph_dafny
make transpile_go
make polymorph_go
cd ./runtimes/go/ImplementationFromDafny-go/
go mod init github.com/dafny-lang/DafnyStandardLibGo
# TODO: This should handwritten (in the makefile or something)
echo "replace github.com/dafny-lang/DafnyRuntimeGo => ../../../../../DafnyRuntimeGo/" >> go.mod;
- name: Setup Java 17 for codegen
uses: actions/setup-java@v3
with:
distribution: "corretto"
java-version: 17

- name: Generate Polymorph Dafny and Go code
shell: bash
working-directory: ./${{ matrix.library }}
run: |
export DAFNY_VERSION=4.6
make polymorph_dafny
sh ./removeDotFromExtern.sh
make transpile_go
make polymorph_go
- name: Setup smithy-dafny-conversion
uses: gradle/gradle-build-action@v2
with:
arguments: publishToMavenLocal
build-root-directory: smithy-dafny-conversion

goimports -w runtimes/go/
cd runtimes/go/TestsFromDafny-go/
go run TestsFromDafny.go
- name: Install Smithy-Dafny codegen dependencies
uses: ./.github/actions/install_smithy_dafny_codegen_dependencies

- name: Install smithy-dafny-codegen locally
uses: gradle/gradle-build-action@v2
with:
arguments: :smithy-dafny-codegen:pTML
build-root-directory: codegen

- name: Execute smithy-dafny-codegen-test tests
uses: gradle/gradle-build-action@v2
env:
JUNIT_SHARD: ${{ matrix.shard }}
JUNIT_SHARD_COUNT: ${{ inputs.num_shards }}
with:
arguments: :smithy-dafny-codegen-test:test --tests '*smithygo*' --info
build-root-directory: codegen
2 changes: 1 addition & 1 deletion .github/workflows/test_models_rust_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: "1.76.0"
toolchain: "1.80.0"
rustflags: ""
components: rustfmt

Expand Down
12 changes: 5 additions & 7 deletions SmithyDafnyMakefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ _polymorph_dafny: OUTPUT_DAFNY=\
--output-dafny $(if $(DIR_STRUCTURE_V2), $(LIBRARY_ROOT)/dafny/$(SERVICE)/Model, $(LIBRARY_ROOT)/Model)
_polymorph_dafny: INPUT_DAFNY=\
--include-dafny $(PROJECT_ROOT)/$(STD_LIBRARY)/src/Index.dfy
_polymorph_dafny: _polymorph removeDots
_polymorph_dafny: _polymorph

# Generates dotnet code for all namespaces in this project
.PHONY: polymorph_dotnet
Expand Down Expand Up @@ -767,6 +767,10 @@ clean_go:
rm -rf $(LIBRARY_ROOT)/runtimes/go/ImplementationFromDafny-go
rm -rf $(LIBRARY_ROOT)/runtimes/go/TestsFromDafny-go

test_go:
cd runtimes/go/TestFromDafny-go
go run TestsFromDafny.go

########################## Python targets

# Python MUST transpile dependencies first to generate .dtr files
Expand Down Expand Up @@ -862,9 +866,3 @@ local_transpile_test_single: TRANSPILE_DEPENDENCIES= \
$(patsubst %, -library:$(PROJECT_ROOT)/%, $(PROJECT_INDEX)) \
-library:$(PROJECT_ROOT)/$(STD_LIBRARY)/src/Index.dfy
local_transpile_test_single: transpile_test

removeDots:
chmod +x ./removeDotFromExtern.sh
./removeDotFromExtern.sh

transpile_implementation_go: removeDots
80 changes: 80 additions & 0 deletions TestModels/Aggregate/runtimes/rust/src/standard_library_externs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Annotation to ignore the case of this module
use crate::r#_Wrappers_Compile;
use crate::UTF8;

impl crate::UTF8::_default {
pub fn Encode(
s: &::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
) -> ::std::rc::Rc<
r#_Wrappers_Compile::Result<
UTF8::ValidUTF8Bytes,
::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
>,
> {
let v = s.to_array();
let mut _accumulator: Vec<u8> = vec![];
// Use of .encode_utf8 method.
let mut surrogate: Option<u16> = None;
for c in v.iter() {
let s = if let Some(s) = surrogate {
String::from_utf16(&[s, c.0])
} else {
String::from_utf16(&[c.0])
};
surrogate = None;
match s {
Ok(value) => {
_accumulator.extend(value.as_bytes());
continue;
}
Err(e) => {
if 0xD800 <= c.0 && c.0 <= 0xDFFF {
surrogate = Some(c.0);
continue;
}
return ::std::rc::Rc::new(r#_Wrappers_Compile::Result::<UTF8::ValidUTF8Bytes, ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>>::Failure {
error: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(
&e.to_string())
});
}
}
}
if let Some(s) = surrogate {
return ::std::rc::Rc::new(r#_Wrappers_Compile::Result::<UTF8::ValidUTF8Bytes, ::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>>::Failure {
error: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(
&format!("Surrogate pair missing: 0x{:04x}", s))
});
}
::std::rc::Rc::new(r#_Wrappers_Compile::Result::<
UTF8::ValidUTF8Bytes,
::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
>::Success {
value: ::dafny_runtime::Sequence::from_array_owned(_accumulator),
})
}
pub fn Decode(
b: &::dafny_runtime::Sequence<u8>,
) -> ::std::rc::Rc<
r#_Wrappers_Compile::Result<
::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
>,
> {
let b = String::from_utf8(b.to_array().as_ref().clone());
match b {
Ok(s) => {
::std::rc::Rc::new(r#_Wrappers_Compile::Result::<::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>>::Success {
value: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(&s)
})
},
Err(e) => {
return ::std::rc::Rc::new(r#_Wrappers_Compile::Result::<::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>,
::dafny_runtime::Sequence<::dafny_runtime::DafnyCharUTF16>>::Failure {
error: ::dafny_runtime::dafny_runtime_conversions::unicode_chars_false::string_to_dafny_string(
&e.to_string())
})
}
}
}
}
Loading
Loading