Unimplemented IR generation feature bitcast between different types

Peter Wood in Swift
15 Aug 2014, 12:43

UPD: bug was fixed in Xcode Beta 6 

As I’ve mentioned in one of my previous posts, Eltima dev team started a new project in Swift.

What I’ve been thinking of recently, is Swift performance speed for certain things like work with arrays. So I even went to some Internet forums, like devforums.apple.com, to learn more about it. They say that when optimization is on, app’s performance greatly improves. So I decided to check the application our team is writing, and see how it is working with optimization enabled and whether the speed is the same as in Objective-C code.

Jumping slightly ahead, I must admit that miracles do not happen: though enabled, optimization did not result in increasing performance in our app.

But let’s get back to enabling optimization. When trying to compile our new app with the optimization turned on, no matter whether it is release version or debug one with -O flag, Xcode displayed the following error:

<unknown>:0: error: unimplemented IR generation feature bitcast between types of different size

Although when the optimization is turned off, the project compiles and works fine. What the heck!

I used to get this error earlier starting from beta3. That’s when I got fed up and decided to find the way out. The golden section search came to my aid, though I won’t mention what a great deal of time I spent on this. As a result I found a piece of code which initializes the error. Meet the hero of the day:

       var aDictionary = ["view":buttonsView]  

The simplest structure drove Clang crazy! I’ve checked several samples and it became clear that dictionary creation via code of [key:object] type surely leads to this error.

But finding the reason is only the first step. More important is to find a solution, because as you remember, we tried to check the app’s performance. It’s vital at this stage to decide whether method of working with big arrays should be changed or not.

The fix turned out to be rather simple. It’s getting dictionary via NSDictionary:

var aDictionary:Dictionary = ["view":buttonsView] as NSDictionary  

or

var aDictionary:Dictionary = NSDictionary(object: buttonsView, forKey: "view")  

Once certain pieces of code were changed that way, the app compiled perfectly, even with optimization enabled.

Note: If you get “unimplemented IR generation feature bitcast between types of different size” error when compiling Swift project with optimization on, it’s not obligatory caused by dictionary creation. Clang might generate this error message in some other cases as well. But the most possible reason is the one I’ve just described above.

Hope this article help you become one of the first Swift experts.