swiftlang / swift

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

Compiler crash when building Swift using `std::function` with `-enable-experimental-cxx-interop` #63944

Open jpsim opened 1 year ago

jpsim commented 1 year ago

Description

When building Swift code with a recent toolchain that uses an std::function with -enable-experimental-cxx-interop, the compiler crashes, possibly running out of memory.

Steps to reproduce

C++:

#include <functional>

using Func = std::function<int(int)>;
inline int invokeWith42(Func fn) { return fn(42); }

Swift:

print(invokeWith42(Func { $0 + 1 })) // as a block
let cClosure: @convention(c) (Int) -> Int = { $0 + 1 }
print(invokeWith42(Func(cClosure))) // as a c function pointer

Full project:

swift-cxx-interop-demo.zip

Full logs:

$ /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2023-02-23-a.xctoolchain/usr/bin/swift run
Building for debugging...
error: compile command failed due to signal 6 (use -v to see invocation)
Dependent types cannot show up in debug information
UNREACHABLE executed at /Users/ec2-user/jenkins/workspace/oss-swift-package-macos/llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp:3438!
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2023-02-23-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /path/to/src/swift-cxx-interop-demo/Sources/CxxInterop/main.swift -emit-dependencies-path /path/to/src/swift-cxx-interop-demo/.build/arm64-apple-macosx/debug/CxxInterop.build/main.d -emit-reference-dependencies-path /path/to/src/swift-cxx-interop-demo/.build/arm64-apple-macosx/debug/CxxInterop.build/main.swiftdeps -target arm64-apple-macosx13.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -enable-experimental-cxx-interop -sdk /Applications/Xcode-14.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -I /path/to/src/swift-cxx-interop-demo/.build/arm64-apple-macosx/debug -I Sources/CxxTest -I /Applications/Xcode-14.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode-14.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -module-cache-path /path/to/src/swift-cxx-interop-demo/.build/arm64-apple-macosx/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2023-02-23-a.xctoolchain/usr/bin/swift-driver -entry-point-function-name CxxInterop_main -empty-abi-descriptor -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2023-02-23-a.xctoolchain/usr/lib/swift/host/plugins -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2023-02-23-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=/path/to/src/swift-cxx-interop-demo/.build/arm64-apple-macosx/debug/CxxTest.build/module.modulemap -Xcc -I -Xcc /path/to/src/swift-cxx-interop-demo/Sources/CxxTest/include -module-name CxxInterop -target-sdk-version 13.1 -target-sdk-name macosx13.1 -o /path/to/src/swift-cxx-interop-demo/.build/arm64-apple-macosx/debug/CxxInterop.build/main.swift.o -index-store-path /path/to/src/swift-cxx-interop-demo/.build/arm64-apple-macosx/debug/index/store -index-system-modules
1.  Apple Swift version 5.9-dev (LLVM 9e0f849c04f21c4, Swift 83888d305ede1f5)
2.  Compiling with the current language version
3.  While evaluating request IRGenRequest(IR Generation for file "/path/to/src/swift-cxx-interop-demo/Sources/CxxInterop/main.swift")
4.  /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2023-02-23-a.xctoolchain/usr/bin/../include/c++/v1/__functional/function.h:1000:5: Generating code for declaration 'std::function<int (int)>::function'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000109178be4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109177e68 llvm::sys::RunSignalHandlers() + 128
2  swift-frontend           0x0000000109179224 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x000000019aabc2a4 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000019aa8dcec pthread_kill + 288
5  libsystem_c.dylib        0x000000019a9c62c8 abort + 180
6  swift-frontend           0x00000001090d9df0 llvm::install_out_of_memory_new_handler() + 0
7  swift-frontend           0x0000000106bc49d0 clang::CodeGen::CGDebugInfo::CreateTypeNode(clang::QualType, llvm::DIFile*) + 1112
8  swift-frontend           0x0000000106bb6af0 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) + 148
9  swift-frontend           0x0000000106bbac0c clang::CodeGen::CGDebugInfo::CreateType(clang::TemplateSpecializationType const*, llvm::DIFile*) + 88
10 swift-frontend           0x0000000106bb6af0 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) + 148
11 swift-frontend           0x0000000106bbdf54 clang::CodeGen::CGDebugInfo::CollectTemplateParams(llvm::Optional<clang::CodeGen::CGDebugInfo::TemplateArgs>, llvm::DIFile*) + 336
12 swift-frontend           0x0000000106bc5248 clang::CodeGen::CGDebugInfo::collectFunctionDeclProps(clang::GlobalDecl, llvm::DIFile*, llvm::StringRef&, llvm::StringRef&, llvm::DIScope*&, llvm::MDTupleTypedArrayWrapper<llvm::DINode>&, llvm::DINode::DIFlags&) + 732
13 swift-frontend           0x0000000106bc7600 clang::CodeGen::CGDebugInfo::emitFunctionStart(clang::GlobalDecl, clang::SourceLocation, clang::SourceLocation, clang::QualType, llvm::Function*, bool) + 876
14 swift-frontend           0x0000000106d7013c clang::CodeGen::CodeGenFunction::StartFunction(clang::GlobalDecl, clang::QualType, llvm::Function*, clang::CodeGen::CGFunctionInfo const&, clang::CodeGen::FunctionArgList const&, clang::SourceLocation, clang::SourceLocation) + 13760
15 swift-frontend           0x0000000106d729a0 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) + 752
16 swift-frontend           0x0000000106b86a64 clang::CodeGen::CodeGenModule::codegenCXXStructor(clang::GlobalDecl) + 284
17 swift-frontend           0x0000000106df016c (anonymous namespace)::ItaniumCXXABI::emitCXXStructor(clang::GlobalDecl) + 496
18 swift-frontend           0x0000000106d876c0 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) + 388
19 swift-frontend           0x0000000106d7e3e4 clang::CodeGen::CodeGenModule::EmitDeferred() + 456
20 swift-frontend           0x0000000106d7cca0 clang::CodeGen::CodeGenModule::Release() + 76
21 swift-frontend           0x0000000106e09574 (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) + 80
22 swift-frontend           0x0000000104c44c20 swift::irgen::IRGenModule::finalize() + 328
23 swift-frontend           0x0000000104bf8324 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 2284
24 swift-frontend           0x0000000104c47c94 swift::GeneratedModule swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 196
25 swift-frontend           0x0000000104c07c4c llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 372
26 swift-frontend           0x0000000104bfa400 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 212
27 swift-frontend           0x000000010481afd0 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1664
28 swift-frontend           0x000000010481a3a8 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 576
29 swift-frontend           0x00000001048293b8 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 160
30 swift-frontend           0x000000010481c0c0 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3240
31 swift-frontend           0x000000010467dd30 swift::mainEntry(int, char const**) + 3304
32 dyld                     0x000000019a763e50 start + 2544

