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-9849] LoadableByAddress fails to handle functions that return a closure in a tuple #52260

Closed
rxwei opened this issue Feb 3, 2019 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@rxwei
Copy link
Member

rxwei commented Feb 3, 2019

Previous ID SR-9849
Radar None
Original Reporter @rxwei
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee shajrawi (JIRA)
Priority Medium

md5: c3a6bdc89ef66210628537f725a8e2f3

relates to:

  • TF-11 [AD] partial_apply IRGen crash due to parameter type mismatch

Issue Description:

struct Large {
  var a: Int = 1
  var b: Int = 1
  var c: Int = 1
  var d: Int = 1
  var e: Int = 1
  var f: Int = 1
  var g: Int = 1
  var h: Int = 1
}

func test(_ x: Large) -> (Large, (Large) -> Large) {
  return (x, {$0})
}

Run it with

swiftc -Xllvm -sil-verify-after-pass=loadable-address test.swift

Verification failure:

SIL verification failed: return value type does not match return type of function: functionResultType == instResultType
Verifying instruction:
     %7 = tuple (%3 : $Large, %6 : $@callee_guaranteed (@in_constant Large) -> @out Large) // user: %9
->   return %7 : $(Large, @callee_guaranteed (Large) -> Large) // id: %9
In function:
// test(_:)
sil hidden @$s4testAAyAA5LargeV_A2CctACF : $@convention(thin) (@in_constant Large) -> (Large, @owned @callee_guaranteed (@in_constant Large) -> @out Large) {
// %0                                             // user: %2
bb0(%0 : $*Large):
  %1 = alloc_stack $Large                         // users: %3, %8, %2
  copy_addr [take] %0 to [initialization] %1 : $*Large // id: %2
  %3 = load %1 : $*Large                          // users: %7, %4
  debug_value %3 : $Large, let, name "x", argno 1 // id: %4
  // function_ref closure #​1 in test(_:)
  %5 = function_ref @$s4testAAyAA5LargeV_A2CctACFA2CcfU_ : $@convention(thin) (@in_constant Large) -> @out Large // user: %6
  %6 = thin_to_thick_function %5 : $@convention(thin) (@in_constant Large) -> @out Large to $@callee_guaranteed (@in_constant Large) -> @out Large // user: %7
  %7 = tuple (%3 : $Large, %6 : $@callee_guaranteed (@in_constant Large) -> @out Large) // user: %9
  dealloc_stack %1 : $*Large                      // id: %8
  return %7 : $(Large, @callee_guaranteed (Large) -> Large) // id: %9
} // end sil function '$s4testAAyAA5LargeV_A2CctACF'

Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-tensorflow-DEVELOPMENT-2019-01-21-a.xctoolchain/usr/bin/swift -frontend -c -primary-file test.swift -target x86_64-apple-darwin18.2.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -Xllvm -sil-verify-after-pass=loadable-address -color-diagnostics -module-name test -o /var/folders/lt/hxxf77kd79q3cszbw48rrd_m0000gn/T/test-b9869b.o
1.  While running pass #​38 SILModuleTransform "LoadableByAddress".
2.  While verifying SIL function "@$s4testAAyAA5LargeV_A2CctACF".
 for 'test(_:)' at test.swift:12:1
0  swift                    0x000000010d133048 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x000000010d1322c5 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x000000010d133652 SignalHandler(int) + 258
3  libsystem_platform.dylib 0x00007fff605f9b3d _sigtramp + 29
4  swift                    0x000000010df82008 (anonymous namespace)::DarwinX86AsmBackend::getCompactUnwindRegNum(unsigned int) const::CU64BitRegs + 239294
5  libsystem_c.dylib        0x00007fff604b71c9 abort + 127
6  swift                    0x000000010a3ba5b9 (anonymous namespace)::SILVerifier::_require(bool, llvm::Twine const&, std::__1::function<void ()> const&) + 633
7  swift                    0x000000010a3cee3c swift::SILInstructionVisitor<(anonymous namespace)::SILVerifier, void>::visit(swift::SILInstruction*) + 70924
8  swift                    0x000000010a3bc4ac (anonymous namespace)::SILVerifier::visitSILBasicBlock(swift::SILBasicBlock*) + 1196
9  swift                    0x000000010a3b6877 swift::SILFunction::verify(bool) const + 8007
10 swift                    0x000000010a3b9983 swift::SILModule::verify() const + 211
11 swift                    0x000000010a094a8e swift::SILPassManager::runModulePass(unsigned int) + 2078
12 swift                    0x000000010a095184 swift::SILPassManager::execute() + 692
13 swift                    0x00000001095de8fb swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 187
14 swift                    0x00000001095de352 runIRGenPreparePasses(swift::SILModule&, swift::irgen::IRGenModule&) + 162
15 swift                    0x00000001095dc8ae performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 894
16 swift                    0x00000001095dce96 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, llvm::GlobalVariable**) + 86
17 swift                    0x0000000109466f6b performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 13739
18 swift                    0x000000010946292d swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3021
19 swift                    0x00000001094146be main + 686
20 libdyld.dylib            0x00007fff6040eed9 start + 1
21 libdyld.dylib            0x0000000000000011 start + 2680099129

This is currently blocking our ongoing automatic differentiation work. We are considering disabling LoadableByAddress on certain function types in the TensorFlow branch.

@belkadan
Copy link
Contributor

belkadan commented Feb 4, 2019

cc @eeckstein

@belkadan
Copy link
Contributor

belkadan commented Feb 4, 2019

cc shajrawi (JIRA User)

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 5, 2019

Comment by Joe Shajrawi (JIRA)

#22362

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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
Projects
None yet
Development

No branches or pull requests

3 participants