Skip to content

Perform fragile layout for stored properties in classes #15720

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 8 commits into from
Apr 10, 2018

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Apr 3, 2018

Fixes rdar://problem/38506059 and https://bugs.swift.org/browse/SR-7206.

@slavapestov slavapestov requested a review from jrose-apple April 3, 2018 23:12
@slavapestov slavapestov force-pushed the class-resilience-hack branch from aeda303 to a0a5d5c Compare April 4, 2018 01:29
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

Assertion failed: (V[I]->getType() == T->getTypeAtIndex(I) && "Initializer for composite element doesn't match!"), function ConstantAggregate, file /Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/llvm/lib/IR/Constants.cpp, line 878.
21:04:22 0  swift                    0x000000010b46a9e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
21:04:22 1  swift                    0x000000010b46b076 SignalHandler(int) + 422
21:04:22 2  libsystem_platform.dylib 0x00007fff4fd30f5a _sigtramp + 26
21:04:22 3  libsystem_malloc.dylib   0x00007fff4fc58384 tiny_malloc_from_free_list + 431
21:04:22 4  libsystem_c.dylib        0x00007fff4fb5b312 abort + 127
21:04:22 5  libsystem_c.dylib        0x00007fff4fb23368 basename_r + 0
21:04:22 6  swift                    0x000000010b292a7f llvm::ConstantAggregate::ConstantAggregate(llvm::CompositeType*, llvm::Value::ValueTy, llvm::ArrayRef<llvm::Constant*>) + 447
21:04:22 7  swift                    0x000000010b2a16f7 llvm::ConstantUniqueMap<llvm::ConstantStruct>::create(llvm::StructType*, llvm::ConstantAggrKeyType<llvm::ConstantStruct>, std::__1::pair<unsigned int, std::__1::pair<llvm::StructType*, llvm::ConstantAggrKeyType<llvm::ConstantStruct> > >&) + 71
21:04:22 8  swift                    0x000000010b293df2 llvm::ConstantUniqueMap<llvm::ConstantStruct>::getOrCreate(llvm::StructType*, llvm::ConstantAggrKeyType<llvm::ConstantStruct>) + 386
21:04:22 9  swift                    0x000000010b293bdb llvm::ConstantStruct::get(llvm::StructType*, llvm::ArrayRef<llvm::Constant*>) + 203
21:04:22 10 swift                    0x0000000107afaa60 swift::irgen::emitConstantObject(swift::irgen::IRGenModule&, swift::ObjectInst*, swift::irgen::StructLayout*) + 560
21:04:22 11 swift                    0x0000000107bedaf5 swift::irgen::IRGenModule::emitSILStaticInitializers() + 453
21:04:22 12 swift                    0x0000000107b01649 swift::irgen::IRGenerator::emitGlobalTopLevel() + 601
21:04:22 13 swift                    0x0000000107bc77de performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, unsigned int) + 1198
21:04:22 14 swift                    0x0000000107bc613d swift::performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::GlobalVariable**) + 829
21:04:22 15 swift                    0x0000000107a64e3f performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 15535
21:04:22 16 swift                    0x0000000107a6017e swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3310
21:04:22 17 swift                    0x0000000107a1e5b3 main + 2051
21:04:22 18 libdyld.dylib            0x00007fff4faaf115 start + 1

Sigh... this hack might not work out in practice.

@slavapestov slavapestov force-pushed the class-resilience-hack branch from a0a5d5c to 720134d Compare April 10, 2018 00:35
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov force-pushed the class-resilience-hack branch from 720134d to b33cba3 Compare April 10, 2018 01:03
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov force-pushed the class-resilience-hack branch from b33cba3 to 852ee8d Compare April 10, 2018 06:08
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 852ee8db63a63b6fe52c41b9a885cf3bac3085af

- Narrow the fix to classes with @objc ancestry only

- Pass -enable-class-resilience in class resilience executable test so that
  we exercise resilience there

- Only enable fragile layout if the class has @objc ancestry

- Add an IRGen test
@slavapestov slavapestov force-pushed the class-resilience-hack branch from 852ee8d to d751dcc Compare April 10, 2018 07:01
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 852ee8db63a63b6fe52c41b9a885cf3bac3085af

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 852ee8db63a63b6fe52c41b9a885cf3bac3085af

@slavapestov slavapestov merged commit ddea849 into swiftlang:master Apr 10, 2018
Copy link
Contributor

@jrose-apple jrose-apple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an IRGen expert, but it looks good to me (well, as good as possible for this kind of workaround), and ready to go for the 4.2 branch. Glad the field access thing wasn't too bad.

@@ -245,6 +249,10 @@ namespace {
}

if (superclass->hasClangNode()) {
// Perform fragile layout if the class has @objc ancestry.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment's out of date since we ended up deciding not to conditionalize on that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is still valid. Note that we only set CompletelyFragileLayout if the superclass has a Clang node.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. That's not sufficient; you could be the grandchild of an imported class. I'm…sorry for not catching that sooner.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine. We walk all superclasses up to the root here.

TC.pushCompletelyFragile();
}

CompletelyFragileScope(IRGenModule &IGM)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: can you make these constructors explicit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I usually remember to do that. I'll make a follow up patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants