Commit Graph

1782 Commits

Author SHA1 Message Date
Mike Ash
794ff31d73 Merge pull request #19794 from mikeash/fix-instruments-and-retain-counts
[Runtime] Fix swift_retainCount for deiniting objects and BridgeObject tagged values. Make swift_bridgeObjectRetain/Release bail out early for tagged values.
2018-10-11 14:32:43 -04:00
Saleem Abdulrasool
f7f1f026f4 stdlib: install the image registrar in the static runtime
We were previously only installing the image registration helper in the shared
runtime location.  When building with a static runtime, we would look in the
wrong location.  Ensure that we install to both locations to repair the static
builds.
2018-10-11 10:42:25 -07:00
Doug Gregor
aba018c1e8 [ABI] Pass requirement base descriptor to swift_getAssociatedTypeWitness().
Have clients pass the requirement base descriptor to
swift_getAssociatedTypeWitness(), so that the witness index is just one
subtraction away, avoiding several dependent loads (witness table ->
conformance descriptor -> protocol descriptor -> requirement offset)
in the hot path.
2018-10-10 22:45:59 -07:00
Mike Ash
101c7cbbdb [Runtime] Fix a leak when reading a weak property with Mirror.
SR-8878 rdar://problem/44872927
2018-10-09 12:48:44 -04:00
Mike Ash
1afd079b78 [Runtime] Fix swift_retainCount for deiniting objects and BridgeObject tagged values. Make swift_bridgeObjectRetain/Release bail out early for tagged values.
The Allocations Instrument overrides swift_retain with a function that records the retain count by calling swift_retainCount. Its assert for bits.getIsDeiniting() is incorrect in that case, so remove it.

The recent change to ObjC tagged pointer bits on x86-64 also caused the various bridgeObjectRetain/Release functions to call through to swift_retain for BridgeObject tagged values on Mac. swift_retain ignored those values so there was no functional change, except when Instruments overrode it and passed them to swift_retainCount, which tried to dereference them and crashed. Modify bridgeObjectRetain/Release to bail out early again. Also modify swift_retainCount to ignore those values in case anything else expects retainCount to work on any pointer swift_retain accepts.

rdar://problem/45102538
2018-10-09 10:04:06 -04:00
Mike Ash
f4db1dd7a4 Merge pull request #19614 from mikeash/no-internal-export
[Stdlib] Change SWIFT_RUNTIME_STDLIB_INTERNAL to not export the symbol.
2018-10-05 09:26:03 -04:00
Doug Gregor
6e0d1d3222 Merge pull request #19719 from DougGregor/superclass-mangled-name
[ABI] Use mangled superclass names from class context descriptors.
2018-10-04 19:58:46 -07:00
Doug Gregor
2b44e8578f [ABI] Use mangled superclass names from class context descriptors.
Rather than rely on the metadata initialization function to compute and
fill in the superclass, use the mangled superclass name to construct the
superclass metadata.
2018-10-04 15:43:24 -07:00
Mike Ash
a78a01a392 [Stdlib] Make _swift_extractDynamicValue INTERNAL as it's used by Foundation. 2018-10-04 13:20:53 -04:00
Mike Ash
fa4178c5e8 [IRGen][Runtime] Adjust the ObjC reserved bits on x86-64 to exactly match what the target uses.
Previously we had a single mask for all x86-64 targets which included both the top and bottom bits. This accommodated simulators, which use the top bit, while macOS uses the bottom bit, but reserved one bit more than necessary on each. This change breaks out x86-64 simulators from non-simulators and reserves only the one bit used on each.

