Commit Graph

1960 Commits

Author SHA1 Message Date
Doug Gregor
06807c2ea6 [Runtime] Only scan the type descriptor once for metadata cache entries.
Rather than scanning the type descriptor each time we perform a comparison
or hash of a metadata cache entry, do so only once to establish the number
of key parameters and the number of witness tables. Use those values to
more efficiently compare keys.
2018-11-25 22:10:04 -08:00
Doug Gregor
32f577abf2 [Runtime] Perform “deep” comparisons of witness tables when uniquing metadata.
Metadata uniquing might encounter witness tables that were distinctly
generated but come from identical descriptors. Handle this case in metadata
uniquing be looking into the protocol conformance descriptors themselves.
2018-11-20 22:07:55 -08:00
Doug Gregor
d9bb81bc20 [Runtime] Cache protocol conformance descriptors, not witness tables.
The conformance cache was caching the witness table for a conformance
`T: P`, where `T` is a concrete type and `P` is a protocol. However, it
essentially picked one of potentially many witness tables for that
conformance, because retroactive conformances might produce different results
from different modules.

Make the conformance cache what is says it is: a cache of the conformance
descriptor for a given `T: P`, potentially filtered by a module (when
requested). Clients of the conformance cache can choose how to interpret
the protocol conformance descriptor, e.g., by instantiating a witness table.

We can bring back a specific conformance cache for swift_conformsToProtocol()
if it is profitable.

(cherry picked from commit 0af2af00a739a4d912d2a9c3b196449e4164484f)
2018-11-16 22:26:40 -08:00
Saleem Abdulrasool
a79c14164b Merge pull request #20633 from compnerd/weak-win
runtime: adjust LLVMSupport for Windows
2018-11-16 13:31:48 -08:00
Doug Gregor
d4fe6e9ff7 [Runtime] Fix a bug in handling multi-level generic environment substitutions. 2018-11-16 10:39:19 -08:00
Doug Gregor
cc2ee165a1 [ABI] Use generic environment to handle mangled generic keypath types.
Always use mangled type names to represent type metadata in keypath patterns.
For generic types, use the generic environment to pull substituted types
from the instantiation arguments.

Finishes the type metadata part of rdar://problem/38038799.
2018-11-16 10:13:07 -08:00
Doug Gregor
cdd2928fec [Runtime] Generalize SubstGenericParametersFromMetadata slightly.
Only use the metadata and context information during initial setup, not
later on. NFC just yet.
2018-11-16 10:13:06 -08:00
Saleem Abdulrasool
6072d9f5df runtime: adjust LLVMSupport for Windows
Windows does not support weak linking.  Use an undocumented linker
feature to provide a default implementation for report_bad_alloc_error
in the case that we are not linking against LLVMSupport.
2018-11-16 08:42:10 -08:00
Mike Ash
68094fac75 Merge pull request #20608 from mikeash/fix-bundleForClass-nil
[Runtime] Accept Nil in the patched bundleForClass:.
2018-11-16 10:43:54 -05:00
John McCall
ff6d031482 Allow TypeReference to refer to protocol descriptors.
We should also allow references via manglings just to cover the
general case if we need it, but this is useful on its own so that
we can emit a reference to any natively-declared Swift type.
2018-11-16 00:39:10 -05:00
swift-ci
126f9d7773 Merge pull request #20610 from DougGregor/abi-symbolic-accessor-ref-2-byte 2018-11-15 17:30:19 -08:00
Doug Gregor
986b8f3f9f [Runtime] Make swift_getTypeByMangled(Name|Node) overridable.
Rename the funnel points for demangling strings/nodes to metadata to
swift_getTypeByMangled(Name|Node) and make them overridable. This will let
us back-deploy mangling improvements and bug fixes.
2018-11-15 16:43:38 -08:00
Doug Gregor
723b56e64f [Standard library] Simplify _getTypeByMangledName.
Simplify the signature of the internal _getTypeByMangledName() used by the
standard library to what we actually (currently) use. Drop it as a
compatibility override, because it’s not a useful place to introduce
customization.
2018-11-15 16:10:11 -08:00
Doug Gregor
cd6d6be64d [Runtime] Consolidate runtime functions used for demangle-to-metadata.
Clean up the interfaces used to go from a mangled name or demangle tree to
metadata. Parameterize these interfaces for generic parameter substitutions
(already in use) and dependent conformance substitutions (speculative).
2018-11-15 15:57:44 -08:00
Doug Gregor
3eb171d814 [ABI] Ensure that symbolic references to accessor functions are 2-byte aligned
When we emit "false" symbolic references to accesors for conformances or
type metadata, ensure that we end up with two-byte-aligned symbolic
references. This addresses a problem with ARM+Thumb compilation where the
low bit wasn't getting set for Thumb code.

