Skip to content
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

[SR-10983] Synthesizing Initializer with Default Values Fails with Empty Property Wrapper Initializer #53373

Closed
swift-ci opened this issue Jun 20, 2019 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software property wrappers Feature: property wrappers

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10983
Radar None
Original Reporter calebkleveter (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Apple Swift version 5.1 (swiftlang-1100.0.43.3 clang-1100.0.26.3)

Target: x86_64-apple-darwin18.6.0

Xcode 11.0 beta 2 (11M337n)

macOS 10.14.5 (18F132)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, PropertyWrappers
Assignee None
Priority Medium

md5: e11e42c6502eb9c93d5ca94efca08d88

Issue Description:

I created a property wrapper that holds types that conform to LosslessStringConvertible. Along with the initialValue initializer, it has a zero-argument initializer that creates an instance of the wrapped type with an empty string.

When I create a struct that uses the property wrapper on a property and try to use the default initializer without parameters, I get a compiler crash:

Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret Development/Playgrounds/Codable.playground/Contents.swift -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name Contents
1.  While emitting IR SIL function "@$s8Contents3FooVACycfC".
 for 'init()' (at Development/Playgrounds/Codable.playground/Contents.swift:13:8)
0  swift                    0x0000000106dc5963 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x0000000106dc5136 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff64960b5d _sigtramp + 29
3  swift                    0x00000001039bea40 swift::Type::transformRec(llvm::function_ref<llvm::Optional<swift::Type> (swift::TypeBase*)>) const + 6848
4  swift                    0x0000000102a990d1 llvm::GetElementPtrInst::getGEPReturnType(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>) + 113
5  swift                    0x0000000102a98e2d llvm::GetElementPtrInst::Create(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&, llvm::Instruction*) + 173
6  swift                    0x0000000102a98b90 llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>::CreateConstInBoundsGEP2_32(llvm::Type*, llvm::Value*, unsigned int, unsigned int, llvm::Twine const&) + 304
7  swift                    0x0000000102cc5a52 swift::irgen::ElementLayout::project(swift::irgen::IRGenFunction&, swift::irgen::Address, llvm::Optional<swift::irgen::NonFixedOffsetsImpl*>, llvm::Twine const&) const + 850
8  swift                    0x0000000102c18039 swift::irgen::RecordTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true, true>::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address, bool) const + 201
9  swift                    0x0000000102c18057 swift::irgen::RecordTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true, true>::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address, bool) const + 231
10 swift                    0x0000000102c18057 swift::irgen::RecordTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true, true>::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address, bool) const + 231
11 swift                    0x0000000102c18057 swift::irgen::RecordTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true, true>::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address, bool) const + 231
12 swift                    0x0000000102c18057 swift::irgen::RecordTypeInfo<(anonymous namespace)::LoadableStructTypeInfo, swift::irgen::LoadableTypeInfo, (anonymous namespace)::StructFieldInfo, true, true>::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address, bool) const + 231
13 swift                    0x0000000102c73f39 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 37433
14 swift                    0x0000000102c6818a swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9818
15 swift                    0x0000000102b1b147 swift::irgen::IRGenerator::emitLazyDefinitions() + 9095
16 swift                    0x0000000102c450d0 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**) + 1344
17 swift                    0x0000000102c427d9 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**) + 825
18 swift                    0x0000000102a34c2c performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 37516
19 swift                    0x0000000102a280a4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6868
20 swift                    0x00000001029b7333 main + 1219
21 libdyld.dylib            0x00007fff647753d5 start + 1
[1]    77141 segmentation fault  swift Development/Playgrounds/Codable.playground/Contents.swift

Here is a MVP to create the crash:

@propertyDelegate struct Default<T> where T: LosslessStringConvertible {
    var value: T

    init(initialValue: T) {
        self.value = initialValue
    }

    init() {
        self.value = T("")!
    }
}

struct Foo {
    @Default var str: String
}

let foo = Foo()
print(foo)

A couple of things to note:

  • Removing the initialValue initializer fixes the issue.

  • Passing in a custom value to the `Foo` initializer instead of using the default argument also fixes the issue.

@belkadan
Copy link
Contributor

This is already fixed on master! @DougGregor, can you point to the PR?

@DougGregor
Copy link
Member

Yeah, fixed by #25386

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software property wrappers Feature: property wrappers
Projects
None yet
Development

No branches or pull requests

4 participants