Commit Graph

1537 Commits

Author SHA1 Message Date
John McCall
dd99536d31 Move the metadata-pattern header into the type context descriptor.
This is yet another waypoint on the path towards the final
generic-metadata design.  The immediate goal is to make the
pattern a private implementation detail and to give the runtime
more visibility into the allocation and caching of generic types.
2018-02-26 12:10:24 -05:00
swift-ci
63b1e11bd1 Merge remote-tracking branch 'origin/master' into master-next 2018-02-26 08:49:36 -08:00
Joe Groff
4c2dde56a0 IRGen: Lower external key path components.
The key path pattern needs to include a reference to the external descriptor, along with hooks for lowering its type arguments and indices, if any. The runtime will need to instantiate and interpolate the external component when the key path object is instantiated.

While we're here, let's also reserve some more component header bytes for future expansion, since this is an ABI we're going to be living with for a while.
2018-02-23 19:03:15 -08:00
swift-ci
fc39bb57bb Merge remote-tracking branch 'origin/master' into master-next 2018-02-21 17:45:02 -08:00
Pavel Yaskevich
333f6146fc [IRGen] NFC: Update structure of ClassContextDescriptor representation 2018-02-21 15:26:29 -08:00
swift-ci
c93e69746b Merge remote-tracking branch 'origin/master' into master-next 2018-02-21 10:59:05 -08:00
Pavel Yaskevich
437019067a [IRGen] Ensure that all of the field type metadata is properly forced 2018-02-20 18:49:01 -08:00
Pavel Yaskevich
f6be62dfdb [IRGen] Remove lazy field type accessor functions
All of their usages have been replaced with new runtime
`swift_getFieldAt` method.
2018-02-20 18:45:41 -08:00
Pavel Yaskevich
50785df558 [Runtime] NFC: Update names of the field section to swift5_fieldmd 2018-02-20 18:20:09 -08:00
Pavel Yaskevich
877c70bae9 [Runtime/Metadata] Add support for dynamic field descriptor registration 2018-02-20 18:20:09 -08:00
Bob Wilson
4e1944a871 Merge pull request #14572 from bob-wilson/rdar36683229
master-next: DLLImport values should not be hidden
2018-02-19 08:31:30 -08:00
Doug Gregor
6c6f0d0d5f Merge pull request #14646 from DougGregor/relative-objc-classrefs
[Runtime] Reference ObjC class objects indirectly in conformance records
2018-02-14 16:30:32 -08:00
Doug Gregor
65b4c9a25a [Runtime] Reference ObjC class objects indirectly in conformance records.
Within conformance records, reference Objective-C class objects
indirectly so the runtime can update those references appropriately.
We don't need to do this for classes with Swift metadata.

Fixes the ABI-affecting part of rdar://problem/36310179.
2018-02-14 13:53:43 -08:00
Bob Wilson
f96408de26 master-next: DLLImport values should not be hidden
LLVM r322806 defaults to make symbols with non-default visibility be marked
as dso_local. However, there is also an assertion that DLLImport symbols
are not dso_local, since that combination makes no sense. These changes
revealed some problems in Swift's IR linkage for PublicExternal,
HiddenExternal and PrivateExternal SIL linkage. Those mean different things
for definitions vs. declarations.

PublicExternal definitions were marked with DLLExport but with
AvailableExternally linkage. That seems inconsistent. AvailableExternally
symbols are not supposed to be emitted at all.

HiddenExternal and PrivateExternal symbols were using the same visibility
and storage class regardless of whether they were declarations or
definitions. This change fixes that so that those symbols are either hidden
or DLLImport but not both at the same time.

rdar://problem/36683229
2018-02-12 15:27:10 -08:00
Joe Groff
953dddd5d3 IRGen/Runtime: Allow mangled type refs to embed "symbolic references" to type context descriptors.
This makes resolving mangled names to nominal types in the same module more efficient, and for eventual secrecy improvements, also allows types in the same module to be referenced from mangled typerefs without encoding any source-level name information about them.
2018-02-10 10:43:47 -08:00
Harlan
5e02d2a877 Implement #warning and #error (#14048)
* Implement #warning and #error

* Fix #warning/#error in switch statements

* Fix AST printing for #warning/#error

* Add to test case

* Add extra handling to ParseDeclPoundDiagnostic

* fix dumping

* Consume the right paren even in the failure case