Fixes rdar://problem/46067353.
2018-11-15 14:51:55 -08:00
Mike Ash
bdb822a788 [Runtime] Accept Nil in the patched bundleForClass:.
The patched +[NSBundle bundleForClass:] crashes on Nil, while the original Foundation implementation returns the main bundle. Avoid the crash and pass Nil through to Foundation. This also ensures that Nil is passed through to class_getImageName rather than crashing.

SR-9188 rdar://problem/45849924
2018-11-15 17:19:12 -05:00
Doug Gregor
9191ffe124 [Runtime] Eliminate more dead code for flat generic argument indices. 2018-11-15 11:25:02 -08:00
Doug Gregor
201c13ab01 [Runtime] Remove code for handling “flat” generic argument indices.
We no longer encode “flat” indices in the metadata, and have no need for
this now-dead decoding code.
2018-11-15 11:12:41 -08:00
Doug Gregor
a53b2e285c [Standard library] Drop _typeByMangledName().
This underscored function was only intended for testing; drop it from the
ABI. We’re keeping _typeByName because it’s used by Foundation.
2018-11-15 11:06:52 -08:00
Doug Gregor
dc73c67d10 [Runtime] Allow overrides or swift_getAssociated(Type|Conformance)Witness.
Split these two functions into a fast path (for the cached case) and a slow
path. Make the slow path overridable, so we can patch it in the future if
needed.
2018-11-14 21:10:42 -08:00
Doug Gregor
d92a5e8356 [Runtime] Add metadata for Builtin.Int7
Fixes rdar://problem/45880755.
2018-11-14 09:35:15 -08:00
Doug Gregor
c367c8e9cb [Runtime] Adjust "conforming type" based on a given conformance descriptor.
When we are looking for the specific type for a protocol conformance (e.g.,
because we may have a subclass of the type that declared conformances), don't
go back through swift_conformsToProtocol() multiple times, which
requires more lookups in the global conformance table. Instead, use
the (known) protocol conformance descriptor.
2018-11-13 20:45:03 -08:00
Joe Groff
ca402f19b1 Give multi-payload enums extra inhabitants.
Previously, they would forward their unused spare bits to be used by other multi-payload enums, but
did not implement anything for single-payload extra inhabitants.
2018-11-13 18:08:01 -08:00
swift-ci
9334458c61 Merge pull request #20472 from DougGregor/abi-mangled-assoc-conformances-in-witness-tables 2018-11-12 21:09:34 -08:00
Arnold Schwaighofer
853388c930 Merge pull request #20478 from aschwaighofer/disable_dynamic_replacement_chaining
Add support to modify chaining behavior of dynamic replacements
2018-11-12 10:37:58 -08:00
Doug Gregor
81610fdc02 [ABI] Use faux mangled names for associated conformances in witness tables
The current representation of an associated conformance in a witness
tables (e.g., Iterator: IteratorProtocol within a witness table for
Sequence) is a function that the client calls.

