Commit Graph

643 Commits

Author SHA1 Message Date
Mike Ash
d05a8cab34 [Runtime] Add dump() methods to TypeContextDescriptor and EnumDescriptor. 2019-06-24 11:24:53 -04:00
Saleem Abdulrasool
33767d6052 runtime: silence a unused definition warning (NFC)
When building without assertions, the variable will be unreferenced on
non-ObjC runtimes.  Sink the evaluation into the assertion and move the
declaration into the ObjC runtime case.
2019-06-02 11:22:35 -07:00
Joe Groff
9e1907a2ed Introduce a backward-deployment library for SR-10600.
Build a static archive that can be linked into executables and take advantage of the Swift runtime's
hooking mechanism to work around the issue Doug fixed in https://github.com/apple/swift/pull/24759.
The Swift 5.0 version of swift_conformsToProtocol would return a false negative in some cases where
a subclass conforms using an inherited conformance, so work around this by successively retrying
the original implementation up the superclass chain to try to find a match.
2019-05-24 09:28:49 -07:00
Slava Pestov
97be86bbca Runtime: Don't try to register class stubs on older objc runtimes
This will allow us to emit class stubs unconditionally, rather than
checking the -enable-resilient-objc-class-stubs flag.

Part of <rdar://problem/49090631>.
2019-05-10 21:26:09 -04:00
Slava Pestov
bc4d70c12a Runtime: Fix condition for class stubs support
Fixes <rdar://problem/50068190>.
2019-04-20 18:14:09 -04:00
Joe Groff
05dfec0cda Push the conformance accessor hack down into getTypeByMangledName. 2019-04-17 14:44:40 -07:00
David Zarzycki
ec7647b6b7 [Runtime] Fix trivial Linux build failure 2019-03-27 08:50:20 -04:00
Slava Pestov
9ceb3faee9 Runtime: Add support for Objective-C resilient class stubs
This adds a new tail-allocated field to class context descriptors storing
a pointer to an Objective-C class stub.

When the stub is present, we use the new _objc_realizeClassFromSwift()
entry point to realize the class instead of calling objc_readClassPair().

This should attach categories to the realized class, if they were emitted
to reference the stub.
2019-03-26 18:42:59 -04:00
Erik Eckstein
3c73685b93 runtime: avoid memory allocations in checkTransitiveCompleteness
Use SmallVector instead of std::vector and a SmallPtrSet-like implementation for the set.
2019-03-13 11:49:58 -07:00
Erik Eckstein
abccbd8c8c runtime: make the old remangler allocation free.
Extract common code from the old and new remangler into a common base class.
This lets the old remangler benefit from the changes I did recently in the new remangler.
2019-03-13 11:49:58 -07:00
Erik Eckstein
4186c69103 runtime: Fix a compiler warning in release the build 2019-03-13 11:49:58 -07:00
David Zarzycki
b032d0b38f [Runtime] NFC: Move LLVM_ATTRIBUTE_USED from declaration to definition
This is both more correct and now required to keep building with
top-of-tree clang.
2019-03-08 12:35:53 -05:00
Saleem Abdulrasool
d4757d4b7a Merge pull request #22857 from compnerd/foreign-imports
IRGen: lazy initialize ForeignClassMetadata
2019-03-07 21:34:31 -08:00
Saleem Abdulrasool
3f829c28d2 IRGen: lazy initialize ForeignClassMetadata
This is needed for Windows which does not support cross-module data
references without indirection.  By lazy initializing the data, we can
indirect through the IAT for the data pointer and fill in the parent
pointer.
2019-03-07 16:19:07 -08:00
Mike Ash
c4434fe2a9 Merge pull request #23064 from mikeash/dynamically-select-is-swift-bit
[Runtime] Dynamically select the is-Swift bit at runtime on Apple platforms.
2019-03-07 16:48:15 -05:00
Mike Ash
fbe990481b [Runtime] Dynamically select the is-Swift bit at runtime on Apple platforms.
Recent Swift uses 2 as the is-Swift bit when running on newer versions, and 1 on older versions. Since it's difficult or impossible to know what we'll be running on at build time, make the selection at runtime.
2019-03-07 10:12:27 -05:00
Erik Eckstein
a60086f1dd Runtime: use lambdas to avoid allocations in std::function
Instead of capturing SubstGenericParametersFromMetadata and SubstGenericParametersFromWrittenArgs by value, capture by reference.
This avoids those instances to be copied and thus avoids a lot of mallocs.