* Diagnose extra tokens on the same line after a diagnostic directive
2018-02-03 18:07:05 -05:00
Doug Gregor
b9e91e3934 [ABI] Describe module context and conditional requirements of conformances.
Extend protocol conformance descriptors with two more bits of information:

* For retroactive conformances, add the module in which the conformance
  occurs. This will eventually be used for error reporting/ambiguity
  resolution when retroactive conformances collide.
* For conditional conformances, add the conditional requirements. We need
  these for runtime evaluation of conditional conformances.
2018-02-02 16:41:27 -08:00
Doug Gregor
28c489c16d [ABI] Mangle retroactive conformances as part of bound generic types.
A "retroactive" protocol conformance is a conformance that is provided
by a module that is neither the module that defines the protocol nor
the module that defines the conforming type. It is possible for such
conformances to conflict at runtime, if defined in different modules
that were not both visible to the compiler at the same time.

When mangling a bound generic type, also mangle retroactive protocol
conformances that were needed to satisfy the generic requirements of
the generic type. This prevents name collisions between (e.g.) types
formed using retroactive conformances from different modules. The
impact on the size of the mangling is expected to be relatively small,
because most conformances are not retroactive.

Fixes the ABI part of rdar://problem/14375889.
2018-01-31 09:53:38 -08:00
Joe Groff
a7a3b17597 Replace nominal type descriptors with a hierarchy of context descriptors.
This new format more efficiently represents existing information, while
more accurately encoding important information about nested generic
contexts with same-type and layout constraints that need to be evaluated
at runtime. It's also designed with an eye to forward- and
backward-compatible expansion for ABI stability with future Swift
versions.
2018-01-29 16:19:25 -08:00
Doug Gregor
902ea27a67 [IRGen] Consistently record runtime metadata for foreign types.
All Swift-defined nominal types have their runtime metadata recorded
in a special section, so it can be found later. This recording is
suppressed when that type is stated to conform to a protocol, because
the runtime can find nominal types in either place.

Imported types would get their conformances recorded, but would not
get recorded in the runtime metadata record otherwose. Therefore, the
runtime would not be able to find such types by name.

For any foreign type whose metadata we emit, make sure that metadata
can be found by a runtime lookup.
2018-01-20 22:06:33 -08:00
Doug Gregor
e766473ed9 [ABI] Emit separate symbols for protocol conformance descriptors.
Emit protocol conformance descriptors as separate symbols, rather than
inlining them within the section for protocol conformance records. We
want separate symbols for protocol conformances both because it is easier
to make them variable-length (as required for conditional
conformances) and because we want to reference them from witness
tables (both of which are coming up).
2018-01-17 10:35:16 -08:00
Doug Gregor
bc866086d9 [Mangling] Add a mangling for protocol conformance descriptors. 2018-01-17 10:33:30 -08:00
Doug Gregor
663d6af063 [ABI] Factor out the protocol conformance flags (again).
Protocol conformance records are becoming richer and more interesting;
separate out the "flags" word and add the various other fields that we
want there (is-retroactive, is-synthesized-nonunique, # of conditional
requirements).
2018-01-17 10:06:07 -08:00
swift-ci
15f085bbd5 Merge pull request #13935 from DougGregor/irgen-access-function-array 2018-01-15 23:43:05 -08:00
Slava Pestov
c857a480e1 SIL: Introduce SILLinkage::PublicNonABI
This is going to be used for "always emit into client" functions,
such as default argument generators and stored property
initializers.

- In dead function elimination, these functions behave identically to
  public functions, serving as "anchors" for the mark-and-sweep
  analysis.

- There is no external variant of this linkage, because external
  declarations can use HiddenExternal linkage -- the definition should
  always be emitted by another translation unit in the same Swift
  module.

- When deserialized, they receive shared linkage, because we want the
  linker to coalesce multiple copies of the same deserialized
  definition if it was deserialized from multiple translation units
  in the same Swift module.

- When IRGen emits a definition with this linkage, it receives the
  same LLVM-level linkage as a hidden definition, ensuring it does not
  have a public entry point.