Expected behavior

Should compile successfully.

Environment

Additional context

https://github.com/apple/swift/pull/63893

zoecarver commented 1 year ago

Yeah, I can reproduce this locally. This crash happens when we are emitting debug info which the Swift Package does by default. If you need a quick work around, I verified that disabling debug info in the Swift package fixes the issue, however, we'll obviously still want to fix this bug properly.

jpsim commented 1 year ago

ok so I think I can bypass it by compiling without emitting debug info, but then I get the following linker errors:

ld: warning: Could not find or use auto-linked library 'swiftCxxStdlib'
ld: warning: Could not find or use auto-linked library 'swiftCxx'
ld: warning: Could not find or use auto-linked library 'swiftstd'
Undefined symbols for architecture arm64:
  "std::__1::__function::__func<long (long) block_pointer __strong, std::__1::allocator<std::__1::allocator>, int (int)>::~__func()", referenced from:
      vtable for std::__1::__function::__func<long (long) block_pointer __strong, std::__1::allocator<std::__1::allocator>, int (int)> in libswift-cxx-interop-demo.lo(main.swift.o)
  "std::__1::__function::__func<long (long) block_pointer __strong, std::__1::allocator<std::__1::allocator>, int (int)>::~__func()", referenced from:
      vtable for std::__1::__function::__func<long (long) block_pointer __strong, std::__1::allocator<std::__1::allocator>, int (int)> in libswift-cxx-interop-demo.lo(main.swift.o)
ld: symbol(s) not found for architecture arm64

Should I file a separate issue to track this?

zoecarver commented 1 year ago

That's OK. We are tracking this. That's what's blocking the PR. Basically, we need to tell clang that we are actually using these symbols. We've found a couple edge cases here, hopefully this is one of the last ones. To work around this, you can manually tell clang that those symbols are required by explicitly referencing them in a .cpp file. For example, adding a .cpp file with something along these lines should fix the first linker error:

using Func = std::function<int(int)>;
int add(int a) { }
void test() {
  Func test = add;
  test(42);
}

Then you can do something similar for the second one (wrt blocks).

jpsim commented 1 year ago

Hmm, still seeing linker failures with this:

// CxxTest.hpp
#ifndef CxxTest_hpp
#define CxxTest_hpp

#include <functional>

using Func = std::function<int(int)>;
inline int invokeWith42(Func fn) { return fn(42); }
void logCXXGreeting();

#endif

// CxxTest.cpp
#include "CxxTest.hpp"
#include <iostream>

void logCXXGreeting() {
  std::cout << "Hello from C++!\n";
}

