Commit Graph

619 Commits

Author SHA1 Message Date
Joe Groff
445bde5127 IRGen: Give ObjC metadata symbols internal linkage.
This preserves the symbol names in (unstripped) binaries, so we can use them for link ordering and
memory usage analysis.
2020-07-29 13:49:25 -07:00
Joe Groff
c99b654352 IRGen: Method implementations for elided vtable entries are direct and don't need ptrauth 2020-07-24 15:22:32 -07:00
Joe Groff
3a9440a379 IRGen: Elide nonoverridden entries from public resilient vtables.
A formally virtual method still needs to provide the ABI of an overridable
method, including a dispatch thunk, method descriptor, and support in the
method lookup function for the class to handle `super.` calls from clients.
2020-07-23 20:40:49 -07:00
Nate Chandler
8ec75d4933 [metadata prespecialization] Support classes with non-generic ancestors.
Previously, metadata prespecialization for classes only occurred when
all of a specialized generic class's ancestors were themselves generic.
Here, that requirement is lifted so that generic classes with concrete
ancestors are also eligible for prespecialization.
2020-06-08 14:57:50 -07:00
nate-chandler
5204af327a Merge pull request #30089 from nate-chandler/generic-metadata-prespecialization-components/classes
[metadata prespecialization] Support for classes.
2020-05-29 17:32:30 -07:00
Nate Chandler
bdef1cef23 [metadata prespecialization] Support for classes.
When generic metadata for a class is requested in the same module where
the class is defined, rather than a call to the generic metadata
accessor or to a variant of typeForMangledNode, a call to a new
accessor--a canonical specialized generic metadata accessor--is emitted.
The new function is defined schematically as follows:

    MetadataResponse `canonical specialized metadata accessor for C<K>`(MetadataRequest request) {
      (void)`canonical specialized metadata accessor for superclass(C<K>)`(::Complete)
      (void)`canonical specialized metadata accessor for generic_argument_class(C<K>, 1)`(::Complete)
      ...
      (void)`canonical specialized metadata accessor for generic_argument_class(C<K>, count)`(::Complete)
      auto *metadata = objc_opt_self(`canonical specialized metadata for C<K>`);
      return {metadata, MetadataState::Complete};
    }

where generic_argument_class(C<K>, N) denotes the Nth generic argument
which is both (1) itself a specialized generic type and is also (2) a
class.  These calls to the specialized metadata accessors for these
related types ensure that all generic class types are registered with
the Objective-C runtime.

To enable these new canonical specialized generic metadata accessors,
metadata for generic classes is prespecialized as needed. So are the
metaclasses and the corresponding rodata.

Previously, the lazy objc naming hook was registered during process
execution when the first generic class metadata was instantiated. Since
that instantiation may occur "before process launch" (i.e. if the
generic metadata is prespecialized), the lazy naming hook is now
installed at process launch.
2020-05-29 13:20:33 -07:00
David Zarzycki
9526384aff [IRGen] NFC: Narrow the scope of some code
This code is only used on one side of a if/else branch, so let's
just move it inside the `else` block.
2020-05-28 11:23:18 -04:00
Anthony Latsis
55447e66aa Merge pull request #31645 from AnthonyLatsis/relocate-to-iterabledc
[NFC] AST: Relocate some conformance lookup client methods from DeclContext to IterableDeclContext
2020-05-18 22:25:08 +03:00
Anthony Latsis
bfe25fabeb [NFC] AST: Relocate getLocalConformances to IterableDeclContext 2020-05-08 17:43:09 +03:00
Slava Pestov
8e35609df2 IRGen: Sign the class stub initialization callback pointer on arm64e
The Objective-C runtime expects a signed pointer here. The existing test
would have caught this, except it was always disabled because the
symbol name passed to the dlsym() check should not have had the leading
'_'.

