Commit Graph

643 Commits

Author SHA1 Message Date
Kuba Mracek
14fad63602 Refactor swift_allocateGenericClassMetadata to improve readability. NFC. 2018-01-02 10:33:18 -08:00
swift-ci
1e8445fbe4 Merge pull request #13570 from rjmccall/metadata-init-abi 2017-12-20 22:17:43 -08:00
John McCall
9bbbe2c418 Update the metadata-initialization ABI:
- 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.
2017-12-21 00:26:37 -05:00
Joe Groff
05fc210be6 Runtime: Compact the uniquing header for foreign metadata records.
We can reduce the uniquing header from 3–4 pointer-sized words down to 1–2 32-bit words + one pointer:

- The initialization function (when present) and name are always emitted into the same binary image, so we can use relative references to shrink these down to 32-bit fields.
- We don't ever simultaneously need the initialization flags and the initialized uniqued pointer. (Keeping the "initialization function" flag bit theoretically lets us turn a "consume" load into a "relaxed" load, but that makes no practical difference on most contemporary architectures.) 12 flag bits Ought To Be Enough For Anyone and lets us reliably tell a valid pointer from a flag set, so overlap the initialization flags with the eventual invasive cache value.

The invasive cache is left inline, since we've decided we're not going to make the rest of type metadata records ever be true-const, so they'll already be sitting on a dirty page. A dynamic linker that was sufficiently Swift-optimized to precalculate the other load-time-initialized entries in metadata could likely precompute the invasive cache value as well.

rdar://problem/22527141
2017-12-20 14:06:01 -08:00
Joe Groff
e353f76db0 Merge pull request #13373 from jckarter/ntd-trailing-objects
Runtime: Refactor NominalTypeDescriptor to use TrailingObjects.
2017-12-11 20:04:00 -08:00
Joe Groff
fe192c6daf Runtime: Refactor NominalTypeDescriptor to use TrailingObjects.
NFC intended. The layout of trailing matter here is getting fairly complex, so it's good to use LLVM's existing library code to keep track of it. We use a fork of llvm's TrailingObjects.h header so that future changes to LLVM don't disturb the ABI of Swift runtime objects that use the template.
2017-12-11 16:26:29 -08:00
Slava Pestov
ffabf60118 IRGen: Hollow out generic class templates
Don't emit placeholders for field offsets and vtable entries,
since they were always null. Instead, calculate the final size
of class metadata at runtime using the size of the superclass
metadata and the number of immediate members, and only copy
this prefix from the template to the instantiated metadata,
zero-filling the rest.

