This code would previously read off the end of the allocated metadata to fetch these values. This was usually harmless, as the value was never used in that case. However, on rare occasions the metadata would be right before unmapped memory, and this read would crash trying to access that unmapped memory.
rdar://problem/39866044
* Remove RegisterPreservingCC. It was unused.
* Remove DefaultCC from the runtime. The distinction between C_CC and DefaultCC
was unused and inconsistently applied. Separate C_CC and DefaultCC are
still present in the compiler.
* Remove function pointer indirection from runtime functions except those
that are used by Instruments. The remaining Instruments interface is
expected to change later due to function pointer liability.
* Remove swift_rt_ wrappers. Function pointers are an ABI liability that we
don't want, and there are better ways to get nonlazy binding if we need it.
The fully custom wrappers were only needed for RegisterPreservingCC and
for optimizing the Instruments function pointers.
- Create the value witness table as a separate global object instead
of concatenating it to the metadata pattern.
- Always pass the metadata to the runtime and let the runtime handle
instantiating or modifying the value witness table.
- Pass the right layout algorithm version to the runtime; currently
this is always "Swift 5".
- Create a runtime function to instantiate single-case enums.
Among other things, this makes the copying of the VWT, and any
modifications of it, explicit and in the runtime, which is more
future-proof.
So far single payload enums were implemented in terms of runtime functions which
internally emitted several calls to value witnesses.
This commit adds value witnesses to get and store the enum tag side stepping the
need for witness calls as this information is statically available in many cases
/// int (*getEnumTagSinglePayload)(const T* enum, UINT_TYPE emptyCases)
/// Given an instance of valid single payload enum with a payload of this
/// witness table's type (e.g Optional<ThisType>) , get the tag of the enum.
/// void (*storeEnumTagSinglePayload)(T* enum, INT_TYPE whichCase,
/// UINT_TYPE emptyCases)
/// Given uninitialized memory for an instance of a single payload enum with a
/// payload of this witness table's type (e.g Optional<ThisType>), store the
/// tag.
A simple 'for element in array' loop in generic code operating on a
ContigousArray of Int is ~25% faster on arm64.
rdar://31408033
Changes:
* Terminate all namespaces with the correct closing comment.
* Make sure argument names in comments match the corresponding parameter name.
* Remove redundant get() calls on smart pointers.
* Prefer using "override" or "final" instead of "virtual". Remove "virtual" where appropriate.
This affects the computed stride for fixed-sized types in IRGen as well as the stored stride in value witness tables.
The reason is to let comparisons and difference operations work for pointers to zero-sized types.
(Currently this is achieved by using Builtin.strideof_nonzero in MemoryLayout.stride, but this requires a std::max(1, stride) operation after loading the stride)
This reverts commit 893d1dc523.
This looks like a likely culprit that broke tests on the iOS Simulator:
Failing Tests (6):
Swift :: IRGen/class_resilience.swift
Swift :: IRGen/concrete_inherits_generic_base.swift
Swift :: IRGen/enum_resilience.swift
Swift :: IRGen/foreign_types.sil
Swift :: IRGen/nested_types.sil
Swift :: IRGen/struct_resilience.swift
need to be modified by the runtime, and only actually store to them
when that would change anything.
Unfortunately, Linux is considerably better than Darwin at shaking
these bugs out because Darwin will leave global data mutable after
resolving relocations in it.
This makes sure that runtime functions use proper calling conventions, get the required visibility, etc.
We annotate the most popular runtime functions in terms of how often they are invoked from Swift code.
- Almost all variants of retain/release functions are annotated to use the new calling convention.
- Some popular non-reference counting functions like swift_getGenericMetadata or swift_dynamicCast are annotated as well.
The set of runtime functions annotated to use the new calling convention should exactly match the definitions in RuntimeFunctions.def!
Set up a separate libSwiftStubs.a archive for C++ stub functionality that's needed by the standard library but not part of the core runtime interface. Seed it with the Stubs.cpp and LibcShims.cpp files, which consist only of stubs, though a few stubs are still strewn across the runtime code base.
This reverts commit r30215.
Fixes a bunch of problems on the ASAN bot.
Before:
Swift :: 1_stdlib/ErrorType.swift
Swift :: 1_stdlib/Runtime.swift
Swift :: Constraints/bridging.swift
Swift :: Constraints/diagnostics.swift
Swift :: Constraints/lvalues.swift
Swift :: DebugInfo/variables-repl.swift
Swift :: Interpreter/enum_runtime_alignment.swift
Swift :: Interpreter/nil_error_value.swift
Swift :: Interpreter/return_from_main.swift
Swift :: Misc/misc_diagnostics.swift
Swift :: Prototypes/Result.swift
Swift :: expr/expressions.swift
Swift-Unit :: runtime/SwiftRuntimeTests/MetadataTest.installCommonValueWitnesses_pod_indirect
After:
Swift :: Constraints/bridging.swift
Swift :: Constraints/diagnostics.swift
Swift :: Constraints/lvalues.swift
Swift :: Misc/misc_diagnostics.swift
Swift :: expr/expressions.swift
Swift-Unit :: runtime/SwiftRuntimeTests/MetadataTest.installCommonValueWitnesses_pod_indirect
Swift SVN r30396
Full type metadata isn't necessary to calculate the runtime layout of a dependent struct or enum; we only need the non-function data from the value witness table (size, alignment, extra inhabitant count, and POD/BT/etc. flags). This can be generated more efficiently than the type metadata for many types--if we know a specific instantiation is fixed-layout, we can regenerate the layout information, or if we know the type has the same layout as another well-known type, we can get the layout from a common value witness table. This breaks a deadlock in most (but not all) cases where a value type is recursive using classes or fixed-layout indirected structs like UnsafePointer. rdar://problem/19898165
This time, factor out the ObjC-dependent parts of the tests so they only run with ObjC interop.
Swift SVN r30266
Full type metadata isn't necessary to calculate the runtime layout of a dependent struct or enum; we only need the non-function data from the value witness table (size, alignment, extra inhabitant count, and POD/BT/etc. flags). This can be generated more efficiently than the type metadata for many types--if we know a specific instantiation is fixed-layout, we can regenerate the layout information, or if we know the type has the same layout as another well-known type, we can get the layout from a common value witness table. This breaks a deadlock in most (but not all) cases where a value type is recursive using classes or fixed-layout indirected structs like UnsafePointer. rdar://problem/19898165
Swift SVN r30243
This came up for multi-payload enums without generic parameters, eg
enum MyError {
case BusError
case TrainError(Int)
case DataLoss(String)
}
Fixes <rdar://problem/21739870>.
Swift SVN r30215
These will be used for reflection, and eventually to speed up generic
operations on single payload enums as well.
Progress on <rdar://problem/21739870>.
Swift SVN r30214
This change attempts to introduce the functionality without being too
disruptive. After we branch, I want to consolidate some of the runtime
functions and implement this functionality for multi-payload enums
as well, which requires adding new runtime metadata.
Example:
(swift) enum Color { case Red, Green, Blue(Int) }
(swift) print(Color.Red)
REPL.Color.Red
(swift) print(Color.Blue(5))
REPL.Color.Blue(5)
Implements <rdar://problem/18334936>.
Swift SVN r28430
The standard library has grown significantly, and we need a new
directory structure that clearly reflects the role of the APIs, and
allows future growth.
See stdlib/{public,internal,private}/README.txt for more information.
Swift SVN r25876