Commit Graph

1549 Commits

Author SHA1 Message Date
John McCall
dff0031b02 Apply generic metadata patterns to all types and change their layout.
The layout changes to become relative-address based.  For this to be
truly immutable (at least on Darwin), things like the RO data patterns
must be moved out of the pattern header.  Additionally, compress the
pattern header so that we do not include metadata about patterns that
are not needed for the type.

Value metadata patterns just include the metadata kind and VWT.

The design here is meant to accomodate non-default instantiation
patterns should that become an interesting thing to support in the
future, e.g. for v-table specialization.
2018-03-05 19:05:41 -05:00
Huon Wilson
ce1bb8b13c [IRGen] Cond. conformance witness table count isn't needed dynamically.
The count of the number of witness tables was designed to be an
assertion/check that we've hooked up all the infrastructure
correctly. Everything is now implemented, and the assertion has never
triggered, so it can be removed, saving some work.

Fixes rdar://problem/38038928.
2018-03-06 00:22:05 +11:00
swift-ci
9dbb5effd5 Merge remote-tracking branch 'origin/master' into master-next 2018-03-04 01:29:35 -08:00
John McCall
a7c5c80799 Compute class metadata bounds solely from class-descriptor chain information.
Change the "metadata base offset" variable into a "class metadata bounds"
variable that contains the base offset and the +/- bounds on the class.
Link this variable from the class descriptor when the class has a resilient
superclass; otherwise, store the +/- bounds there.  Use this variable to
compute the immediate-members offset for various runtime queries.  Teach the
runtime to fill it in lazily and remove the code to compute it from the
generated code for instantiation.  Identify generic arguments with the start
of the immediate class metadata members / end of the {struct,enum} metadata
header and remove the generic-arguments offset from generic type descriptors.
2018-03-04 02:14:32 -05:00
swift-ci
b8b47f2786 Merge remote-tracking branch 'origin/master' into master-next 2018-03-01 19:10:48 -08:00
Doug Gregor
719533b3f9 Revert "[Runtime] Reference ObjC class objects indirectly in conformance records."
This reverts commit 65b4c9a25a. It broke
the stdlib/ErrorBridged.swift test at -Onone. Fixes rdar://problem/37925234.
2018-03-01 17:07:02 -08:00
swift-ci
757e39aea4 Merge remote-tracking branch 'origin/master' into master-next 2018-02-28 19:52:22 -08:00
swift-ci
72d7dd2013 Merge pull request #14710 from compnerd/got-coff 2018-02-28 19:47:05 -08:00
Saleem Abdulrasool
ae5cfaed4c IRGen: adjust protocol conformance references in PE/COFF
There is no GOT on PE/COFF.  However, the IAT entries serve the same
purpose.  Use the synthetic symbol which will be initialized externally
by the loader to compute the address.  This allows for cross-module
protocol references on Windows.
2018-02-28 14:00:14 -08:00
swift-ci
00dfc9cff2 Merge remote-tracking branch 'origin/master' into master-next 2018-02-28 08:12:19 -08:00
John McCall
8d93cee012 Add a superclass reference to class descriptors. 2018-02-28 00:38:00 -05:00
swift-ci
96b5717d8f Merge remote-tracking branch 'origin/master' into master-next 2018-02-26 11:09:40 -08:00
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