Skip to content

Commit b8a91c9

Browse files
committed
embedded: make sure to de-serialize vtable/wtable methods before trying to specialize them
Fixes a compiler crash. rdar://138341211
1 parent 81001ac commit b8a91c9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/GenericSpecialization.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ private struct VTableSpecializer {
8686
let methodSubs = classContextSubs.getMethodSubstitutions(for: entry.implementation)
8787

8888
guard !methodSubs.conformances.contains(where: {!$0.isValid}),
89+
context.loadFunction(function: entry.implementation, loadCalleesRecursively: true),
8990
let specializedMethod = context.specialize(function: entry.implementation, for: methodSubs) else
9091
{
9192
context.diagnosticEngine.diagnose(entry.methodDecl.location.sourceLoc, .non_final_generic_class_function)
@@ -125,6 +126,7 @@ func specializeWitnessTable(forConformance conformance: Conformance,
125126
let methodSubs = conformance.specializedSubstitutions.getMethodSubstitutions(for: origMethod)
126127

127128
guard !methodSubs.conformances.contains(where: {!$0.isValid}),
129+
context.loadFunction(function: origMethod, loadCalleesRecursively: true),
128130
let specializedMethod = context.specialize(function: origMethod, for: methodSubs) else
129131
{
130132
context.diagnosticEngine.diagnose(errorLocation.sourceLoc, .cannot_specialize_witness_method, requirement)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %{python} %utils/split_file.py -o %t %s
3+
4+
// RUN: %target-swift-frontend -enable-experimental-feature Extern -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -enable-experimental-feature Embedded -parse-as-library
5+
// RUN: %target-swift-frontend -enable-experimental-feature Extern -c -I %t %t/Main.swift -enable-experimental-feature Embedded -o %t/a.o
6+
7+
// REQUIRES: OS=macosx || OS=linux-gnu
8+
9+
// BEGIN MyModule.swift
10+
11+
12+
// Check that the compiler can build this and doesn't crash.
13+
14+
public class SubClass<T> {
15+
}
16+
17+
// BEGIN Main.swift
18+
19+
import MyModule
20+
21+
var dummy: [SubClass<Int>] = []

0 commit comments

Comments
 (0)