Skip to content

Instantly share code, notes, and snippets.

@groue
Created July 24, 2015 13:46
Show Gist options
  • Save groue/2fbc11591794efa12fc6 to your computer and use it in GitHub Desktop.
Save groue/2fbc11591794efa12fc6 to your computer and use it in GitHub Desktop.
// Library code
class Model { }
protocol Fetchable {
typealias FetchableType
static func fetchAll(sql: String) -> [FetchableType]
}
extension Fetchable where Self : Model, FetchableType == Self {
static func fetchAll(sql: String) -> [FetchableType] {
return [] // bare minimal, for demonstration purpose
}
}
// Userland code
class Parent: Model, Fetchable {
typealias FetchableType = Parent
}
class Child: Parent {
typealias FetchableType = Child
}
func f() {
let parents = Parent.fetchAll("SELECT * FROM ...") // [Parent]
// The line below makes the compiler crash. Comment it and the compiler is happy.
let children = Child.fetchAll("SELECT * FROM ...") // [Children]
}
@groue
Copy link
Author

groue commented Jul 24, 2015

Does not crash in a Playground.

Crashes in a regular swift file with

SIL verification failed: substituted callee type does not match substitutions
  $@convention(thin) (@owned String, @thick Child.Type) -> @owned Array<Parent>
  $@convention(thin) (@owned String, @thick Child.Type) -> @owned Array<Child>
Verifying instruction:
     // function_ref static ext.GRDB.GRDB.Fetchable<A where A: GRDB.Model, A: GRDB.Fetchable, A == A.FetchableType>.fetchAll <A where A: GRDB.Model, A: GRDB.Fetchable, A == A.FetchableType> (A.Type)(Swift.String) -> Swift.Array<A.FetchableType>
  %10 = function_ref @_TZFeRdq_C4GRDB5Modelq_S_9Fetchablezq_qq_S1_13FetchableType_S_S1_8fetchAlluRdq_S0_q_S1_zq_qq_S1_13FetchableType_fMq_FSSGSaqq_S1_13FetchableType_ : $@convention(thin) <τ_0_0 where τ_0_0 : Model, τ_0_0 : Fetchable, τ_0_0.FetchableType == τ_0_0> (@owned String, @thick τ_0_0.Type) -> @owned Array<τ_0_0.FetchableType> // user: %18
     %11 = metatype $@thick Child.Type            // user: %18
     %17 = apply %12(%14, %15, %16, %13) : $@convention(thin) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String // user: %18
->   %18 = apply %10<Child>(%17, %11) : $@convention(thin) <τ_0_0 where τ_0_0 : Model, τ_0_0 : Fetchable, τ_0_0.FetchableType == τ_0_0> (@owned String, @thick τ_0_0.Type) -> @owned Array<τ_0_0.FetchableType> // users: %19, %20
     debug_value %18 : $Array<Child>  // let children // id: %19
     release_value %18 : $Array<Child>            // id: %20
