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-11381] Property wrappers make the compiler trap #53782

Closed
swift-ci opened this issue Aug 27, 2019 · 4 comments
Closed

[SR-11381] Property wrappers make the compiler trap #53782

swift-ci opened this issue Aug 27, 2019 · 4 comments
Assignees
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-11381
Radar None
Original Reporter adtrevor (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash, PropertyWrappers
Assignee @theblixguy
Priority Medium

md5: 896760e95591438c18a0b690df19e706

is duplicated by:

  • SR-11443 Property Wrapper overwrites type declaration

Issue Description:

Hello,

This small code snippet:

@propertyWrapper
struct Foo<T> {
    init(wrappedValue: T) {
    }
    var wrappedValue: T {
        fatalError()
    }
}

struct Hey {
    @Foo var a: Int = nil // <- incorrectly attempting to assign a nil
}

Make the compiler trap with the following error on the Swift toolchain of Xcode beta 6:
Abort trap: 6

CompileSwift normal x86_64 /Users/adtrevor/Development/OptPropertyWrappers/Sources/OptPropertyWrappers/main.swift (in target 'OptPropertyWrappers' from project 'OptPropertyWrappers')
    cd /Users/adtrevor/Development/OptPropertyWrappers
    /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/adtrevor/Development/OptPropertyWrappers/Sources/OptPropertyWrappers/main.swift -emit-module-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/Objects-normal/x86_64/main\~partial.swiftmodule -emit-module-doc-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/Objects-normal/x86_64/main\~partial.swiftdoc -serialize-diagnostics-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/Objects-normal/x86_64/main.swiftdeps -target x86_64-apple-macos10.10 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Products/Debug -F /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Products/Debug -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -Xcc -working-directory -Xcc /Users/adtrevor/Development/OptPropertyWrappers -enable-anonymous-context-mangled-names -Xcc -I/Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Products/Debug/include -Xcc -I/Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/DerivedSources-normal/x86_64 -Xcc -I/Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/DerivedSources/x86_64 -Xcc -I/Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/DerivedSources -Xcc -DDEBUG=1 -module-name OptPropertyWrappers -o /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/Objects-normal/x86_64/main.o -index-store-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Index/DataStore -index-system-modules

Function return type does not match operand type of return inst!
  ret { i64, i8 } { i64 0, i8 1 }, !dbg !99
 i64in function $s19OptPropertyWrappers3HeyV1aACSi_tcfcfA_
<unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log
<unknown>:0: note: Broken function found, compilation aborted!
Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/adtrevor/Development/OptPropertyWrappers/Sources/OptPropertyWrappers/main.swift -emit-module-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/Objects-normal/x86_64/main~partial.swiftmodule -emit-module-doc-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/Objects-normal/x86_64/main~partial.swiftdoc -serialize-diagnostics-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/Objects-normal/x86_64/main.swiftdeps -target x86_64-apple-macos10.10 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Products/Debug -F /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Products/Debug -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -Xcc -working-directory -Xcc /Users/adtrevor/Development/OptPropertyWrappers -enable-anonymous-context-mangled-names -Xcc -I/Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Products/Debug/include -Xcc -I/Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/DerivedSources-normal/x86_64 -Xcc -I/Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/DerivedSources/x86_64 -Xcc -I/Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/DerivedSources -Xcc -DDEBUG=1 -module-name OptPropertyWrappers -o /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Build/Intermediates.noindex/OptPropertyWrappers.build/Debug/OptPropertyWrappers.build/Objects-normal/x86_64/main.o -index-store-path /Users/adtrevor/Library/Developer/Xcode/DerivedData/OptPropertyWrappers-eppxmnrjdzeorudxgbwvjputzllj/Index/DataStore -index-system-modules 
1.  Running pass 'Module Verifier' on function '@"$s19OptPropertyWrappers3HeyV1aACSi_tcfcfA_"'
0  swift                    0x0000000113be2013 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x0000000113be17e6 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff6d332b1d _sigtramp + 29
3  libsystem_platform.dylib 0x000000011d8c05f8 _sigtramp + 2958613240
4  libsystem_c.dylib        0x00007fff6d208a38 abort + 120
5  swift                    0x000000010f8304f0 std::__1::unique_ptr<swift::DiagnosticConsumer, std::__1::default_delete<swift::DiagnosticConsumer> > llvm::function_ref<std::__1::unique_ptr<swift::DiagnosticConsumer, std::__1::default_delete<swift::DiagnosticConsumer> > (swift::InputFile const&)>::callback_fn<createSerializedDiagnosticConsumerIfNeeded(swift::FrontendInputsAndOutputs const&)::$_15>(long, swift::InputFile const&) + 0
6  swift                    0x0000000113b5b236 llvm::report_fatal_error(llvm::Twine const&, bool) + 278
7  swift                    0x0000000113b5b11b llvm::report_fatal_error(char const*, bool) + 43
8  swift                    0x0000000113b1b483 (anonymous namespace)::VerifierLegacyPass::runOnFunction(llvm::Function&) + 115
9  swift                    0x0000000113abd6f6 llvm::FPPassManager::runOnFunction(llvm::Function&) + 1590
10 swift                    0x0000000113ac866e llvm::legacy::FunctionPassManager::run(llvm::Function&) + 446
11 swift                    0x000000010fa48298 swift::performLLVM(swift::IRGenOptions&, swift::DiagnosticEngine*, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, swift::version::Version const&, llvm::StringRef, swift::UnifiedStatsReporter*) + 4648
12 swift                    0x000000010f839fa3 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 38307
13 swift                    0x000000010f82d1f4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
14 swift                    0x000000010f7ba763 main + 1219
15 libdyld.dylib            0x00007fff6d1312a5 start + 1
error: Abort trap: 6 (in target 'OptPropertyWrappers' from project 'OptPropertyWrappers')
@theblixguy
Copy link
Collaborator

I can reproduce this when I invoke swiftc path_to_code.swift but not when I invoke swift path_to_code.swift - both on master and Xcode 11 b5. I also cannot reproduce this crash on Xcode 11 b5 playgrounds.

However, I wonder if it should be diagnosed in the type checker. The property's type here is Int, whereas the type of the wrappedValue is inferred to be Int?. I think the above is equivalent to @Foo<Int?>(wrappedValue: Optional<Int>.none) var a: Int which throws an error as expected, but the above doesn't. Although I might be wrong...

@belkadan
Copy link
Contributor

I believe this one's been fixed on master, too, but I don't know if the fix made it to the 5.1 branch. @DougGregor?

@theblixguy
Copy link
Collaborator

The crash was fixed, which is why it compiled when I tested it, but the underlying issue wasn't - it was still incorrectly rewriting the type. Fixed here: #27226

@theblixguy
Copy link
Collaborator

Fixed on master. Please verify using the next available snapshot!

@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