Fixes <rdar://problem/57679510>.
2020-05-01 21:55:11 -04:00
Erik Eckstein
e196932f67 Remove includes to llvm's CallSite.h
Fixes a master-next compile problem
2020-04-28 11:58:38 +02:00
Slava Pestov
1851630e81 IRGen: Fix crash with empty-sized field in a class with resilient ancestry
The problem was that HasObjCAncestry was not getting set if
HasResilientAncestry was true, and thus emitFieldOffsetGlobals() was
marking the field offset as const even though the Objective-C
runtime might slide it.

Fixes <rdar://problem/48031465>.
2020-04-27 19:41:42 -04:00
Arnold Schwaighofer
94e9aeb1a2 Merge pull request #30667 from aschwaighofer/revert_objc_protocol_method_uniquing
Revert "Merge pull request #30612 from aschwaighofer/irgen_also_uniqu…
2020-03-27 08:36:53 -07:00
Robert Widmann
4accf59a3b Merge pull request #30618 from CodaFi/protocol-adoption-program
[NFC] Add LookupConformancesInContextRequest
2020-03-26 17:18:55 -07:00
Arnold Schwaighofer
c9d490c5a9 Revert "Merge pull request #30612 from aschwaighofer/irgen_also_unique_ext_method_types_list"
This reverts commit f0cdd76f18, reversing
changes made to 703fe0f1a1.

Revert "IRGen: Refactor getObjCEncodingForMethod and getObjectEncodingFromClangNode into one"

This reverts commit 0082682b0d.

Revert "Merge pull request #30438 from aschwaighofer/irgen_prefer_clang_type_encoding"

This reverts commit eeb7fa52b2, reversing
changes made to 77af77fa8a.

Revert "Merge pull request #30433 from aschwaighofer/irgen_no_duplicate_objc_method_descriptor_entries"

This reverts commit 77af77fa8a, reversing
changes made to 841eeb05b0.

This reverts the changes for

rdar://60461850, rdar://60474785, rdar://60778637

There is still at least an issue that we address with PR#30654.

Revert until we have confidence that this is the right fix set.
2020-03-26 15:00:15 -07:00
Robert Widmann
a9e11e3130 [NFC] Separate Taking Redundant Conformance Diagnostics From The Lookup Table 2020-03-24 12:40:11 -07:00
Arnold Schwaighofer
e344971de7 IRGen: Also unique selectors in extended method types list
rdar://60778637
2020-03-24 09:39:44 -07:00
Arnold Schwaighofer
a5b277b5e0 IRGen: Unique method descriptors in objc method lists
Before this patch we used to get duplicate entries because we would
define implicit function delcarations, e.g for

(func_decl "perform(_:)" interface type='<Self where Self : NSObjectProtocol> (Self) -> (Selector?) -> Unmanaged<AnyObject>?' access=public @objc
  (parameter "self")
  (parameter_list
    (parameter "aSelector" type='Selector?' interface type='Selector?')))

we will define:

(func_decl implicit "performSelector(_:)" access=public @objc
  (parameter "self")
  (parameter_list
    (parameter "aSelector" type='Selector?' interface type='Selector?')))

rdar://60461850
2020-03-16 11:22:04 -07:00
Kuba (Brecka) Mracek
0d400ca310 Merge branch 'master' into mracek/arm64e 2020-03-04 09:36:25 -08:00
Slava Pestov
3904fe83fb AST: Centralize ABI-related deployment target checks
There were a couple of methods in LangOptions and some related ones in
Availability and ASTContext that were added more recently.

