Commit Graph

1350 Commits

Author SHA1 Message Date
Slava Pestov
d4285266ee Merge pull request #13845 from slavapestov/class-dispatch-thunks-irgen
Generate class dispatch thunks in IRGen
2018-01-16 11:48:07 -08:00
Doug Gregor
cb5780f8b5 [IRGen] Don't use "readnone" for calls to metadata accessors with buffers.
When we allocate and pass a buffer to the nominal type access function,
mark the call as "inaccessiblemem_or_argmemonly" rather than "readnone".
2018-01-15 22:08:37 -08:00
Slava Pestov
c13ccde39f IRGen: Refactor emitVirtualMethodValue() 2018-01-15 21:10:05 -08:00
Doug Gregor
644226838b [ABI] Pass only three direct args to nominal type access functions.
The nominal type access functions took all of the generic arguments
directly, which is hard to call from the runtime. Instead, pass up to
three generic arguments directly (because it’s good for code size), and put the rest into an array.
2018-01-13 22:33:46 -08:00
John McCall
52bb547a7e Merge pull request #13866 from rjmccall/accessor-decl
Split AccessorDecl out from FuncDecl.  NFC.
2018-01-12 17:02:35 -05:00
swift-ci
9b58ed0ad7 Merge pull request #13884 from DougGregor/runtime-substitution-mangled-to-metadata 2018-01-12 13:43:10 -08:00
John McCall
7f0f8830cd Split AccessorDecl out from FuncDecl. NFC.
This has three principal advantages:

- It gives some additional type-safety when working
  with known accessors.

- It makes it significantly easier to test whether a declaration
  is an accessor and encourages the use of a common idiom.

- It saves a small amount of memory in both FuncDecl and its
  serialized form.
2018-01-12 14:20:27 -05:00
Slava Pestov
9ff97367df AST: Rename hasFixedLayout() to isResilient() and flip polarity
In IRGen we call this isResilient() already in IRGen, and it's
more consistent to call it the same thing everywhere.
2018-01-11 21:57:42 -08:00
Doug Gregor
3405852ef0 [Runtime] Find metadata for substitutions into demangled dependent members.
Extend the protocol descriptor with a (space-separated) list of associated
type names, in the order of their requirements. Use this information in
the runtime to support lookup of associated type witnesses by name when
mapping a mangled name to a type and substituting generic parameters.
2018-01-11 16:04:53 -08:00
swift-ci
0eb3ff53a8 Merge pull request #13874 from DougGregor/runtime-tuple-metadata-opt 2018-01-11 12:22:50 -08:00
Doug Gregor
93cd5e8270 [ABI] Make TargetTupleTypeFlags size_t sized and move “labels” bit.
Addresses feedback from @rjmccall.
2018-01-11 11:08:12 -08:00
Doug Gregor
adf38f5486 [Runtime] Pack element count into the flags of swift_getTupleTypeMetadata.
Reduces the # of parameters we need to pass to this runtime API.
2018-01-11 10:06:57 -08:00
Slava Pestov
3dae007465 IRGen: Remove FieldAccess::NonConstantIndirect 2018-01-10 21:32:54 -08:00
Slava Pestov
698881d5c6 IRGen: Protocol dispatch thunks
We want to be able to re-order existing protocol requirements
and add new protocol requirements with default implementations.

Enable this by wrapping the witness table lookup inside a
thunk and calling the thunk, instead of open-coding the
witness table lookup directly in client code.
2018-01-10 13:54:21 -08:00
Slava Pestov
2bd4f9bf66 IRGen: Fix formatting 2018-01-10 13:48:30 -08:00
Doug Gregor
0f4963dba8 [IRGen] Put references to all emitted protocols into a special section.
Introduce a new section that contains (relative) references to all of the
Swift protocol descriptors emitted into this module. We'll use this to
find protocol descriptors by name.
2018-01-09 16:10:18 -08:00
Doug Gregor
5853cf3c87 [Runtime] Teach swift_getTupleTypeMetadata() to copy "labels" string.
Introduce a flags parameter to swift_getTupleTypeMetadata(). Add a flag
stating when the "labels" parameter points into nonconstant memory, in
which case we need to make a copy of the string before adding an entry
into the concurrent map.
2018-01-05 23:11:21 -08:00
Pavel Yaskevich
fc64e34c8e Merge pull request #13701 from xedin/rdar-36278686
[Runtime/ABI] Optimize number of function metadata ABI endpoints
2018-01-05 21:47:13 -08:00
Pavel Yaskevich
0f071848f3 [Runtime/ABI] NFC: Refactor function type metadata generation 2018-01-05 13:38:20 -08:00
Pavel Yaskevich
86de71ee6d [Runtime/ABI] Remove swift_getFunctionTypeMetadata{1-3}WithFlags
Since it's not very common to use such ABI endpoints, let's remove
them and use the most general one `swift_getFunctionTypeMetadata`
instead when function parameters have flags attached to them.

