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-11407] swiftc crash due to generic constraints, I guess #53808

Closed
mayoff opened this issue Aug 31, 2019 · 15 comments
Closed

[SR-11407] swiftc crash due to generic constraints, I guess #53808

mayoff opened this issue Aug 31, 2019 · 15 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 type checker Area → compiler: Semantic analysis

Comments

@mayoff
Copy link

mayoff commented Aug 31, 2019

Previous ID SR-11407
Radar rdar://problem/54979757
Original Reporter @mayoff
Type Bug
Status Resolved
Resolution Done
Environment

Xcode Version 11.0 beta 6 (11M392r) — this is really beta 7
macOS 10.15 Beta (19A546d) — also beta 7

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

md5: 1b4882d67244b42cb5d290f64788bdca

Issue Description:

The following makes swiftc crash (Xcode 11 beta 7):

@usableFromInline final class Box<Wrapped> {
    init(_ wrapped: Wrapped) { }
}


public protocol List {
    associatedtype Element
    var node: ListNode<Element, Self>? { get }
}

public struct ListNode<Element, Rest: List> where Rest.Element == Element { }

public struct Strict<Element>: List {
    public var node: ListNode<Element, Strict<Element>>? {
        fatalError()
    }

    var box: Box<ListNode<Element, Self>>?
}

Here's the log:

Showing All Messages
CompileSwift normal x86_64 /Users/mayoff/TestProjects/crash/crash/main.swift (in target 'crash' from project 'crash')
    cd /Users/mayoff/TestProjects/crash
    /Users/mayoff/Downloads/Xcode-11b7.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/mayoff/TestProjects/crash/crash/main.swift -emit-module-path /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/x86_64/main\~partial.swiftmodule -emit-module-doc-path /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/x86_64/main\~partial.swiftdoc -serialize-diagnostics-path /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/x86_64/main.swiftdeps -target x86_64-apple-macos10.15 -enable-objc-interop -sdk /Users/mayoff/Downloads/Xcode-11b7.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Products/Debug -F /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Products/Debug -enable-testing -g -module-cache-path /Users/mayoff/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -Xcc -working-directory -Xcc /Users/mayoff/TestProjects/crash -enable-anonymous-context-mangled-names -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/crash-generated-files.hmap -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/crash-own-target-headers.hmap -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/crash-all-target-headers.hmap -Xcc -iquote -Xcc /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/crash-project-headers.hmap -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Products/Debug/include -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/DerivedSources-normal/x86_64 -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/DerivedSources/x86_64 -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/DerivedSources -Xcc -DDEBUG=1 -module-name crash -o /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/x86_64/main.o -index-store-path /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Index/DataStore -index-system-modules

Stack dump:
0.  Program arguments: /Users/mayoff/Downloads/Xcode-11b7.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/mayoff/TestProjects/crash/crash/main.swift -emit-module-path /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/x86_64/main~partial.swiftmodule -emit-module-doc-path /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/x86_64/main~partial.swiftdoc -serialize-diagnostics-path /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/x86_64/main.dia -emit-dependencies-path /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/x86_64/main.d -emit-reference-dependencies-path /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/x86_64/main.swiftdeps -target x86_64-apple-macos10.15 -enable-objc-interop -sdk /Users/mayoff/Downloads/Xcode-11b7.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -I /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Products/Debug -F /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Products/Debug -enable-testing -g -module-cache-path /Users/mayoff/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -Xcc -working-directory -Xcc /Users/mayoff/TestProjects/crash -enable-anonymous-context-mangled-names -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/crash-generated-files.hmap -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/crash-own-target-headers.hmap -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/crash-all-target-headers.hmap -Xcc -iquote -Xcc /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/crash-project-headers.hmap -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Products/Debug/include -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/DerivedSources-normal/x86_64 -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/DerivedSources/x86_64 -Xcc -I/Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/DerivedSources -Xcc -DDEBUG=1 -module-name crash -o /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Build/Intermediates.noindex/crash.build/Debug/crash.build/Objects-normal/x86_64/main.o -index-store-path /Users/mayoff/Library/Developer/Xcode/DerivedData/crash-bsarcyzifzljewfdgfxisbgurbhn/Index/DataStore -index-system-modules 
1.  While emitting SIL for getter for node (at /Users/mayoff/TestProjects/crash/crash/main.swift:15:16)
2.  While silgen emitFunction SIL function "@$s5crash6StrictV4nodeXevg".
 for getter for node (at /Users/mayoff/TestProjects/crash/crash/main.swift:15:16)
