Skip to content

Commit f5fae2d

Browse files
authored
Merge pull request #82766 from eeckstein/fix-metatype-in-mpo
MandatoryPerformanceOptimizations: don't specialize vtables for thin class metatype instructions
2 parents 4c1dbd7 + 2b8c63d commit f5fae2d

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/ModulePasses/MandatoryPerformanceOptimizations.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ private func optimize(function: Function, _ context: FunctionPassContext, _ modu
117117
}
118118
}
119119
case let metatype as MetatypeInst:
120-
if context.options.enableEmbeddedSwift {
120+
if context.options.enableEmbeddedSwift,
121+
metatype.type.representationOfMetatype == .thick {
121122
let instanceType = metatype.type.loweredInstanceTypeOfMetatype(in: function)
122123
if instanceType.isClass {
123124
specializeVTable(forClassType: instanceType, errorLocation: metatype.location, moduleContext) {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %{python} %utils/split_file.py -o %t %s
3+
4+
// RUN: %target-swift-frontend -I %t %t/Main.swift -enable-experimental-feature Embedded -cxx-interoperability-mode=default -c -o %t/a.o -Rmodule-loading
5+
6+
// REQUIRES: swift_feature_Embedded
7+
8+
// BEGIN header.h
9+
10+
class C;
11+
12+
void retainC(C * _Nonnull obj);
13+
void releaseC(C * _Nonnull obj);
14+
15+
class C {
16+
public:
17+
C(const C &) = delete;
18+
C() {};
19+
20+
virtual void foo();
21+
22+
static C * _Nonnull create () __attribute__((swift_attr("returns_retained")));
23+
}
24+
__attribute__((swift_attr("import_reference")))
25+
__attribute__((swift_attr("retain:retainC")))
26+
__attribute__((swift_attr("release:releaseC")));
27+
28+
// BEGIN module.modulemap
29+
30+
module MyModule {
31+
header "header.h"
32+
}
33+
34+
// BEGIN Main.swift
35+
36+
import MyModule
37+
38+
public func test()
39+
{
40+
let c = C.create()
41+
c.foo()
42+
}

0 commit comments

Comments
 (0)