In function:
// GRDB.f () -> ()
sil @_TF4GRDB1fFT_T_ : $@convention(thin) () -> () {
bb0:
  // function_ref static ext.GRDB.GRDB.Fetchable<A where A: GRDB.Model, A: GRDB.Fetchable, A == A.FetchableType>.fetchAll <A where A: GRDB.Model, A: GRDB.Fetchable, A == A.FetchableType> (A.Type)(Swift.String) -> Swift.Array<A.FetchableType>
  %0 = function_ref @_TZFeRdq_C4GRDB5Modelq_S_9Fetchablezq_qq_S1_13FetchableType_S_S1_8fetchAlluRdq_S0_q_S1_zq_qq_S1_13FetchableType_fMq_FSSGSaqq_S1_13FetchableType_ : $@convention(thin) <τ_0_0 where τ_0_0 : Model, τ_0_0 : Fetchable, τ_0_0.FetchableType == τ_0_0> (@owned String, @thick τ_0_0.Type) -> @owned Array<τ_0_0.FetchableType> // user: %8
  %1 = metatype $@thick Parent.Type               // user: %8
  // function_ref Swift.String.init (Swift.String.Type)(_builtinStringLiteral : Builtin.RawPointer, byteSize : Builtin.Word, isASCII : Builtin.Int1) -> Swift.String
  %2 = function_ref @_TFSSCfMSSFT21_builtinStringLiteralBp8byteSizeBw7isASCIIBi1__SS : $@convention(thin) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String // user: %7
  %3 = metatype $@thin String.Type                // user: %7
  %4 = string_literal utf8 "SELECT * FROM ..."    // user: %7
  %5 = integer_literal $Builtin.Word, 17          // user: %7
  %6 = integer_literal $Builtin.Int1, -1          // user: %7
  %7 = apply %2(%4, %5, %6, %3) : $@convention(thin) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String // user: %8
  %8 = apply %0<Parent>(%7, %1) : $@convention(thin) <τ_0_0 where τ_0_0 : Model, τ_0_0 : Fetchable, τ_0_0.FetchableType == τ_0_0> (@owned String, @thick τ_0_0.Type) -> @owned Array<τ_0_0.FetchableType> // users: %9, %21
  debug_value %8 : $Array<Parent>  // let parents // id: %9
  // function_ref static ext.GRDB.GRDB.Fetchable<A where A: GRDB.Model, A: GRDB.Fetchable, A == A.FetchableType>.fetchAll <A where A: GRDB.Model, A: GRDB.Fetchable, A == A.FetchableType> (A.Type)(Swift.String) -> Swift.Array<A.FetchableType>
  %10 = function_ref @_TZFeRdq_C4GRDB5Modelq_S_9Fetchablezq_qq_S1_13FetchableType_S_S1_8fetchAlluRdq_S0_q_S1_zq_qq_S1_13FetchableType_fMq_FSSGSaqq_S1_13FetchableType_ : $@convention(thin) <τ_0_0 where τ_0_0 : Model, τ_0_0 : Fetchable, τ_0_0.FetchableType == τ_0_0> (@owned String, @thick τ_0_0.Type) -> @owned Array<τ_0_0.FetchableType> // user: %18
  %11 = metatype $@thick Child.Type               // user: %18
  // function_ref Swift.String.init (Swift.String.Type)(_builtinStringLiteral : Builtin.RawPointer, byteSize : Builtin.Word, isASCII : Builtin.Int1) -> Swift.String
  %12 = function_ref @_TFSSCfMSSFT21_builtinStringLiteralBp8byteSizeBw7isASCIIBi1__SS : $@convention(thin) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String // user: %17
  %13 = metatype $@thin String.Type               // user: %17
  %14 = string_literal utf8 "SELECT * FROM ..."   // user: %17
  %15 = integer_literal $Builtin.Word, 17         // user: %17
  %16 = integer_literal $Builtin.Int1, -1         // user: %17
  %17 = apply %12(%14, %15, %16, %13) : $@convention(thin) (Builtin.RawPointer, Builtin.Word, Builtin.Int1, @thin String.Type) -> @owned String // user: %18
  %18 = apply %10<Child>(%17, %11) : $@convention(thin) <τ_0_0 where τ_0_0 : Model, τ_0_0 : Fetchable, τ_0_0.FetchableType == τ_0_0> (@owned String, @thick τ_0_0.Type) -> @owned Array<τ_0_0.FetchableType> // users: %19, %20
  debug_value %18 : $Array<Child>  // let children // id: %19
  release_value %18 : $Array<Child>               // id: %20
  release_value %8 : $Array<Parent>               // id: %21
  %22 = tuple ()                                  // user: %23
  return %22 : $()                                // id: %23
}

