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-7097] Swift 4.1 Crashing on Generic Types #49645

Closed
swift-ci opened this issue Feb 28, 2018 · 12 comments
Closed

[SR-7097] Swift 4.1 Crashing on Generic Types #49645

swift-ci opened this issue Feb 28, 2018 · 12 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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7097
Radar rdar://problem/38001269
Original Reporter calebkleveter (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment
Apple Swift version 4.1-dev (LLVM 1c8b50929b, Clang 420ae40df6, Swift 6d0629e252)
Target: x86_64-apple-darwin17.4.0

Vapor Framework: 3.0.0-rc.1.1
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: b93b4a3f0b16de9abdfd2d2df0216ce7

Issue Description:

I am getting a compiler crash that appears to be an issue with generics. I have a protocol that conforms to multiple other protocols, some coming from the Vapor framework, some I built:

protocol ProjectModel: Content, Model, Migration, Timestampable, SoftDeletable, FailableJSONRepresentable, Parameter, Publicizable, Updatable, ResponseDecodable 

I then have a generic class that has some further restrictions:

final class ProjectController<M: CoreticsModel> where M.ResolvedParameter == Future<M>, M.Database: QuerySupporting

And then I have an extension method on a protocol that takes in a controller:

extension Router {
    func controller<Model>(at path: PathComponent..., controller: ProjectController<Model>.Type)

}

This is the stack trace that I get from the compiler

Assertion failed: (hasVal), function operator*, file /Users/buildnode/jenkins/workspace/oss-swift-4.1-package-osx/llvm/include/llvm/ADT/Optional.h, line 146.
0 swift 0x000000010a90ebe8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x000000010a90f2f6 SignalHandler(int) + 694
2 libsystem_platform.dylib 0x00007fff7a6d4f5a _sigtramp + 26
3 libsystem_platform.dylib 0x0000000000003450 _sigtramp + 2240996624
4 libsystem_c.dylib 0x00007fff7a4ff312 abort + 127
5 libsystem_c.dylib 0x00007fff7a4c7368 basename_r + 0
6 swift 0x00000001074e2ddf swift::irgen::emitGenericRequirementFromSubstitutions(swift::irgen::IRGenFunction&, swift::CanGenericSignature, swift::ModuleDecl&, swift::irgen::GenericRequirement, swift::SubstitutionMap const&) + 255
7 swift 0x00000001074e8520 void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::EmitPolymorphicArguments::emit(swift::SubstitutionMap const&, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&)::$_23>(long, swift::irgen::GenericRequirement) + 32
8 swift 0x00000001074e8677 void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::PolymorphicConvention::enumerateUnfulfilledRequirements(llvm::function_ref<void (swift::irgen::GenericRequirement)> const&)::$_9>(long, swift::irgen::GenericRequirement) + 215
9 swift 0x00000001074dbabc swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::irgen::GenericRequirement)> const&) + 332
10 swift 0x00000001074e2302 swift::irgen::emitPolymorphicArguments(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::SubstitutionMap const&, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&) + 386
11 swift 0x000000010755c108 (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 1928
12 swift 0x0000000107543eef (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 7151
13 swift 0x0000000107541e11 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 1361
14 swift 0x0000000107451055 swift::irgen::IRGenerator::emitGlobalTopLevel() + 485
15 swift 0x000000010751e774 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, unsigned int) + 1124
16 swift 0x000000010751ee06 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, unsigned int, llvm::GlobalVariable**) + 86
17 swift 0x00000001073c7d8a performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13786
18 swift 0x00000001073c37d0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3376
19 swift 0x0000000107383083 main + 3075
20 libdyld.dylib 0x00007fff7a453115 start + 1
Stack dump:
Assertion failed: (hasVal), function operator*, file /Users/buildnode/jenkins/workspace/oss-swift-4.1-package-osx/llvm/include/llvm/ADT/Optional.h, line 146.
0 swift 0x000000010a90ebe8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 swift 0x000000010a90f2f6 SignalHandler(int) + 694
2 libsystem_platform.dylib 0x00007fff7a6d4f5a _sigtramp + 26
3 libsystem_platform.dylib 0x0000000000003450 _sigtramp + 2240996624
4 libsystem_c.dylib 0x00007fff7a4ff312 abort + 127
5 libsystem_c.dylib 0x00007fff7a4c7368 basename_r + 0
6 swift 0x00000001074e2ddf swift::irgen::emitGenericRequirementFromSubstitutions(swift::irgen::IRGenFunction&, swift::CanGenericSignature, swift::ModuleDecl&, swift::irgen::GenericRequirement, swift::SubstitutionMap const&) + 255
7 swift 0x00000001074e8520 void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::EmitPolymorphicArguments::emit(swift::SubstitutionMap const&, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&)::$_23>(long, swift::irgen::GenericRequirement) + 32
8 swift 0x00000001074e8677 void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<(anonymous namespace)::PolymorphicConvention::enumerateUnfulfilledRequirements(llvm::function_ref<void (swift::irgen::GenericRequirement)> const&)::$_9>(long, swift::irgen::GenericRequirement) + 215
9 swift 0x00000001074dbabc swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::irgen::GenericRequirement)> const&) + 332
10 swift 0x00000001074e2302 swift::irgen::emitPolymorphicArguments(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::SubstitutionMap const&, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&) + 386
11 swift 0x000000010755c108 (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 1928
12 swift 0x0000000107543eef (anonymous namespace)::IRGenSILFunction::emitSILFunction() + 7151
13 swift 0x0000000107541e11 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 1361
14 swift 0x0000000107451055 swift::irgen::IRGenerator::emitGlobalTopLevel() + 485
15 swift 0x000000010751e774 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, unsigned int) + 1124
16 swift 0x000000010751ee06 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, unsigned int, llvm::GlobalVariable**) + 86
17 swift 0x00000001073c7d8a performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13786
18 swift 0x00000001073c37d0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3376
19 swift 0x0000000107383083 main + 3075
20 libdyld.dylib 0x00007fff7a453115 start + 1
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-27-a.xctoolchain/usr/bin/swift -frontend -c /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Configuration/Boot.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Configuration/Configure.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Configuration/Database.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Configuration/Router.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Controllers/Controllers.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Controllers/ProjController.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Controllers/SearchController.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Address/Address.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Company/Company+Updatable.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Company/Company.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Company/CompanyAddress.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Company/CompanyPerson.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Company/CompanyPersonType.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Company/CompanyType.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/ProjModel.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Person/Person+Updatable.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Person/Person.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Person/PersonAddress.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Person/PersonChange.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Person/PersonConnection.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Source/Source.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/SourcePivot/SourcePivot.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/Sources.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Models/User/User.swift -primary-file /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Routes/Routes.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Utilities/ProjError.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Utilities/JSON+Request.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Utilities/Public.swift /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Utilities/Updatable.swift -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -I /Users/calebkleveter/Development/Skelpo/Proj/.build/x86_64-apple-macosx10.10/debug -I /Users/calebkleveter/Development/Skelpo/Proj/.build/checkouts/engine.git-3311994267206676365/Sources/CHTTP/include -F /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/calebkleveter/Development/Skelpo/Proj/.build/x86_64-apple-macosx10.10/debug/ModuleCache -swift-version 4 -Onone -D SWIFT_PACKAGE -color-diagnostics -Xcc -fmodule-map-file=/Users/calebkleveter/Development/Skelpo/Proj/.build/x86_64-apple-macosx10.10/debug/CHTTP.build/module.modulemap -emit-module-doc-path /Users/calebkleveter/Development/Skelpo/Proj/.build/x86_64-apple-macosx10.10/debug/App.build/Routes~partial.swiftdoc -parse-as-library -module-name App -emit-module-path /Users/calebkleveter/Development/Skelpo/Proj/.build/x86_64-apple-macosx10.10/debug/App.build/Routes~partial.swiftmodule -emit-dependencies-path /Users/calebkleveter/Development/Skelpo/Proj/.build/x86_64-apple-macosx10.10/debug/App.build/Routes.d -emit-reference-dependencies-path /Users/calebkleveter/Development/Skelpo/Proj/.build/x86_64-apple-macosx10.10/debug/App.build/Routes.swiftdeps -num-threads 4 -o /Users/calebkleveter/Development/Skelpo/Proj/.build/x86_64-apple-macosx10.10/debug/App.build/Routes/Routes.swift.o
1.  While emitting IR SIL function "@_T05Vapor6RouterP3AppE15configureRoutesyyF".
for 'configureRoutes()' at /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Routes/Routes.swift:6:5
<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)1. While emitting IR SIL function "@_T05Vapor6RouterP3AppE15configureRoutesyyF".
for 'configureRoutes()' at /Users/calebkleveter/Development/Skelpo/Proj/Sources/App/Routes/Routes.swift:6:5
<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)// code placeholder