rdar://problem/34805348 rdar://problem/29765919
2018-10-04 12:34:08 -04:00
Doug Gregor
0970ab9ef8 [Runtime] Check demangled superclass names against compiler-provided super.
Introduce a sanity check verifying that we can demangle the superclass
of a class when forming type metadata, and that the result matches the
compiler-provided superclass metadata.
2018-10-03 22:19:25 -07:00
Doug Gregor
a4778e1c0c [ABI] Only emit resilient superclass descriptor references in class metadata.
The superclass descriptor reference in class context descriptors is only used
for metadata bound computations when the superclass is resilient. Only
include the superclass descriptor reference when the class has a resilient
superclass, using a trailing record. It’s a tiny space savings for
classes that don’t have resilient superclasses.
2018-10-03 20:05:28 -07:00
Mike Ash
e18e03171f [Stdlib] Change SWIFT_RUNTIME_STDLIB_INTERNAL to not export the symbol.
The functions in LibcShims are used externally, some directly and some through @inlineable functions. These are changed to SWIFT_RUNTIME_STDLIB_SPI to better match their actual usage. Their names are also changed to add "_swift" to the front to match our naming conventions.

Three functions from SwiftObject.mm are changed to SPI and get a _swift prefix.

A few other support functions are also changed to SPI. They already had a prefix and look like they were meant to be SPI anyway. It was just hard to notice any mixup when they were #defined to the same thing.

rdar://problem/35863717
2018-10-03 09:55:33 -04:00
Doug Gregor
df7744e484 Merge pull request #19480 from DougGregor/mangled-assoc-type-witness
[ABI] Use mangled names for associated type witnesses.
2018-10-01 06:57:45 -07:00
Doug Gregor
9a403a0dae [Runtime] Only cache completed type metadata for associated type witnesses.
This is the scheme used for metadata caches elsewhere, and it
eliminates the need to check the metadata state along the hot path of
swift_getAssociatedTypeWitness().
2018-09-30 21:35:15 -07:00
Doug Gregor
65c0c842ed [ABI] Rework the tagging of default associated type witnesses.
Encode default associated type witnesses using a sentinel prefix byte
(0xFF) in the mangled name rather than as a second low bit on the
reference. Align all of the mangled names used for type references to
2 bytes (so we get that low bit regardless) and separate the symbol
names for default associated type witnesses vs. other kinds of
metadata or reflection metadata.
2018-09-28 23:38:38 -07:00
Doug Gregor
22808d1831 [Runtime] Make swift_getAssociatedTypeWitness() bounds checking an assertion. 2018-09-28 10:48:23 -07:00
Doug Gregor
441fee071a [Witness tables] Use a discriminator bit for default associated type witnesses
Indicate whether a particular associated type witness is a default (whose
mangled name is relative to the protocol) vs. being supplied as part of the
conformance (whose mangled name is relative to the conforming type). The
use of pointer identity to distinguish these cases can fail due to the
coalescing of these linker symbols.
2018-09-27 13:26:31 -07:00
Max Moiseev
b9b568b6ec Merge pull request #19565 from moiseev/try-bang-location-info
try! error message should report the right location
2018-09-27 09:12:46 -07:00
Doug Gregor
1416f8dd7d [Runtime] Witness table accessors no longer take the count. 2018-09-26 23:19:34 -07:00
Doug Gregor
5d2f55751a [Runtime] Substitute into associated types using the original conforming type
When producing an associated type witness from a mangled name, adjust the
conforming type metadata to find the original conforming type, which may
be a superclass of the conforming type given.
2018-09-26 23:19:34 -07:00
Doug Gregor
f64044e762 [Runtime] Improve fatal error when unable to demangle an associated type witness. 2018-09-26 23:19:33 -07:00
Doug Gregor
5f56d2faf9 [Runtime] Properly turn a const char* into a StringRef for a mangled name.
Use makeSymbolicMangledNameStringRef() to skip over null characters within
symbolic references.
2018-09-26 23:19:33 -07:00
Doug Gregor
c3d0ba8df4 [IRGen/Runtime] Witness tables with dependent associated types need instantiation.
Associated type witnesses in a witness table are cache entries, which are
updated by the runtime when the associated types are first accessed. The
presence of an associated type witness that involves type parameters requires
the runtime to instantiate the witness table; account for that in the runtime.
The presence of any associated type witness makes the witness table
non-constant.
2018-09-26 23:19:33 -07: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
Doug Gregor
c45c84d913 [Runtime] Handle all generic parameters at once demangling to metadata.
When demangling a symbolic reference to a nested generic type, the
demangle-to-metadata path will be given all levels of generic arguments at
once. Cope with this in the demangling-to-metadata path.

