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 enum equality.

Progress on: #1034
  • Loading branch information
thomasvl committed Aug 13, 2020
1 parent 8ed7c0d commit 22bd22b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Sources/protoc-gen-swift/OneofGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,21 @@ class OneofGenerator {
p.print(
"\(visibility)static func ==(lhs: \(swiftFullName), rhs: \(swiftFullName)) -> Bool {\n")
p.indent()
p.print("switch (lhs, rhs) {\n")
p.print(
"// The use of inline closures is to circumvent 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 (lhs, rhs) {\n")
for f in fields {
p.print("case (\(f.dottedSwiftName)(let l), \(f.dottedSwiftName)(let r)): return l == r\n")
p.print(
"case (\(f.dottedSwiftName), \(f.dottedSwiftName)): return {\n")
p.indent()
p.print(
"guard case \(f.dottedSwiftName)(let l) = lhs, case \(f.dottedSwiftName)(let r) = rhs else { preconditionFailure() }\n",
"return l == r\n")
p.outdent()
p.print(
"}()\n")
}
if fields.count > 1 {
// A tricky edge case: If the oneof only has a single case, then
Expand Down

0 comments on commit 22bd22b

Please sign in to comment.