SR-10028
rdar://problem/48575729
2019-03-06 14:37:03 -08:00
Slava Pestov
6ac91701dd Runtime: Add precondition check to swift_updateClassMetadata()
This initialization pattern can only be used if there is a backward deployment
layout (IRGen calls this ClassMetadataStrategy::FixedOrUpdate) or if we are
running on a newer Objective-C runtime that supports class metadata update
hooks (IRGen calls this ClassMetadataStrategy::Update).

If neither condition holds, we must trap here to avoid undefined behavior.
2019-02-18 22:39:13 -05:00
Erik Eckstein
80e86fb5c3 Runtime: make the demangler use stack allocated memory.
This reduces the amount of mallocs significantly.
2019-02-15 09:29:49 -08:00
John McCall
a074bc2ed4 Add new APIs for init/updateClassMetadata that can report dependencies. 2019-02-05 16:44:56 -05:00
John McCall
d07efd37e0 Requestify the mangling-to-metadata APIs.
Note that I've called out a couple of suspicious places where we
are requesting abstract metadata for superclasses but probably
need to be requesting something more complete.
2019-02-05 16:20:48 -05:00
John McCall
de4564877a Separate CC attrs in the compatibility-override macro; NFC. 2019-02-05 16:20:48 -05:00
Mike Ash
e07e1db12a [Stdlib] Put $ at the end of the Swift module's generic class ObjC names.
This avoids name conflicts between generic classes in the Swift modules of the old and new stdlibs when loaded into the same process.
2019-01-15 12:21:20 -05:00
Doug Gregor
cacd72f18c [Runtime] Properly unique foreign witness tables.
The Name field of a type descriptor is not the appropriate
way to compare types for uniquing. Instead, use TypeContextIdentity.

Fixes rdar://problem/46685973.
2018-12-13 13:43:36 -08:00
John McCall
724c192120 Propagate the XI count into the get/store XI tag callbacks.
This allows callers to avoid needing to reload these tags in common cases.
2018-12-11 22:18:44 -05:00
John McCall
2ba7090fe8 Remove the extra-inhabitant value witness functions.
This is essentially a long-belated follow-up to Arnold's #12606.
The key observation here is that the enum-tag-single-payload witnesses
are strictly more powerful than the XI witnesses: you can simulate
the XI witnesses by using an extra case count that's <= the XI count.
Of course the result is less efficient than the XI witnesses, but
that's less important than overall code size, and we can work on
fast-paths for that.

The extra inhabitant count is stored in a 32-bit field (always present)
following the ValueWitnessFlags, which now occupy a fixed 32 bits.
This inflates non-XI VWTs on 32-bit targets by a word, but the net effect
on XI VWTs is to shrink them by two words, which is likely to be the
more important change.  Also, being able to access the XI count directly
should be a nice win.
2018-12-11 22:18:44 -05:00
Greg Parker
368ca184fa [runtime] Fix some bugs when the stable ABI's is-Swift bit is set. (#21114)
* cmake: Propagate SWIFT_DARWIN_ENABLE_STABLE_ABI_BIT to overlay builds.
* runtime: Clear the correct bit in getROData()
* test/IRGen/objc_class_export.swift: Allow either is-Swift bit.
* test/stdlib/SwiftObjectNSObject.swift: Allow either name for SwiftObject.
2018-12-07 12:47:39 -08:00
Adrian Prantl
ff63eaea6f Remove \brief commands from doxygen comments.
We've been running doxygen with the autobrief option for a couple of
years now. This makes the \brief markers into our comments
redundant. Since they are a visual distraction and we don't want to
encourage more \brief markers in new code either, this patch removes
them all.

