swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.28k stars 10.33k forks source link

[SR-11063] propertyWrapper type checking compiler crash #53455

Open keith opened 5 years ago

keith commented 5 years ago
Previous ID SR-11063
Radar None
Original Reporter @keith
Type Bug
Environment Xcode 11.0 beta 3 (11M362v)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, CompilerCrash, PropertyWrappers | |Assignee | None | |Priority | Medium | md5: 13964a708ebbf17a7cdfaf48c8843efe

is duplicated by:

Issue Description:

With this code:

class Thing {
    @Foo var bar: String? = nil
}

@propertyWrapper
class Foo<T> {
    var wrappedValue: T

    init(abc: T) {
        self.wrappedValue = abc
    }
}

and running `swift /tmp/foo.swift`, you get this crash:

Stack dump:
0.      Program arguments: /Applications/Xcode-11.0.0b3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret /tmp/foo.swift -enable-objc-interop -sdk /Applications/Xcode-11.0.0b3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name foo
1.      While type-checking 'Thing' (at /tmp/foo.swift:1:1)
2.      While type-checking declaration 0x7ffbbf0d04f8 (at /tmp/foo.swift:2:10)
3.      While evaluating request PropertyWrapperBackingPropertyInfoRequest(foo.(file).Thing.bar@/tmp/foo.swift:2:14)
4.      While evaluating request PropertyWrapperBackingPropertyTypeRequest(foo.(file).Thing.bar@/tmp/foo.swift:2:14)
5.      While type-checking expression at [/tmp/foo.swift:2:6 - line:2:29] RangeText="Foo var bar: String? = "
0  swift                    0x0000000104d1ac83 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x0000000104d1a456 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff78c08b5d _sigtramp + 29
3  libsystem_platform.dylib 000000000000000000 _sigtramp + 2269082816
4  swift                    0x000000010186fb01 swift::InFlightDiagnostic::fixItReplace(swift::SourceRange, llvm::StringRef) + 81
5  swift                    0x0000000101439baa swift::diagnoseArgumentLabelError(swift::ASTContext&, swift::Expr const*, llvm::ArrayRef<swift::Identifier>, bool, swift::InFlightDiagnostic*) + 5610
6  swift                    0x00000001013c1320 swift::constraints::RelabelArguments::diagnose(swift::Expr*, bool) const + 224
7  swift                    0x00000001012f5ae4 swift::constraints::ConstraintSystem::applySolutionFixes(swift::Expr*, swift::constraints::Solution const&)::DiagnosticWalker::diagnose(swift::Expr*) + 260
8  swift                    0x00000001012f5897 swift::constraints::ConstraintSystem::applySolutionFixes(swift::Expr*, swift::constraints::Solution const&)::DiagnosticWalker::walkToExprPost(swift::Expr*) + 23
9  swift                    0x00000001014a62e2 swift::TypeChecker::typeCheckExpressionImpl(swift::Expr*&, swift::DeclContext*, swift::TypeLoc, swift::ContextualTypePurpose, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>, swift::ExprTypeCheckListener&, swift::constraints::ConstraintSystem*) + 2594
10 swift                    0x00000001014a9bdc swift::TypeChecker::typeCheckBinding(swift::Pattern*&, swift::Expr*&, swift::DeclContext*) + 972
11 swift                    0x00000001014aa941 swift::TypeChecker::typeCheckPatternBinding(swift::PatternBindingDecl*, unsigned int) + 209
12 swift                    0x000000010154c530 swift::SimpleRequest<swift::PropertyWrapperBackingPropertyTypeRequest, (swift::CacheKind)1, swift::Type, swift::VarDecl*>::evaluateRequest(swift::PropertyWrapperBackingPropertyTypeRequest const&, swift::Evaluator&) + 704
13 swift                    0x0000000101864206 llvm::Expected<swift::PropertyWrapperBackingPropertyTypeRequest::OutputType> swift::Evaluator::getResultUncached<swift::PropertyWrapperBackingPropertyTypeRequest>(swift::PropertyWrapperBackingPropertyTypeRequest const&) + 518
14 swift                    0x0000000101863cfa swift::PropertyWrapperBackingPropertyTypeRequest::OutputType swift::evaluateOrDefault<swift::PropertyWrapperBackingPropertyTypeRequest>(swift::Evaluator&, swift::PropertyWrapperBackingPropertyTypeRequest, swift::PropertyWrapperBackingPropertyTypeRequest::OutputType) + 410
15 swift                    0x000000010154cdd2 swift::SimpleRequest<swift::PropertyWrapperBackingPropertyInfoRequest, (swift::CacheKind)1, swift::PropertyWrapperBackingPropertyInfo, swift::VarDecl*>::evaluateRequest(swift::PropertyWrapperBackingPropertyInfoRequest const&, swift::Evaluator&) + 98
16 swift                    0x0000000101864ee6 llvm::Expected<swift::PropertyWrapperBackingPropertyInfoRequest::OutputType> swift::Evaluator::getResultUncached<swift::PropertyWrapperBackingPropertyInfoRequest>(swift::PropertyWrapperBackingPropertyInfoRequest const&) + 518
17 swift                    0x00000001018648f8 swift::PropertyWrapperBackingPropertyInfoRequest::OutputType swift::evaluateOrDefault<swift::PropertyWrapperBackingPropertyInfoRequest>(swift::Evaluator&, swift::PropertyWrapperBackingPropertyInfoRequest, swift::PropertyWrapperBackingPropertyInfoRequest::OutputType) + 456
18 swift                    0x00000001013ee216 swift::maybeAddAccessorsToStorage(swift::AbstractStorageDecl*) + 806
19 swift                    0x00000001014c202b void llvm::function_ref<void (swift::VarDecl*)>::callback_fn<(anonymous namespace)::DeclChecker::visitBoundVars(swift::Pattern*)::'lambda'(swift::VarDecl*)>(long, swift::VarDecl*) + 43
20 swift                    0x00000001014b5e29 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 3737
21 swift                    0x00000001014b555b (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 1483
22 swift                    0x00000001015769b6 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int) + 1702
23 swift                    0x0000000100c6e1ca swift::CompilerInstance::performSemaUpTo(swift::SourceFile::ASTStage_t) + 4746
24 swift                    0x000000010096603a performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 794
25 swift                    0x0000000100962474 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6868
26 swift                    0x00000001008f0fb3 main + 1219
27 libdyld.dylib            0x00007fff78a1d3d5 start + 1
28 libdyld.dylib            0x000000000000000a start + 2271095862
zsh: segmentation fault  PATH="/usr/bin" swift /tmp/foo.swift
belkadan commented 5 years ago

Fixed in master (and I assume 5.1 soon too). @DougGregor, do you have the Radar for this one?

DougGregor commented 5 years ago

Huh, I'm not sure what fixed this, so I'm not 100% certain the fix is on the 5.1 branch. I'll investigate.

swift-ci commented 3 years ago

Comment by Christos Koninis (JIRA)

This is not reproduced in Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)