Resolves: rdar://problem/36278686
2018-01-04 16:32:51 -08:00
Pavel Yaskevich
8409cdb8a2 [Runtime/ABI] Add swift_getFunctionTypeMetadata0 function
This ABI endpoint is used to retrieve metadata about functions
without parameters. Which is very common use-case and it
makes sense to save some code size for that.
2018-01-04 16:32:51 -08:00
Doug Gregor
afc5cf5bfb Merge pull request #13734 from DougGregor/nominal-type-refs
[Runtime] Never use type metadata references in conformance records.
2018-01-04 16:02:12 -08:00
Mark Lacey
55eb741fde Fix build failure due to race between two PRs.
The first of the following commits did some renames that result in the
second to fail, but they were both in CI being tested simultaneously,
passed, and were merged.

12a774abec
93af58dead
2018-01-04 12:42:27 -08:00
Doug Gregor
6118d86032 [Runtime] Introduce equality operation for nominal type descriptors.
Nominal type descriptors are not always unique, so testing them via pointer
equality is not correct. Introduce an "isEqual()" operation for
nominal type descriptors that performs the appropriate equality check,
using pointer equality when possible, and falling back to string
comparisons of the mangled type name when it is not possible.

Introduce a "nonunique" flag into nominal type descriptors to describe
when they are, in fact, not unique. The only nonunique nominal type
descriptors currently come from Clang-imported types; all
Swift-defined types have unique nominal type descriptors. Use this
flag to make the aforementioned operation efficient in the "unique"
case.

