mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
We would miscompile in mixed-language-version projects when a Swift class was compiled for one language version, while using Objective-C-imported types that are only available to that version, and then imported into a Swift module with a different language version that wasn't able to see all of the properties because of incompatible imported types. This manifested in a number of ways: - We assumed we could re-derive the constant field offsets of the class's ivars from the layout, which is wrong if properties are missing, causing accesses to final properties or subclass properties to go to the wrong offsets. - We assumed we could re-derive the instance size and alignment of a class instance in total, causing code to allocate the wrong amount of memory. - We neglected to account for the space that stored properties take up in the field offset vector of the class object, causing us to load vtable entries for following subclass methods from the wrong offsets. Eventually, resilience should reduce our exposure to these kinds of problems. As an incremental step in the right direction, when we look at a class from another module in IRGen, treat it as always variably-sized, so we don't try to hardcode offsets, size, or alignment of its instances. When we import a class, and we're unable to import a stored property, leave behind a new kind of MissingMemberDecl that records the number of field offset vector slots it will take up, so that we lay out subclass objects and compute vtable offsets correctly. Fixes rdar://problem/35330067. A side effect of this is that the RemoteAST library is no longer able to provide fixed field offsets for class ivars. This doesn't appear to impact the lldb test suite, and they will ultimately need to use more abstract access patterns to get ivar offsets from resilient classes (if they aren't already), so I just removed the RemoteAST test cases that tested for class field offsets for now.
15 lines
265 B
Swift
15 lines
265 B
Swift
import Foundation
|
|
import ObjCStuff
|
|
|
|
open class ButtHolder {
|
|
public final var x: Int
|
|
public final var y: [OJCCloud.Butt: String]
|
|
public final var z: String
|
|
|
|
open func virtual() {
|
|
print("\(x) \(y) \(z)")
|
|
}
|
|
|
|
public init() { x = 0; y = [:]; z = "" }
|
|
}
|