-
Notifications
You must be signed in to change notification settings - Fork 8
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: Rust codegen for Constraints #582
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8437692
fix conversions for DafnyUtf8Bytes
alex-chew 316e2de
feat: Rust codegen for Constraints model
alex-chew fef3d37
Merge branch 'main-1.x' into alexchew/rust-codegen-constraints
alex-chew 1fc2cbd
avoid recalculating lengths
alex-chew feb1999
regenerate Rust runtime for Positional test model
alex-chew 6f4eefa
improve validation error representation
alex-chew 9e398f1
regenerate Rust runtime for Positional test model
alex-chew 32ba8f2
use dafny_runtime::Object more safely
alex-chew a6d9d83
regenerate runtime
alex-chew 0cf629a
Committing Constraints Rust code for review purposes
robin-aws 62bb88e
count UTF-16 code points for @length
alex-chew 9acf8c2
Merge branch 'main-1.x' into alexchew/rust-codegen-constraints
alex-chew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ CORES=2 | |
|
||
ENABLE_EXTERN_PROCESSING=1 | ||
|
||
TRANSPILE_TESTS_IN_RUST=1 | ||
|
||
include ../SharedMakefile.mk | ||
|
||
PROJECT_SERVICES := \ | ||
|
@@ -19,13 +21,19 @@ SMITHY_DEPS=dafny-dependencies/Model/traits.smithy | |
# This project has no dependencies | ||
# DEPENDENT-MODELS:= | ||
|
||
# First, export DAFNY_VERSION=4.2 | ||
# Three separate items, because 'make polymorph_code_gen' doesn't quite work | ||
polymorph: | ||
npm i --no-save prettier@3 [email protected] | ||
make polymorph_dafny | ||
make polymorph_java | ||
make polymorph_dotnet | ||
clean: _clean | ||
rm -rf $(LIBRARY_ROOT)/runtimes/java/src/main/dafny-generated | ||
rm -rf $(LIBRARY_ROOT)/runtimes/java/src/main/smithy-generated | ||
rm -rf $(LIBRARY_ROOT)/runtimes/java/src/test/dafny-generated | ||
|
||
# Patch out tests that Rust codegen doesn't support | ||
transpile_rust: | transpile_implementation_rust transpile_dependencies_rust remove_unsupported_rust_tests | ||
|
||
remove_unsupported_rust_tests: | ||
$(MAKE) _sed_file \ | ||
SED_FILE_PATH=$(LIBRARY_ROOT)/runtimes/rust/src/implementation_from_dafny.rs \ | ||
SED_BEFORE_STRING='let mut allowBadUtf8BytesFromDafny: bool = true' \ | ||
SED_AFTER_STRING='let mut allowBadUtf8BytesFromDafny: bool = false' | ||
|
||
# Python | ||
|
||
|
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,25 @@ | ||
[package] | ||
name = "simple_constraints" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[features] | ||
wrapped-client = [] | ||
|
||
[dependencies] | ||
aws-smithy-runtime = {version = "1.7.1", features=["client"]} | ||
aws-smithy-runtime-api = {version = "1.7.2", features=["client"]} | ||
aws-smithy-types = "1.2.4" | ||
dafny_runtime = { path = "../../../dafny-dependencies/dafny_runtime_rust"} | ||
|
||
[dependencies.tokio] | ||
version = "1.26.0" | ||
features = ["full"] | ||
|
||
[dev-dependencies] | ||
simple_constraints = { path = ".", features = ["wrapped-client"] } | ||
|
||
[lib] | ||
path = "src/implementation_from_dafny.rs" |
69 changes: 69 additions & 0 deletions
69
TestModels/Constraints/runtimes/rust/tests/simple_constraints_test.rs
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,69 @@ | ||
extern crate simple_constraints; | ||
|
||
/// Smoke tests for constraint validation when calling in from Rust code. | ||
mod simple_constraints_test { | ||
use simple_constraints::*; | ||
|
||
fn client() -> Client { | ||
let config = SimpleConstraintsConfig::builder().build().expect("config"); | ||
client::Client::from_conf(config).expect("client") | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_empty_input() { | ||
let result = client().get_constraints().send().await; | ||
assert!(result.is_ok()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_short_string() { | ||
let result = client().get_constraints().my_string("").send().await; | ||
let error = result.err().expect("error"); | ||
assert!(matches!( | ||
error, | ||
simple_constraints::types::error::Error::ValidationError(..) | ||
)); | ||
assert!(error.to_string().contains("my_string")); | ||
|
||
use std::error::Error; | ||
let source_message = error.source().expect("source").to_string(); | ||
assert!(source_message.contains("my_string")); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_good_string() { | ||
let result = client().get_constraints().my_string("good").send().await; | ||
assert!(result.is_ok()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_long_string() { | ||
let result = client() | ||
.get_constraints() | ||
.my_string("too many characters") | ||
.send() | ||
.await; | ||
let message = result.err().expect("error").to_string(); | ||
assert!(message.contains("my_string")); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_small_int() { | ||
let result = client().get_constraints().one_to_ten(0).send().await; | ||
let message = result.err().expect("error").to_string(); | ||
assert!(message.contains("one_to_ten")); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_good_int() { | ||
let result = client().get_constraints().one_to_ten(5).send().await; | ||
assert!(result.is_ok()); | ||
} | ||
|
||
#[tokio::test] | ||
async fn test_big_int() { | ||
let result = client().get_constraints().one_to_ten(99).send().await; | ||
let message = result.err().expect("error").to_string(); | ||
assert!(message.contains("one_to_ten")); | ||
} | ||
} |
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like going through a aws_smithy_types::error is adding complexity without adding value.
Couldn't we just make a wrap_validation_err out of a String and leave it as that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's valuable: it makes it possible to programmatically handle validation errors, and I can see that being useful for middleware that handles translation of Smithy-modeled types, for example.
As long as displaying these errors gives a good user experience I say we keep them.