Swift 2.0b4: swiftc crashes compiling function taking function & closing over function it (re)assigns

Originator:rix.rob
Number:rdar://22138918 Date Originated:04-Aug-2015 04:20 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (7A165t)
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
Provide a descriptive summary of the issue.

Steps to Reproduce:
This code:
func s() {
	var f: () -> () = {}
	let _: (() -> ()) -> () = { g in
		let _f = f
		f = {
			_f()
			g()
		}
	}
}

Expected Results:
shouldn’t crash swiftc

Actual Results:
but totally does:
rob@Resonance ~/Desktop> swiftc boom.swift; and ./boom
argument type mismatch!
  argument:   %1 = argument of bb0 : $@box @callee_owned () -> () // user: %13
  expected: $@box (() -> ())
SIL verification failed: entry point argument types do not match function type: std::equal(entry->bbarg_begin(), entry->bbarg_end(), ti->getParameterSILTypes().begin(), [&](SILArgument *bbarg, SILType ty) { auto mappedTy = F.mapTypeIntoContext(ty); if (bbarg->getType() != mappedTy) { llvm::errs() << "argument type mismatch!\n"; llvm::errs() << "  argument: "; bbarg->dump(); llvm::errs() << "  expected: "; mappedTy.dump(); return false; } return true; })
In function:
// boom.(s () -> ()).(closure #2)
sil shared @_TFF4boom1sFT_T_U0_FFT_T_T_ : $@convention(thin) (@owned @callee_owned () -> (), @owned @box (() -> ()), @inout @callee_owned () -> ()) -> () {
bb0(%0 : $@callee_owned () -> (), %1 : $@box @callee_owned () -> (), %2 : $*@callee_owned () -> ()):
  debug_value %0 : $@callee_owned () -> ()  // let g // id: %3
  %4 = load %2 : $*@callee_owned () -> ()         // users: %5, %6, %8, %10, %12
  strong_retain %4 : $@callee_owned () -> ()      // id: %5
  debug_value %4 : $@callee_owned () -> ()  // let _f // id: %6
  // function_ref boom.(s () -> ()).(closure #2).(closure #1)
  %7 = function_ref @_TFFF4boom1sFT_T_U0_FFT_T_T_U_FT_T_ : $@convention(thin) (@owned @callee_owned () -> (), @owned @callee_owned () -> ()) -> () // user: %10
  strong_retain %4 : $@callee_owned () -> ()      // id: %8
  strong_retain %0 : $@callee_owned () -> ()      // id: %9
  %10 = partial_apply %7(%4, %0) : $@convention(thin) (@owned @callee_owned () -> (), @owned @callee_owned () -> ()) -> () // user: %11
  assign %10 to %2 : $*@callee_owned () -> ()     // id: %11
  strong_release %4 : $@callee_owned () -> ()     // id: %12
  strong_release %1 : $@box @callee_owned () -> () // id: %13
  strong_release %0 : $@callee_owned () -> ()     // id: %14
  %15 = tuple ()                                  // user: %16
  return %15 : $()                                // id: %16
}

0  swift                    0x000000010ebbeb8b llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x000000010ebbf2cb SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff85ef3eaa _sigtramp + 26
3  swift                    0x000000010f1bda87 FirstTarget + 61919
4  swift                    0x000000010ebbf0c6 abort + 22
5  swift                    0x000000010cd6b239 (anonymous namespace)::SILVerifier::_require(bool, llvm::Twine const&, std::__1::function<void ()> const&) + 425
6  swift                    0x000000010cd682d0 swift::SILFunction::verify() const + 2336
7  swift                    0x000000010cda9c70 swift::Lowering::SILGenModule::emitClosure(swift::AbstractClosureExpr*) + 256
8  swift                    0x000000010ce000eb (anonymous namespace)::RValueEmitter::visitAbstractClosureExpr(swift::AbstractClosureExpr*, swift::Lowering::SGFContext) + 107
9  swift                    0x000000010cdf5f47 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 151
10 swift                    0x000000010cdef66f swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*) + 303
11 swift                    0x000000010cddfd08 swift::Lowering::SILGenFunction::visitPatternBindingDecl(swift::PatternBindingDecl*) + 232
12 swift                    0x000000010ce4326a swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 362
13 swift                    0x000000010ce430f5 swift::Lowering::SILGenFunction::emitStmt(swift::Stmt*) + 21
14 swift                    0x000000010ce0a496 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 390
15 swift                    0x000000010cda8131 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 513
16 swift                    0x000000010cdb001f swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 255
17 swift                    0x000000010cdac14b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 587
18 swift                    0x000000010cdacfdf swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 975
19 swift                    0x000000010cdad43b swift::performSILGeneration(swift::FileUnit&, swift::SILOptions&, llvm::Optional<unsigned int>, bool) + 123
20 swift                    0x000000010cba4c61 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 9569
21 swift                    0x000000010cba24e3 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2627
22 swift                    0x000000010cb9e5af main + 2015
23 libdyld.dylib            0x00007fff942115ad start + 1
Stack dump:
0.	Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file boom.swift -target x86_64-apple-darwin15.0.0 -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -color-diagnostics -module-name boom -o /var/folders/9y/f7n4rvx901nctm_5d16c1wm40000gn/T/boom-6bb0c8.o 
1.	While emitting SIL for 's' at boom.swift:1:1
2.	While silgen closureexpr SIL function @_TFF4boom1sFT_T_U0_FFT_T_T_ for expression at [boom.swift:3:28 - line:9:2] RangeText="{ g in
		let _f = f
		f = {
			_f()
			g()
		}
	}"
3.	While verifying SIL function @_TFF4boom1sFT_T_U0_FFT_T_T_ for expression at [boom.swift:3:28 - line:9:2] RangeText="{ g in
		let _f = f
		f = {
			_f()
			g()
		}
	}"
<unknown>:0: error: unable to execute command: Illegal instruction: 4
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)


Regression:
N/A

Notes:
N/A

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!