Replace this with something more like what we do for associated types:
an associated conformance is either a pointer to the witness table (once
it is known) or a pointer to a mangled name that describes that 
conformance. On first access, demangle the mangled name and replace the
entry with the resulting witness table. This will give us a more compact
representation of associated conformances, as well as always caching
them.

For now, the mangled name is a sham: it’s a mangled relative reference to
the existing witness table accessors, not a true mangled name. In time,
we’ll extend the support here to handle proper mangled names.

Part of rdar://problem/38038799.
2018-11-12 09:42:51 -08:00
John McCall
3e5165d1ab Change the compiler ABI of keypaths.
Previously, the stdlib provided:

- getters for AnyKeyPath and PartialKeyPath, which have remained;

- a getter for KeyPath, which still exists alongside a new read
  coroutine; and

- a pair of owned mutable addressors that provided modify-like behavior
  for WritableKeyPath and ReferenceWritableKeyPath, which have been
  replaced with modify coroutines and augmented with dedicated setters.

SILGen then uses the most efficient accessor available for the access
it's been asked to do: for example, if it's been asked to produce a
borrowed r-value, it uses the read accessor.

Providing a broad spectrum of accessor functions here seems acceptable
because the code-size hit is fixed-size: we don't need to generate
extra code per storage declaration to support more alternatives for
key paths.

Note that this is just the compiler ABI; the implementation is still
basically what it was.  That means the implementation of the setters
and the read accessor is pretty far from optimal.  But we can improve
the implementation later; we can't improve the ABI.

The coroutine accessors have to be implemented in C++ and used via
hand-rolled declarations in SILGen because it's not currently possible
to declare independent coroutine accessors in Swift.
2018-11-10 02:08:04 -05:00
John McCall
75e1df6ef8 [NFC] Minor conveniences for working with metadata. 2018-11-10 02:08:04 -05:00
rposts
12be5b598c ConfigureSystemZ changes 2018-11-09 17:27:58 -05:00
Arnold Schwaighofer
fb7b223ba2 Add support to modify chaining behavior of dynamic replacements
Default to not chain dynamic replacements: Only one replacement and the
original implementation are active.
2018-11-09 13:17:09 -08:00
swift-ci
aa3e16dc8f Merge pull request #20462 from aschwaighofer/dyn_repl_entry_point_must_hold_lock 2018-11-09 09:57:01 -08:00
Johannes Weiss
17e5fa3506 Merge pull request #19421 from weissi/jw-managed-buffer-realloc
implement ManagerBuffer.reallocated to allow realloc'ing the storage
2018-11-09 17:14:08 +00:00
Arnold Schwaighofer
4cb1c339b3 The runtime entry points for enabling/disabling a dynamic replacement scope also must hold the lock 2018-11-09 09:01:07 -08:00
Doug Gregor
f7b2522bdc [ABI] Retrieve all associated conformances via a runtime function.
Introduce a new runtime entry point, swift_getAssociatedConformanceWitness(),
which extracts an associated conformance witness from a witness table.
Teach IRGen to use this entry point rather than loading the witness
from the witness table and calling it directly.

There’s no advantage to doing this now, but it is staging for changing the
representation of associated conformances in witness tables.
2018-11-08 16:42:08 -08:00
Doug Gregor
5758cdcfcc [ABI] Eliminate the special structure for generic parameter references.
TargetGenericParamRef is a specialized structure used to describe the
subject of a generic requirement, e.g., the “T.Assoc” in “T.Assoc: P”.
Replace it with a mangled name, for several reasons:

1) Mangled type names are also fairly concise, can often be shared, and
are a well-tested path
2) Mangled type names can express any type, which might be useful in the
future
3) This structure doesn’t accommodate specifically stating where the
conformances come from (to extract associated type witnesses). Neither
can mangled names, but we’d like to do that work in only one place.

