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

Rendering: Traits used recursively in their direct struct members cause a StackOverflowError #1296

Closed
kubukoz opened this issue Nov 15, 2023 · 1 comment · Fixed by #1305
Closed
Assignees
Labels
bug Something isn't working

Comments

@kubukoz
Copy link
Member

kubukoz commented Nov 15, 2023

Version: 0.18.3

Minimal example:

$version: "2"

namespace input

@trait
structure Person {
    @Person
    name: String
}
Stack trace

java.lang.StackOverflowError
	at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1694)
	at software.amazon.smithy.model.Model.toSet(Model.java:773)
	at software.amazon.smithy.model.Model.getMemberShapes(Model.java:470)
	at smithy4s.codegen.internals.SmithyToIR.smithy4s$codegen$internals$SmithyToIR$$getAdtParent(SmithyToIR.scala:1124)
	at smithy4s.codegen.internals.SmithyToIR$UnRef$.$anonfun$unapply$3(SmithyToIR.scala:1148)
	at scala.Option.orElse(Option.scala:477)
	at smithy4s.codegen.internals.SmithyToIR$UnRef$.$anonfun$unapply$1(SmithyToIR.scala:1148)
	at scala.Option.map(Option.scala:242)
	at smithy4s.codegen.internals.SmithyToIR$UnRef$.unapply(SmithyToIR.scala:1142)
	at smithy4s.codegen.internals.SmithyToIR.unfoldNodeAndType(SmithyToIR.scala:1183)
	at smithy4s.codegen.internals.SmithyToIR.$anonfun$unfoldTrait$1(SmithyToIR.scala:1177)
	at smithy4s.codegen.internals.recursion$.hylo(recursion.scala:41)
	at smithy4s.codegen.internals.recursion$.ana(recursion.scala:63)
	at smithy4s.codegen.internals.SmithyToIR.smithy4s$codegen$internals$SmithyToIR$$unfoldTrait(SmithyToIR.scala:1177)
	at smithy4s.codegen.internals.SmithyToIR.$anonfun$hints$5(SmithyToIR.scala:968)
	at scala.collection.immutable.List.map(List.scala:246)
	at smithy4s.codegen.internals.SmithyToIR.smithy4s$codegen$internals$SmithyToIR$$hints(SmithyToIR.scala:968)
	at smithy4s.codegen.internals.SmithyToIR$ShapeExt.$anonfun$fields$2(SmithyToIR.scala:1001)
	at scala.collection.StrictOptimizedIterableOps.map(StrictOptimizedIterableOps.scala:100)
	at scala.collection.StrictOptimizedIterableOps.map$(StrictOptimizedIterableOps.scala:87)
	at scala.collection.mutable.ArrayBuffer.map(ArrayBuffer.scala:43)
	at smithy4s.codegen.internals.SmithyToIR$ShapeExt.fields(SmithyToIR.scala:990)
	at smithy4s.codegen.internals.SmithyToIR.unfoldNodeAndType(SmithyToIR.scala:1186)
	at smithy4s.codegen.internals.SmithyToIR.$anonfun$unfoldTrait$1(SmithyToIR.scala:1177)
	at smithy4s.codegen.internals.recursion$.hylo(recursion.scala:41)
	at smithy4s.codegen.internals.recursion$.ana(recursion.scala:63)
	at smithy4s.codegen.internals.SmithyToIR.smithy4s$codegen$internals$SmithyToIR$$unfoldTrait(SmithyToIR.scala:1177)
	at smithy4s.codegen.internals.SmithyToIR.$anonfun$hints$5(SmithyToIR.scala:968)
	at scala.collection.immutable.List.map(List.scala:246)
	at smithy4s.codegen.internals.SmithyToIR.smithy4s$codegen$internals$SmithyToIR$$hints(SmithyToIR.scala:968)
	at smithy4s.codegen.internals.SmithyToIR$ShapeExt.$anonfun$fields$2(SmithyToIR.scala:1001)
	at scala.collection.StrictOptimizedIterableOps.map(StrictOptimizedIterableOps.scala:100)
	at scala.collection.StrictOptimizedIterableOps.map$(StrictOptimizedIterableOps.scala:87)
	at scala.collection.mutable.ArrayBuffer.map(ArrayBuffer.scala:43)
	at smithy4s.codegen.internals.SmithyToIR$ShapeExt.fields(SmithyToIR.scala:990)
	at smithy4s.codegen.internals.SmithyToIR.unfoldNodeAndType(SmithyToIR.scala:1186)
	at smithy4s.codegen.internals.SmithyToIR.$anonfun$unfoldTrait$1(SmithyToIR.scala:1177)
	at smithy4s.codegen.internals.recursion$.hylo(recursion.scala:41)
	at smithy4s.codegen.internals.recursion$.ana(recursion.scala:63)
	at smithy4s.codegen.internals.SmithyToIR.smithy4s$codegen$internals$SmithyToIR$$unfoldTrait(SmithyToIR.scala:1177)
	at smithy4s.codegen.internals.SmithyToIR.$anonfun$hints$5(SmithyToIR.scala:968)
	at scala.collection.immutable.List.map(List.scala:246)
	at smithy4s.codegen.internals.SmithyToIR.smithy4s$codegen$internals$SmithyToIR$$hints(SmithyToIR.scala:968)
	at smithy4s.codegen.internals.SmithyToIR$ShapeExt.$anonfun$fields$2(SmithyToIR.scala:1001)
	at scala.collection.StrictOptimizedIterableOps.map(StrictOptimizedIterableOps.scala:100)
	at scala.collection.StrictOptimizedIterableOps.map$(StrictOptimizedIterableOps.scala:87)
...

This is probably not a recent regression.

Note: this works fine:

$version: "2"

namespace input

@trait
structure Person {
    b: B
}

structure B {
    @Person
    s: String
}

Note 2: unions aren't affected:

$version: "2"

namespace input

@trait
union Person {
    @Person(u: "demo")
    name: String
    u: String
}

Note 3: collections (list member, map key/value) are affected.

Note 4: EDIT: collections are a different issue, actually.

@kubukoz kubukoz added the bug Something isn't working label Nov 15, 2023
@ghostbuster91
Copy link
Contributor

I am going to take a look at it.

@kubukoz kubukoz changed the title Rendering: Traits used recursively in their direct members cause a StackOverflowError Rendering: Traits used recursively in their direct struct members cause a StackOverflowError Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants