Swift optimization issue in macOS Sequoia

I'm using this library for encoding / decoding RSA keys. https://github.com/Kitura/BlueRSA

It's worked fine up until macOS sequoia. The issue I'm having is the tests pass when in Debug mode, but the moment I switch to Release mode, the library no longer works.

I ruled this down the swift optimization level.

If I change the Release mode to no optimization, the library works again. Wondering where in the code this could be an issue? How would optimization break the functionality?

Answered by DTS Engineer in 813243022
How would optimization break the functionality?

That’s not uncommon. It’s easy to write code that relies on undefined behaviour — it’s harder to do in Swift than in C, but still possible — and such code can stop working if you change your optimisation settings.

It’s also possible that this is a bug in the compiler.

But in my experience it’s never aliens rarely a compiler bug. Looking at the code you referenced, it’s full of unsafe pointers, and those definitely make it easier for undefined behaviour to creep in.

You have a bunch of choices here:

  • You could debug the code to see why it’s failing. That’ll tell you whether it’s a bug in the code or a bug in the compiler.

  • You could find a different library to do this work.

  • You could stop using RSA. OK, OK, I know that’s not realistic, but a geek can dream!

  • You could ship the unoptimised library.

Of these, the only one I don’t like is the last one. As the old addage goes: Bugs that mysteriously disappear can mysteriously reappear.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

How would optimization break the functionality?

That’s not uncommon. It’s easy to write code that relies on undefined behaviour — it’s harder to do in Swift than in C, but still possible — and such code can stop working if you change your optimisation settings.

It’s also possible that this is a bug in the compiler.

But in my experience it’s never aliens rarely a compiler bug. Looking at the code you referenced, it’s full of unsafe pointers, and those definitely make it easier for undefined behaviour to creep in.

You have a bunch of choices here:

  • You could debug the code to see why it’s failing. That’ll tell you whether it’s a bug in the code or a bug in the compiler.

  • You could find a different library to do this work.

  • You could stop using RSA. OK, OK, I know that’s not realistic, but a geek can dream!

  • You could ship the unoptimised library.

Of these, the only one I don’t like is the last one. As the old addage goes: Bugs that mysteriously disappear can mysteriously reappear.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Swift optimization issue in macOS Sequoia
 
 
Q