Commit Graph

655 Commits

Author SHA1 Message Date
Mike Ash
1da182555a [Runtime] When the ObjC runtime supports lazy class names, lazily create the ObjC names for generic classes.
rdar://problem/57674583
2019-12-12 15:25:22 -05:00
Varun Gandhi
affa1b49bf [Runtime] Memset Extradata fully before copy from pattern. (#28478)
The third argument of memset needs a size in *bytes* not words.
2019-12-04 08:48:01 -08:00
Mike Ash
3912e7c8ac [Runtime] Enhance Metadata::dump to dump the number of generic args and the pointer of each. 2019-11-22 13:17:54 -05:00
Mike Ash
7b650c5da5 [Runtime] Extend Metadata::dump for existential type metadata.
Dump whether it's class bounded, the protocols it contains, and the superclass constraint if there is one.
2019-10-30 09:36:14 -04:00
Jordan Rose
a6dd630ca3 Eliminate Builtin.UnknownObject as an AST type (#27378)
This removes it from the AST and largely replaces it with AnyObject
at the SIL and IRGen layers. Some notes:

- Reflection still uses the notion of "unknown object" to mean an
  object with unknown refcounting. There's no real reason to make
  this different from AnyObject (an existential containing a
  single object with unknown refcounting), but this way nothing
  changes for clients of Reflection, and it's consistent with how
  native objects are represented.

- The value witness table and reflection descriptor for AnyObject
  use the mangling "BO" instead of "yXl".

- The demangler and remangler continue to support "BO" because it's
  still in use as a type encoding, even if it's not an AST-level
  Type anymore.

- Type-based alias analysis for Builtin.UnknownObject was incorrect,
  so it's a good thing we weren't using it.

- Same with enum layout. (This one assumed UnknownObject never
  referred to an Objective-C tagged pointer. That certainly wasn't how
  we were using it!)
2019-09-26 17:48:04 -07:00
Joe Groff
f1e84994ed Demangler: Make symbolic reference resolver part of demangle(Symbol|Type) calls.
This makes for a cleaner and less implicit-context-heavy API, and makes it easier for symbolic
reference resolvers to do context-dependent things (like map the in-memory base address back to a
remote address in MetadataReader).
2019-09-13 15:47:08 -07:00
Azoy
ab5ef84046 Fix crash on tuple metadata dump 2019-08-03 01:27:44 -04:00
JF Bastien
31e6a989f5 [NFC] Don't use LLVM_ALIGNAS (#26411)
It's not useful anymore, and I'm about to remove it in upstream.
2019-07-30 13:14:02 -07:00
Michael Munday
2f8b5ac9e2 Runtime: print type layout values correctly on big-endian systems
The memcpy in the type layout verifier was not correct for big-
endian systems. While we are here change 'long long' to a fixed
width unsigned type (uint64_t). It doesn't really make sense to
print the value as a signed number since we have zero extended
it from its original bit width using the memcpy.
2019-07-15 03:24:22 -04:00
Jordan Rose
284b674900 [Runtime] Improve dump() for Metadata and (Type)ContextDescriptor
No functionality change.
2019-07-08 17:46:08 -07:00
Saleem Abdulrasool
c0fb0036a3 Runtime: add a workaround for Windows ARM64
Unfortunately, `std::atomic` in msvcprt as of 14.21.27702 is broken for
double-width atomics on ARM64.  This has been reported to Microsoft and
is going to be fixed in VC++ 2019u3.  For the time being, add a partial
template specialisation for the two double-word sized types temporarily
as a workaround.  This allows the standard library build to get further.
2019-07-03 09:27:59 -07:00
Jordan Rose
57a0c9f5f8 [Runtime] Fix some type mismatch errors (#25790)
Harmless in practice, but still good hygiene.
2019-06-26 15:17:50 -07:00
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