https://github.com/apple/swift
Revision e80da7b57595f0c96275ab7f6e5abeb101b374b2 authored by John McCall on 20 February 2019, 06:06:59 UTC, committed by John McCall on 26 February 2019, 20:58:24 UTC
Field offset vectors are always filled out with either zero or the static layout's offset, depending on the metadata initialization strategy.  This change means that the static layout's offset will only be non-zero for properties with a statically-known layout.  Existing runtimes doing dynamic class layout assign class properties a zero offset if the field offset vector entry is zero and the property is zero-sized.  So this effectively brings the compiler into accord with the runtime (for all newly-compiled Swift code, which will eventually be all Swift code because the current public releases of Swift 5 are not yet considered ABI-stable) and guarantees a zero value for the offset everywhere.

Since the runtime will agree with the compiler about the zero value of the offset, the compiler can continue to emit such offset variables as constant.  The exception to this rule is if the class has non-fragile ObjC ancestry, in which case the ObjC runtime (which is not aware of this special rule for empty fields) will attempt to slide it along with everything else.

Fixes rdar://48031465, in which the `FixedClassMetadataBuilder` for a class with a legacy-fixed layout was writing a non-zero offset for an empty field into the field offset vector, causing the runtime to not apply the special case and thus to compute a non-zero offset, which it then attempted to copy into the global field offset variable, which the compiler had emitted as a true-constant zero.
1 parent c94688b
History
Tip revision: e80da7b57595f0c96275ab7f6e5abeb101b374b2 authored by John McCall on 20 February 2019, 06:06:59 UTC
Always give known-empty class properties a zero offset in the static layout.
Tip revision: e80da7b
File Mode Size
.github
apinotes
benchmark
bindings
cmake
docs
include
lib
stdlib
test
tools
unittests
utils
validation-test
.clang-format -rw-r--r-- 19 bytes
.dir-locals.el -rw-r--r-- 1.4 KB
.flake8 -rw-r--r-- 1.2 KB
.gitignore -rw-r--r-- 2.0 KB
.mailmap -rw-r--r-- 8.2 KB
CHANGELOG.md -rw-r--r-- 257.9 KB
CMakeLists.txt -rw-r--r-- 40.0 KB
CODE_OF_CONDUCT.md -rw-r--r-- 3.3 KB
CODE_OWNERS.TXT -rw-r--r-- 1.7 KB
CONTRIBUTING.md -rw-r--r-- 544 bytes
LICENSE.txt -rw-r--r-- 11.5 KB
README.md -rw-r--r-- 17.6 KB

README.md

back to top