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-4390] Crash using nested typealias from generic type in Swift 3.1 #46969

Closed
swift-ci opened this issue Mar 28, 2017 · 6 comments
Closed

[SR-4390] Crash using nested typealias from generic type in Swift 3.1 #46969

swift-ci opened this issue Mar 28, 2017 · 6 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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4390
Radar rdar://problem/31480755
Original Reporter benasher44 (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment

macOS Sierra 10.12.4
Xcode 8.3 (App Store) / Swift 3.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 3.1Regression, CompilerCrash
Assignee @slavapestov
Priority Medium

md5: 99b1892d1013637dbc2b1a0784c49ce5

is duplicated by:

  • SR-4498 Compiler crash on referencing typealias from generic type without generic arguments

relates to:

  • SR-4498 Compiler crash on referencing typealias from generic type without generic arguments

Issue Description:

This used to work in Swift 3.0, but this crashes in Swift 3.1:

public struct T<Specific> {
    public typealias Closure = (Specific) -> Void
}

let closure: T.Closure = { (input: String) in
    print("\(input)")
}

Here's the crash trace:

$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift test.swift
0 swift 0x0000000108436eb7 PrintStackTraceSignalHandler(void*) + 39
1 swift 0x0000000108436366 SignalHandler(int) + 646
2 libsystem_platform.dylib 0x00007fffbbe84b3a _sigtramp + 26
3 libsystem_platform.dylib 0x00007fff5aa1f4c0 _sigtramp + 2662967712
4 swift 0x0000000106286cde swift::NominalTypeDecl::hasFixedLayout() const + 14
5 swift 0x0000000105e884d2 (anonymous namespace)::LowerType::visitAnyStructType(swift::CanType, swift::StructDecl*) + 50
6 swift 0x0000000105e87adc swift::Lowering::TypeConverter::getTypeLoweringForUncachedLoweredType(swift::Lowering::TypeConverter::TypeKey) + 76
7 swift 0x0000000105e87318 swift::Lowering::TypeConverter::getTypeLowering(swift::Lowering::AbstractionPattern, swift::Type, unsigned int) + 2328
8 swift 0x0000000105ab87a0 swift::Lowering::SILGenModule::getSILGlobalVariable(swift::VarDecl*, swift::ForDefinition_t) + 1888
9 swift 0x0000000105a8395d swift::Lowering::SILGenFunction::emitInitializationForVarDecl(swift::VarDecl*) + 573
10 swift 0x0000000105a85ae3 swift::Lowering::SILGenFunction::emitPatternBinding(swift::PatternBindingDecl*, unsigned int) + 83
11 swift 0x0000000105a43231 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 577
12 swift 0x0000000105a4233b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 1483
13 swift 0x0000000105a43f62 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 1666
14 swift 0x000000010525600f swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 42239
15 swift 0x000000010520588c main + 9052
16 libdyld.dylib 0x00007fffbbc75235 start + 1
17 libdyld.dylib 0x000000000000000a start + 1144565206
Stack dump:
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret test.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -color-diagnostics -module-name test

The workaround is pretty straightforward, so overall the impact wasn't too bad. You just remove the explicit type, so let closure: T.Closure becomes let closure

@belkadan
Copy link
Contributor

On master:

Bad base type
UNREACHABLE executed at /Volumes/Data/swift-public/swift/lib/AST/Type.cpp:3218!
0  swift                    0x000000010c7458f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010c7448c6 llvm::sys::RunSignalHandlers() + 86
2  swift                    0x000000010c745eb9 SignalHandler(int) + 361
3  libsystem_platform.dylib 0x00007fffaeb4ab3a _sigtramp + 26
4  libsystem_platform.dylib 0x0000000111cd6551 _sigtramp + 1662564913
5  libsystem_c.dylib        0x00007fffae9cf420 abort + 129
6  swift                    0x000000010c6e5127 llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 471
7  swift                    0x000000010a60264a swift::TypeBase::getContextSubstitutions(swift::DeclContext const*, swift::GenericEnvironment*) + 906
8  swift                    0x000000010a5fe253 swift::TypeBase::getContextSubstitutionMap(swift::ModuleDecl*, swift::DeclContext const*, swift::GenericEnvironment*) + 67
9  swift                    0x000000010a4b5e91 swift::TypeChecker::substMemberTypeWithBase(swift::ModuleDecl*, swift::TypeDecl*, swift::Type) + 241
10 swift                    0x000000010a47abfc swift::TypeChecker::lookupMemberType(swift::DeclContext*, swift::Type, swift::Identifier, swift::OptionSet<swift::NameLookupFlags, unsigned int>) + 972
11 swift                    0x000000010a4b772e resolveIdentTypeComponent(swift::TypeChecker&, swift::DeclContext*, llvm::ArrayRef<swift::ComponentIdentTypeRepr*>, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 1086
12 swift                    0x000000010a4b6fa2 swift::TypeChecker::resolveIdentifierType(swift::DeclContext*, swift::IdentTypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 146
13 swift                    0x000000010a4b7dd6 (anonymous namespace)::TypeResolver::resolveType(swift::TypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>) + 198
14 swift                    0x000000010a4b7cdd swift::TypeChecker::resolveType(swift::TypeRepr*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 173
15 swift                    0x000000010a4b681b swift::TypeChecker::validateType(swift::TypeLoc&, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 331
16 swift                    0x000000010a47d7c9 swift::TypeChecker::typeCheckPattern(swift::Pattern*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>) + 953
17 swift                    0x000000010a45024f validatePatternBindingEntries(swift::TypeChecker&, swift::PatternBindingDecl*) + 639
18 swift                    0x000000010a44b008 (anonymous namespace)::DeclChecker::visit(swift::Decl*) + 328
19 swift                    0x000000010a44aeb4 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 100
20 swift                    0x000000010a4b155c swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 444
21 swift                    0x000000010a4b0f9c swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 140
22 swift                    0x000000010a4c482f swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) + 1663
23 swift                    0x000000010a0af7f0 swift::CompilerInstance::performSema() + 3616
24 swift                    0x0000000109637a8f swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4911
25 swift                    0x00000001095f4060 main + 3312
26 libdyld.dylib            0x00007fffae93b235 start + 1
27 libdyld.dylib            0x000000000000000f start + 1366052315
Stack dump:
0.  Program arguments: /Volumes/Data/swift-public/build/ninja/swift-macosx-x86_64/bin/swift -frontend -c -primary-file - -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Volumes/Data/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -color-diagnostics -module-name main -o /var/folders/_d/dmrgv26d3bs6lkrks9z825_w0000gn/T/--578a83.o 
1.  While type-checking declaration 0x7fd8bd09c6f8 at <stdin>:5:1
2.  While resolving type T.Closure at [<stdin>:5:14 - line:5:16] RangeText="T.C"

@belkadan
Copy link
Contributor

@swift-ci create

@slavapestov
Copy link
Member

This only worked in 3.0 on accident. We should have diagnosed this as invalid, because there's really no way to make it work with how we model typealiases nested inside other types.

@slavapestov
Copy link
Member

Another workaround is to write

let closure: T.Closure<String> = ...

@slavapestov
Copy link
Member

Ok, this no longer crashes, you get a diagnostic instead. We can't make this work properly, and we never intended for it to work in the first place.

#8338

@swift-ci
Copy link
Collaborator Author

Comment by Ben A (JIRA)

Awesome![]( Thanks @slavapestov)

@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
Projects
None yet
Development

No branches or pull requests

4 participants