Refactor the three older checks to the newer scheme.
2020-03-03 22:49:19 -05:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Arnold Schwaighofer
4cf5c2e60f Merge pull request #29219 from aschwaighofer/irgen_fix_zero_size_field_instanceStart_2
IRGen: Correctly compute instanceStart for a Swift class that starts …
2020-01-15 13:06:14 -08:00
Varun Gandhi
fe9a4db090 [NFC] Add emitAndAddMethodList to replace several similar methods. (#29207) 2020-01-15 09:48:55 -08:00
Arnold Schwaighofer
7f20d937e9 IRGen: Correctly compute instanceStart for a Swift class that starts with an empty field and is followed by a resilient field
We used to crash for classes that have an empty and a resilient field
during intialization if the object was in the shared cache.

  class CrashInInit {
    var empty = EmptyStruct()
    var resilient = ResilientThing()
  }

What happened was that for such a class we we would compute a
instanceStart of 0. The shared cache builder would then slide the value
of the constant ivar offset for the empty field from 0 to 16. However,
the field offset for empty fields is assumed to be zero and the runtime
does not compute a different value for the empty field and so the field
offset for the empty field remains 0. The runtime then trys to reconcile
the field offset (0) and the ivar offset (16) trying to write to the ivar
offset. However, the ivar offset is marked as constant and so we
crashed.
This can be avoided by correctly computing the instanceStart for such a
class to be 16 such that the shared cache builder does not update the
value of the empty field.

rdar://rdar://58458169
2020-01-15 06:18:41 -08:00
Arnold Schwaighofer
2ea1c5cc41 Use IGM.getMaximalTypeExpansionContext() in more places 2019-11-11 14:21:52 -08:00
Arnold Schwaighofer
4cba76309f IRGen: Add TypeExpansionContext to IRGen 2019-11-11 14:21:52 -08:00
Anthony Latsis
6325915b4b NFC: Solidify and tidy up the BraceStmt interface 2019-10-30 16:43:59 +03:00
Slava Pestov
797a7974bc Sema: Fold NominalTypeDecl::computeType() into validateDecl() 2019-10-10 19:55:01 -04:00
Brent Royal-Gordon
fb20b503ba Merge branch 'master' into master-rebranch
# Conflicts:
#	lib/ClangImporter/ClangImporter.cpp
#	test/IRGen/builtins.swift
#	test/IRGen/enum.sil
#	tools/driver/autolink_extract_main.cpp
#	utils/build-presets.ini
2019-08-08 17:07:59 -07:00
Slava Pestov
19344e0f1a IRGen: Fix crash if the type of a class stored property hasn't been validated yet
This is a regression from recent changes to make finalizeDecl() do
less work. All these resolveDeclSignature() calls will hopefully go
away soon, once validateDecl() is refactored into a getInterfaceType()
request.
2019-08-07 17:33:09 -04:00
Slava Pestov
0c5d52d860 AST: Introduce AbstractStorageDecl::get{Parsed,Opaque}Accessor()
Also, change visitOpaqueAccessors() to call getOpaqueAccessor() instead of
asserting if the expected accessor does not exist.
2019-08-02 19:34:43 -04:00
Slava Pestov
64c32c695b AST: Remove a few utility methods from AbstractStorageDecl
Since the return value of getAccessor() depends on mutable state, it
does not make sense in the request evaluator world. Let's begin by
removing some utility methods derived from getAccessor(), replacing
calls to them with calls to getAccessor().
2019-08-01 18:31:58 -04:00
Slava Pestov
1124f68dae IRGen: Cope with stored properties that haven't been validated yet 2019-07-31 21:22:22 -04:00
Jiri Dutkevic
8150a01069 [IRGen] Use Singleton metadata strategy in JIT mode.
FixedOrUpdate strategy does not work for non-generic classes in JIT mode.

Fixes rdar://49639321
2019-07-05 15:28:08 -07:00
swift-ci
1a66cdc9ed Merge remote-tracking branch 'origin/master' into master-next 2019-05-10 20:08:56 -07:00
Slava Pestov
12469f5a9b IRGen: Always emit class stubs for classes with resilient ancestry
This logic is no longer guarded by a flag. Sema will still emit certain
diagnostics if the flag is not specified though.

Progress on <rdar://problem/49090631>.
2019-05-10 21:26:10 -04:00
swift-ci
32e725208d Merge remote-tracking branch 'origin/master' into master-next 2019-05-01 18:10:37 -07:00
Slava Pestov
3b6ec6c651 IRGen: Move some deployment target checks to LangOptions 2019-05-01 15:13:12 -04:00
swift-ci
53d5e800c1 Merge remote-tracking branch 'origin/master' into master-next 2019-04-19 16:50:46 -07:00
Slava Pestov
d6868acf8a IRGen: Categories on class stubs should go in a separate list and section 2019-04-19 16:50:29 -04:00
swift-ci
707344affa Merge remote-tracking branch 'origin/master' into master-next 2019-04-12 07:29:33 -07:00
Slava Pestov
af83492a45 IRGen: Lazily emit reflection field descriptors
Previously even if a type's metadata was optimized away, we would still
emit a field descriptor, which in turn could reference nominal type
descriptors for other types via symbolic references, etc.
2019-04-12 01:46:23 -04:00
swift-ci
36d8c65f53 Merge remote-tracking branch 'origin/master' into master-next 2019-03-27 05:29:27 -07:00
Slava Pestov
68c07620cd IRGen: Emit Objective-C resilient class stubs if experimental flag is on
Non-generic classes with resilient ancestry do not have statically-emitted
metadata, so we can now emit an Objective-C resilient class stub instead.

Also, when emitting an Objective-C category, reference the class stub if
the class has resilient ancestry; previously this case would hit an assert.

Note that class stubs always start with a zero word, with the address point
pointing immediately after. This works around a linker issue, where the
linker tries to coalesce categories and gets confused upon encountering a
class stub.
2019-03-26 18:53:09 -04:00
Slava Pestov
4207738e17 Add mangling and IRGen LinkEntity for Objective-C resilient class stubs 2019-03-26 18:44:44 -04:00
Saleem Abdulrasool
b97857e99f IRGen: adjust for SVN r355989
SVN r355989 adds support for the XCOFF file format.  For now, treat it as a COFF
target, though XCOFF and COFF are different.
2019-03-13 13:31:24 -07:00
John McCall
7f55a4a4f0 Always give known-empty class properties a zero offset in the static layout.
Field offset vectors are always filled out with either zero or the static layout's offset, depending on the metadata initialization strategy.  This change means that the static layout's offset will only be non-zero for properties with a statically-known layout.  Existing runtimes doing dynamic class layout assign class properties a zero offset if the field offset vector entry is zero and the property is zero-sized.  So this effectively brings the compiler into accord with the runtime (for all newly-compiled Swift code, which will eventually be all Swift code because the current public releases of Swift 5 are not yet considered ABI-stable) and guarantees a zero value for the offset everywhere.

Since the runtime will agree with the compiler about the zero value of the offset, the compiler can continue to emit such offset variables as constant.  The exception to this rule is if the class has non-fragile ObjC ancestry, in which case the ObjC runtime (which is not aware of this special rule for empty fields) will attempt to slide it along with everything else.

Fixes rdar://48031465, in which the `FixedClassMetadataBuilder` for a class with a legacy-fixed layout was writing a non-zero offset for an empty field into the field offset vector, causing the runtime to not apply the special case and thus to compute a non-zero offset, which it then attempted to copy into the global field offset variable, which the compiler had emitted as a true-constant zero.
2019-02-20 00:53:11 -05:00
Slava Pestov
eec0fcdf49 IRGen: When available, use ClassMetadataStrategy::Update even if we don't have legacy type info
If we know our deployment target has a new Objective-C runtime, we can
emit fixed metadata for classes with resilient types even if those
types do not appear in the YAML legacy type info.

Fixes <rdar://problem/47649465>.
2019-02-18 22:39:13 -05:00
Slava Pestov
9a6126b148 IRGen: Move fine-grained flags from ClassLayoutBuilder to ClassLayout
Another refactoring in preparation for adding the new type of class
metadata emitted when deploying to a target with a new Objective-C
runtime.

Progress on <rdar://problem/47649465>.
2019-02-18 22:39:13 -05:00
Slava Pestov
040323e967 IRGen: Introduce ClassMetadataStrategy to clean up some checks
This consolidates the various doesClassMetadataRequire*() checks, making
them more managable.

This also adds a forth state, ClassMetadataStrategy::Update. This will be used
when deploying to the new Objective-C runtime. For now it's not plumbed through.

Progress on <rdar://problem/47649465>.
2019-02-18 22:39:13 -05:00