Skip to content

IRGen: Perform completely fragile layout for all classes, not just @objc ancestry #17196

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
merged 1 commit into from
Jun 14, 2018
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
15 changes: 8 additions & 7 deletions lib/IRGen/GenClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ namespace {

unsigned NumInherited = 0;

// If the class has @objc ancestry, we lay out resiliently-typed fields
// as if they were fragile.
bool CompletelyFragileLayout = false;
// For now we always lay out resiliently-typed fields as if they
// were fragile.
bool CompletelyFragileLayout;

// Does the class metadata require dynamic initialization above and
// beyond what the runtime can automatically achieve?
Expand Down Expand Up @@ -171,6 +171,11 @@ namespace {
ReferenceCounting refcounting)
: StructLayoutBuilder(IGM)
{
// Perform fragile layout if Objective-C interop is enabled.
CompletelyFragileLayout =
(IGM.Context.LangOpts.EnableObjCInterop &&
!IGM.IRGen.Opts.EnableClassResilience);

// Start by adding a heap header.
switch (refcounting) {
case ReferenceCounting::Native:
Expand Down Expand Up @@ -249,10 +254,6 @@ namespace {
}

if (superclass->hasClangNode()) {
// Perform fragile layout if the class has @objc ancestry.
if (!IGM.IRGen.Opts.EnableClassResilience)
CompletelyFragileLayout = true;

// If the superclass was imported from Objective-C, its size is
// not known at compile time. However, since the field offset
// vector only stores offsets of stored properties defined in
Expand Down
27 changes: 27 additions & 0 deletions test/IRGen/completely_fragile_class_layout.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -enable-resilience -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
// RUN: %target-swift-frontend -I %t -emit-ir -enable-resilience %s | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize -DINT=i%target-ptrsize
// RUN: %target-swift-frontend -I %t -emit-ir -enable-resilience -O %s

// REQUIRES: objc_interop

import resilient_struct

// Class has static metadata:
// CHECK-LABEL: $S31completely_fragile_class_layout23ClassWithResilientFieldCMf

// CHECK-LABEL: define swiftcc %swift.metadata_response @"$S31completely_fragile_class_layout23ClassWithResilientFieldCMa
// CHECK: call %objc_class* @swift_getInitializedObjCClass(%objc_class* {{.*}} @"$S31completely_fragile_class_layout23ClassWithResilientFieldCMf"
// CHECK: ret

public class ClassWithResilientField {
var first: Int
var second: Size
var third: Int

init(x: Int, y: Size, z: Int) {
self.first = x
self.second = y
self.third = z
}
}
45 changes: 0 additions & 45 deletions test/IRGen/objc_class_resilience.swift

This file was deleted.