Skip to content

Commit 745a4a3

Browse files
committed
IRGen: Disable resilient class metadata unless -enable-class-resilience is passed in
Resilient classes are not fully implemented yet, and can cause crashes at runtime; add a flag disabling them until the code is done, to unblock standard library testing with resilience enabled.
1 parent 53b3a69 commit 745a4a3

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ namespace swift {
141141
/// \brief Enable experimental nested generic types feature.
142142
bool EnableExperimentalNestedGenericTypes = false;
143143

144+
/// \brief Staging flag for class resilience, which we do not want to enable
145+
/// fully until more code is in place, to allow the standard library to be
146+
/// tested with value type resilience only.
147+
bool EnableClassResilience = false;
148+
144149
/// Should we check the target OSs of serialized modules to see that they're
145150
/// new enough?
146151
bool EnableTargetOSChecking = true;

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ def enable_resilience : Flag<["-"], "enable-resilience">,
331331
HelpText<"Compile the module to export resilient interfaces for all "
332332
"public declarations by default">;
333333

334+
def enable_class_resilience : Flag<["-"], "enable-class-resilience">,
335+
HelpText<"Compile the module to export resilient interfaces for all "
336+
"public classes by default (doesn't work yet)">;
337+
334338
def group_info_path : Separate<["-"], "group-info-path">,
335339
HelpText<"The path to collect the group information of the compiled module">;
336340

lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,9 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
787787
Opts.EnableExperimentalNestedGenericTypes |=
788788
Args.hasArg(OPT_enable_experimental_nested_generic_types);
789789

790+
Opts.EnableClassResilience |=
791+
Args.hasArg(OPT_enable_class_resilience);
792+
790793
Opts.DisableAvailabilityChecking |=
791794
Args.hasArg(OPT_disable_availability_checking);
792795
if (FrontendOpts.InputKind == InputFileKind::IFK_SIL)

lib/IRGen/ClassMetadataLayout.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ template <class Impl> class ClassMetadataLayout : public MetadataLayout<Impl> {
8888
// Skip superclass fields if superclass is resilient.
8989
// FIXME: Needs runtime support to ensure the field offset vector is
9090
// populated correctly.
91-
if (!IGM.isResilient(superclassDecl, ResilienceExpansion::Maximal)) {
91+
if (!IGM.Context.LangOpts.EnableClassResilience ||
92+
!IGM.isResilient(superclassDecl, ResilienceExpansion::Maximal)) {
9293
addClassMembers(superclassDecl, superclass);
9394
}
9495
}

lib/IRGen/GenClass.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,16 @@ namespace {
242242

243243
// If the superclass is resilient to us, we cannot statically
244244
// know the layout of either its instances or its class objects.
245-
ClassHasFixedFieldCount = false;
245+
//
246+
// FIXME: We need to implement indirect field/vtable entry access
247+
// before we can enable this
248+
if (IGM.Context.LangOpts.EnableClassResilience) {
249+
ClassHasFixedFieldCount = false;
250+
} else {
251+
addFieldsForClass(superclass, superclassType);
252+
NumInherited = Elements.size();
253+
}
254+
246255
ClassHasFixedSize = false;
247256

248257
// Furthermore, if the superclass is a generic context, we have to

test/IRGen/class_resilience.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %target-swift-frontend -I %S/../Inputs -enable-source-import -emit-ir -enable-resilience %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
2-
// RUN: %target-swift-frontend -I %S/../Inputs -enable-source-import -emit-ir -enable-resilience -O %s
1+
// RUN: %target-swift-frontend -I %S/../Inputs -enable-source-import -emit-ir -enable-resilience -enable-class-resilience %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-runtime
2+
// RUN: %target-swift-frontend -I %S/../Inputs -enable-source-import -emit-ir -enable-resilience -enable-class-resilience -O %s
33

44
// CHECK: %swift.type = type { [[INT:i32|i64]] }
55

0 commit comments

Comments
 (0)