Eventually, we would like to switch all clients over to take all
levels of generic arguments at once.
2018-09-26 15:33:15 -07:00
Doug Gregor
cf2a47e14c [Runtime] Handle non-key generic parameters when demangling to metadata.
When forming metadata for a nested generic type, gather all of the
generic arguments from the parent type “as written”, so that we can directly
map generic parameters to those generic arguments when they occur within
requirements. This allows us to demangle nested types within extensions
that have same-type constraints on generic parameters into type metadata.

Fixes rdar://problem/37170296.
2018-09-26 14:41:04 -07:00
Doug Gregor
546e7e264b [Runtime] Factor out a function object to look into “written” generic args.
NFC
2018-09-26 14:01:03 -07:00
Doug Gregor
9436793852 [Runtime] Split out the code to extract all “written” generic args from metadata
NFC. We’ll need this code elsewhere.
2018-09-26 13:47:01 -07:00
Maxim Moiseev
5f17e64be0 try! error message should reprt the right location
At the moment the location being reported is inside the standard
library, which is not very helpful. Instead, the location should point
at the `try!` expression in the application code.

Fixes: rdar://problem/21407683
2018-09-26 11:22:41 -07:00
Doug Gregor
d73a2e0d39 [Runtime] Properly form generic arguments for metadata-to-demangle-tree.
When mapping from type metadata to a demangle tree, fill in the complete
set of generic arguments. Most of the effort here is in dealing with
extensions that involve same-type constraints on a generic parameter, e.g.,

  extension Array where String == Element { }
  extension Dictionary where Key == Value { }

In such cases, the metadata won’t contain generic arguments for every
generic parameter. Rather, the generic arguments for non-key generic
parameters will need to be computed based on the same-type requirements
of the context. Do so, and eliminate the old hacks that put the generic
arguments on the innermost type. We don’t need them any more.

Part of rdar://problem/37170296.
2018-09-25 23:10:08 -07:00
Doug Gregor
3dda40b17e [Runtime] Match up extensions of Objective-C classes by mangled nodes.
When comparing an extension context for Objective-C classes, there are no
context descriptors to use. Instead, perform a string match.
2018-09-25 10:53:54 -07:00
Slava Pestov
c67d4ab3b0 Merge pull request #19474 from slavapestov/class-backward-deployment
More progress on backward deployment support for classes with resiliently-sized fields
2018-09-24 15:34:42 -07:00
Saleem Abdulrasool
e0e75ead37 Merge pull request #19434 from compnerd/a-stable-future
runtime: remove unnecessary preprocessor condition, flip cases (NFC)
2018-09-24 14:33:41 -07:00
Mike Ash
1fb165a0ea Merge branch 'master' into rename-conflicting-classes-and-methods 2018-09-24 10:17:22 -04:00
Slava Pestov
4da47823a5 Runtime/IRGen: Add new initialization pattern for classes with backward deployment layout
If a class has a backward deployment layout:

- We still want to emit it using the FixedClassMetadataBuilder.

- We still want it to appear in the objc_classes section, and get an
  OBJC_CLASS_$_ symbol if its @objc.

- However, we want to use the singleton metadata initialization pattern
  in the metadata accessor.

- We want to emit metadata for all field types, and call the
  swift_updateClassMetadata() function to initialize the class
  metadata.