2018-01-14 22:59:40 -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
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
Slava Pestov
d134529e54 IRGen: Field offset symbols of resilient classes have hidden linkage
Fixes <rdar://problem/34078503>.
2018-01-10 21:35:00 -08:00
Slava Pestov
3dae007465 IRGen: Remove FieldAccess::NonConstantIndirect 2018-01-10 21:32:54 -08:00
Slava Pestov
ca757bb66f IRGen: Export updateLinkageForDefinition() 2018-01-10 13:48:30 -08:00
Slava Pestov
3a24135478 IRGen: Add link entities for method dispatch thunks 2018-01-10 13:48:30 -08:00
swift-ci
ea489cead0 Merge pull request #13844 from DougGregor/runtime-protocol-name-lookup 2018-01-09 23:06:09 -08:00
Doug Gregor
f0371c0539 [IRGen] Fix ELF section name for Swift protocols. 2018-01-09 22:16:17 -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
John McCall
3c54c0edfc IRGen and basic optimizer support for coroutines. 2018-01-09 11:35:09 -05:00
Slava Pestov
217a548edf IRGen: Remove unused Function link entity kind 2018-01-08 21:02:33 -08:00
Slava Pestov
7f28f8a918 IRGen: Remove unused Other link entity kind 2018-01-08 20:50:21 -08:00
Slava Pestov
ce3e6c32bb IRGen: Remove unused ReflectionSuperclassDescriptor link entity kind 2018-01-08 20:46:02 -08:00
Vedant Kumar
9aa34d6448 [Coverage] Eagerly lower functions with coverage instrumentation
Lazy functions may never be lowered during IRGenSIL, but they must be
lowered if they have code coverage instrumentation. Otherwise, records
in the coverage mapping may reference non-existent name data, because
the corresponding function (with the instrprof_increment intrinsic) has
no entry in the profile symbol table.

rdar://36061003
2018-01-05 17:20:20 -08:00
Doug Gregor
d8abec46f8 Revert "[Runtime] Reference ObjC class objects indirectly in conformance records."
This reverts commit 32ab89b0cc.
2018-01-04 17:04:34 -08:00
Doug Gregor
e0255467cb [Runtime] Never use type metadata references in conformance records.
Only foreign classes and other imported types were making use of the
type metadata reference form in conformance records. Switch those over
to using nominal type descriptors, so we're using nominal type
descriptors for everything possible.

Only Objective-C-defined classes use a different representation now.
2018-01-04 12:52:42 -08:00
Doug Gregor
3219047783 [Runtime] Clean up TypeMetadataRecordKind and TargetProtocolConformanceRecord.
Per JoeG's comments, thanks!
2018-01-03 13:21:10 -08:00
Doug Gregor
310bd6be48 [Runtime] Mangle the reference kind in the lower two bits of type references.
The separate section of type references uses the same type reference format
as in protocol conformance records. As with protocol conformance records,
mangle the type reference kind into the lower two bits. Then, eliminate the
separate "flags" field from the type metadata record. Finally, rename
the section because the Swift 5 stable format for this section is
different from prior formats, and the two runtimes need to be able to
coexist.
2018-01-03 10:49:21 -08:00
Doug Gregor
bfd2230c6d [Runtime] Eliminate ProtocolConformanceFlags.
Eliminate the separate flags field in protocol conformance records, now that
all of the information is stored in spare bits elsewhere. Reserve this
32-bit value for future use to describe conditional requirements.
2018-01-03 10:49:21 -08:00
Doug Gregor
aee0c681e4 [Runtime] Pack TypeMetadataRecordKind into spare bits of protocol conformances
Use the spare bits within the type reference field to describe the kinds
of type metadata records, so that we no longer need to rely on a
separate "flags" field.
2018-01-03 09:23:31 -08:00
Doug Gregor
d64592264e [Runtime] Use nominal type descriptor references for non-foreign types.
Rather than emitting unique, direct type metadata for non-foreign
types, emit a reference to the nominal type descriptor. This collapses
the set of type metadata reference kinds to 3: nominal type
descriptor, (indirect) Objective-C class object, and nonuniqued
foreign type metadata.
2018-01-03 00:02:07 -08:00
Doug Gregor
c1782d8cc0 [Runtime] Eliminate the UniqueDirectClass metadata record kind.
Now that references to Objective-C class objects are indirected
(via UniqueIndirectClass), classes with Swift type metadata can be
directly referenced (via UniqueDirectType) rather than hopping through
swift_getObjCClassMetadata().
2018-01-02 22:48:54 -08:00
Doug Gregor
32ab89b0cc [Runtime] Reference ObjC class objects indirectly in conformance records.
Within conformance records, reference Objective-C class objects
indirectly so the runtime can update those references appropriately.
We don't need to do this for classes with Swift metadata.
2018-01-02 22:17:46 -08:00