Commit Graph

99 Commits

Author SHA1 Message Date
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
Arnold Schwaighofer
89e972f5a8 SILGen: Implement withoutActuallyEscaping verification
Check that an ``withoutActuallyEscaping(noescape_closure) { // scope}`` closure
has not escaped in the scope using the ``is_escaping_closure %closure``
instruction.

rdar://35525730
2018-03-07 09:00:12 -08:00
Arnold Schwaighofer
5940796cc1 SIL: Add an is_escaping_closure instruction
Will be used to verify that withoutActuallyEscaping's block does not
escape the closure.

``%escaping = is_escaping_closure %closure`` tests the reference count. If the
closure is not uniquely referenced it prints out and error message and
returns true. Otherwise, it returns false. The returned result can be
used with a ``cond_fail %escaping`` instruction to abort the program.

rdar://35525730
2018-03-07 08:56:00 -08: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
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
Pavel Yaskevich
877c70bae9 [Runtime/Metadata] Add support for dynamic field descriptor registration 2018-02-20 18:20:09 -08:00
troughton
cf28ff448c Remove TwoWordPair and use SwiftCC instead. 2018-02-03 09:43:00 +13:00
Arnold Schwaighofer
aa76808b48 IRGen: swift_getFunctionTypeMetadata is ReadOnly
It only accesses the type arguments passed indirectly via an array
2018-01-31 08:05:27 -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
e766473ed9 [ABI] Emit separate symbols for protocol conformance descriptors.
Emit protocol conformance descriptors as separate symbols, rather than
inlining them within the section for protocol conformance records. We
want separate symbols for protocol conformances both because it is easier
to make them variable-length (as required for conditional
conformances) and because we want to reference them from witness
tables (both of which are coming up).
2018-01-17 10:35:16 -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
swift-ci
ea489cead0 Merge pull request #13844 from DougGregor/runtime-protocol-name-lookup 2018-01-09 23:06:09 -08:00
Doug Gregor
0f4963dba8 [IRGen] Put references to all emitted protocols into a special section.
Introduce a new section that contains (relative) references to all of the
Swift protocol descriptors emitted into this module. We'll use this to
find protocol descriptors by name.
2018-01-09 16:10:18 -08:00
John McCall
3c54c0edfc IRGen and basic optimizer support for coroutines. 2018-01-09 11:35:09 -05:00
Doug Gregor
5853cf3c87 [Runtime] Teach swift_getTupleTypeMetadata() to copy "labels" string.
Introduce a flags parameter to swift_getTupleTypeMetadata(). Add a flag
stating when the "labels" parameter points into nonconstant memory, in
which case we need to make a copy of the string before adding an entry
into the concurrent map.
2018-01-05 23:11:21 -08:00
Pavel Yaskevich
0f071848f3 [Runtime/ABI] NFC: Refactor function type metadata generation 2018-01-05 13:38:20 -08:00
Pavel Yaskevich
86de71ee6d [Runtime/ABI] Remove swift_getFunctionTypeMetadata{1-3}WithFlags
Since it's not very common to use such ABI endpoints, let's remove
them and use the most general one `swift_getFunctionTypeMetadata`
instead when function parameters have flags attached to them.

Resolves: rdar://problem/36278686
2018-01-04 16:32:51 -08:00
Pavel Yaskevich
8409cdb8a2 [Runtime/ABI] Add swift_getFunctionTypeMetadata0 function
This ABI endpoint is used to retrieve metadata about functions
without parameters. Which is very common use-case and it
makes sense to save some code size for that.
2018-01-04 16:32:51 -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
Erik Eckstein
48d49a4cc2 Fix the IR attributes of swift_getObjectType.
It's not readnone, because it reads the metatype from an object.
Readnone would let the llvm ARC optimizer reschedule the call with a release-call for the object.

fixes SR-6560.
2017-12-11 18:16:46 -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
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
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
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
e7dbf7cc4d runtime: Add and use swift_deallocUninitializedObject for uninitialized objects
This is different from swift_deallocObject in that it applies to objects
at +1 while swift_deallocObject actually only applies to objects whose
state is deiniting (swift_release was called).
2017-11-03 09:44:07 -07:00
Arnold Schwaighofer
e0646d4321 IRGen: Use swiftcc for swift_unexpectedError and swift_errorInMain
It is a runtime function defined in swift. This currently did not have
ABI implications because the ABI happened to be compatible but ...

SR-6235
rdar://problem/35222489
2017-10-27 10:56:44 -07:00
Joe Groff
9af6cd8537 Merge pull request #12009 from jckarter/revive-type-layout-verifier
IRGen: Un-bit-rot type layout verifier.
2017-09-19 17:55:37 -07:00
Joe Groff
e1a05d768e IRGen: Un-bit-rot type layout verifier. 2017-09-19 14:45:44 -07:00
Arnold Schwaighofer
3ae6d7cb4d runtime/IRGen: return the argument from swift_retain family of functions
On architectures where the calling convention uses the same argument register as
return register this allows the argument register to be live through the calls.

We use LLVM's 'returned' attribute on the parameter to facilitate this.

We used to perform this optimization via an optimization pass. This was ripped
out some time ago around commit 955e4ed652.
By using LLVM's 'returned' attribute on swift_*retain, we get the same
optimization from the LLVM backend.
2017-09-19 07:16:37 -07:00
Arnold Schwaighofer
d008e37b13 Merge pull request #11950 from aschwaighofer/runtime_return_dest_2
runtime: Also return the destination argument of the unknownWeak- and…
2017-09-15 14:54:44 -07:00