Commit Graph

652 Commits

Author SHA1 Message Date
John McCall
f22d02a67a Detect unbreakable metadata dependency cycles and abort with a diagnostic. 2018-04-01 19:23:57 -04:00
John McCall
ea7dd7eca3 Minor changes to how we track and lock around metadata dependencies
to enable the general cycle-dependency runtime error.
2018-04-01 19:23:57 -04:00
John McCall
4d461831b8 Optimize the layout of MetadataCacheEntryBase to pack fields more effectively. 2018-04-01 19:23:57 -04:00
Slava Pestov
f197c137a3 Runtime: Remove old 'default requirements at the end' mechanism 2018-03-29 15:23:20 -07:00
Slava Pestov
72b56ec66b Runtime: New mechanism for resilient witness table instantiation 2018-03-29 14:03:58 -07:00
Slava Pestov
d1c6e1d24a SIL: Generalize default witness tables now that defaulted witnesses don't have to go at the end
NFC until the new witness table instantiation mechanism is enabled.
2018-03-29 14:03:58 -07:00
John McCall
aceb2fd5ce Ensure the transitive completion of type arguments and the superclass
before declaring nominal type metadata complete.

Also, future-proof MetadataState.
2018-03-29 13:52:36 -04:00
John McCall
583bec3b2c Add a runtime function to query the current runtime state of a metadata.
This functions returns the metadata purely for liveness purposes.
2018-03-26 02:48:52 -04:00
John McCall
6d99a7755a Restructure how we finalize VWTs in the runtime to potentially allow asynchronous queries.
I keep finding reasons to want such queries and then deciding that they're
unnecessary.  Let's at least do this much, though.
2018-03-26 01:13:45 -04:00
John McCall
ba17f320c6 Extract MetadataRequest::BasicKind as MetadataState. NFC.
I de-templated MetadataState and MetadataRequest because we weren't
relying on the template and because using the template was causing
conversion problems due to the inability to directly template an enum
in C++.
2018-03-26 01:13:45 -04:00
Slava Pestov
b1f4430410 Runtime: Rename swift_initClassMetadata_UniversalStrategy()
Rename it to swift_initClassMetadata() just like we recently did
swift_initStructMetadata(), and add a StructLayoutFlags parameter
so we can version calls to this function in the future.

Maybe at some point this will become a separate ClassLayoutFlags
type, but at this point it doesn't matter because IRGen always
passes a value of 0.
2018-03-23 18:59:07 -06:00
Arnold Schwaighofer
9d8c381ab4 Remove resilient tag indices 2018-03-20 13:19:56 -07:00
John McCall
31f2eec044 Change type metadata accessors to support incomplete metadata.
This includes global generic and non-generic global access
functions, protocol associated type access functions,
swift_getGenericMetadata, and generic type completion functions.

The main part of this change is that the functions now need to take
a MetadataRequest and return a MetadataResponse, which is capable
of expressing that the request can fail.  The state of the returned
metadata is reported as an second, independent return value; this
allows the caller to easily check the possibility of failure without
having to mask it out from the returned metadata pointer, as well
as allowing it to be easily ignored.

Also, change metadata access functions to use swiftcc to ensure that
this return value is indeed returned in two separate registers.

Also, change protocol associated conformance access functions to use
swiftcc.  This isn't really related, but for some reason it snuck in.
Since it's clearly the right thing to do, and since I really didn't
want to retroactively tease that back out from all the rest of the
test changes, I've left it in.

Also, change generic metadata access functions to either pass all
the generic arguments directly or pass them all indirectly.  I don't
know how we ended up with the hybrid approach.  I needed to change all
the code-generation and calls here anyway in order to pass the request
parameter, and I figured I might as well change the ABI to something
sensible.
2018-03-18 21:38:08 -04:00
John McCall
1d4fc1933b Let the runtime copy generic arguments into place. 2018-03-17 11:40:31 -04:00
John McCall
aa0658decf Allow value witness tables to advertise themselves as incomplete
and use that when evaluating how complete an incomplete metadata is.
2018-03-17 11:40:30 -04:00
John McCall
3d5d643b9e Substantially simplify the synchronization scheme for metadata caches.
I was trying to make the entry-delegation thing do *way* too much.
Just give the entry access to the lock/queue and introduce subclasses
which simplify most of the work.

