Commit Graph

562 Commits

Author SHA1 Message Date
Nate Chandler
6d0c34caf3 [Runtime] Add entry point to compare conformance descriptors.
The new function swift_compareProtocolConformanceDescriptors calls
through to the preexisting code in MetadataCacheKey which has been
extracted out from MetadataCacheKey::compareWitnessTables into a new
public static function
MetadataCacheKey::compareProtocolConformanceDescriptors.

The new function's availability is "future" for now.
2020-06-22 15:01:28 -07:00
swift-ci
ecad335f70 Merge pull request #32476 from nate-chandler/runtime/add-swift_compareTypeContextDescriptors 2020-06-22 14:40:35 -07:00
Nate Chandler
2c6d7d78df [Runtime] Add entry point to compare type context descriptors.
The new function `swift_compareTypeContextDescriptors` is equivalent to
a call through to swift::equalContexts.  The implementation it the same
as that of swift::equalContexts with the following removals:
- Handling of context descriptors of kind other outside of
  ContextDescriptorKind::Type_First...ContextDescriptorKind::Type_Last.
  Because the arguments are both TypeContextDescriptors, the kinds are
  known to fall within that range.
- Casting to TypeContextDescriptor.  The arguments are already of that
  type.

For now, the new function has "future" availability.
2020-06-22 12:07:02 -07:00
Mike Ash
3fcf86ac01 [Reflection][swift-inspect] Show tag names when dumping raw metadata allocations. 2020-06-17 11:31:12 -04:00
Mike Ash
cd624bf380 [Runtime][Reflection][swift-inspect] Add facilities for tracking and examining backtraces for metadata allocations.
rdar://problem/63674755
2020-06-11 14:49:52 -04:00
Mike Ash
e1c47cf593 [Runtime] Comment the MetadataAllocatorTags enum. 2020-05-29 08:31:04 -07:00
Mike Ash
2c7f09cef7 [Tools] Add some metadata printing to swiftdt.
rdar://problem/55481578
2020-05-29 08:31:03 -07:00
Mike Ash
22cfe461ec [Tools] Super rough draft of swiftdt dumping MetadataAllocator contents.
rdar://problem/55481578
2020-05-29 08:31:03 -07:00
Nate Chandler
2863f1964d [Runtime] Handle incomplete class metadata in _checkGenericRequirements.
When constructing the metadata for a type Gen<T : Super>
where Super is a superclass constraint, the generic argument K at which
the metadata for Gen is being instantiated is verified to be a subclass
of Super via _checkGenericRequirements.

Previously, that check was done using swift_dynamicCastMetatype.  That
worked for the most part but provided an incorrect answer if the
metadata for K was not yet complete.  These classes are incomplete more
often thanks to __swift_instantiateConcreteTypeFromMangledNameAbstract.

That issue occurred concretely in the following case:

  Framework with Library Evolution enabled:

    open class Super { ... }
    public struct Gen<T : Super> {
    }

  Target in a different resilience domain from that framework:

    class Sub : Super {
      var gen: Gen<Sub>?
    }

Here, the mechanism for checking whether the generic argument K at which
the metadata for Gen is being instantiated handles the case where K's
metadata is incomplete.  At worst, every superclass name from super(K)
up to Super are demangled to instantiate metadata.  A number of faster
paths are included as well.

rdar://problem/60790020
2020-04-03 13:28:54 -07:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Joe Groff
bfc9ba98f8 Runtime: Don't export equalContexts.
This should be an internal-only helper.
2019-05-23 10:44:55 -07:00
Saleem Abdulrasool
5066729677 Runtime: remove keypath functions in the compiler build
The host tools may be built with the host compiler.  cl objects to the
"extern C" function returning a C++ type which the keypath functions do.
However, these declarations are needed only in the runtime, which is
always built with clang.  Preprocess away the declarations during the
build of the compiler.  This allows us to build with cl once more.
2019-02-25 11:21:28 -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
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
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
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
Slava Pestov
12de97c73f Runtime: Some const correctness 2018-11-26 21:22:48 -05: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
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
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
bc239d37a2 [Runtime] Use the Swift calling convention for swift_getAssociatedTypeWitness.
Runtime functions need to use the Swift calling convention for any function
returning MetadataResponse, so that we get the two values returned in separate
registers.