0  swift                    0x0000000110b94013 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x0000000110b937e6 SignalHandler(int) + 358
2  libsystem_platform.dylib 0x00007fff65386b1d _sigtramp + 29
3  libsystem_platform.dylib 0x00007ffee34acc18 _sigtramp + 2115133720
4  swift                    0x000000010ccbe44b swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 3051
5  swift                    0x000000010cc742fa swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 426
6  swift                    0x000000010cbd93ac swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 1004
7  swift                    0x000000010ccce157 (anonymous namespace)::SILGenType::emitType() + 1319
8  swift                    0x000000010cbe4d6d swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 77
9  swift                    0x000000010cbe3fb6 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1238
10 swift                    0x000000010cbe5a16 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 1238
11 swift                    0x000000010c7e98b9 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 28345
12 swift                    0x000000010c7df1f4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6820
13 swift                    0x000000010c76c763 main + 1219
14 libdyld.dylib            0x00007fff651852a5 start + 1
error: Segmentation fault: 11 (in target 'crash' from project 'crash')
@mayoff
Copy link
Author

mayoff commented Aug 31, 2019

Also tested with nightly build swift-DEVELOPMENT-SNAPSHOT-2019-08-30-a.xctoolchain and it still crashes.

:; /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swiftc -v /Users/mayoff/TestProjects/crash/crash/main.swift
Apple Swift version 5.1-dev (LLVM c5340df2d1, Swift dcd0893efe)
Target: x86_64-apple-darwin19.0.0
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-08-30-a.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/mayoff/TestProjects/crash/crash/main.swift -target x86_64-apple-darwin19.0.0 -enable-objc-interop -color-diagnostics -module-name main -o /var/folders/kn/1d839myx4tlghz34f_lh3hvc0000gn/T/main-e81105.o
Assertion failed: (!result.getType()->hasError() && "interface type of result should not contain error types"), function SILFunctionType, file /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/AST/ASTContext.cpp, line 3282.
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-08-30-a.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/mayoff/TestProjects/crash/crash/main.swift -target x86_64-apple-darwin19.0.0 -enable-objc-interop -color-diagnostics -module-name main -o /var/folders/kn/1d839myx4tlghz34f_lh3hvc0000gn/T/main-e81105.o 
1.  Apple Swift version 5.1-dev (LLVM c5340df2d1, Swift dcd0893efe)
2.  While emitting SIL for getter for node (at /Users/mayoff/TestProjects/crash/crash/main.swift:15:16)
0  swift                    0x0000000109a70515 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000109a6f805 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000109a70af8 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff65386b1d _sigtramp + 29
4  libsystem_platform.dylib 0x0000000000004640 _sigtramp + 2596789056
5  libsystem_c.dylib        0x00007fff6525ca08 abort + 120
6  libsystem_c.dylib        0x00007fff6525bcc2 err + 0
7  swift                    0x0000000109e85403 swift::SILFunctionType::SILFunctionType(swift::GenericSignature*, swift::SILFunctionType::ExtInfo, swift::SILCoroutineKind, swift::ParameterConvention, llvm::ArrayRef<swift::SILParameterInfo>, llvm::ArrayRef<swift::SILYieldInfo>, llvm::ArrayRef<swift::SILResultInfo>, llvm::Optional<swift::SILResultInfo>, swift::ASTContext const&, swift::RecursiveTypeProperties, llvm::Optional<swift::ProtocolConformanceRef>) (.cold.18) + 35
8  swift                    0x0000000106e0129f swift::SILFunctionType::SILFunctionType(swift::GenericSignature*, swift::SILFunctionType::ExtInfo, swift::SILCoroutineKind, swift::ParameterConvention, llvm::ArrayRef<swift::SILParameterInfo>, llvm::ArrayRef<swift::SILYieldInfo>, llvm::ArrayRef<swift::SILResultInfo>, llvm::Optional<swift::SILResultInfo>, swift::ASTContext const&, swift::RecursiveTypeProperties, llvm::Optional<swift::ProtocolConformanceRef>) + 1647
9  swift                    0x0000000106e018f0 swift::SILFunctionType::get(swift::GenericSignature*, swift::SILFunctionType::ExtInfo, swift::SILCoroutineKind, swift::ParameterConvention, llvm::ArrayRef<swift::SILParameterInfo>, llvm::ArrayRef<swift::SILYieldInfo>, llvm::ArrayRef<swift::SILResultInfo>, llvm::Optional<swift::SILResultInfo>, swift::ASTContext const&, llvm::Optional<swift::ProtocolConformanceRef>) + 1008
10 swift                    0x0000000106973c85 getSILFunctionType(swift::SILModule&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::AnyFunctionType::ExtInfo, (anonymous namespace)::Conventions const&, swift::ForeignInfo const&, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SubstitutionMap>, llvm::Optional<swift::ProtocolConformanceRef>) + 4981
11 swift                    0x000000010696e01f getNativeSILFunctionType(swift::SILModule&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::AnyFunctionType::ExtInfo, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::SubstitutionMap>, llvm::Optional<swift::ProtocolConformanceRef>) + 1775
12 swift                    0x000000010696ecbc getUncachedSILFunctionTypeForConstant(swift::SILModule&, swift::SILDeclRef, swift::CanTypeWrapper<swift::AnyFunctionType>) + 764
13 swift                    0x000000010696f66b swift::Lowering::TypeConverter::getConstantInfo(swift::SILDeclRef) + 203
14 swift                    0x00000001069ac1fd swift::SILFunctionBuilder::getOrCreateFunction(swift::SILLocation, swift::SILDeclRef, swift::ForDefinition_t, swift::ProfileCounter) + 77
15 swift                    0x000000010647e799 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 409
16 swift                    0x000000010647eeef swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 591
17 swift                    0x00000001065563c5 void llvm::function_ref<void (swift::AccessorDecl*)>::callback_fn<(anonymous namespace)::SILGenType::visitAccessors(swift::AbstractStorageDecl*)::'lambda'(swift::AccessorDecl*)>(long, swift::AccessorDecl*) + 21
18 swift                    0x0000000106e9e901 swift::AbstractStorageDecl::visitEmittedAccessors(llvm::function_ref<void (swift::AccessorDecl*)>) const + 81
19 swift                    0x00000001065560ee swift::ASTVisitor<(anonymous namespace)::SILGenType, void, void, void, void, void, void>::visit(swift::Decl*) + 814
20 swift                    0x0000000106553ddb (anonymous namespace)::SILGenType::emitType() + 379
21 swift                    0x0000000106553c59 swift::Lowering::SILGenModule::visitNominalTypeDecl(swift::NominalTypeDecl*) + 25
22 swift                    0x0000000106483d46 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 822
23 swift                    0x0000000106484bef swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 287
24 swift                    0x0000000106485026 swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&) + 38
25 swift                    0x00000001061a0d1e performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 7614
26 swift                    0x000000010619e030 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3024
27 swift                    0x0000000106145799 main + 729
28 libdyld.dylib            0x00007fff651852a5 start + 1
29 libdyld.dylib            0x000000000000000d start + 2598874473
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation) 

