Skip to content

Commit

Permalink
Work around excessive stack space in non optimized builds during oneo…
Browse files Browse the repository at this point in the history
…f visiting

Progress on: apple#1034
  • Loading branch information
thomasvl committed Aug 11, 2020
1 parent a4964d3 commit 1329280
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Sources/protoc-gen-swift/OneofGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,18 @@ class OneofGenerator {
p.print("try visitor.visitSingular\(field.protoGenericType)Field(value: v, fieldNumber: \(field.number))\n")
p.outdent()
} else {
p.print("switch \(storedProperty) {\n")
p.print(
"// The use of inline closures is to circumvents an issue where the compiler\n",
"// allocates stack space for every case branch when no optimizations are\n",
"// enabled. https://github.com/apple/swift-protobuf/issues/1034\n",
"switch \(storedProperty) {\n")
for f in group {
p.print("case \(f.dottedSwiftName)(let v)?:\n")
p.print("case \(f.dottedSwiftName)?: try {\n")
p.indent()
p.print("guard case \(f.dottedSwiftName)(let v)? = \(storedProperty) else { preconditionFailure() }\n")
p.print("try visitor.visitSingular\(f.protoGenericType)Field(value: v, fieldNumber: \(f.number))\n")
p.outdent()
p.print("}()\n")
}
if fieldSortedGrouped.count == 1 {
// Cover not being set.
Expand Down

0 comments on commit 1329280

Please sign in to comment.