int add(int a) { return a; }
void test() {
  Func test = add;
  test(42);
}
// main.swift
import CxxTest
import CxxStdlib

logCXXGreeting()

print(invokeWith42(Func { $0 + 1 })) // as a block
let cClosure: @convention(c) (Int) -> Int = { $0 + 1 }
print(invokeWith42(Func(cClosure))) // as a c function pointer

ld: warning: Could not find or use auto-linked library 'swiftCxxStdlib'
ld: warning: Could not find or use auto-linked library 'swiftCxx'
ld: warning: Could not find or use auto-linked library 'swiftstd'
Undefined symbols for architecture arm64:
  "std::__1::__function::__func<long (long) block_pointer __strong, std::__1::allocator<std::__1::allocator>, int (int)>::~__func()", referenced from:
      vtable for std::__1::__function::__func<long (long) block_pointer __strong, std::__1::allocator<std::__1::allocator>, int (int)> in libswift-cxx-interop-demo.lo(main.swift.o)
  "std::__1::__function::__func<long (long) block_pointer __strong, std::__1::allocator<std::__1::allocator>, int (int)>::~__func()", referenced from:
      vtable for std::__1::__function::__func<long (long) block_pointer __strong, std::__1::allocator<std::__1::allocator>, int (int)> in libswift-cxx-interop-demo.lo(main.swift.o)
ld: symbol(s) not found for architecture arm64
jpsim commented 10 months ago

I wanted to see if this had improved since my initial report, so I tried the initial example with the latest Swift toolchain on macOS and now getting these errors:

/Users/jp/src/swift-63944/Sources/swift-63944/main.swift:3:20: error: cannot convert value of type 'Int32' to expected argument type 'Func' (aka 'std.__1.function<>')
print(invokeWith42(Func { $0 + 1 })) // as a block
                   ^