This change exposed an existing bug where we improperly calculated the
generic parameter counts for extensions of nested generic types. Fix that
bug here (which broke an execution test).
2018-11-08 13:58:17 -08:00
Johannes Weiss
2d9fa20c6b implement ManagerBuffer.reallocated to allow realloc'ing the storage 2018-11-08 18:18:23 +00:00
Joe Groff
ff7afcdfd7 Give more extra inhabitants to BridgeObject.
The standard library never ended up needing the low extra inhabitants (<4G on 64-bit Darwin,
<4K elsewhere), so BridgeObject can have the same set of extra inhabitants as the other refcounted
types, allowing `String?????` and `Array??????????` to still use optimized representations.
rdar://problem/45881464
2018-11-07 19:03:22 -08:00
Arnold Schwaighofer
44b3a47e56 Merge pull request #20333 from aschwaighofer/dynamic_function_replacement
Dynamic function replacement
2018-11-07 13:08:46 -08:00
Doug Gregor
9dd6a5f033 [Runtime] Use the old remangler to compute the @objc protocol name.
The “old” mangling that is used for runtime names of @objc protocols
uses a simpler substitution scheme, so you can’t simply take a mangled
name from the new mangling and fix up the ends.

Fixes rdar://problem/45685649.
2018-11-06 15:16:33 -08:00
Arnold Schwaighofer
152e8db8bb IRGen and runtime implementation for dynamic replacements 2018-11-06 09:58:36 -08:00
Saleem Abdulrasool
1ed7874596 Runtime: silence some warnings
Silence warnings about deleted defaulted constructors due to the
non-trivial constructor for the atomic type.  Guard a conditionally used
function with the appropriate guard.
2018-11-04 20:30:34 -08:00
Saleem Abdulrasool
5ee35666c4 Runtime: add UnknownObject on non-ObjC builds
The UnknownObject type is used for the block convention block pointers.
This is used in libdispatch and we cannot build for Windows without it.
2018-11-03 18:06:11 -07:00
Slava Pestov
2f901a7fa1 Runtime: Add a FIXME 2018-11-02 00:47:11 -04:00
Slava Pestov
d093fcb4a4 Reflection: Decode imported Objective-C classes and protocols as their own TypeRef
Right now we expect that every class and protocol has a field
descriptor that tells us if the entity is @objc or not.

For imported types, the descriptor will not exist if we did not
directly emit a field whose concrete type contains the imported
type. For example, in lldb, we might have a generic type whose
runtime substituted type includes an imported type.

In this case, TypeLowering would fail to produce a layout because
it did not find a field descriptor for the imported type.

A better approach is to have the TypeDecoder call a different
factory method for imported types, and handle them specially in
TypeLowering, bypassing the field type metadata altogether.
2018-11-02 00:47:11 -04:00
Doug Gregor
8552af0884 Merge pull request #20217 from DougGregor/runtime-objc-existential-conforms-to-protocol
[Runtime] Check for @objc existentials conforming to @objc protocols.
2018-11-01 09:33:26 -07:00
Doug Gregor
452e1b12e1 [Runtime] Check for @objc existentials conforming to @objc protocols.
When checking conformance requirements against an @objc protocol, also
check for an @objc existential using protocol_conformsToProtocol().
Fixes rdar://problem/45685649.
2018-11-01 06:37:39 -07:00
John McCall
abdba1d3f4 Change the integer-literal type from Int2048 to IntLiteral.
Part of SR-290.
2018-10-31 23:14:58 -04:00
John McCall
cf511445e2 Basic support for Builtin.IntegerLiteral. 2018-10-31 18:42:34 -04:00
John McCall
0bb884546b Add a runtime interface for working with Builtin.IntegerLiteral values. 2018-10-31 04:58:18 -04:00
Saleem Abdulrasool
9f7ee563cb Merge pull request #20113 from compnerd/metadata
runtime: adjust known metadata for SIMD vector types
2018-10-29 14:47:16 -07:00