This code worked in the Swift snapshot that was released with Xcode 9.3 beta, build 9Q107o (if I remember the build number correctly).

@jckarter
Copy link
Member

@swift-ci create

@DougGregor
Copy link
Member

I don't see a way to reproduce this (is there a project we can build?), but it looks a lot like SR-7072.

@DougGregor
Copy link
Member

calebkleveter (JIRA User), can you try the latest 4.1 development snapshot from https://swift.org/download/#snapshots, from February 27th or newer? This looks like the same failure we fixed yesterday for SR-7072, but I can't verify myself without building your project.

@gwynne
Copy link
Contributor

gwynne commented Feb 28, 2018

@DougGregor If I'm not mistaken, he was already on the most recent snapshot when this crash happened.

@DougGregor
Copy link
Member

Oh, thanks @gwynne. I checked the hash, and that snapshot didn't pick up what I think is the fix, because this:

#14850

went in too late yesterday.

@DougGregor
Copy link
Member

calebkleveter (JIRA User), do you have project sources you can attach? Without them, we're not able to reproduce the problem (or verify whether it was indeed fixed as part of SR-7072)

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 2, 2018

Comment by Caleb Kleveter (JIRA)

@DougGregor I was able to reproduce the issue with this project. I am not sure how much of this code actually contributes to the issue, as I don't have time to trim it down right now, but the Sources/App/Controllers/TodoController.swift and Sources/App/Models/Todo.swift are the files that would be of most interest.