For now, this function just performs the idempotent initialization of
invoking a static method on the class, causing it to be realized with
the Objective-C runtime.
2018-09-23 21:26:46 -07:00
Slava Pestov
0088055f77 Runtime: Set up the class's runtime name in initGenericObjCClass() 2018-09-23 21:26:46 -07:00
Slava Pestov
0e4248375d Runtime: Introduce a new code path for initializing non-generic class metadata
It's a bit simpler because we don't have to change the ivar descriptors
back and forth.
2018-09-23 21:26:46 -07:00
Slava Pestov
62aecd31b7 Runtime: Split up swift_initClassMetadata()
- Rename _swift_initializeSuperclass() to copySuperclassMetadataToSubclass(),
- Factor out initClassFieldOffsetVector()
- Factor out initClassVTable()
- Factor out initGenericObjCClass()
2018-09-23 21:26:46 -07:00
Slava Pestov
6084dc285e Runtime: Only initialize metaclass superclass if superclass is generic
Otherwise, we emitted a static reference to its metaclass, so there's
no need to overwrite it here. This doesn't really improve anything,
it was just something I noticed while auditing this code in
preparation for a refactoring, so may as well fix it.
2018-09-23 21:26:46 -07:00
Slava Pestov
724830acd5 Runtime: Use the resilient metadata allocator instead of malloc() for resilient classes
Also move getResilientMetadataAllocator() and swift_relocateClassMetadata() to the top
of the "classes" section, instead of putting it in the middle.
2018-09-23 21:26:46 -07:00
Doug Gregor
18e6ea76dd Merge pull request #19486 from DougGregor/runtime-metadata-subst-same-type-extensions
[Runtime] Handle non-key arguments when substituting from metadata.
2018-09-23 20:26:28 -07:00
Doug Gregor
3ea48770fe [Runtime] Handle non-key arguments when substituting from metadata.
Reimplement SubstGenericParametersFromMetadata to cope with non-key
generic parameters, which are counted when referring to generic parameters
from metadata but do not have corresponding generic arguments.
2018-09-22 23:32:49 -07:00
Doug Gregor
5a87435b8e [Runtime] Simplify ProtocolConformanceDescriptor::getWitnessTable().
Use SubstGenericParametersFromMetadata to handle substitutions when
checking generic requirements, extending SubstGenericParametersFromMetadata
for this purpose.
2018-09-22 20:51:03 -07:00
Doug Gregor
0a775dab54 [Runtime] Extract a function object for demangling using base metadata.
The field metadata translation has a great little lambda for extracting
generic arguments from metadata when demangling. Extract it into a
reusable function object.
2018-09-22 20:38:47 -07:00
Doug Gregor
15214b3f5b Merge pull request #19483 from DougGregor/runtime-demangle-fixes
[Runtime] Fixes for demangling to metadata
2018-09-22 07:26:27 -07:00
Doug Gregor
298458a926 [Runtime demangler] Mangled extension context doesn’t always have Type.
The demangle tree for an extension type context doesn’t always have a
Type node wrapping it, and that’s okay.
2018-09-22 00:08:48 -07:00
Doug Gregor
3f79cb9976 [Runtime] Replace outdated signature for associated type access functions.
The resolution of generic parameter references, which is used for
checking generic requirements at runtime, was written in terms of an
outdated signature for associated type access functions that did not
account for the MetadataRequest parameter or MetadataResponse result.
Use the existing AssociatedTypeAccessFunction typedef instead.

Fixes SR-7553 / rdar://problem/39769906
2018-09-21 23:47:02 -07:00
Doug Gregor
6982284baf [Runtime] Only request Abstract metadata when demangling to metadata.
When SWIFT_ENABLE_MANGLED_NAME_VERIFICATION is set, we would end up
deadlocking when we encounter a metadata cycle. The demangling code only
requires abstract metadata, because at most it needs type identity and
filling in the type arguments of generics. Update clients of
_getTypeByMangledName to assert the kind of metadata they require.
2018-09-21 22:40:44 -07:00
Saleem Abdulrasool
f9af5cb685 Merge pull request #19462 from compnerd/what-is-in-a-name
stdlib: check for ARM/ARM64 more thoroughly (NFC)
2018-09-21 14:19:47 -07:00