Use the new isEqual() operation for protocol conformance lookup, and
make sure we're caching results based on the known-canonical nominal
type descriptor.
2018-01-04 12:36:34 -08:00
Slava Pestov
3269b9ad2a Merge pull request #13718 from slavapestov/class-resilience-part-12
Class resilience part 12
2018-01-04 11:57:39 -08:00
Doug Gregor
12a774abec [Runtime] Fill in the superclass of foreign class metadata.
When emitting foreign class metadata (e.g., for an imported CF type), fill
in the superclass when we have one. The superclass will itself be a foreign
metadata candidate, so also register an initialization function that uniques
the superclass metadata once we've picked the canonical foreign class
metadata.
2018-01-04 10:15:32 -08:00
Doug Gregor
7458640883 [Runtime] Add nominal type descriptor field to foreign class metadata.
Like other nominal type metadata, include a nominal type descriptor in
foreign class metadata.
2018-01-04 10:12:19 -08:00
Slava Pestov
93af58dead IRGen: Correctly calculate base offset variable for generic classes
If a generic class has non-resilient ancestry, we cannot use
the template size so far as the constant value of the base offset
variable, because the template will not contain entries for all
metadata members; instead, use metadata layout as with everything
else.
2018-01-03 22:11:41 -08:00
Slava Pestov
8024b81594 IRGen: Preliminary implementation of resilient method overrides
This is not the final mechanism, because it does not allow
re-ordering superclass methods, but at least it works if
you don't do that.
2018-01-03 19:30:30 -08:00
Slava Pestov
e3d6a2b9a2 IRGen: Correctly set class metadata base offset variable
We need to subtract the address point from the metadata size,
since the metadata size includes prefix matter.
2018-01-02 22:29:08 -08:00
Kuba Mracek
bc91d76a69 Always emit vtable descriptors in ClassNominalTypeDescriptorBuilder. 2018-01-02 08:00:12 -08:00
Slava Pestov
0103cf6e75 IRGen: Use dynamic offsets in resilient class metadata 2017-12-25 00:00:44 -08:00
Slava Pestov
e774042fdc IRGen: Simplify initialization of generic arguments in type metadata
This makes it work with dynamic offsets too, but that case
doesn't come up yet.
2017-12-23 16:18:53 -08:00
Greg Parker
c677a5dc11 [IRGen][runtime] Prepare to change the is-Swift bit in class metadata. (#13595)
Swift class metadata has a bit to distinguish it from non-Swift Objective-C
classes. The stable ABI will use a different bit so that stable Swift and
pre-stable Swift can be distinguished from each other.

No bits are actually changed yet. Enabling the new bit needs to wait for
other coordination such as libobjc.

rdar://35767811
2017-12-22 00:52:00 -08:00
swift-ci
1e8445fbe4 Merge pull request #13570 from rjmccall/metadata-init-abi 2017-12-20 22:17:43 -08:00
John McCall
9bbbe2c418 Update the metadata-initialization ABI:
- Create the value witness table as a separate global object instead
  of concatenating it to the metadata pattern.

- Always pass the metadata to the runtime and let the runtime handle
  instantiating or modifying the value witness table.

- Pass the right layout algorithm version to the runtime; currently
  this is always "Swift 5".

- Create a runtime function to instantiate single-case enums.

Among other things, this makes the copying of the VWT, and any
modifications of it, explicit and in the runtime, which is more
future-proof.
2017-12-21 00:26:37 -05:00
Joe Groff
c283a69cfe Merge pull request #13539 from jckarter/squeeze-foreign-metadata-header
Runtime: Compact the uniquing header for foreign metadata records.
2017-12-20 20:08:16 -08:00
Joe Groff
05fc210be6 Runtime: Compact the uniquing header for foreign metadata records.
We can reduce the uniquing header from 3–4 pointer-sized words down to 1–2 32-bit words + one pointer:

- The initialization function (when present) and name are always emitted into the same binary image, so we can use relative references to shrink these down to 32-bit fields.
- We don't ever simultaneously need the initialization flags and the initialized uniqued pointer. (Keeping the "initialization function" flag bit theoretically lets us turn a "consume" load into a "relaxed" load, but that makes no practical difference on most contemporary architectures.) 12 flag bits Ought To Be Enough For Anyone and lets us reliably tell a valid pointer from a flag set, so overlap the initialization flags with the eventual invasive cache value.

The invasive cache is left inline, since we've decided we're not going to make the rest of type metadata records ever be true-const, so they'll already be sitting on a dirty page. A dynamic linker that was sufficiently Swift-optimized to precalculate the other load-time-initialized entries in metadata could likely precompute the invasive cache value as well.

rdar://problem/22527141
2017-12-20 14:06:01 -08:00
Slava Pestov
76499a3ce3 IRGen: Emit immediate class member offset global variable
Not used to access metadata members just yet.
2017-12-19 02:58:35 -07:00
Slava Pestov
fa719f75bd SIL: SILVTableVisitor no longer needs a TypeLowering reference 2017-12-18 23:28:33 -08:00
Slava Pestov
c16c2c35bf SIL: Move getOverriddenVTableEntry() from TypeLowering to SILDeclRef
There's no reason for this to be an instance method on the TypeLowering
object, because it (no longer?) uses any type lowering operations.
2017-12-18 23:28:33 -08:00
Joe Groff
3d5874844b IRGen: Elaborate a cut-off comment. 2017-12-18 11:26:19 -08:00
Erik Eckstein
48d49a4cc2 Fix the IR attributes of swift_getObjectType.
It's not readnone, because it reads the metatype from an object.
Readnone would let the llvm ARC optimizer reschedule the call with a release-call for the object.

fixes SR-6560.
2017-12-11 18:16:46 -08:00
Slava Pestov
ffabf60118 IRGen: Hollow out generic class templates
Don't emit placeholders for field offsets and vtable entries,
since they were always null. Instead, calculate the final size
of class metadata at runtime using the size of the superclass
metadata and the number of immediate members, and only copy
this prefix from the template to the instantiated metadata,
zero-filling the rest.

For this to work with non-generic resilient classes and
non-generic subclasses of generic classes, we need a new
runtime entry point to relocate non-generic class metadata,
calculating its size at runtime using the same strategy.
2017-12-08 13:50:56 -08:00
Slava Pestov
176efde3fd IRGen: Redo fill ops
Instead of recording the current offset in the template, just
collect the fill ops into a vector and emit them at the
generic argument offset stored in the MetadataLayout.

For now this is NFC, but this allows the template to omit
entries for generic arguments entirely once some more
machinery is in place.
2017-12-07 14:21:58 -08:00
Slava Pestov
0fa7440e51 IRGen/Runtime: Remove old class metadata relocation mechanism 2017-12-07 14:21:58 -08:00
Slava Pestov
df780c05c1 IRGen: Move field type vector slot to appear before the address point 2017-12-05 21:33:35 -08:00
Slava Pestov
ed97617590 IRGen: Move generic class dependent data to appear before the address point 2017-12-05 21:33:35 -08:00
Slava Pestov
6cc4c1fab4 IRGen: Split up class metadata emission into fixed and resilient cases 2017-12-05 21:33:34 -08:00
Slava Pestov
d2994035e6 IRGen: Fix inconsistent indentation 2017-12-05 16:31:47 -08:00