diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenVisitor.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenVisitor.kt index 281161eef4..889674babc 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenVisitor.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenVisitor.kt @@ -31,7 +31,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.implBlock import software.amazon.smithy.rust.codegen.core.smithy.DirectedWalker import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator @@ -67,7 +67,7 @@ class ClientCodegenVisitor( private val protocolGenerator: ClientProtocolGenerator init { - val symbolVisitorConfig = SymbolVisitorConfig( + val rustSymbolProviderConfig = RustSymbolProviderConfig( runtimeConfig = settings.runtimeConfig, renameExceptions = settings.codegenConfig.renameExceptions, nullabilityCheckMode = NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1, @@ -82,7 +82,7 @@ class ClientCodegenVisitor( model = codegenDecorator.transformModel(untransformedService, baseModel) // the model transformer _might_ change the service shape val service = settings.getService(model) - symbolProvider = RustClientCodegenPlugin.baseSymbolProvider(model, service, symbolVisitorConfig) + symbolProvider = RustClientCodegenPlugin.baseSymbolProvider(model, service, rustSymbolProviderConfig) codegenContext = ClientCodegenContext(model, symbolProvider, service, protocol, settings, codegenDecorator) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt index cda2005a52..d50f1d421a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustClientCodegenPlugin.kt @@ -23,10 +23,10 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolP import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.EventStreamSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeMetadataProvider import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig import java.util.logging.Level import java.util.logging.Logger @@ -74,10 +74,10 @@ class RustClientCodegenPlugin : ClientDecoratableBuildPlugin() { * The Symbol provider is composed of a base [SymbolVisitor] which handles the core functionality, then is layered * with other symbol providers, documented inline, to handle the full scope of Smithy types. */ - fun baseSymbolProvider(model: Model, serviceShape: ServiceShape, symbolVisitorConfig: SymbolVisitorConfig) = - SymbolVisitor(model, serviceShape = serviceShape, config = symbolVisitorConfig) + fun baseSymbolProvider(model: Model, serviceShape: ServiceShape, rustSymbolProviderConfig: RustSymbolProviderConfig) = + SymbolVisitor(model, serviceShape = serviceShape, config = rustSymbolProviderConfig) // Generate different types for EventStream shapes (e.g. transcribe streaming) - .let { EventStreamSymbolProvider(symbolVisitorConfig.runtimeConfig, it, model, CodegenTarget.CLIENT) } + .let { EventStreamSymbolProvider(rustSymbolProviderConfig.runtimeConfig, it, model, CodegenTarget.CLIENT) } // Generate `ByteStream` instead of `Blob` for streaming binary shapes (e.g. S3 GetObject) .let { StreamingShapeSymbolProvider(it, model) } // Add Rust attributes (like `#[derive(PartialEq)]`) to generated shapes diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt index d82e7b93c4..ce0034841c 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt @@ -19,7 +19,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.core.testutil.testRustSettings @@ -49,7 +49,7 @@ fun clientTestRustSettings( customizationConfig, ) -val ClientTestSymbolVisitorConfig = SymbolVisitorConfig( +val ClientTestRustSymbolProviderConfig = RustSymbolProviderConfig( runtimeConfig = TestRuntimeConfig, renameExceptions = true, nullabilityCheckMode = NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1, @@ -60,7 +60,7 @@ fun testSymbolProvider(model: Model, serviceShape: ServiceShape? = null): RustSy RustClientCodegenPlugin.baseSymbolProvider( model, serviceShape ?: ServiceShape.builder().version("test").id("test#Service").build(), - ClientTestSymbolVisitorConfig, + ClientTestRustSymbolProviderConfig, ) fun testCodegenContext( diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt index c7dd8efc70..d26cee721f 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt @@ -10,7 +10,7 @@ import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.testutil.ClientTestSymbolVisitorConfig +import software.amazon.smithy.rust.codegen.client.testutil.ClientTestRustSymbolProviderConfig import software.amazon.smithy.rust.codegen.core.rustlang.RustType import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.EventStreamSymbolProvider @@ -46,7 +46,7 @@ class EventStreamSymbolProviderTest { ) val service = model.expectShape(ShapeId.from("test#TestService")) as ServiceShape - val provider = EventStreamSymbolProvider(TestRuntimeConfig, SymbolVisitor(model, service, ClientTestSymbolVisitorConfig), model, CodegenTarget.CLIENT) + val provider = EventStreamSymbolProvider(TestRuntimeConfig, SymbolVisitor(model, service, ClientTestRustSymbolProviderConfig), model, CodegenTarget.CLIENT) // Look up the synthetic input/output rather than the original input/output val inputStream = model.expectShape(ShapeId.from("test.synthetic#TestOperationInput\$inputStream")) as MemberShape @@ -82,7 +82,7 @@ class EventStreamSymbolProviderTest { ) val service = model.expectShape(ShapeId.from("test#TestService")) as ServiceShape - val provider = EventStreamSymbolProvider(TestRuntimeConfig, SymbolVisitor(model, service, ClientTestSymbolVisitorConfig), model, CodegenTarget.CLIENT) + val provider = EventStreamSymbolProvider(TestRuntimeConfig, SymbolVisitor(model, service, ClientTestRustSymbolProviderConfig), model, CodegenTarget.CLIENT) // Look up the synthetic input/output rather than the original input/output val inputStream = model.expectShape(ShapeId.from("test.synthetic#TestOperationInput\$inputStream")) as MemberShape diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RustSymbolProvider.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RustSymbolProvider.kt new file mode 100644 index 0000000000..7b8b115d76 --- /dev/null +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RustSymbolProvider.kt @@ -0,0 +1,73 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.core.smithy + +import software.amazon.smithy.codegen.core.Symbol +import software.amazon.smithy.codegen.core.SymbolProvider +import software.amazon.smithy.model.knowledge.NullableIndex +import software.amazon.smithy.model.shapes.MemberShape +import software.amazon.smithy.model.shapes.OperationShape +import software.amazon.smithy.model.shapes.Shape +import software.amazon.smithy.model.shapes.UnionShape +import software.amazon.smithy.model.traits.EnumDefinition +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule + +/** + * SymbolProvider interface that carries both the inner configuration and a function to produce an enum variant name. + */ +interface RustSymbolProvider : SymbolProvider, ModuleProvider { + fun config(): RustSymbolProviderConfig + fun toEnumVariantName(definition: EnumDefinition): MaybeRenamed? + + override fun moduleForShape(shape: Shape): RustModule.LeafModule = config().moduleProvider.moduleForShape(shape) + override fun moduleForOperationError(operation: OperationShape): RustModule.LeafModule = + config().moduleProvider.moduleForOperationError(operation) + override fun moduleForEventStreamError(eventStream: UnionShape): RustModule.LeafModule = + config().moduleProvider.moduleForEventStreamError(eventStream) + + /** Returns the symbol for an operation error */ + fun symbolForOperationError(operation: OperationShape): Symbol + + /** Returns the symbol for an event stream error */ + fun symbolForEventStreamError(eventStream: UnionShape): Symbol +} + +/** + * Provider for RustModules so that the symbol provider knows where to organize things. + */ +interface ModuleProvider { + /** Returns the module for a shape */ + fun moduleForShape(shape: Shape): RustModule.LeafModule + + /** Returns the module for an operation error */ + fun moduleForOperationError(operation: OperationShape): RustModule.LeafModule + + /** Returns the module for an event stream error */ + fun moduleForEventStreamError(eventStream: UnionShape): RustModule.LeafModule +} + +/** + * Configuration for symbol providers. + */ +data class RustSymbolProviderConfig( + val runtimeConfig: RuntimeConfig, + val renameExceptions: Boolean, + val nullabilityCheckMode: NullableIndex.CheckMode, + val moduleProvider: ModuleProvider, +) + +/** + * Default delegator to enable easily decorating another symbol provider. + */ +open class WrappingSymbolProvider(private val base: RustSymbolProvider) : RustSymbolProvider { + override fun config(): RustSymbolProviderConfig = base.config() + override fun toEnumVariantName(definition: EnumDefinition): MaybeRenamed? = base.toEnumVariantName(definition) + override fun toSymbol(shape: Shape): Symbol = base.toSymbol(shape) + override fun toMemberName(shape: MemberShape): String = base.toMemberName(shape) + override fun symbolForOperationError(operation: OperationShape): Symbol = base.symbolForOperationError(operation) + override fun symbolForEventStreamError(eventStream: UnionShape): Symbol = + base.symbolForEventStreamError(eventStream) +} diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolMetadataProvider.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolMetadataProvider.kt index a1faf8702c..276e7017ce 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolMetadataProvider.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolMetadataProvider.kt @@ -14,12 +14,10 @@ import software.amazon.smithy.model.shapes.ListShape import software.amazon.smithy.model.shapes.MapShape import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.NumberShape -import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape -import software.amazon.smithy.model.traits.EnumDefinition import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.SensitiveTrait import software.amazon.smithy.model.traits.StreamingTrait @@ -28,19 +26,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata import software.amazon.smithy.rust.codegen.core.rustlang.Visibility import software.amazon.smithy.rust.codegen.core.util.hasTrait -/** - * Default delegator to enable easily decorating another symbol provider. - */ -open class WrappingSymbolProvider(private val base: RustSymbolProvider) : RustSymbolProvider { - override fun config(): SymbolVisitorConfig = base.config() - override fun toEnumVariantName(definition: EnumDefinition): MaybeRenamed? = base.toEnumVariantName(definition) - override fun toSymbol(shape: Shape): Symbol = base.toSymbol(shape) - override fun toMemberName(shape: MemberShape): String = base.toMemberName(shape) - override fun symbolForOperationError(operation: OperationShape): Symbol = base.symbolForOperationError(operation) - override fun symbolForEventStreamError(eventStream: UnionShape): Symbol = - base.symbolForEventStreamError(eventStream) -} - /** * Attach `meta` to symbols. `meta` is used by the generators (e.g. StructureGenerator) to configure the generated models. * diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt index 46b4e84ca3..1261689a63 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt @@ -64,27 +64,6 @@ val SimpleShapes: Map, RustType> = mapOf( StringShape::class to RustType.String, ) -/** - * Provider for RustModules so that the symbol provider knows where to organize things. - */ -interface ModuleProvider { - /** Returns the module for a shape */ - fun moduleForShape(shape: Shape): RustModule.LeafModule - - /** Returns the module for an operation error */ - fun moduleForOperationError(operation: OperationShape): RustModule.LeafModule - - /** Returns the module for an event stream error */ - fun moduleForEventStreamError(eventStream: UnionShape): RustModule.LeafModule -} - -data class SymbolVisitorConfig( - val runtimeConfig: RuntimeConfig, - val renameExceptions: Boolean, - val nullabilityCheckMode: CheckMode, - val moduleProvider: ModuleProvider, -) - /** * Track both the past and current name of a symbol * @@ -96,26 +75,6 @@ data class SymbolVisitorConfig( */ data class MaybeRenamed(val name: String, val renamedFrom: String?) -/** - * SymbolProvider interface that carries both the inner configuration and a function to produce an enum variant name. - */ -interface RustSymbolProvider : SymbolProvider, ModuleProvider { - fun config(): SymbolVisitorConfig - fun toEnumVariantName(definition: EnumDefinition): MaybeRenamed? - - override fun moduleForShape(shape: Shape): RustModule.LeafModule = config().moduleProvider.moduleForShape(shape) - override fun moduleForOperationError(operation: OperationShape): RustModule.LeafModule = - config().moduleProvider.moduleForOperationError(operation) - override fun moduleForEventStreamError(eventStream: UnionShape): RustModule.LeafModule = - config().moduleProvider.moduleForEventStreamError(eventStream) - - /** Returns the symbol for an operation error */ - fun symbolForOperationError(operation: OperationShape): Symbol - - /** Returns the symbol for an event stream error */ - fun symbolForEventStreamError(eventStream: UnionShape): Symbol -} - /** * Make the return [value] optional if the [member] symbol is as well optional. */ @@ -148,11 +107,11 @@ fun Shape.contextName(serviceShape: ServiceShape?): String { open class SymbolVisitor( private val model: Model, private val serviceShape: ServiceShape?, - private val config: SymbolVisitorConfig, + private val config: RustSymbolProviderConfig, ) : RustSymbolProvider, ShapeVisitor { private val nullableIndex = NullableIndex.of(model) - override fun config(): SymbolVisitorConfig = config + override fun config(): RustSymbolProviderConfig = config override fun toSymbol(shape: Shape): Symbol { return shape.accept(this) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt index 2e80865640..023f30236e 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt @@ -28,8 +28,8 @@ import software.amazon.smithy.rust.codegen.core.smithy.ModuleProvider import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait @@ -74,7 +74,7 @@ private object CodegenCoreTestModules { } } -val TestSymbolVisitorConfig = SymbolVisitorConfig( +val TestRustSymbolProviderConfig = RustSymbolProviderConfig( runtimeConfig = TestRuntimeConfig, renameExceptions = true, nullabilityCheckMode = NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1, @@ -116,7 +116,7 @@ fun String.asSmithyModel(sourceLocation: String? = null, smithyVersion: String = internal fun testSymbolProvider(model: Model): RustSymbolProvider = SymbolVisitor( model, ServiceShape.builder().version("test").id("test#Service").build(), - TestSymbolVisitorConfig, + TestRustSymbolProviderConfig, ).let { BaseSymbolMetadataProvider(it, model, additionalAttributes = listOf(Attribute.NonExhaustive)) } .let { RustReservedWordSymbolProvider(it, model) } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWordsTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWordsTest.kt index 9ef10a5af8..ebdf9cdc47 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWordsTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWordsTest.kt @@ -15,7 +15,7 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumDefinition import software.amazon.smithy.rust.codegen.core.smithy.MaybeRenamed import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.orNull @@ -23,7 +23,7 @@ import software.amazon.smithy.rust.codegen.core.util.toPascalCase internal class RustReservedWordSymbolProviderTest { class Stub : RustSymbolProvider { - override fun config(): SymbolVisitorConfig = PANIC() + override fun config(): RustSymbolProviderConfig = PANIC() override fun symbolForOperationError(operation: OperationShape): Symbol = PANIC() override fun symbolForEventStreamError(eventStream: UnionShape): Symbol = PANIC() diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGeneratorTest.kt index e1ae567571..5fb91663ef 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGeneratorTest.kt @@ -18,7 +18,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.smithy.Default import software.amazon.smithy.rust.codegen.core.smithy.MaybeRenamed import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig import software.amazon.smithy.rust.codegen.core.smithy.setDefault import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest @@ -66,7 +66,7 @@ internal class BuilderGeneratorTest { val baseProvider = testSymbolProvider(StructureGeneratorTest.model) val provider = object : RustSymbolProvider { - override fun config(): SymbolVisitorConfig { + override fun config(): RustSymbolProviderConfig { return baseProvider.config() } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt index 0b113a9121..7a3cff39d3 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt @@ -20,7 +20,7 @@ import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RustCrate -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig import software.amazon.smithy.rust.codegen.core.smithy.generators.error.ErrorImplGenerator import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerEnumGenerator @@ -48,8 +48,8 @@ class PythonServerCodegenVisitor( ) : ServerCodegenVisitor(context, codegenDecorator) { init { - val symbolVisitorConfig = - SymbolVisitorConfig( + val rustSymbolProviderConfig = + RustSymbolProviderConfig( runtimeConfig = settings.runtimeConfig, renameExceptions = false, nullabilityCheckMode = NullableIndex.CheckMode.SERVER, @@ -76,15 +76,15 @@ class PythonServerCodegenVisitor( fun baseSymbolProviderFactory( model: Model, serviceShape: ServiceShape, - symbolVisitorConfig: SymbolVisitorConfig, + rustSymbolProviderConfig: RustSymbolProviderConfig, publicConstrainedTypes: Boolean, includeConstraintShapeProvider: Boolean, - ) = RustServerCodegenPythonPlugin.baseSymbolProvider(model, serviceShape, symbolVisitorConfig, publicConstrainedTypes) + ) = RustServerCodegenPythonPlugin.baseSymbolProvider(model, serviceShape, rustSymbolProviderConfig, publicConstrainedTypes) val serverSymbolProviders = ServerSymbolProviders.from( model, service, - symbolVisitorConfig, + rustSymbolProviderConfig, settings.codegenConfig.publicConstrainedTypes, ::baseSymbolProviderFactory, ) diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerSymbolProvider.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerSymbolProvider.kt index ca750bbb5c..e8974f46bc 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerSymbolProvider.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerSymbolProvider.kt @@ -22,9 +22,9 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig import software.amazon.smithy.rust.codegen.core.smithy.SymbolMetadataProvider import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.core.smithy.expectRustMetadata import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticOutputTrait @@ -46,7 +46,7 @@ import software.amazon.smithy.rust.codegen.core.util.isStreaming class PythonServerSymbolVisitor( private val model: Model, serviceShape: ServiceShape?, - config: SymbolVisitorConfig, + config: RustSymbolProviderConfig, ) : SymbolVisitor(model, serviceShape, config) { private val runtimeConfig = config().runtimeConfig diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/RustServerCodegenPythonPlugin.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/RustServerCodegenPythonPlugin.kt index e5694a06cd..8642e4049b 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/RustServerCodegenPythonPlugin.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/RustServerCodegenPythonPlugin.kt @@ -14,7 +14,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolP import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.EventStreamSymbolProvider -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig import software.amazon.smithy.rust.codegen.server.python.smithy.customizations.DECORATORS import software.amazon.smithy.rust.codegen.server.smithy.ConstrainedShapeSymbolMetadataProvider import software.amazon.smithy.rust.codegen.server.smithy.ConstrainedShapeSymbolProvider @@ -70,18 +70,18 @@ class RustServerCodegenPythonPlugin : SmithyBuildPlugin { fun baseSymbolProvider( model: Model, serviceShape: ServiceShape, - symbolVisitorConfig: SymbolVisitorConfig, + rustSymbolProviderConfig: RustSymbolProviderConfig, constrainedTypes: Boolean = true, ) = // Rename a set of symbols that do not implement `PyClass` and have been wrapped in // `aws_smithy_http_server_python::types`. - PythonServerSymbolVisitor(model, serviceShape = serviceShape, config = symbolVisitorConfig) + PythonServerSymbolVisitor(model, serviceShape = serviceShape, config = rustSymbolProviderConfig) // Generate public constrained types for directly constrained shapes. // In the Python server project, this is only done to generate constrained types for simple shapes (e.g. // a `string` shape with the `length` trait), but these always remain `pub(crate)`. .let { if (constrainedTypes) ConstrainedShapeSymbolProvider(it, model, serviceShape, constrainedTypes) else it } // Generate different types for EventStream shapes (e.g. transcribe streaming) - .let { EventStreamSymbolProvider(symbolVisitorConfig.runtimeConfig, it, model, CodegenTarget.SERVER) } + .let { EventStreamSymbolProvider(rustSymbolProviderConfig.runtimeConfig, it, model, CodegenTarget.SERVER) } // Add Rust attributes (like `#[derive(PartialEq)]`) to generated shapes .let { BaseSymbolMetadataProvider(it, model, additionalAttributes = listOf()) } // Constrained shapes generate newtypes that need the same derives we place on types generated from aggregate shapes. diff --git a/codegen-server/python/src/test/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerSymbolProviderTest.kt b/codegen-server/python/src/test/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerSymbolProviderTest.kt index 96439ac787..92f89bf5e6 100644 --- a/codegen-server/python/src/test/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerSymbolProviderTest.kt +++ b/codegen-server/python/src/test/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerSymbolProviderTest.kt @@ -12,7 +12,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustType import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerSymbolVisitor -import software.amazon.smithy.rust.codegen.server.smithy.testutil.ServerTestSymbolVisitorConfig +import software.amazon.smithy.rust.codegen.server.smithy.testutil.ServerTestRustSymbolProviderConfig internal class PythonServerSymbolProviderTest { private val pythonBlobType = RustType.Opaque("Blob", "aws_smithy_http_server_python::types") @@ -45,7 +45,7 @@ internal class PythonServerSymbolProviderTest { value: Timestamp } """.asSmithyModel() - val provider = PythonServerSymbolVisitor(model, null, ServerTestSymbolVisitorConfig) + val provider = PythonServerSymbolVisitor(model, null, ServerTestRustSymbolProviderConfig) // Struct test val timestamp = provider.toSymbol(model.expectShape(ShapeId.from("test#TimestampStruct\$inner"))).rustType() @@ -95,7 +95,7 @@ internal class PythonServerSymbolProviderTest { value: Blob } """.asSmithyModel() - val provider = PythonServerSymbolVisitor(model, null, ServerTestSymbolVisitorConfig) + val provider = PythonServerSymbolVisitor(model, null, ServerTestRustSymbolProviderConfig) // Struct test val blob = provider.toSymbol(model.expectShape(ShapeId.from("test#BlobStruct\$inner"))).rustType() diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/RustServerCodegenPlugin.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/RustServerCodegenPlugin.kt index f63f6977c4..9bc9abeb44 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/RustServerCodegenPlugin.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/RustServerCodegenPlugin.kt @@ -13,10 +13,10 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolP import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.EventStreamSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeMetadataProvider import software.amazon.smithy.rust.codegen.core.smithy.StreamingShapeSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.server.smithy.customizations.CustomValidationExceptionWithReasonDecorator import software.amazon.smithy.rust.codegen.server.smithy.customizations.ServerRequiredCustomizations import software.amazon.smithy.rust.codegen.server.smithy.customizations.SmithyValidationExceptionDecorator @@ -65,15 +65,15 @@ class RustServerCodegenPlugin : ServerDecoratableBuildPlugin() { fun baseSymbolProvider( model: Model, serviceShape: ServiceShape, - symbolVisitorConfig: SymbolVisitorConfig, + rustSymbolProviderConfig: RustSymbolProviderConfig, constrainedTypes: Boolean = true, includeConstrainedShapeProvider: Boolean = true, ) = - SymbolVisitor(model, serviceShape = serviceShape, config = symbolVisitorConfig) + SymbolVisitor(model, serviceShape = serviceShape, config = rustSymbolProviderConfig) // Generate public constrained types for directly constrained shapes. .let { if (includeConstrainedShapeProvider) ConstrainedShapeSymbolProvider(it, model, serviceShape, constrainedTypes) else it } // Generate different types for EventStream shapes (e.g. transcribe streaming) - .let { EventStreamSymbolProvider(symbolVisitorConfig.runtimeConfig, it, model, CodegenTarget.SERVER) } + .let { EventStreamSymbolProvider(rustSymbolProviderConfig.runtimeConfig, it, model, CodegenTarget.SERVER) } // Generate [ByteStream] instead of `Blob` for streaming binary shapes (e.g. S3 GetObject) .let { StreamingShapeSymbolProvider(it, model) } // Add Rust attributes (like `#[derive(PartialEq)]`) to generated shapes diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt index a686c6ad04..3cffaea4aa 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt @@ -36,7 +36,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings import software.amazon.smithy.rust.codegen.core.smithy.DirectedWalker import software.amazon.smithy.rust.codegen.core.smithy.RustCrate -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator @@ -105,7 +105,7 @@ open class ServerCodegenVisitor( protected var validationExceptionConversionGenerator: ValidationExceptionConversionGenerator init { - val symbolVisitorConfig = SymbolVisitorConfig( + val rustSymbolProviderConfig = RustSymbolProviderConfig( runtimeConfig = settings.runtimeConfig, renameExceptions = false, nullabilityCheckMode = NullableIndex.CheckMode.SERVER, @@ -129,7 +129,7 @@ open class ServerCodegenVisitor( val serverSymbolProviders = ServerSymbolProviders.from( model, service, - symbolVisitorConfig, + rustSymbolProviderConfig, settings.codegenConfig.publicConstrainedTypes, RustServerCodegenPlugin::baseSymbolProvider, ) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerSymbolProviders.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerSymbolProviders.kt index 0c6bec0c6f..f9fd256d3a 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerSymbolProviders.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerSymbolProviders.kt @@ -8,7 +8,7 @@ package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig /** * Just a handy class to centralize initialization all the symbol providers required by the server code generators, to @@ -26,17 +26,17 @@ class ServerSymbolProviders private constructor( fun from( model: Model, service: ServiceShape, - symbolVisitorConfig: SymbolVisitorConfig, + rustSymbolProviderConfig: RustSymbolProviderConfig, publicConstrainedTypes: Boolean, - baseSymbolProviderFactory: (model: Model, service: ServiceShape, symbolVisitorConfig: SymbolVisitorConfig, publicConstrainedTypes: Boolean, includeConstraintShapeProvider: Boolean) -> RustSymbolProvider, + baseSymbolProviderFactory: (model: Model, service: ServiceShape, rustSymbolProviderConfig: RustSymbolProviderConfig, publicConstrainedTypes: Boolean, includeConstraintShapeProvider: Boolean) -> RustSymbolProvider, ): ServerSymbolProviders { - val baseSymbolProvider = baseSymbolProviderFactory(model, service, symbolVisitorConfig, publicConstrainedTypes, publicConstrainedTypes) + val baseSymbolProvider = baseSymbolProviderFactory(model, service, rustSymbolProviderConfig, publicConstrainedTypes, publicConstrainedTypes) return ServerSymbolProviders( symbolProvider = baseSymbolProvider, constrainedShapeSymbolProvider = baseSymbolProviderFactory( model, service, - symbolVisitorConfig, + rustSymbolProviderConfig, publicConstrainedTypes, true, ), @@ -44,7 +44,7 @@ class ServerSymbolProviders private constructor( baseSymbolProviderFactory( model, service, - symbolVisitorConfig, + rustSymbolProviderConfig, false, false, ), diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt index 421e85902b..b225b555c5 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt @@ -16,7 +16,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.implBlock import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProviderConfig import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.server.smithy.RustServerCodegenPlugin @@ -29,7 +29,7 @@ import software.amazon.smithy.rust.codegen.server.smithy.customizations.SmithyVa import software.amazon.smithy.rust.codegen.server.smithy.generators.ServerBuilderGenerator // These are the settings we default to if the user does not override them in their `smithy-build.json`. -val ServerTestSymbolVisitorConfig = SymbolVisitorConfig( +val ServerTestRustSymbolProviderConfig = RustSymbolProviderConfig( runtimeConfig = TestRuntimeConfig, renameExceptions = false, nullabilityCheckMode = NullableIndex.CheckMode.SERVER, @@ -50,7 +50,7 @@ fun serverTestSymbolProviders( ServerSymbolProviders.from( model, serviceShape ?: testServiceShapeFor(model), - ServerTestSymbolVisitorConfig, + ServerTestRustSymbolProviderConfig, ( settings ?: serverTestRustSettings( (serviceShape ?: testServiceShapeFor(model)).id, @@ -99,7 +99,7 @@ fun serverTestCodegenContext( val serverSymbolProviders = ServerSymbolProviders.from( model, service, - ServerTestSymbolVisitorConfig, + ServerTestRustSymbolProviderConfig, settings.codegenConfig.publicConstrainedTypes, RustServerCodegenPlugin::baseSymbolProvider, )