0  swift                    0x0000000111dc3b8b llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x0000000111dc42cb SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff8aee7f1a _sigtramp + 26
3  libsystem_platform.dylib 0x0000000000000005 _sigtramp + 1964081413
4  swift                    0x0000000111dc40c6 abort + 22
5  swift                    0x000000010ff70239 (anonymous namespace)::SILVerifier::_require(bool, llvm::Twine const&, std::__1::function<void ()> const&) + 425
6  swift                    0x000000010ff8429e (anonymous namespace)::SILVerifier::checkFullApplySite(swift::FullApplySite) + 814
7  swift                    0x000000010ff711b2 swift::SILVisitor<(anonymous namespace)::SILVerifier, void>::visit(swift::ValueBase*) + 3282
8  swift                    0x000000010ff6e15b swift::SILFunction::verify() const + 6059
9  swift                    0x000000010ffad141 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 529
10 swift                    0x000000010ffb501f swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 255
11 swift                    0x000000010ffb114b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 587
12 swift                    0x000000010ffb1f55 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 837
13 swift                    0x000000010ffb23b6 swift::performSILGeneration(swift::ModuleDecl*, swift::SILOptions&, bool, bool) + 38
14 swift                    0x000000010fda9b6c performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 9324
15 swift                    0x000000010fda74e3 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2627
16 swift                    0x000000010fda35af main + 2015
17 libdyld.dylib            0x00007fff87a1a5c9 start + 1
18 libdyld.dylib            0x000000000000006f start + 2019449511
Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c /Users/groue/Documents/git/groue/GRDB/GRDB/Row.swift /Users/groue/Documents/git/groue/GRDB/GRDB/DatabaseValueConvertible.swift /Users/groue/Documents/git/groue/GRDB/GRDB/Statement.swift /Users/groue/Documents/git/groue/GRDB/GRDB/Fetchable.swift /Users/groue/Documents/git/groue/GRDB/GRDB/DatabaseQueue.swift /Users/groue/Documents/git/groue/GRDB/GRDB/Configuration.swift /Users/groue/Documents/git/groue/GRDB/GRDB/DatabaseValue.swift /Users/groue/Documents/git/groue/GRDB/GRDB/DatabaseMigrator.swift /Users/groue/Documents/git/groue/GRDB/GRDB/DatabaseDate.swift /Users/groue/Documents/git/groue/GRDB/GRDB/UpdateStatement.swift /Users/groue/Documents/git/groue/GRDB/GRDB/Database.swift /Users/groue/Documents/git/groue/GRDB/GRDB/SelectStatement.swift /Users/groue/Documents/git/groue/GRDB/GRDB/RowModel.swift /Users/groue/Documents/git/groue/GRDB/GRDB/QueryArguments.swift /Users/groue/Documents/git/groue/GRDB/GRDB/DatabaseError.swift -target x86_64-apple-macosx10.10 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -I /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Products/Debug -F /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Products/Debug -application-extension -enable-testing -g -import-underlying-module -module-cache-path /Users/groue/Library/Developer/Xcode/DerivedData/ModuleCache -serialize-debugging-options -Xcc -I/Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/GRDB-generated-files.hmap -Xcc -I/Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/GRDB-own-target-headers.hmap -Xcc -I/Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/GRDB-all-non-framework-target-headers.hmap -Xcc -ivfsoverlay -Xcc /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/all-product-headers.yaml -Xcc -iquote -Xcc /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/GRDB-project-headers.hmap -Xcc -I/Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Products/Debug/include -Xcc -I/Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/DerivedSources/x86_64 -Xcc -I/Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/DerivedSources -Xcc -DDEBUG=1 -Xcc -ivfsoverlay -Xcc /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/unextended-module-overlay.yaml -Xcc -working-directory/Users/groue/Documents/git/groue/GRDB -emit-module-doc-path /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/GRDB.swiftdoc -Onone -module-name GRDB -emit-module-path /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/GRDB.swiftmodule -emit-objc-header-path /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/GRDB-Swift.h -serialize-diagnostics-path /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/Row.dia -emit-dependencies-path /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/Row.d -num-threads 8 -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/Row.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/DatabaseValueConvertible.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/Statement.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/Fetchable.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/DatabaseQueue.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/Configuration.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/DatabaseValue.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/DatabaseMigrator.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/DatabaseDate.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/UpdateStatement.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/Database.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/SelectStatement.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/RowModel.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/QueryArguments.o -o /Users/groue/Library/Developer/Xcode/DerivedData/GRDB-frzxtxksvfwsbrhgywmipmwfjwpl/Build/Intermediates/GRDB.build/Debug/GRDBOSX.build/Objects-normal/x86_64/DatabaseError.o 
1.  While emitting SIL for 'f' at /Users/groue/Documents/git/groue/GRDB/GRDB/Fetchable.swift:228:1
2.  While verifying SIL function @_TF4GRDB1fFT_T_ for 'f' at /Users/groue/Documents/git/groue/GRDB/GRDB/Fetchable.swift:228:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment