Skip to content

Commit 8e96e1a

Browse files
authored
Merge pull request #82800 from eeckstein/fix-metatype-in-mpo-6.2
[6.2] MandatoryPerformanceOptimizations: don't specialize vtables for thin class metatype instructions
2 parents 092441e + 6c36196 commit 8e96e1a

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
@@ -122,7 +122,8 @@ private func optimize(function: Function, _ context: FunctionPassContext, _ modu
122122
}
123123
}
124124
case let metatype as MetatypeInst:
125-
if context.options.enableEmbeddedSwift {
125+
if context.options.enableEmbeddedSwift,
126+
metatype.type.representationOfMetatype == .thick {
126127
let instanceType = metatype.type.loweredInstanceTypeOfMetatype(in: function)
127128
if instanceType.isClass {
128129
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)