For this to work with non-generic resilient classes and
non-generic subclasses of generic classes, we need a new
runtime entry point to relocate non-generic class metadata,
calculating its size at runtime using the same strategy.
2017-12-08 13:50:56 -08:00
Thomas Roughton
c5bf2ec553 [runtime] Remove TwoWordPair and use the Swift calling convention instead. (#13299) 2017-12-07 19:27:24 -08:00
Slava Pestov
0fa7440e51 IRGen/Runtime: Remove old class metadata relocation mechanism 2017-12-07 14:21:58 -08:00
Slava Pestov
40ed4e0353 Runtime: Remove "copy prefix" logic
When allocating metadata for a generic class we would copy
any prefix matter from the superclass metadata, if the
superclass metadata's address point was greater than our
address point.

While we may use prefix matter for resilient metadata
in the future, I don't believe just copying bytes like
this will prove useful.
2017-12-05 16:31:46 -08:00
Pavel Yaskevich
cf0c757b1f [RemoteAST] Fix metadata reader to properly read function metadata 2017-11-07 17:56:11 -08:00
Pavel Yaskevich
be3d1af525 [ABI/Runtime] NFC: Rename function metadata arguments to parameters 2017-11-07 12:45:32 -08:00
Pavel Yaskevich
622cc1c64a [ABI/IRGen] Add custom function parameter flags representation for metadata use 2017-11-07 12:45:32 -08:00
Pavel Yaskevich
e9d4a5304e [IRGen] Fix function metadata endpoints to use separate parameter/flags arguments
Switch most general endpoint to be `flags, parameters, parameterFlags, result`,
instead of opaque `void **`, more specialized ones to use follow argument scheme:
`flags, param0, [flags0], ..., paramN, [flagsN], result` and store parameter/flags
information separately in `FunctionCacheEntry::{Key, Data}` as well.
2017-11-07 12:45:32 -08:00
Pavel Yaskevich
f5ed1a8759 [IRGen] Switch function metdata to use Metdata * for parameter references 2017-11-07 12:45:32 -08:00
Pavel Yaskevich
9b3739b91d [IRGen] Add parameter flags to function type metadata
Currently only single 'inout' flag has been encoded into function
metadata, these changes extend function metadata to support up to
32 flags per parameter.
2017-11-07 12:45:32 -08:00
Pavel Yaskevich
659c1bc2e0 Revert "[IRGen] Add parameter flags to function type metadata"
This reverts commit b33a6c7cdf.
2017-11-07 00:24:24 -08:00
Pavel Yaskevich
37185390f8 Revert "[IRGen] Switch function metdata to use Metdata * for parameter references"
This reverts commit 99f188e311.
2017-11-07 00:24:23 -08:00
Pavel Yaskevich
72bf180d0f Revert "[IRGen] Fix function metadata endpoints to use separate parameter/flags arguments"
This reverts commit 728d2a4c2f.
2017-11-07 00:24:22 -08:00
Pavel Yaskevich
aa89c4f4a8 Revert "[ABI/IRGen] Add custom function parameter flags representation for metadata use"
This reverts commit f6b0d2d2cf.
2017-11-07 00:24:21 -08:00
Pavel Yaskevich
4f354a7f09 Revert "[ABI/Runtime] NFC: Rename function metadata arguments to parameters"
This reverts commit 801b35e28c.
2017-11-07 00:24:20 -08:00
Pavel Yaskevich
e23a6f1359 Merge pull request #12500 from xedin/fn-metadata-changes
[IRGen] Improvements to function type metadata
2017-11-06 19:50:19 -08:00
Joe Groff
f8aef0a7e3 Merge pull request #12732 from jckarter/objc-class-metadata-unwrapping
[WIP] Runtime: Put ObjC class wrapper unwrapping behind a runtime call.
2017-11-06 11:32:15 -08:00
Pavel Yaskevich
801b35e28c [ABI/Runtime] NFC: Rename function metadata arguments to parameters 2017-11-06 11:16:46 -08:00
Pavel Yaskevich
f6b0d2d2cf [ABI/IRGen] Add custom function parameter flags representation for metadata use 2017-11-06 11:16:46 -08:00
Pavel Yaskevich
728d2a4c2f [IRGen] Fix function metadata endpoints to use separate parameter/flags arguments
Switch most general endpoint to be `flags, parameters, parameterFlags, result`,
instead of opaque `void **`, more specialized ones to use follow argument scheme:
`flags, param0, [flags0], ..., paramN, [flagsN], result` and store parameter/flags
information separately in `FunctionCacheEntry::{Key, Data}` as well.
2017-11-06 11:16:46 -08:00
Pavel Yaskevich
99f188e311 [IRGen] Switch function metdata to use Metdata * for parameter references 2017-11-06 11:16:46 -08:00
Pavel Yaskevich
b33a6c7cdf [IRGen] Add parameter flags to function type metadata
Currently only single 'inout' flag has been encoded into function
metadata, these changes extend function metadata to support up to
32 flags per parameter.
2017-11-06 11:16:46 -08:00
Joe Groff
95d251051b Runtime: Put ObjC class wrapper unwrapping behind a runtime call.
This is a small code size win, and also gives us some abstraction so that future cooperative ObjC compilers/runtimes might be able to interoperate ObjC class objects with Swift type metadata efficiently than they currently are in the fragile Swift runtime.

While I'm here, I also noticed that swift_getObjCClassMetadata was unnecessarily getting exposed in non-ObjC-interop runtime builds, so I fixed that as well.
2017-11-03 10:18:38 -07:00
Arnold Schwaighofer
a77911ea93 Fix tuple witness instantiation 2017-10-31 17:46:37 -07:00
Arnold Schwaighofer
865d85bd1c Reapply the enum value witness patch
Revert "Revert "Merge pull request #12606 from aschwaighofer/single_payload_enum_witness""

This reverts commit c422f80307.
2017-10-31 17:28:15 -07:00
Arnold Schwaighofer
c422f80307 Revert "Merge pull request #12606 from aschwaighofer/single_payload_enum_witness"
This reverts commit 0b414e45c5, reversing
changes made to fb27e7d32a.

There are failures on the resilient bot and lldb test case fails.
2017-10-31 08:24:26 -07:00
Arnold Schwaighofer
43b9d13a2e Add value witnesses for single payload enums
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
2017-10-23 13:31:46 -07:00
Pavel Yaskevich
0ccf4fabd7 Merge pull request #12320 from xedin/rdar-31408030
[IRGen/Runtime] Update Function Metadata
2017-10-12 17:45:09 -07:00
Pavel Yaskevich
c5cff769c7 [IRGen] Update Function Metadata to use AnyFunctionType::Param
This changes layout of the parameter metadata from single tuple record
(in case of materializable type) to N records each corresponding to
invididual function parameter, where functions with no parameters
`() -> Void` get 0 records allocated.
2017-10-12 15:58:19 -07:00
Saleem Abdulrasool
2f41cc216c Merge pull request #12012 from paulmenage/asan
[Metadata] Unpoison memory being returned from the metadata allocator
2017-10-12 14:27:30 -07:00
Joe Groff
9e7b60326c Runtime: Remove API for getting generic metadata pattern from nominal type descriptors.
The NTD now references the metadata accessor function for the type, which is a better interface for most things one would want to do with type metadata from a nominal type. The only remaining use in the runtime self really has no requirement to do so. For now, don't disturb the binary layout to prevent breaking downstream clients.
2017-10-04 12:42:06 -07:00
Joe Groff
0f137aaae2 Runtime: Remove apparently-unused Metadata::getGenericPattern() method. 2017-10-04 11:47:27 -07:00
Saleem Abdulrasool
086c12114d IRGen: switch to absolute pointers for nominal type descriptors
Alter the value metadata layout to use an absolute pointer for the
nominal type descriptor rather than a relative offset relative to the
complete type metadata.  Although this is slightly less efficient in
terms of load times, this is more portable across different
environments.  For example, PE/COFF does not provide a cross-section
relative offset relocation.  Other platform ports are unable to provide
a 64-bit relative offset encoding.

Given that the value witness table reference in the value metadata is
currently an absolute pointer, this page is most likely going to be
dirtied by the loader.
2017-10-03 14:45:45 -07:00
Slava Pestov
3ab5b6fa19 IRGen/Runtime: Remove parent field from type metadata
We no longer need this for anything, so remove it from metadata
altogether. This simplifies logic for emitting type metadata and
makes type metadata smaller.

We still pass the parent metadata pointer to type constructors;
removing that is a separate change.
2017-09-25 15:45:17 -07:00
Paul Menage
0766f03182 [Metadata] Unpoison memory being returned from the metadata allocator
Call __asan_unpoison_memory_region() rather than __asan_poison_memory_region()
2017-09-19 16:46:49 -07:00
Saleem Abdulrasool
635bb00d61 runtime: make LLP64 clean
This is a blanket pass replacing use of `__LP64__` with
`__POINTER_WIDTH__ == 64`.  The latter is more expressive and also LLP64
clean.  This change is needed to enable support for Windows x86_64 which
is a LLP64 environment.
2017-09-17 18:41:10 -07:00
Arnold Schwaighofer
8a85a9efd5 Use array copy runtime implementation instead of the array value witnesses
And add builtins for the added runtime functions (assign-take, assign-copy).

rdar://27412867
SR-3376
2017-09-12 12:43:26 -07:00
Greg Parker
dd38ace506 [runtime] Fix more const cast warnings. (#11725)
* [runtime] Fix more const cast warnings.
2017-09-05 13:13:01 -07:00
John McCall
936f8ddddb Use void* as the target pointer type for relative references to
opaque functions.
2017-08-25 20:02:57 -04:00
John McCall
9a228e96e1 Change the structure of emitted protocol and generic-wtable metadata:
- Always include an array of requirement descriptors in the protocol
  descriptor.  For now, this doesn't contain anything except a general
  requirement kind and an optional default implementation, but eventually
  this can be augmented with type / name metadata.  This array is always
  emitted as constant.

- Guarantee the value of the extent fields in a protocol descriptor and
  slightly tweak their meaning.

- Move the private-data field out of line in a generic witness table
  descriptor so that the main descriptor can be emitted as constant.

- Rely on IRGen's notion of the witness-table layout instead of assuming
  that SILWitnessTable and SILDefaultWitnessTable match the actual
  physical layout.

This version of the patch uses a hack in which we assign internal rather
than private linkage to certain symbols in order to work around a Darwin
linker bug.
2017-08-25 01:42:44 -04:00
Slava Pestov
d73712d79b IRGen/Runtime: Initialize generic and resilient class vtables from nominal type descriptor
Previous patches changed the runtime to copy the vtable from the
superclass rather than IRGen emitting it statically for generic
and resilient classes.

However for generic classes we would still copy the vtable entries
for methods defined in the immediate class from the template.

Instead, store them in the nominal type descriptor, where they use
less space since we can use relative pointers, and copy them out of
there.

This will allow us to 'slim down' generic class templates eventually.
2017-08-24 15:42:08 -07:00
Slava Pestov
ed8ced5665 IRGen/Runtime: Use relative pointers in default witness table entries
This to shrink the size of the protocol descriptor, removes a 32-bit
padding field, and reduces the number of relocations.
2017-08-24 04:31:24 -07:00
John McCall
bfd71a80e7 Prefer anonymous functions instead of member pointers here.
This is blocking proper const-correctness for value witness types.
2017-08-22 01:47:47 -04:00
John McCall
9f8093f376 Create a central x-macro database of value witnesses. NFC. 2017-08-21 20:17:02 -04:00