Also, fix some bad reasoning around the attempts to avoid acquiring
locks in the absence of waiters.  It really is always necessary to
acquire the lock when notifying; waiters cannot atomically set the
has-waiters flag and wait, so we have to protect against the
possibility that we notify before they can wait.
2018-03-17 11:40:30 -04:00
John McCall
3cf9a6f91a Add the caching machinery for arbitrary metadata dependencies.
We aren't taking advantage of this yet.
2018-03-17 11:40:30 -04:00
swift-ci
f764e685c2 Merge pull request #15177 from darquro/excise-iostream-from-metadata 2018-03-12 09:39:11 -07:00
darquro
71e27406dd [stdlib] Excise #include <iostream> from Metadata.cpp. (SR-7164) 2018-03-12 20:29:27 +09:00
Joe Groff
98ee6a5d7d Runtime: Prefab metadata records for Any and AnyObject.
Metadata for these types gets demanded fairly frequently, and it's a decent code size savings not having to emit a runtime call to access them.
2018-03-10 10:15:42 -08:00
Joe Groff
57d6772d48 Runtime: Use type context descriptors to unique foreign metadata.
Now that every foreign type has a type context descriptor, we can use that for a uniquing key instead of a dedicated mangled string, saving some code size especially in code that makes heavy use of imported types. rdar://problem/37537241
2018-03-10 10:15:38 -08:00
John McCall
f304c321f3 Rewrite MetadataCache to be a more natural extension of ConcurrentMap.
Change generic witness table instantiation to use a more lightweight
entry scheme that allocates the witness table as part of the entry.

In contrast, change generic metadata instantiation to use a more
straightforward allocation scheme where the metadata is a totally
independent allocation.

This is preparation for proper cyclic-dependency handling.
2018-03-08 02:29:20 -05:00
John McCall
9c8bdf24a7 Fill in the field-offset vector and payload size for fixed-layout value metadata.
This regression wasn't caught by normal testing because the emission
pattern substantially changed anyway, breaking tests that were looking for
the field-offset vector, and because normal execution testing doesn't
actually use the field-offset vector and enum payload size fields.
Reflection, which does use these fields, was skating by for common types
because metadata is typically allocated out of freshly zeroed pages and
most such types have only one field.

Also, don't emit a completion function for value metadata with fixed layout.

We really shouldn't have to emit field-offset vectors for fixed-layout types;
the layout should just go in the type descriptor.  But for now, this is what
we have to do.
2018-03-07 01:18:44 -05:00
John McCall
9a4540e84d Split the instantiation function into two phases.
The allocation phase is guaranteed to succeed and just puts enough
of the structure together to make things work.

The completion phase does any component metadata lookups that are
necessary (for the superclass, fields, etc.) and performs layout;
it can fail and require restart.

Next up is to support this in the runtime; then we can start the
process of making metadata accessors actually allow incomplete
metadata to be fetched.
2018-03-06 03:07:55 -05:00
John McCall
11e3d16c93 Merge pull request #14998 from rjmccall/generic-metadata-patterns
Apply generic metadata patterns to all types and change their layout.
2018-03-05 22:45:23 -05:00
Huon Wilson
216e69e810 Merge pull request #14973 from huonw/no-dynamic-count
[IRGen] Cond. conformance witness table count isn't needed dynamically.
2018-03-05 16:07:14 -08:00
John McCall
dff0031b02 Apply generic metadata patterns to all types and change their layout.
The layout changes to become relative-address based.  For this to be
truly immutable (at least on Darwin), things like the RO data patterns
must be moved out of the pattern header.  Additionally, compress the
pattern header so that we do not include metadata about patterns that
are not needed for the type.

Value metadata patterns just include the metadata kind and VWT.

