Skip to content

[IRGen] Use Singleton metadata strategy in JIT mode [5.1] #26002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/IRGen/GenClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,11 @@ IRGenModule::getClassMetadataStrategy(const ClassDecl *theClass) {
// If we have resiliently-sized fields, we might be able to use the
// update pattern.
if (resilientLayout.doesMetadataRequireUpdate()) {

// FixedOrUpdate strategy does not work in JIT mode
if (IRGen.Opts.UseJIT)
return ClassMetadataStrategy::Singleton;

// The update pattern only benefits us on platforms with an Objective-C
// runtime, otherwise just use the singleton pattern.
if (!Context.LangOpts.EnableObjCInterop)
Expand Down
6 changes: 6 additions & 0 deletions test/IRGen/Inputs/legacy_type_info/jit_metadata_strategy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Name: resilient_struct
Decls:
- Name: 16resilient_struct15ResilientDoubleV
Size: 8
Alignment: 8
ExtraInhabitants: 0
40 changes: 40 additions & 0 deletions test/IRGen/jit_metadata_strategy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -enable-library-evolution %S/../Inputs/resilient_struct.swift -emit-module-path %t/resilient_struct.swiftmodule
// 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/jit_metadata_strategy.yaml | %FileCheck %s

// REQUIRES: objc_interop

import resilient_struct

// ClassMetadataStrategy::Fixed
class FixedSizeClass {
var v4: String?
var v5: Int?
var v6: String?
}

// ClassMetadataStrategy::Singleton
class GenericSuperclass<T> { }
class ClassWithGenericSuperclass: GenericSuperclass<Int> {
var v1: ResilientDouble?
var v2: ResilientDouble?
var v3: ResilientDouble?
var v4: String?
var v5: Int?
var v6: String?
}

// ClassMetadataStrategy::FixedOrUpdate when compiling
// ClassMetadataStrategy::Singleton when interpreting
class ClassNeedingUpdate {
var v1: ResilientDouble?
var v2: ResilientDouble?
var v3: ResilientDouble?
var v4: String?
var v5: Int?
var v6: String?
}

// CHECK-LABEL: define{{( protected)?}} private void @runtime_registration
// CHECK: call void @swift_instantiateObjCClass({{.*}} @"$s21jit_metadata_strategy14FixedSizeClassCN")
// CHECK-NOT: call void @swift_instantiateObjCClass({{.*}} @"$s21jit_metadata_strategy18ClassNeedingUpdateCN")
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Name: resilient_struct
Decls:
- Name: 16resilient_struct15ResilientDoubleV
Size: 8
Alignment: 8
ExtraInhabitants: 0
44 changes: 44 additions & 0 deletions test/Interpreter/jit_metadata_strategy.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// RUN: %empty-directory(%t)
// 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

// 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/jit_metadata_strategy.yaml

// REQUIRES: objc_interop
// REQUIRES: swift_interpreter

import resilient_struct

@_optimize(none) func blackHole<T>(_: T) {}

// ClassMetadataStrategy::Fixed
class FixedSizeClass {
var v4: String?
var v5: Int?
var v6: String?
}

// ClassMetadataStrategy::Singleton
class GenericSuperclass<T> { }
class ClassWithGenericSuperclass: GenericSuperclass<Int> {
var v1: ResilientDouble?
var v2: ResilientDouble?
var v3: ResilientDouble?
var v4: String?
var v5: Int?
var v6: String?
}

// ClassMetadataStrategy::FixedOrUpdate when compiling
// ClassMetadataStrategy::Singleton when interpreting
class ClassNeedingUpdate {
var v1: ResilientDouble?
var v2: ResilientDouble?
var v3: ResilientDouble?
var v4: String?
var v5: Int?
var v6: String?
}

blackHole(FixedSizeClass())
blackHole(ClassWithGenericSuperclass())
blackHole(ClassNeedingUpdate())