What's Dead & Exploded in Swift's Exception Stack

What's Dead & Exploded in Swift's exception stack?

What does it mean?

The Swift compiler marks function arguments for a number of reasons, mostly related to internal optimizations. For your question, we'll focus on the mangler, as that's what's contributing to your pretty stack trace, and the Node Printer. As of the time of this post, the function specialization mangler has 6 marks it can apply to an argument:

  • Dead

    The argument is unused in the function body and can be removed in a dead argument elimination pass.

  • Closure

    The argument is a closure and may require further mangling/demangling.

  • Constant

    The argument is a constant.

  • Owned to Guaranteed

    A caller-owned argument transfers ownership to the callee. The argument thus has a strong reference associated with it [the caller] and is guaranteed to live through the call, so the compiler allows the caller to elide the transfer and instead aggregate retains itself.

  • SROA

    A Scalar Replacement of Aggregates pass should optimize this argument.

  • In Out To Value

    The parameter was marked inout but the callee doesn't actually mutate it.

The AST Node Printer adds one more mark

  • Exploded

    The value comes with an explosion schema that has been realized when the call was made.

For all intents and purposes we only care about Dead, Owned to Guaranteed, and Exploded.

The only one that may still seem mystifying is Exploded. An Explosion is an optimization construct the Swift compiler uses to determine a strategy to unpack values from small structs and enums into registers. Thus, when the Node Printer says a value is Exploded, what it means it has already unpacked the value into registers before the call.

does it matter for debugging purposes?

Nope.

Swift owned to guaranteed

In my opinion, you are looking at wrong places. When I am looking at the logs, what I see is:

  1. A click on a button
  2. onButtonTableViewCellClick
  3. Obj-C to Swift internals (you can learn more in What's Dead & Exploded in Swift's exception stack?)
  4. Indexing String by Int (see String.subscript.getter (Swift.Int) -> String)

We can be sure that the crash happened somewhere here:

return String(Array(self.characters)[i])

I think we can rule out nil because that would cause an earlier crash. Most likely you have an character index out of bounds problem. That means i is either negative or higher than length - 1 (maybe you are indexing an empty text?)

Unfortunately, the important code is in onButtonTableViewCellClick and you haven't posted that.

I have error in swift loop]

You can use the where clause!

for z in 0...25 where z % 5 == 0 {
print(z)
}

It basically filters out z values and it only leaves the z values that are divisible by 5, which is what you want.

This is wayyyy more swifty than the C-style for loop.

Another way to do this is with stride:

for i in stride(from: 0, through: 25, by: 5) {
print(i)
}

Swift protocol with associatedtype error

You have a couple of options.

Firstly you can use a specific type of FooDelegate, like SomeFoo:

class Bar {
//In Bar instance runtime ,it will call delegate to do something...
var delegate: SomeFoo!
}

Or you can make Bar generic and define what type of Item the delegate needs:

class Bar<F> where F: FooDelegate, F.Item == Int {
//In Bar instance runtime ,it will call delegate to do something...
var delegate: F!
}

Full Project Swift Compile Error Immediately After Successful Run with a New Project

You are getting the use of undeclared type ViewController error because there is no type called ViewController. It should be UIViewController.

Many of the other errors depend on this very fact - Since ViewController is not a type within the Cocoa Touch Framework, the class is non-existent and thus does not have any of those properties that you et in the other errors.

Of course, without seeing any of your code it is hard to locate the culprit, but the fact that you are declaring your viewController as being of type ViewController instead of UIViewController is probably a big part of it.



Related Topics



Leave a reply



Submit