[swift] Inner functions cannot have recursive calls
| Originator: | chriseidhof | ||
| Number: | rdar://17746344 | Date Originated: | 21-Jul-2014 |
| Status: | Open | Resolved: | |
| Product: | Product Version: | ||
| Classification: | Reproducible: |
Summary:
When creating an inner function (a function inside a function) the inner function cannot recurse.
Steps to Reproduce:
The simplest (although non-sensical) function I could come up with:
func hello() {
func next() {
return next()
}
}
The compiler fails to generate code for this. Also, consider the slightly more advanced function:
func hello2() {
var i = 0
func next(x: Int) -> Int {
i+=1
return next(i)
}
}
Expected Results:
I expected this to compile (and run infinitely)
Actual Results:
In the case above, the compiler fails with:
Instruction does not dominate all uses!
%6 = bitcast %SS* %0 to %swift.opaque*, !dbg !74
%2 = bitcast %swift.opaque* %6 to i8*, !dbg !71
LLVM ERROR: Broken function found, compilation aborted!
For hello2, the compiler fails with a different error message:
0 swift 0x0000000101100de8 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x00000001011012d4 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff885995aa _sigtramp + 26
3 libsystem_platform.dylib 0x00007ff030b86010 _sigtramp + 2824784512
4 swift 0x00000001004c0e83 swift::irgen::CallEmission::emitCallSite(bool) + 115
5 swift 0x00000001004c0c81 swift::irgen::CallEmission::emitToUnmappedExplosion(swift::irgen::Explosion&) + 33
6 swift 0x00000001004c1619 swift::irgen::CallEmission::emitToExplosion(swift::irgen::Explosion&) + 505
7 swift 0x0000000100542835 swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 51237
8 swift 0x0000000100535800 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8896
9 swift 0x00000001004b6f57 swift::irgen::IRGenModule::emitLazyDefinitions() + 199
10 swift 0x000000010052261d performIRGeneration(swift::IRGenOptions&, swift::Module*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1997
11 swift 0x0000000100522f23 swift::performIRGeneration(swift::IRGenOptions&, swift::SourceFile&, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, unsigned int) + 51
12 swift 0x0000000100494b8e frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 4958
13 swift 0x000000010049381d main + 1533
14 libdyld.dylib 0x00007fff90e4e5fd start + 1
Version:
Xcode6-Beta3
Notes:
Configuration:
Attachments:
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!
This is a known bug.
(People often encourage to file duplicates as a way of casting votes, but in case of Swift in particular, Swift Lattner explicitly asked not to. So don't.)