Patch produced by

      for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done
2018-12-04 15:45:04 -08:00
Doug Gregor
2c5ecb477a Merge pull request #20858 from DougGregor/mangled-base-protocol-witnesses
[ABI] Use mangled names for base protocol witnesses.
2018-12-04 11:28:27 -08:00
Doug Gregor
f2dd852f94 [ABI] Optimize out the witness table pattern for resilient conformances.
Resilient conformances now put all witnesses into the resilient witness
table, so optimize away the witness table pattern for such cases. Teach
the runtime to fill in the protocol conformance descriptor, because that’s
the only bit of real information that would be in the pattern.

This is a minor optimization enabled by rdar://problem/46282080.
2018-12-03 20:16:18 -08:00
Slava Pestov
213d089c28 Runtime: Don't crash when overriding a weak-imported method that's not available 2018-12-03 20:36:03 -05:00
Doug Gregor
c0519c7185 [ABI] Put mangled inherited protocol witnesses into the resilient witness table
Emit mangled inherited protocol witnesses into the resilient witness table,
and realize them when we instantiate the resilient witness table. Don’t
put mangled inherited protocol witnesses into non-resilient witness tables:
there is no efficient way to make sure they are realized, so keep the
previous instantiation-function approach.

Implements the rest of rdar://problem/46282080.
2018-12-03 17:29:33 -08:00
Greg Parker
70bbeaab78 [runtime] Register a hook for class name lookup from libobjc (#20650)
libobjc needs to look up classes by name. Some Swift classes, such as
instantiated generics and their subclasses, are created only on demand.
Now a by-name lookup from libobjc counts as a demand for those classes.

rdar://problem/27808571
2018-11-29 17:06:28 -08:00
Doug Gregor
19941d3494 [Runtime] Have the runtime copy instantiation arguments into private data.
Rather than having the witness table instantiation function copy the 
instantiation arguments that corresponding to conditional requirements
into the private area, have the runtime do it. We’re going to depend on
these lining up anyway (and the witness table can of course have *more*
private slots that it manages some other way), so centralize the code.

More of rdar://problem/46282080.
2018-11-29 17:05:05 -08:00
Doug Gregor
3ef38ab94e [Runtime] Eagerly realize mangled base protocol witnesses.
If the witness for a base protocol is a mangled name, eagerly turn that name
into a witness table via swift_getAssociatedConformanceWitness(). This
allows the compiler to emit base protocol witnesses as mangled names
(as it does for associated conformances).
2018-11-29 17:04:41 -08:00
Slava Pestov
86f23ec83f Runtime: Fill in the value witness table of a class when doing singleton metadata initialization
On Windows the image format does not support cross-image absolute
data symbol references. One case where we emit these is in class
metadata, because the value witness table always points at the
value witness table for Builtin.NativeObject, defined in the
runtime.

Instead, fill in the value witness table at runtime when doing
singleton metadata initialization.

Another change that will come later is to force use of singleton
metadata initialization on Windows, even if the class is otherwise
completely fixed.
2018-11-26 22:12:00 -05:00
Slava Pestov
76dce7c5e0 Runtime: The class metadata relocation function can be null
IRGen always just emits a simple implementation that immediately
calls swift_relocateClassMetadata(); so allow the function to be
null in this case to save on code size.
2018-11-26 21:22:48 -05:00
Slava Pestov
12de97c73f Runtime: Some const correctness 2018-11-26 21:22:48 -05:00
Doug Gregor
39481149a3 [Runtime] Compute generic metadata cache info once per type.
Rather than scanning through the generic parameters and generic requirements
each time we form a key for the generic metadata cache, compute these
values once, when the cache itself is first initialized.
2018-11-26 10:46:42 -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
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
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
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
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
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
75e1df6ef8 [NFC] Minor conveniences for working with metadata. 2018-11-10 02:08:04 -05: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