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

Extract builderInstantiator interface to prepare for nullability changes #2988

Merged
merged 2 commits into from
Sep 19, 2023

Conversation

rcoh
Copy link
Collaborator

@rcoh rcoh commented Sep 15, 2023

Motivation and Context

#1725 exposed the need for easily configuring builder behavior between client & server

Description

  • extract builderGenerator interface and attach it to codegenContext to avoid loads of threading it up and down

Testing

  • codegen unit tests
  • codegen diff audit

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions
Copy link

A new generated diff is ready to view.

  • No codegen difference in the AWS SDK
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • Server Test Python (ignoring whitespace)
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

@rcoh
Copy link
Collaborator Author

rcoh commented Sep 18, 2023

audited codegen, no diff

@rcoh
Copy link
Collaborator Author

rcoh commented Sep 18, 2023

no changelog, internal only change

@github-actions
Copy link

A new generated diff is ready to view.

  • No codegen difference in the AWS SDK
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

Copy link
Contributor

@david-perez david-perez left a 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** 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
Copy link
Contributor

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?

Copy link
Collaborator Author

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));
Copy link
Contributor

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).*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** 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
Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Collaborator Author

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 @@
/*
Copy link
Contributor

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.

Copy link
Collaborator Author

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

Comment on lines 98 to 99
) :
BuilderInstantiator {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
) :
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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
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.

@rcoh rcoh enabled auto-merge September 19, 2023 13:56
@rcoh rcoh added this pull request to the merge queue Sep 19, 2023
@github-actions
Copy link

A new generated diff is ready to view.

  • No codegen difference in the AWS SDK
  • No codegen difference in the Client Test
  • No codegen difference in the Server Test
  • No codegen difference in the Server Test Python
  • No codegen difference in the Server Test Typescript

A new doc preview is ready to view.

Merged via the queue into main with commit 5239e9c Sep 19, 2023
41 checks passed
@rcoh rcoh deleted the builder-instantiator branch September 19, 2023 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants