Segmentation fault: 11 with property wrappers

Hello there!

I have the following code to define a property wrapper (this property wrapper is in separated module):

@propertyWrapper
public struct ViewRemovable<T: UIView> {
  public var wrappedValue: T? {
    didSet {
      oldValue?.removeFromSuperview()
    }
  }
  
  public init(_ value: T? = nil) {
    wrappedValue = value
  }
}

And I was using it like this (it worked fine):

final class ContentItemCell: UICollectionViewCell {
  ...
  @ViewRemovable private var content: UIView?
  ...
}

But now I need to change it to this:

  @ViewRemovable private var content: ContentKind.Content?

ContentKind is an enum:

enum ContentKind {
  typealias Content = UIView & Accessible
  ...
}

Accessible is a custom protocol.

The compiler is crashing with Segmentation fault: 11 error:

1.	Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
2.	
3.	Contents of /var/folders/kv/ccbtkwmn43l_zfmpqf7n0dgw0000gn/T/TemporaryDirectory.PlvIvz/sources-1:
---
...
---
4.	While emitting IR SIL function "@$s3App15ContentItemCellC8_content33_7107E058EA79EE0E7EE1B0F7EBA09011LL12UIComponents13ViewRemovableVy9Protocols10Accessible_So6UIViewCXcGvpfi".
 for expression at [/Users/roger/Developer/iOS/ios-newsstand/app/App/Components/Store Collection View/Views/ContentItemCell.swift:25:4 - line:25:4] RangeText=""
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000114641c27 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x0000000114640bb8 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x0000000114642236 SignalHandler(int) + 278
3  libsystem_platform.dylib 0x00007ff81ea51e2d _sigtramp + 29
4  libsystem_platform.dylib 0x00007ff7b0889e50 _sigtramp + 18446744071862190144
5  swift-frontend           0x000000011443c9ac llvm::ConstantExpr::getCast(unsigned int, llvm::Constant*, llvm::Type*, bool) + 844
6  swift-frontend           0x000000010f7eb529 llvm::IRBuilderBase::CreateCast(llvm::Instruction::CastOps, llvm::Value*, llvm::Type*, llvm::Twine const&) + 169
7  swift-frontend           0x000000010facc17c emitCastToSubstSchema(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::ExplosionSchema const&, swift::irgen::Explosion&) + 348
8  swift-frontend           0x000000010faca93f swift::irgen::CallEmission::emitToExplosion(swift::irgen::Explosion&, bool) + 3055
9  swift-frontend           0x000000010fca1a19 (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 4409
10 swift-frontend           0x000000010fc8135f swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 10335
11 swift-frontend           0x000000010fb2ba77 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) + 1607
12 swift-frontend           0x000000010fc4fde0 swift::performIRGeneration(swift::ModuleDecl*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::GlobalVariable**) + 1872
13 swift-frontend           0x000000010f75e5ca performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2346
14 swift-frontend           0x000000010f7506d7 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 14743
15 swift-frontend           0x000000010f690b08 main + 1032
16 dyld                     0x00000001265bd4fe start + 462
error: Segmentation fault: 11 (in target 'App' from project 'App')

Hi! The compiler itself should never crash, regardless of whether the code it’s compiling is correct or not.

This means you’ve discovered a bug!—Could you please file it at bugs.swift.org with a minimal example reproducing the crash? In the bug report, you can link to your post here too and also post the bug number here once filed.

2 Likes

Hello @xwu!

Thank you for your answer!

As you suggested, I just reported a bug, you can find it here:

Roger

1 Like