-
Notifications
You must be signed in to change notification settings - Fork 196
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
Extract builderInstantiator interface to prepare for nullability changes #2988
Conversation
432642d
to
9a6bd21
Compare
A new generated diff is ready to view.
A new doc preview is ready to view. |
9a6bd21
to
a81109b
Compare
audited codegen, no diff |
no changelog, internal only change |
a81109b
to
eacf466
Compare
A new generated diff is ready to view.
A new doc preview is ready to view. |
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.
The only blocking comment is the one in JsonParserGenerator.kt
, which should be artifact agnostic, but is currently passing in a value to map_err
that only applies to client generation.
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate | ||
import software.amazon.smithy.rust.codegen.core.rustlang.writable | ||
|
||
/** Abstraction for instantiating a builders. |
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.
/** Abstraction for instantiating a builders. | |
/** | |
* Abstraction for instantiating builders. |
@@ -339,6 +340,7 @@ class EventStreamUnmarshallerGenerator( | |||
// TODO(EventStream): Errors on the operation can be disjoint with errors in the union, | |||
// so we need to generate a new top-level Error type for each event stream union. | |||
when (codegenTarget) { | |||
// TODO(https://github.com/awslabs/smithy-rs/issues/1970) It should be possible to unify these branches now |
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.
Why should it be possible?
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.
because we have the builderInstantiator, I think. But it's possible this is more divergence that can't be handled like that.
@@ -352,9 +354,19 @@ class EventStreamUnmarshallerGenerator( | |||
})?; | |||
builder.set_meta(Some(generic)); |
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.
Aside: not sure why we bind the error metadata to a variable named generic
.
/** Set a field on a builder. */ | ||
fun setField(builder: String, value: Writable, field: MemberShape): Writable | ||
|
||
/** Finalize a builder, turning into a built object (or in the case of builders-of-builders, return the builder directly).*/ |
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.
/** Finalize a builder, turning into a built object (or in the case of builders-of-builders, return the builder directly).*/ | |
/** Finalize a builder, turning it into a built object (or in the case of builders-of-builders, return the builder directly).*/ |
fun setField(builder: String, value: Writable, field: MemberShape): Writable | ||
|
||
/** Finalize a builder, turning into a built object (or in the case of builders-of-builders, return the builder directly).*/ | ||
fun finalizeBuilder(builder: String, shape: StructureShape, mapErr: Writable? = null): Writable |
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.
Worth documenting mapErr
.
"builder", shape, | ||
) { | ||
rustTemplate( | ||
"""|err|#{Error}::custom_source("Response was invalid", err)""", *codegenScope, |
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.
This doesn't look correct to me. This only applies to clients, not servers. It only works because ServerBuilderInstantiator
does not rely on the passed in mapErr
writable.
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.
mapErr defines how to convert the error back into the caller error—since the server never returns an error, it doesn't need to use it.
@@ -0,0 +1,6 @@ | |||
/* |
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 don't understand what this file's purpose is.
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.
whoops, thanks. My intellij git broken good catch
) : | ||
BuilderInstantiator { |
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.
) : | |
BuilderInstantiator { | |
) : BuilderInstantiator { |
The current formatting looks odd.
fun finalizeBuilder(builder: String, shape: StructureShape, mapErr: Writable? = null): Writable | ||
|
||
/** Set a field on a builder using the `$setterName` method. $value will be passed directly. */ | ||
fun setFieldBase(builder: String, value: Writable, field: MemberShape) = writable { |
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.
nit:
fun setFieldBase(builder: String, value: Writable, field: MemberShape) = writable { | |
fun setFieldWithSetter(builder: String, value: Writable, field: MemberShape) = writable { |
Base denotes we're doing inheritance. Which we kind of are doing manually in the implementations of this interface.
A new generated diff is ready to view.
A new doc preview is ready to view. |
Motivation and Context
#1725 exposed the need for easily configuring builder behavior between client & server
Description
codegenContext
to avoid loads of threading it up and downTesting
Checklist
CHANGELOG.next.toml
if I made changes to the smithy-rs codegen or runtime cratesCHANGELOG.next.toml
if I made changes to the AWS SDK, generated SDK code, or SDK runtime cratesBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.