Assertion failed: (Val && "isa<> used on a null pointer"), function doit, file Casting.h, line 109.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2023-10-30-a.xctoolchain/usr/bin/swift-frontend -frontend -emit-module -experimental-skip-non-inlinable-function-bodies-without-types /Users/jp/src/swift-63944/Sources/swift-63944/main.swift -target arm64-apple-macos10.13 -Xllvm -aarch64-use-tbi -enable-objc-interop -cxx-interoperability-mode=default -sdk /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -I /Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Products/Debug -I /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Products/Debug/PackageFrameworks -F /Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Products/Debug -F /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -no-color-diagnostics -enable-testing -g -module-cache-path /Users/jp/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -external-plugin-path /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins#/Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins#/Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-plugin-server -serialize-debugging-options -package-name swift_63944 -const-gather-protocols-file /Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Intermediates.noindex/swift-63944.build/Debug/swift-63944.build/Objects-normal/arm64/swift-63944_const_extract_protocols.json -empty-abi-descriptor -validate-clang-modules-once -clang-build-session-file /Users/jp/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/jp/src/swift-63944 -resource-dir /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2023-10-30-a.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -fmodule-map-file=/Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Intermediates.noindex/GeneratedModuleMaps/swift63944CXX.modulemap -Xcc -I/Users/jp/src/swift-63944/Sources/swift63944CXX/include -Xcc -I/Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Products/Debug/include -Xcc -I/Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Intermediates.noindex/swift-63944.build/Debug/swift-63944.build/DerivedSources-normal/arm64 -Xcc -I/Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Intermediates.noindex/swift-63944.build/Debug/swift-63944.build/DerivedSources/arm64 -Xcc -I/Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Intermediates.noindex/swift-63944.build/Debug/swift-63944.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -module-name swift_63944 -disable-clang-spi -target-sdk-version 14.0 -target-sdk-name macosx14.0 -external-plugin-path /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/lib/swift/host/plugins#/Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/local/lib/swift/host/plugins#/Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode-15.0.0-Release.Candidate.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2023-10-30-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2023-10-30-a.xctoolchain/usr/local/lib/swift/host/plugins -emit-module-doc-path /Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Intermediates.noindex/swift-63944.build/Debug/swift-63944.build/Objects-normal/arm64/swift_63944.swiftdoc -emit-module-source-info-path /Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Intermediates.noindex/swift-63944.build/Debug/swift-63944.build/Objects-normal/arm64/swift_63944.swiftsourceinfo -serialize-diagnostics-path /Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Intermediates.noindex/swift-63944.build/Debug/swift-63944.build/Objects-normal/arm64/swift-63944-master-emit-module.dia -emit-dependencies-path /Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Intermediates.noindex/swift-63944.build/Debug/swift-63944.build/Objects-normal/arm64/swift-63944-master-emit-module.d -o /Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Intermediates.noindex/swift-63944.build/Debug/swift-63944.build/Objects-normal/arm64/swift_63944.swiftmodule -emit-abi-descriptor-path /Users/jp/Library/Developer/Xcode/DerivedData/swift-63944-bwuaupwfpjjjqqacevhstopbaolb/Build/Intermediates.noindex/swift-63944.build/Debug/swift-63944.build/Objects-normal/arm64/swift_63944.abi.json
1.  Apple Swift version 5.11-dev (LLVM e22c96610989bdb, Swift bd372c2d6861ce3)
2.  Compiling with the current language version
3.  While evaluating request TypeCheckSourceFileRequest(source_file "/Users/jp/src/swift-63944/Sources/swift-63944/main.swift")
4.  While type-checking statement at [/Users/jp/src/swift-63944/Sources/swift-63944/main.swift:3:1 - line:3:36] RangeText="print(invokeWith42(Func { $0 + 1 })"
5.  While type-checking expression at [/Users/jp/src/swift-63944/Sources/swift-63944/main.swift:3:1 - line:3:36] RangeText="print(invokeWith42(Func { $0 + 1 })"
6.  While type-checking-target starting at /Users/jp/src/swift-63944/Sources/swift-63944/main.swift:3:1
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000107708e08 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000107707564 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000107709458 SignalHandler(int) + 304
3  libsystem_platform.dylib 0x00000001874dea24 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001874afc28 pthread_kill + 288
5  libsystem_c.dylib        0x00000001873bdae8 abort + 180
6  libsystem_c.dylib        0x00000001873bce44 err + 0
7  swift-frontend           0x0000000107abef1c swift::constraints::Solution::getFunctionArgApplyInfo(swift::constraints::ConstraintLocator*) const (.cold.5) + 0
8  swift-frontend           0x00000001033607a4 swift::constraints::Solution::getFunctionArgApplyInfo(swift::constraints::ConstraintLocator*) const + 536
9  swift-frontend           0x00000001032e3bf0 swift::constraints::AllowArgumentMismatch::diagnose(swift::constraints::Solution const&, bool) const + 68
10 swift-frontend           0x000000010321c930 swift::constraints::ConstraintSystem::applySolutionFixes(swift::constraints::Solution const&) + 1572
11 swift-frontend           0x000000010321d070 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SyntacticElementTarget) + 96
12 swift-frontend           0x000000010342f554 swift::TypeChecker::typeCheckTarget(swift::constraints::SyntacticElementTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 396
13 swift-frontend           0x000000010342f370 swift::TypeChecker::typeCheckExpression(swift::constraints::SyntacticElementTarget&, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 184
14 swift-frontend           0x000000010342f230 swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, swift::constraints::ContextualTypeInfo, swift::OptionSet<swift::TypeCheckExprFlags, unsigned int>) + 92
15 swift-frontend           0x000000010350e040 (anonymous namespace)::StmtChecker::typeCheckASTNode(swift::ASTNode&) + 272
16 swift-frontend           0x00000001035111d8 swift::ASTVisitor<(anonymous namespace)::StmtChecker, void, swift::Stmt*, void, void, void, void>::visit(swift::Stmt*) + 328
17 swift-frontend           0x000000010350f7dc bool (anonymous namespace)::StmtChecker::typeCheckStmt<swift::BraceStmt>(swift::BraceStmt*&) + 136
18 swift-frontend           0x000000010350f864 swift::TypeChecker::typeCheckTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 52
19 swift-frontend           0x0000000103548fa0 swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 216
20 swift-frontend           0x000000010354b330 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 388
21 swift-frontend           0x000000010354b0c0 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 84
22 swift-frontend           0x0000000103548de0 swift::TypeCheckSourceFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckSourceFileRequest>(swift::Evaluator&, swift::TypeCheckSourceFileRequest, swift::TypeCheckSourceFileRequest::OutputType) + 44
23 swift-frontend           0x000000010259210c bool llvm::function_ref<bool (swift::SourceFile&)>::callback_fn<swift::CompilerInstance::performSema()::$_7>(long, swift::SourceFile&) + 16
24 swift-frontend           0x000000010258d84c swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<bool (swift::SourceFile&)>) + 160
25 swift-frontend           0x000000010258d78c swift::CompilerInstance::performSema() + 76
26 swift-frontend           0x00000001023adfc4 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 60
27 swift-frontend           0x00000001023a16bc performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 704
28 swift-frontend           0x00000001023a0670 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2628
29 swift-frontend           0x00000001021b2448 swift::mainEntry(int, char const**) + 2192
30 dyld                     0x0000000187157f28 start + 2236

The most relevant bit appears to be this assertion failure:

Assertion failed: (Val && "isa<> used on a null pointer"), function doit, file Casting.h, line 109

Appears to be one of these: https://github.com/apple/swift/blob/51580e3d5508ece210530ef99666f3776b85142c/stdlib/include/llvm/Support/Casting.h#L81-L115