@theblixguy
Copy link
Collaborator

With asserts on near master:

Assertion failed: ((HadError || !M.is<SourceFile*>() || M.get<SourceFile*>()->ASTStage < SourceFile::TypeChecked) && "UnresolvedDeclRef" "in wrong phase"), function walkToExprPre, file /Users/suyashsrijan/Documents/swift-src/swift/include/swift/AST/ExprNodes.def, line 90.

@belkadan
Copy link
Contributor

belkadan commented Sep 3, 2019

The code looks fine to me, so the unreported error in the node getter is very suspect. It may be trying to interpret the fatalError() as the return value (cc neightchan (JIRA User)). Thanks for filing!

@swift-ci create

@mayoff
Copy link
Author

mayoff commented Sep 3, 2019

It also crashes if you replace fatalError() with nil (which is a valid value for the node getter to return).

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 3, 2019

Comment by Nate Chandler (JIRA)

A couple of data points:

Replacing the fatalError() with return nil continues to crash:

final class Box<Wrapped> {
    init(_ wrapped: Wrapped) { }
}


protocol List {
    associatedtype Element
    var node: ListNode<Element, Self>? { get }
}

struct ListNode<Element, Rest: List> where Rest.Element == Element { }

struct Strict<Element>: List {
    var node: ListNode<Element, Strict<Element>>? {
        return nil
    }