@swift-ci
Copy link
Collaborator Author

swift-ci commented Mar 2, 2018

Comment by Caleb Kleveter (JIRA)

I just tried to build the project I linked to above with the 03-1 snapshot, and it crashed with the same error message.

@DougGregor
Copy link
Member

calebkleveter (JIRA User), thank you! I'm able to reproduce the problem with your project. I don't have a fix yet, but this hack works around the crash for me:

diff --git a/Sources/App/Controllers/TodoController.swift b/Sources/App/Controllers/TodoController.swift
index 5577da8..e3152c5 100644
--- a/Sources/App/Controllers/TodoController.swift
+++ b/Sources/App/Controllers/TodoController.swift
@@ -8,5 +8,5 @@ final class Controller<M: LargeProto> where M.ResolvedParameter == Future<M>, M.
 typealias ContollerOne = Controller<ModelOne>
 
 extension Router {
-    func controller<Model>(at path: PathComponent..., controller: Controller<Model>.Type) {}
+  func controller<Model>(at path: PathComponent..., controller: Controller<Model>.Type) where Model.Database: QuerySupporting {}
 }

@DougGregor
Copy link
Member

Way better workaround:

diff --git a/Sources/App/Models/Todo.swift b/Sources/App/Models/Todo.swift
index a122349..17c8293 100644
--- a/Sources/App/Models/Todo.swift
+++ b/Sources/App/Models/Todo.swift
@@ -2,7 +2,7 @@ import FluentMySQL
 import Vapor
 import Foundation
 
-protocol LargeProto: Content, Model, Timestampable, SoftDeletable, Parameter, ResponseEncodable, Migration {
+protocol LargeProto: Content, Model, Timestampable, SoftDeletable, Parameter, ResponseEncodable, Migration where Self.Database == MySQLDatabase, Self.ID == Int {
     var id: Self.ID? { get set }
     
     var createdAt: Date? { get set }
@@ -11,9 +11,6 @@ protocol LargeProto: Content, Model, Timestampable, SoftDeletable, Parameter, Re
 }
 
 extension LargeProto {
-    typealias Database = MySQLDatabase
-    typealias ID = Int
-    
     static var idKey: Self.IDKey {
         return \Self.id
     }

@DougGregor
Copy link
Member

And here's a reduced test case:

protocol P1 { }

protocol P2 {
  associatedtype Assoc
}

protocol P3 : P2 { }

struct S0<M: P3> where M.Assoc: P1 { }

struct ConformsToP1: P1 { }

extension P3 {
  typealias Assoc = ConformsToP1
}

protocol P5 { }

extension P5 {
  func testSR7097<M>(_: S0<M>.Type) {}
}

@DougGregor
Copy link
Member

master: #15002

swift-4.1-branch: #15014

@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

5 participants