Commit Graph

311 Commits

Author SHA1 Message Date
Mike Ash
a78a01a392 [Stdlib] Make _swift_extractDynamicValue INTERNAL as it's used by Foundation. 2018-10-04 13:20:53 -04:00
Doug Gregor
b531b3923f [ABI] Use mangled names for associated type witnesses.
Rather than storing associated type metadata access functions in
witness tables, initially store a pointer to a mangled type name.
On first access, demangle that type name and replace the witness
table entry with the resulting type metadata.

This reduces the code size of protocol conformances, because we no
longer need to create associated type metadata access functions for
every associated type, and the mangled names are much smaller (and
sharable). The same code size improvements apply to defaulted
associated types for resilient protocols, although those are more
rare. Witness tables themselves are slightly smaller, because we
don’t need separate private entries in them to act as caches.

On the caller side, associated type metadata is always produced via
a call to swift_getAssociatedTypeWitness(), which handles the demangling
and caching behavior.

In all, this reduces the size of the standard library by ~70k. There
are additional code-size wins that are possible with follow-on work:

* We can stop emitting type metadata access functions for non-resilient
types that have constant metadata (like `Int`), because they’re only
currently used as associated type metadata access functions.
* We can stop emitting separate associated type reflection metadata,
because the reflection infrastructure can use these mangled names
directly.
2018-09-26 23:19:33 -07:00
Mike Ash
49c3547449 Merge remote-tracking branch 'origin/master' into rename-conflicting-classes-and-methods 2018-09-21 15:52:38 -04:00
Doug Gregor
50d12e05db [Runtime] Fix _ObjectiveCBridgeableWitnessTable::ObjectiveCType
The signature of this function pointer was incorrect, because it had not
yet been updated for the metadata request/response architecture. We
were getting lucky (!).
2018-09-14 20:59:03 -07:00
Mike Ash
798edb9d0e [Runtime][Stdlib][Overlays] Rename various Objective-C classes and methods that would conflict when loading old Swift libraries into a process alongside ABI-stable libraries.
rdar://problem/35768222
2018-09-13 16:55:10 -04:00
Mike Ash
46309d9794 [Runtime] Rename swift_unknown* functions to swift_unknownObject*.
These functions don't accept local variable heap memory, although the names make it sound like they work on anything. When you try, they mistakenly identify such things as ObjC objects, call through to the equivalent objc_* function, and crash confusingly. This adds Object to the name of each one to make it more clear what they accept.

rdar://problem/37285743
2018-08-15 17:48:23 -04:00
Azoy
b8fc8b333c Remove _interface 2018-07-29 10:41:22 -04:00
Doug Gregor
c7a02a26a1 [ABI] Distinguish Swift/ObjC protocols in TargetGenericRequirement.
In a generic requirement, distinguish between Swift and
Objective-C protocols using a spare bit within the relative
(indirectable) reference to the protocol.
2018-07-22 22:48:57 -07:00
Doug Gregor
3464929638 [ABI] Rework existential type metadata to use ProtocolDescriptorRef.
Use ProtocolDescriptorRefs within the runtime representation of
existential type metadata (TargetExistentialTypeMetadata) instead of
bare protocol descriptor pointers. Start rolling out the use of
ProtocolDescriptorRef in a few places in the runtime that touch this
code. Note that we’re not yet establishing any strong invariants on
the TargetProtocolDescriptorRef instances.

While here, replace TargetExistentialTypeMetadata’s hand-rolled pointer 
arithmetic with swift::ABI::TrailingObjects and centralize knowledge of
its layout better.
2018-07-20 20:54:49 -07:00
Michael Gottesman
5648ef219d [+0-all-args] Clean up remains of +1 convention from the runtime. 2018-07-06 23:10:12 -07:00
Mike Ash
e992f46764 [Runtime] Extend ObjC bridging casts to convert NSError to Error when nested in a container type.
rdar://problem/39349762
2018-06-28 13:35:25 -04:00
Doug Gregor
7952a19f31 [Mangling] Introduce known manglings for many more standard library types.
Since the mangling scheme and set of standard library types is effectively
fixed now, introduce known mangling substitutions for a number of new
standard library types, filling out the S[A-Za-z] space.

Reduces standard library binary size by ~195k.
2018-06-19 23:24:38 -07:00
Saleem Abdulrasool
b33a1e1766 runtime: workaround GCC 4.8 libstdc++ C++11 conformance
libstdc++ included with GCC 4.8 does not define `std::max_align_t` as
required by the C++11 specification.  As a workaround, explicitly create
the definition locally.  This was fixed in GCC 4.9 and later.
2018-06-12 12:03:31 -07:00
Pavel Yaskevich
92c4189e2d [Runtime] NFC: remove C style "stddef.h" header from casting 2018-06-10 20:36:27 -07:00
Saleem Abdulrasool
638b89d12d runtime: use std::max_align_t over max_align_t (NFC)
MSVC does not provide a full C99 environment.  Use the C++ equivalent
spelling for the value.  This allows the build to succeed on Windows.
2018-06-08 14:36:19 -07:00
Lily Vulcano
1377ab7d7e Turn on ‘as’ bridging on Darwin. 2018-05-30 15:07:22 -07:00
Mike Ash
0dae9b3dc0 [Runtime] Have swift_dynamicCast unwrap multiple levels of optionals in the source.
The real work is done in checkDynamicCastFromOptional. This code tried to unwrap the source and returned the payload on success. It only did this once, so a type like Optional<Optional<Int>> would come out as Optional<Int> and then a cast to Int would fail.

This change makes checkDynamicCastFromOptional recursive, which makes it unwrap as many levels of Optional as it encounters.

