Skip to content

Commit 7604dd5

Browse files
committed
Enable key path resilience.
1 parent 9c9fa85 commit 7604dd5

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

include/swift/Basic/LangOptions.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ namespace swift {
226226
bool EnableSILOpaqueValues = false;
227227

228228
/// Enables key path resilience.
229-
bool EnableKeyPathResilience = false;
229+
bool EnableKeyPathResilience = true;
230230

231231
/// If set to true, the diagnosis engine can assume the emitted diagnostics
232232
/// will be used in editor. This usually leads to more aggressive fixit.

lib/IRGen/GenKeyPath.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,16 @@
4646
#include "swift/AST/GenericEnvironment.h"
4747
#include "swift/AST/ParameterList.h"
4848
#include "swift/AST/Types.h"
49+
#include "swift/Basic/Statistic.h"
4950
#include "swift/IRGen/Linking.h"
5051

5152
using namespace swift;
5253
using namespace irgen;
5354

55+
#define DEBUG_TYPE "IRGen key paths"
56+
STATISTIC(NumTrivialPropertyDescriptors, "# of trivial property descriptors");
57+
STATISTIC(NumNonTrivialPropertyDescriptors, "# of nontrivial property descriptors");
58+
5459
enum KeyPathAccessor {
5560
Getter,
5661
Setter,
@@ -1207,6 +1212,7 @@ IRGenModule::getAddrOfKeyPathPattern(KeyPathPattern *pattern,
12071212

12081213
void IRGenModule::emitSILProperty(SILProperty *prop) {
12091214
if (prop->isTrivial()) {
1215+
++NumTrivialPropertyDescriptors;
12101216
// All trivial property descriptors can share a single definition in the
12111217
// translation unit.
12121218
if (!TheTrivialPropertyDescriptor) {
@@ -1233,6 +1239,8 @@ void IRGenModule::emitSILProperty(SILProperty *prop) {
12331239
return;
12341240
}
12351241

1242+
++NumNonTrivialPropertyDescriptors;
1243+
12361244
ConstantInitBuilder builder(*this);
12371245
ConstantStructBuilder fields = builder.beginStruct();
12381246
fields.setPacked(true);

test/IRGen/class_resilience.swift

+13-13
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ extension ResilientGenericOutsideParent {
316316
// CHECK-NEXT: [[GENERIC_PARAM:%.*]] = load %swift.type*, %swift.type** [[GENERIC_PARAM_ADDR]]
317317
// CHECK: ret %swift.type* [[GENERIC_PARAM]]
318318

319+
// ResilientChild.field getter dispatch thunk
320+
321+
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc i32 @"$S16class_resilience14ResilientChildC5fields5Int32VvgTj"(%T16class_resilience14ResilientChildC* swiftself)
322+
// CHECK: [[ISA_ADDR:%.*]] = getelementptr inbounds %T16class_resilience14ResilientChildC, %T16class_resilience14ResilientChildC* %0, i32 0, i32 0, i32 0
323+
// CHECK-NEXT: [[ISA:%.*]] = load %swift.type*, %swift.type** [[ISA_ADDR]]
324+
// CHECK-NEXT: [[BASE:%.*]] = load [[INT]], [[INT]]* getelementptr inbounds ([[BOUNDS]], [[BOUNDS]]* @"$S16class_resilience14ResilientChildCMo", i32 0, i32 0)
325+
// CHECK-NEXT: [[METADATA_BYTES:%.*]] = bitcast %swift.type* [[ISA]] to i8*
326+
// CHECK-NEXT: [[VTABLE_OFFSET_TMP:%.*]] = getelementptr inbounds i8, i8* [[METADATA_BYTES]], [[INT]] [[BASE]]
327+
// CHECK-NEXT: [[VTABLE_OFFSET_ADDR:%.*]] = bitcast i8* [[VTABLE_OFFSET_TMP]] to i32 (%T16class_resilience14ResilientChildC*)**
328+
// CHECK-NEXT: [[METHOD:%.*]] = load i32 (%T16class_resilience14ResilientChildC*)*, i32 (%T16class_resilience14ResilientChildC*)** [[VTABLE_OFFSET_ADDR]]
329+
// CHECK-NEXT: [[RESULT:%.*]] = call swiftcc i32 [[METHOD]](%T16class_resilience14ResilientChildC* swiftself %0)
330+
// CHECK-NEXT: ret i32 [[RESULT]]
331+
319332
// ClassWithResilientProperty metadata initialization function
320333

321334

@@ -393,19 +406,6 @@ extension ResilientGenericOutsideParent {
393406
// CHECK: ret void
394407

395408

396-
// ResilientChild.field getter dispatch thunk
397-
398-
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc i32 @"$S16class_resilience14ResilientChildC5fields5Int32VvgTj"(%T16class_resilience14ResilientChildC* swiftself)
399-
// CHECK: [[ISA_ADDR:%.*]] = getelementptr inbounds %T16class_resilience14ResilientChildC, %T16class_resilience14ResilientChildC* %0, i32 0, i32 0, i32 0
400-
// CHECK-NEXT: [[ISA:%.*]] = load %swift.type*, %swift.type** [[ISA_ADDR]]
401-
// CHECK-NEXT: [[BASE:%.*]] = load [[INT]], [[INT]]* getelementptr inbounds ([[BOUNDS]], [[BOUNDS]]* @"$S16class_resilience14ResilientChildCMo", i32 0, i32 0)
402-
// CHECK-NEXT: [[METADATA_BYTES:%.*]] = bitcast %swift.type* [[ISA]] to i8*
403-
// CHECK-NEXT: [[VTABLE_OFFSET_TMP:%.*]] = getelementptr inbounds i8, i8* [[METADATA_BYTES]], [[INT]] [[BASE]]
404-
// CHECK-NEXT: [[VTABLE_OFFSET_ADDR:%.*]] = bitcast i8* [[VTABLE_OFFSET_TMP]] to i32 (%T16class_resilience14ResilientChildC*)**
405-
// CHECK-NEXT: [[METHOD:%.*]] = load i32 (%T16class_resilience14ResilientChildC*)*, i32 (%T16class_resilience14ResilientChildC*)** [[VTABLE_OFFSET_ADDR]]
406-
// CHECK-NEXT: [[RESULT:%.*]] = call swiftcc i32 [[METHOD]](%T16class_resilience14ResilientChildC* swiftself %0)
407-
// CHECK-NEXT: ret i32 [[RESULT]]
408-
409409
// ResilientChild.field setter dispatch thunk
410410

411411
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @"$S16class_resilience14ResilientChildC5fields5Int32VvsTj"(i32, %T16class_resilience14ResilientChildC* swiftself)

0 commit comments

Comments
 (0)