Fixes rdar://problem/45042971 and rdar://problem/45851050.
2018-11-07 09:26:30 -08:00
Arnold Schwaighofer
152e8db8bb IRGen and runtime implementation for dynamic replacements 2018-11-06 09:58:36 -08:00
Doug Gregor
65d5d15fc1 [Runtime] Extend known builtin metadata for floating point and vector types.
Expose symbols for metadata for the various builtin floating point types
and vector types. This is used by the demangler to handle builtin names.

This is a narrow fix for rdar://problem/45569984 (where we couldn’t
demangle a builtin vector type). A more extensive fix will require us
to add a general runtime facility for creating opaque type metadata
with specific size/alignment/stride/uniquing name.
2018-10-26 16:05:31 -07:00
Doug Gregor
dd154f6668 [Runtime] Rename swift_instantiateWitnessTable() -> swift_getWitnessTable()
This runtime function doesn’t always perform instantiation; it’s how we
get a witness table given a conformance, type, and set of instantiation
arguments. Name it accordingly.
2018-10-25 20:35:27 -07:00
Doug Gregor
b5bc06e552 [ABI] Eliminate witness table accessors.
Witness table accessors return a witness table for a given type's
conformance to a protocol. They are called directly from IRGen
(when we need the witness table instance) and from runtime conformance
checking (swift_conformsToProtocol digs the access function out of the
protocol conformance record). They have two interesting functions:

1) For witness tables requiring instantiation, they call
swift_instantiateWitnessTable directly.
2) For synthesized witness tables that might not be unique, they call
swift_getForeignWitnessTable.

