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

Upgrade Smithy to 1.49 #3662

Merged
merged 4 commits into from
May 24, 2024
Merged

Upgrade Smithy to 1.49 #3662

merged 4 commits into from
May 24, 2024

Conversation

ysaito1001
Copy link
Contributor

@ysaito1001 ysaito1001 commented May 23, 2024

Motivation and Context

Upgrades Smithy to 1.49.0

Description

As part of the upgrade, it updates the serializer for EC2 query protocol to handle empty lists in response to this (otherwise a protocol test ec2_empty_query_lists_request would fail).

Testing

Existing tests in CI


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

Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@ysaito1001 ysaito1001 marked this pull request as ready for review May 23, 2024 23:43
@ysaito1001 ysaito1001 requested review from a team as code owners May 23, 2024 23:43
Copy link
Contributor

@landonxjames landonxjames left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines 285 to 319
private fun RustWriter.serializeCollection(
protected open fun RustWriter.serializeCollection(
memberContext: MemberContext,
context: Context<CollectionShape>,
) {
serializeCollectionInner(memberContext, context, this)
}

protected fun serializeCollectionInner(
memberContext: MemberContext,
context: Context<CollectionShape>,
writer: RustWriter,
) {
val flat = memberContext.shape.isFlattened()
val memberOverride =
when (val override = context.shape.member.getTrait<XmlNameTrait>()?.value) {
null -> "None"
else -> "Some(${override.dq()})"
}
val itemName = safeName("item")
safeName("list").also { listName ->
rust("let mut $listName = ${context.writerExpression}.start_list($flat, $memberOverride);")
rustBlock("for $itemName in ${context.valueExpression.asRef()}") {
val itemName = writer.safeName("item")
writer.safeName("list").also { listName ->
writer.rust("let mut $listName = ${context.writerExpression}.start_list($flat, $memberOverride);")
writer.rustBlock("for $itemName in ${context.valueExpression.asRef()}") {
val entryName = safeName("entry")
Attribute.AllowUnusedMut.render(this)
rust("let mut $entryName = $listName.entry();")
writer.rust("let mut $entryName = $listName.entry();")
val targetShape = model.expectShape(context.shape.member.target)
serializeMemberValue(
writer.serializeMemberValue(
MemberContext(entryName, ValueExpression.Reference(itemName), context.shape.member),
targetShape,
)
}
rust("$listName.finish();")
writer.rust("$listName.finish();")
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks to be doing the same thing. Why update it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is working around Kotlin's limitation that an extension method cannot be overridden. Ec2QuerySerializerGenerator, a subclass of QuerySerializerGenerator, needs to override RustWriter.serializeCollection so that it should only call it if an input list is NOT empty (otherwise &ListArg= would be rendered which ec2 query protocol doesn't like in Smithy 1.49). However, we currently couldn't do this in Kotlin if it were not for serializeCollectionInner:

override fun RustWriter.serializeCollection(
        memberContext: MemberContext,
        context: Context<CollectionShape>,
    ) {
        rustBlock("if !${context.valueExpression.asRef()}.is_empty()") {
            super.serializeCollection(memberContext, context) // cannot call super class's extension method like this
        }

Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@ysaito1001 ysaito1001 enabled auto-merge May 24, 2024 18:07
@ysaito1001 ysaito1001 added this pull request to the merge queue May 24, 2024
Merged via the queue into main with commit d5ea2cd May 24, 2024
44 checks passed
@ysaito1001 ysaito1001 deleted the ysaito/upgrade-smithy-1-49 branch May 24, 2024 18:34
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.

4 participants