    var box: Box<ListNode<Element, Self>>?
}

Dropping the where clause from the ListNode definition avoids the crash:

@usableFromInline final class Box<Wrapped> {
    init(_ wrapped: Wrapped) { }
}


public protocol List {
    associatedtype Element
    var node: ListNode<Element, Self>? { get }
}

public struct ListNode<Element, Rest: List> { }

public struct Strict<Element>: List {
    public var node: ListNode<Element, Strict<Element>>? {
        fatalError()
    }

    var box: Box<ListNode<Element, Self>>?
}

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 3, 2019

Comment by Nate Chandler (JIRA)

A workaround: Explicitly define the Element associatedtype:

@usableFromInline final class Box<Wrapped> {
    init(_ wrapped: Wrapped) { }
}


public protocol List {
    associatedtype Element
    var node: ListNode<Element, Self>? { get }
}

public struct ListNode<Element, Rest: List> where Rest.Element == Element { }

public struct Strict<_Element>: List {
    public typealias Element = _Element
    public var node: ListNode<Element, Strict<Element>>? {
        fatalError()
    }

    var box: Box<ListNode<Element, Self>>?
}

@mayoff
Copy link
Author

mayoff commented Sep 3, 2019

It turns out ListNode doesn’t need the Element type parameter at all, because that type is available as Rest.Element. This was my workaround:

public struct ListNode<Rest: List> {
    typealias Element = Rest.Element
}

@CodaFi
Copy link
Member

CodaFi commented Sep 4, 2019

On master we correctly diagnose the original issue.

/Users/rwidmann/test.swift:15:31: error: reference to invalid associated type 'Element' of type 'Strict<_Element>'
    public var node: ListNode<Element, Strict<Element>>? {
                              ^
/Users/rwidmann/test.swift:13:15: error: type 'Strict<_Element>' does not conform to protocol 'List'
public struct Strict<_Element>: List {
              ^
/Users/rwidmann/test.swift:7:20: note: protocol requires nested type 'Element'; do you want to add it?
    associatedtype Element

I believe this was repaired by @xymus or @slavapestov's recent work in and around decl checking.

@slavapestov
Copy link
Member

Thanks for testing! Can you add a regression test, @CodaFi?

@CodaFi
Copy link
Member

CodaFi commented Sep 4, 2019

Can do.

EDIT: #27027

@mayoff
Copy link
Author

mayoff commented Sep 4, 2019

I notice that @CodaFi's quoted diagnostics mention _Element, which neither my nor neightchan (JIRA User)'s source code uses. When I try neightchan (JIRA User)'s source code with the latest trunk development snapshot (swift-DEVELOPMENT-SNAPSHOT-2019-09-03-a.xctoolchain), swiftc still crashes. I don't know if that snapshot is sufficiently up-to-date re master to include the changes @CodaFi was referencing.

@CodaFi
Copy link
Member

CodaFi commented Sep 4, 2019

Aha, it's Nate's reproducer that compiles (look at their declaration of Strict, it includes _Element) but your code that still doesn't. I spoke too soon. I'll look into this.

@swift-ci
Copy link
Collaborator

swift-ci commented Sep 4, 2019

Comment by Nate Chandler (JIRA)

@CodaFi To clarify, that wasn't a reproducer, that was a workaround. The workaround was to change the name of the generic parameter to something else and explicitly define the associatedtype, that is, to change from

public struct Strict<Element>: List {

to

public struct Strict<_Element>: List {
    public typealias Element = _Element

@CodaFi
Copy link
Member

CodaFi commented Sep 4, 2019

I know, I could have sworn commenting out your typealias (which is what I've committed in that linked PR) crashed on my box, but now I'm not sure what to think anymore.

@slavapestov
Copy link
Member

#28157

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

7 participants