The design here is meant to accomodate non-default instantiation
patterns should that become an interesting thing to support in the
future, e.g. for v-table specialization.
2018-03-05 19:05:41 -05:00
Huon Wilson
43196c27ac [IRGen] 'void **' -> 'void ***' in swift_getGenericWitnessTable.
This is simpler, because the native form of that last argument is: a
pointer to a buffer (*) of pointers (*) to witness tables, which is
modelled as a buffer of void *s. Thus, void ***.
2018-03-06 00:22:05 +11:00
Davide Italiano
a59d82188f [Metadata] Define _objc_empty_cache under SWIF_OBJC_INTEROP.
Later code uses the variable under this macro, so defining it
under NDEBUG breaks debug builds of stdlib.
2018-03-04 12:29:09 -08:00
John McCall
a7c5c80799 Compute class metadata bounds solely from class-descriptor chain information.
Change the "metadata base offset" variable into a "class metadata bounds"
variable that contains the base offset and the +/- bounds on the class.
Link this variable from the class descriptor when the class has a resilient
superclass; otherwise, store the +/- bounds there.  Use this variable to
compute the immediate-members offset for various runtime queries.  Teach the
runtime to fill it in lazily and remove the code to compute it from the
generated code for instantiation.  Identify generic arguments with the start
of the immediate class metadata members / end of the {struct,enum} metadata
header and remove the generic-arguments offset from generic type descriptors.
2018-03-04 02:14:32 -05:00
John McCall
f2bb319bdb Change the pattern of generic class metadata instantiation.
Minimize the generic class metadata template by removing the
class header and base-class members.  Add back the set of
information that's really required for instantiation.
Teach swift_allocateGenericClass how to allocate classes without
superclass metadata.  Reorder generic initialization to establish
a stronger phase-ordering between allocation (the part that doesn't
really care about the generic arguments) and initialization (the
part that really does care about the generic arguments and therefore
might need to be delayed to handle metadata cycles).

A similar thing needs to happen for resilient class relocation.
2018-03-04 00:01:56 -05:00
John McCall
dd99536d31 Move the metadata-pattern header into the type context descriptor.
This is yet another waypoint on the path towards the final
generic-metadata design.  The immediate goal is to make the
pattern a private implementation detail and to give the runtime
more visibility into the allocation and caching of generic types.
2018-02-26 12:10:24 -05:00
Michael Gottesman
ba9946a131 Add a dumper/verifier for OpaqueExistentialContainers (i.e. Any) in c++.
The dumper method dumps:

1. The container's metadata pointer.
2. A pointer to the container's value.
3. Whether or not said value is stored inline in the container.

This provides a general overview that can be used even when working with SIL
code in the debugger by grabbing a pointer to swift Anys and then calling the
c++ any method upon them.

The verifier is intended to be used in conjunction with ASAN for maximum
effect to catch use-after-frees of existential boxes.

While implementing this I refactored some code from ExistentialTypeMetadata into
methods on OpaqueExistentialContainer. ExistentialTypeMetadata just calls these
methods now instead of implementing the code inline.
2018-02-23 23:03:55 -08:00
John McCall
23fa44e56c Render TypeContextDescriptor into a proper hierarchy; NFC.
The purpose here is to make it easier to add type-specific fields to the
descriptor.
2018-02-20 15:20:32 -05:00
Pavel Yaskevich
73f09ecbf5 [Runtime] Existential types marked as @objc should satisfy class requirement
Make sure that `checkGenericRequirements` properly enforces
"class requirement" constraint on the generic parameters.
2018-02-14 21:16:44 -08:00
Joe Groff
b53d90e8e2 Merge pull request #14512 from jckarter/mangling-symbolic-references
IRGen/Runtime: Allow mangled type refs to embed "symbolic references" to type context descriptors.
2018-02-12 12:21:19 -08:00
Joe Groff
953dddd5d3 IRGen/Runtime: Allow mangled type refs to embed "symbolic references" to type context descriptors.
This makes resolving mangled names to nominal types in the same module more efficient, and for eventual secrecy improvements, also allows types in the same module to be referenced from mangled typerefs without encoding any source-level name information about them.
2018-02-10 10:43:47 -08:00
Kuba (Brecka) Mracek
6278146ed8 Fix "variable unused" warning in Metadata.cpp in non-assert build 2018-02-08 11:23:13 -08:00
Arnold Schwaighofer
d981bb1d96 Mangling: noescape functions will be trivial and no longer compatible with escape function types.
Mangle escapeness as part of the type.