Extend swift_instantiateWitnessTable() to handle both runtime
uniquing (for #2) as well as handling witness tables that don't have
a "generic table", i.e., don't need any actual instantiation. Use it
as the universal entry point for "get a witness table given a specific
conformance descriptor and type", eliminating witness table accessors
entirely.

Make a few related simplifications:

* Drop the "pattern" from the generic witness table. Instead, store
  the pattern in the main part of the conformance descriptor, always.
* Drop the "conformance kind" from the protocol conformance
  descriptor, since it was only there to distinguish between witness
  table (pattern) vs. witness table accessor.
* Internalize swift_getForeignWitnessTable(); IRGen no longer needs to
  call it.

Reduces the code size of the standard library (+assertions build) by
~149k.

Addresses rdar://problem/45489388.
2018-10-25 20:35:27 -07:00
Doug Gregor
a0e3258ba6 [ABI] Collapse generic witness table into protocol conformance record.
Collapse the generic witness table, which was used only as a uniquing
data structure during witness table instantiation, into the protocol
conformance record. This colocates all of the constant protocol conformance
metadata and makes it possible for us to recover the generic witness table
from the conformance descriptor (including looking at the pattern itself).

Rename swift_getGenericWitnessTable() to swift_instantiateWitnessTable()
to make it clearer what its purpose is, and take the conformance descriptor
directly.
2018-10-22 23:36:31 -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
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
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
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
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
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
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
ca58db21b4 Runtime: Introduce swift_lookUpClassMethod() 2018-09-07 21:50:58 -07:00
Slava Pestov
1a5c0023d6 Rutime: Code review feedback from John 2018-08-24 00:52:36 -07:00
Slava Pestov
8be09fef74 IRGen/Runtime: Rename "InPlaceMetadata" to "SingletonMetadata"
It's not actually "in-place" for resilient classes, which have a
pattern with an allocation function.
2018-08-24 00:52:36 -07:00
Slava Pestov
03cb6d1ff4 IRGen/Runtime: Use a true-const pattern to initialize non-generic resilient class metadata
Previously we would emit class metadata for classes with resilient
ancestry, and relocate it at runtime once the correct size was known.

However most of the fields were blank, so it makes more sense to
construct the metadata from scratch, and store the few bits that we
do need in a true-const pattern where we can use relative pointers.
2018-08-23 23:40:08 -07:00
Slava Pestov
50a037d8ed Runtime: Set the superclass in swift_initClassMetadata()
Now that we don't need the superclass before calling
swift_relocateClassMetadata(), it seems simpler to set it
here instead of doing it in various places in IRGen.
2018-08-20 16:23:07 -07:00
Slava Pestov
3256ee43c0 Runtime: swift_relocateClassMetadata() calculates metadata bounds from the class descriptor
Using the superclass metadata here no longer makes sense with two-phase
init, in case the superclass metadata depends on the class being
instantiated.

It would also be nice to rework the resilient class metadata 'pattern'
to be its own data structure that's true const, instead of just the
prefix of a real class metadata, but for now let's keep the existing
crappy design.
2018-08-20 16:23:07 -07:00
Joe Groff
2166dfcfdd Merge pull request #18746 from jckarter/nominal-type-field-info-xref
IRGen/Runtime: Reference field descriptor directly from type context descriptors.
2018-08-20 13:32:39 -07:00
Joe Groff
c11aacc576 KeyPaths: Put an override shim on swift_getKeyPath.
This will let future compilers that support new key path features backward-deploy logic for interpreting new kinds of key path patterns.
2018-08-16 13:15:21 -07:00
Joe Groff
6ea8134eac Runtime: Simplify getFieldAt and take it private. 2018-08-15 16:44:16 -07:00
Joe Groff
2a8b7f76bf Runtime: Don't register fieldmd sections.
They're no longer necessary to track separately from types.
2018-08-15 16:20:53 -07:00
John McCall
1f80d21e1e Merge pull request #18340 from Azoy/remove-_interface
[Visibility] Remove _INTERFACE
2018-07-29 21:37:37 -04:00
John McCall
436a8b273d Add runtime functions to compute tuple layouts from element layouts.
Previously, when a tuple type had non-fixed layout, we would compute
a layout by building the metadata for that tuple type and then
extracting the layout from the VWT.  This can be quite expensive
because it involves constructing the exact metadata for types like
arrays and functions despite those types being fixed-layout across
all instantiations.  It also tends to cause unnecessary recursive-type
issues, especially with enums where tuples are currently used to model
cases with mutliple payloads.  Since we just need a layout, computing
it directly from element layouts instead of constructing metadata for
the formal type lets us take advantage of all the other fast paths for
layout construction, e.g. for fixed types and single-field aggregates.

This is a good improvement overall, but it also serves to alleviate
some of the problems of rdar://40810002 / SR-7876 in a way that
might be suitable for integration to 4.2.
2018-07-29 18:27:27 -04:00
Azoy
b8fc8b333c Remove _interface 2018-07-29 10:41:22 -04:00
John McCall
db8f23df74 Update the ABI for uniquing foreign type metadata.
- `swift_getForeignTypeMetadata` is now a request/response function.

- The initialization function is now a completion function, and the
  pointer to it has moved into the type descriptor.

- The cache variable is no longer part of the ABI; it's an
  implementation detail of the access function.

- The two points above mean that there is no special header on foreign
  type metadata and therefore that they can be marked constant when
  there isn't something about them that needs to be initialized.

The only foreign-metadata initialization we actually do right now is
of the superclass field of a foreign class, and since that relationship
is a proper DAG, it's not actually possible to have recursive
initialization problems.  But this is the right long-term thing to do,
and it removes one of the last two clients of once-based initialization.
2018-07-29 03:16:35 -04:00
David Zarzycki
8231b3a750 [IRGen & Runtime] Remove prefab'ed VWT for reference storage types
The prefab'ed value witness tables for reference storage types are a
premature optimization. Not all scenarios are covered, and those that
are "look suspect" according to John McCall.
2018-07-28 09:43:12 -04:00
Davide Italiano
44cccd011e Merge pull request #18205 from dcci/valuewittarget
[Runtime] Targetize the layout of ValueWitnessTable.
2018-07-25 14:00:26 -07:00