Swift: Compiler crashes when computing fixpoint of higher-order function

Originator:rix.rob
Number:rdar://17822208 Date Originated:26-Jul-2014 09:01 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode6-Beta4 (6A267n)
Classification:Serious Bug Reproducible:Always
 
Summary:
The compiler crashes when I try to compute the fixpoint of a higher-order function. In this case, the function is a left-fold-esque enumerator a la Oleg Kiselyov’s work on converting from cursors to enumerators and back (see Notes).

I’ve reduced this as best I can.


Steps to Reproduce:
1. Compile this hideously opaque but nevertheless near-minimal test case:

func boom<T>(f: ((T, T -> T) -> T, T, (T -> T)) -> T) -> (T, T -> T) -> T {
	var recursive: ((T, T -> T) -> T)!
	return recursive
}


Expected Results:
Success and joy, quickly turning to boredom and an inevitable move to the next interesting problem.


Actual Results:
💥, and a sense of rapidly coming unglued as I try to work out how to produce this (crucial) fixpoint when I can’t give its type.


Regression:
Doesn’t crash if the second parameter of f is not a closure.
Doesn’t crash if either parameter of f is omitted.
Apparently doesn’t require that the function actually do anything; the implicitly unwrapped function is just there to give it something to return, because it doesn’t crash if it can’t compile the thing in the first place.


Notes:
Related reading on the Oleg Kiselyov’s work (which I believe was part of the lead-up to his implementations of and papers on Iteratees):

http://okmij.org/ftp/papers/LL3-collections-enumerators.txt
http://okmij.org/ftp/Haskell/fold-stream.lhs
http://okmij.org/ftp/Scheme/enumerators-callcc.html

Ultimately, I desire a better way of bridging push and pull APIs. This comes up when trying to implement multireducibles a la zip as Clojure-style Reducers, and also when trying to generalize any (preferably lazy) formulation of map/filter/mapcat to signals of more than one argument.

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!