Skip to content

Commit ef0f7dc

Browse files
authored
Merge pull request #25504 from jirid/fix-jit-metadata-strategy
[IRGen] Use Singleton metadata strategy in JIT mode.
2 parents 7bc5c50 + 8150a01 commit ef0f7dc

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

lib/IRGen/GenClass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2317,6 +2317,11 @@ IRGenModule::getClassMetadataStrategy(const ClassDecl *theClass) {
23172317
// If we have resiliently-sized fields, we might be able to use the
23182318
// update pattern.
23192319
if (resilientLayout.doesMetadataRequireUpdate()) {
2320+
2321+
// FixedOrUpdate strategy does not work in JIT mode
2322+
if (IRGen.Opts.UseJIT)
2323+
return ClassMetadataStrategy::Singleton;
2324+
23202325
// The update pattern only benefits us on platforms with an Objective-C
23212326
// runtime, otherwise just use the singleton pattern.
23222327
if (!Context.LangOpts.EnableObjCInterop)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Name: resilient_struct
2+
Decls:
3+
- Name: 16resilient_struct15ResilientDoubleV
4+
Size: 8
5+
Alignment: 8
6+
ExtraInhabitants: 0
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift-dylib(%t/%target-library-name(resilient_struct)) -enable-library-evolution %S/../Inputs/resilient_struct.swift -emit-module -emit-module-path %t/resilient_struct.swiftmodule -module-name resilient_struct
3+
4+
// RUN: %target-swift-frontend -use-jit %s -emit-ir -lresilient_struct -L %t -I %t -enable-objc-interop -read-legacy-type-info-path=%S/Inputs/legacy_type_info/b.yaml | %FileCheck %s
5+
// RUN: %target-swift-frontend -interpret %s -lresilient_struct -L %t -I %t -enable-objc-interop -read-legacy-type-info-path=%S/Inputs/legacy_type_info/b.yaml
6+
7+
// REQUIRES: objc_interop
8+
// UNSUPPORTED: OS=ios || OS=watchos || OS=tvos
9+
10+
import resilient_struct
11+
12+
@_optimize(none) func blackHole<T>(_: T) {}
13+
14+
// ClassMetadataStrategy::Fixed
15+
class FixedSizeClass {
16+
var v4: String?
17+
var v5: Int?
18+
var v6: String?
19+
}
20+
21+
// ClassMetadataStrategy::Singleton
22+
class GenericSuperclass<T> { }
23+
class ClassWithGenericSuperclass: GenericSuperclass<Int> {
24+
var v1: ResilientDouble?
25+
var v2: ResilientDouble?
26+
var v3: ResilientDouble?
27+
var v4: String?
28+
var v5: Int?
29+
var v6: String?
30+
}
31+
32+
// ClassMetadataStrategy::FixedOrUpdate when compiling
33+
// ClassMetadataStrategy::Singleton when interpreting
34+
class ClassNeedingUpdate {
35+
var v1: ResilientDouble?
36+
var v2: ResilientDouble?
37+
var v3: ResilientDouble?
38+
var v4: String?
39+
var v5: Int?
40+
var v6: String?
41+
}
42+
43+
blackHole(FixedSizeClass())
44+
blackHole(ClassWithGenericSuperclass())
45+
blackHole(ClassNeedingUpdate())
46+
47+
// CHECK-LABEL: define{{( protected)?}} private void @runtime_registration
48+
// CHECK: call void @swift_instantiateObjCClass({{.*}} @"$s21jit_metadata_strategy14FixedSizeClassCN")
49+
// CHECK-NOT: call void @swift_instantiateObjCClass({{.*}} @"$s21jit_metadata_strategy18ClassNeedingUpdateCN")

0 commit comments

Comments
 (0)