Fixes rdar://problem/40171034 and SR-7664.
2018-05-22 15:05:09 -04:00
Joe Groff
681a96b45c Runtime: Tolerate unknown metadata kinds.
We want to be able to potentially introduce new metadata kinds in future Swift compilers, so a runtime ought to be able to degrade gracefully in the face of metadata kinds it doesn't know about. Remove attempts to exhaustively switch over metadata kinds and instead treat unknown metadata kinds as opaque.
2018-05-17 15:35:06 -07:00
Michael Gottesman
0d1f98a4ef Merge pull request #16259 from gottesmm/pr-aab473d24268b0934ac216bf2683f0a2c8e3be0f
[+0-all-args] Make _bridgeAnythingNonVerbatimToObjectiveC() take its …
2018-04-30 13:14:46 -07:00
Michael Gottesman
c31033c525 [+0-all-args] Make _bridgeAnythingNonVerbatimToObjectiveC() take its parameter at +1.
This hoists out the retain into Swift code from the casting runtime and along a
few paths in the runtime allows us to eliminate a dynamic retain release.

rdar://38196046
rdar://38771331
2018-04-30 11:05:00 -07:00
Michael Gottesman
87681375e2 [+0-all-args] Change _swift_stdlib_bridgeErrorToNSError to take its parameter at +1.
This is truly a consuming operation. This can be seen since we always would need
to retain the argument here. This makes guaranteed -> owned less transformation
effective. Instead represent it taking a +1 argument so that the retain happens
outside the builtin instead of inside the builtin.

This also allows me to remove an extra copy from dynamicCastValueToNSError

rdar://38771331
2018-04-30 10:16:41 -07:00
Joe Groff
78b5ff8b6b Runtime: Bridge Error-conforming types to id as NSError instances.
NSError is a more useful box for a swift Error than the generic box. Fixes rdar://problem/38631791 | SR-7232.
2018-04-10 12:23:49 -07:00
Mike Ash
34be7f6f15 Merge branch 'master' into casting-hooks 2018-03-28 14:45:48 -04:00
Mike Ash
f4224b092e [Runtime] Redo compatibility overrides boilerplate using a .def file.
rdar://problem/36997475
2018-03-28 13:39:55 -04:00
Mike Ash
d024fd7487 [Runtime] Fill out a bunch more compatibility hooks.
rdar://problem/36997475
2018-03-22 09:14:55 -07:00
Mike Ash
9e8d4da76f [Runtime] Add a hooking mechanism to allow future apps to extend dynamic casting and type lookup. Make swift_dynamicCast and swift_getTypeByMangledName use these hooks.
rdar://problem/36997475
2018-03-20 16:33:37 -07:00
Arnold Schwaighofer
9d8c381ab4 Remove resilient tag indices 2018-03-20 13:19:56 -07:00
Joe Groff
0d7c42ce66 Runtime: Do the bare minimum balancing for bridge casting at +0.
The logic here is causing leaks in some situations, and it's likely we'll want
bridging calls to go back to +1 again anyway, so do the minimum adaptation to
the +0 convention for now.

rdar://34222540
2018-03-10 02:17:24 -08:00
Michael Gottesman
e66fd1ad0c [+0-all-args] When casting a value to NSError, release the value passed to _swift_stdlib_bridgeErrorToNSError since it is at +0 now.
rdar://34222540
2018-03-05 12:22:09 -08: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
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
Doug Gregor
800e3818b7 [Type metadata] @objc protocol conformance requirements don't have arguments.
@objc protocols don't have witness tables. However, both type metadata
(in the nominal type descriptors) and the runtime code to demangle
type names into metadata weren't acknowledging this. Fix type metadata
emission to not count an "extra argument" for @objc protocol
conformance requirements, and teach the runtime code to properly look
for conformances to @objc protocols (through the Objective-C runtime)
and not record witness tables for them.
2018-02-15 14:07:46 -08:00
Michael Gottesman
7bceb07083 [+0-normal-args] Upstream fixes for _bridgeAnythingNonVerbatimToObjectiveC and _bridgeNonVerbatimFromObjectiveCConditional at +0.
NFC with +1 arguments. I am testing this upstream against SILGen changes.

rdar://34222540
2018-02-14 14:34:20 -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
troughton
cf28ff448c Remove TwoWordPair and use SwiftCC instead. 2018-02-03 09:43:00 +13: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
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
Pavel Yaskevich
10c385d1b7 [Mangling/ABI] Add special LabelList to store parameter labels
Instead of mangling parameter labels as part of the function type
move them to the end of the function name instead, to match the
language semantics.
2017-12-18 15:44:24 -08:00
Thomas Roughton
c5bf2ec553 [runtime] Remove TwoWordPair and use the Swift calling convention instead. (#13299) 2017-12-07 19:27:24 -08:00
Greg Parker
415b36dddc [runtime] Clean up symbol exports in casting and class introspection. (#13005) 2017-12-01 17:48:48 -08:00
Greg Parker
78501448b1 [runtime] Remove _swift_getSuperclass(). (#12988)
There are too many superclass-lookup functions.
This one does not pull its own weight.
2017-11-17 02:57:58 -08:00
Greg Parker
1e894cd80b [runtime] Clean up symbols in error machinery. (#12853)
* [runtime] Clean up symbols in error machinery.

* [runtime] Clean up symbols in Foundation overlay.

* [runtime] Clean up symbols in collections and hashing.

* [runtime] Remove symbol controls from the Linux definition of swift_allocError.

* [tests] Add more stub functions for tests that link directly to the runtime.
2017-11-15 22:20:11 -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
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
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