Part of:
SR-5441
rdar://36116691
2018-02-06 08:51:43 -08:00
troughton
cf28ff448c Remove TwoWordPair and use SwiftCC instead. 2018-02-03 09:43:00 +13:00
Michael Gottesman
6ac81e5489 [metadata] Add dump to Metadata.
We dump the following information:

1. The Kind.
2. Pointer to the value witnesses.
3. Pointer to the class object if one is available.
4. Pointer the type context description if one is available.
5. Pointer to the generic arguments if one is available.

This makes it significantly easier to poke around Metadata.

rdar://34222540
2018-02-01 13:29:08 -08:00
Joe Groff
a7a3b17597 Replace nominal type descriptors with a hierarchy of context descriptors.
This new format more efficiently represents existing information, while
more accurately encoding important information about nested generic
contexts with same-type and layout constraints that need to be evaluated
at runtime. It's also designed with an eye to forward- and
backward-compatible expansion for ABI stability with future Swift
versions.
2018-01-29 16:19:25 -08:00
Greg Parker
e223f1fc9b [IRGen][runtime] Simplify runtime CCs and entry point ABIs (#14175)
* 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.
2018-01-29 13:22:30 -08:00
Greg Parker
7b9224794e [runtime] Reinstate TwoWordPair hack for swiftcall returns. (#14079)
clang is miscompiling some swiftcall functions on armv7s.
Stop using swiftcall in some places until it is fixed.

Reverts c5bf2ec (#13299).

rdar://35973477
2018-01-23 01:04:01 -08:00
Doug Gregor
764cb7003d [ABI] Record proper number of requirements in protocol descriptor.
The prior refactoring to add the protocol conformance descriptor into
witness tables offset the # of requirements stored in the witness
table by 1. Address this oddity in the metadata by ensuring that the #
of requirements (and # of mandatory requirements) in the protocol
descriptor is accurate.
2018-01-18 21:34:31 -08:00
Doug Gregor
40283f9b73 [ABI] Add the protocol conformance descriptor into a witness table.
Extend witness tables with a pointer to the protocol conformance
descriptor from which the witness table was generated. This will allow
us to determine (for example) whether two witness tables were
generated from the same (or equivalent) conformances in the future, as
well as discover more information about the witness table itself.

Fixes rdar://problem/36287959.
2018-01-18 17:13:13 -08:00
Doug Gregor
93cd5e8270 [ABI] Make TargetTupleTypeFlags size_t sized and move “labels” bit.
Addresses feedback from @rjmccall.
2018-01-11 11:08:12 -08:00
Doug Gregor
adf38f5486 [Runtime] Pack element count into the flags of swift_getTupleTypeMetadata.
Reduces the # of parameters we need to pass to this runtime API.
2018-01-11 10:06:57 -08:00
Doug Gregor
c302042dc5 [Runtime] Lookup @objc protocols in mangled name -> type metadata function.
Swift-defined @objc protocols are registered with the Objective-C runtime
under the Swift 3 mangling scheme; look in the Objective-C runting using
objc_getProtocol() with the appropriate name.

Also, correctly compute the "class bound" bit when forming a protocol
composition metatype. The information isn't in the mangled name when it
can be recovered from the protocols themselves, so look at the protocols.
2018-01-10 16:21:42 -08:00
Doug Gregor
61884f7702 [Type decoder] Rework the builder contract for protocols.
TypeDecoder's interface with its builders already treated protocols as
a type (due to their being mangled as "protocol composition containing
one type"), and intermixed protocols with superclasses when forming
compositions. This makes for some awkwardness when working with
protocol descriptors, which are very much a distinct entity from a
type.

Separate out the notion of a "protocol declaration" (now represented
by the builder-provided BuiltProtocolDecl type) from "a protocol
composition containing a single type", similarly to the way we handle
nominal type declarations. Teach remote mirrors and remote AST to
handle the new contract.
2018-01-09 10:46:31 -08:00