Different instance life cycle with 'inout' between Xcode16.2 and 16.3

Hello.

I made a sample code to reproduce problems.

import Foundation

class ParentLevel {
    init(someInfo: inout SomeDesc) throws {
        
    }
    
    deinit {
        print("super deinit...")
    }
}

struct SomeDesc {
    let asdf: String
}

class DecendentLevel: ParentLevel {
    private var descSome = SomeDesc(asdf: "1234")
    
    init(args: String) throws {
        try super.init(someInfo: &descSome)
    }
    deinit {
        print("self deinit...")
    }
}

somewhere in code

        let temp = try! DecendentLevel(args: "123")
        
        print(temp) 

This code works well until Xcode 16.2, but when I compiled and works with Xcode 16.3, it shows EXC_BAD_ACCESS - object released immediately.

I assumed inout, so I fixed init argument of super class to work properly.

class DecendentLevel: ParentLevel {
    private var descSome = SomeDesc(asdf: "1234")
    
    init(args: String) throws {
        var tempSome = SomeDesc(asdf: "1234")
        
        try super.init(someInfo: &tempSome)
        
        descSome = tempSome
    }
    deinit {
        print("self deinit...")
    }
}

But my question is, am I missing something like Swift changes between Swift 6.0 and 6.1?

I tried to find reasons (like release notes, forums, docs) but couldn't get the answer.

Thanks in advance.

  • Test Platform : iOS Simulator iPhone16 Pro (18.4)
  • Xcode 16.3 (16E140)

hi @mocona – i suspect the difference in behavior here is not intentional, but rather an indication of a compiler bug. the failure mode suggests a possible over-release of one of the involved objects (we can see that the generated SIL appears to have a strong_release of the ParentLevel type in the 6.1 compiler that is absent in the 6.0 compiler). i would recommend submitting a bug report when you have a chance.

for what it's worth, i was unable to reproduce the issue locally using the current 6.1 toolchain downloaded via the 'swiftly' tool; it crashed on a compiler assertion when trying to build your sample code.

1 Like

Thank you for reply, @jamieQ .

I'll submit bug report soon. :slight_smile:

And web based SIL info, too. I tried at terminal like

swiftc -emit-sil 

in my original source, but didn't try my sample code again.

Thanks again, and have a good day.

1 Like