Skip to content

[AutoDiff] Emit SIL diff witnesses into original function's IRGenModule. #28237

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

Merged
merged 1 commit into from
Nov 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1072,8 +1072,13 @@ void IRGenerator::emitGlobalTopLevel() {
if (dw.isDeclaration())
continue;

// Emit into same IRGenModule as the VJP.
CurrentIGMPtr IGM = getGenModule(dw.getVJP());
// Emit into same IRGenModule as the original function.
// NOTE(TF-894): Investigate whether `getGenModule(dw.getVJP())` is
// significant/desirable; `getGenModule` seems relevant for multi-threaded
// compilation. When the differentiation transform canonicalizes all
// differentiability witnesses to have JVP/VJP functions, we can assert
// that JVP/VJP functions exist and use `getGenModule(dw.getVJP())`.
CurrentIGMPtr IGM = getGenModule(dw.getOriginalFunction());

IGM->emitSILDifferentiabilityWitness(&dw);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
struct TF_960: Differentiable {
@differentiable
func callAsFunction(_ input: Float) -> Float {
return input
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// RUN: %target-swift-frontend -c %S/Inputs/tf960-irgen-diff-witness-no-derivatives-other-module.swift %s -O -module-name main -num-threads 36
// REQUIRES: asserts

// TF-960: IRGen crash for uncanonicalized differentiability witnesses.
// This issue will become obsolete after TF-894, when the differentiation
// transform canonicalizes differentiability witnesses to have derivative
// functions and assertions are added to IRGen.

// Stack dump:
// ...
// 1. Swift version 5.1.1-dev (Swift af915c09de)
// 0 swiftc 0x0000000109acda65 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
// 1 swiftc 0x0000000109acca68 llvm::sys::RunSignalHandlers() + 248
// 2 swiftc 0x0000000109ace058 SignalHandler(int) + 264
// 3 libsystem_platform.dylib 0x00007fff728e4b5d _sigtramp + 29
// 4 libsystem_platform.dylib 0x00007ff639560230 _sigtramp + 3334977264
// 5 swiftc 0x0000000105b316bb swift::irgen::IRGenerator::emitGlobalTopLevel() + 1307
// 6 swiftc 0x0000000105bf2572 swift::performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::GlobalVariable**) + 1682