Commit Graph

1326 Commits

Author SHA1 Message Date
Doug Gregor
ab3c5dee3e [Concurrency] Introduce Actor protocol to which actor classes all conform.
Introduce a new Actor protocol, which is a class-bound protocol with only
one requirement:

    func enqueue(partialTask: PartialAsyncTask)

All actor classes implicitly conform to this protocol, and will synthesize
a (currently empty) definition of `enqueue(partialTask:)` unless a suitable
one is provided explicitly.
2020-09-28 16:59:21 -07:00
swift_jenkins
f4dec430fb Merge remote-tracking branch 'origin/master' into master-next 2020-09-09 14:09:29 -07:00
Suyash Srijan
49e7c6126c [Diagnostics] Diagnose comparisons with '.nan' and suggest using '.isNan' instead (#33860)
* [AST] Add 'FloatingPoint' known protocol kind

* [Sema] Emit a diagnostic for comparisons with '.nan' instead of using '.isNan'

* [Sema] Update '.nan' comparison diagnostic wording

* [Sema] Explicitly check for either arguments to be '.nan' and tweak a comment

* [Test] Tweak some comments

* [Diagnostic] Change 'isNan' to 'isNaN'

* [Sema] Fix a bug where firstArg was checked twice for FloatingPoint conformance and update some comments

* [Test] Fix comments in test file

* [NFC] Add a new 'isStandardComparisonOperator' method to 'Identifier' and use it in ConstraintSystem

* [NFC] Reuse argument decl extraction code and switch over to the new 'isStandardComparisonOperator' method

* [NFC] Update conformsToKnownProtocol to accept DeclContext and use it to check for FloatingPoint conformance
2020-09-09 22:08:42 +01:00
Nathan Hawes
c453ddf758 Manually merge remote-tracking branch 'upstream/master' into HEAD
Conflicts:
	include/swift/AST/PrettyStackTrace.h
2020-08-17 09:45:56 -07:00
Nate Chandler
e23cc54145 [IRGen] Skip reemitting fields referenced by type context descriptor.
When reemitting a type context descriptor, several fields
- method lookup function
- dispatch thunk
- nonoverride method descriptor
were previously being reemitted.

In a couple of earlier commits, that behavior was altered to delete the
fields before reemitting them.

  3ad2777a68 [IRGen] Erase nonoverride descriptor on emission.
  c25c180c08 [IRGen] Erase thunks before emission.

Here, the behavior is changed to simply exit early when these fields are
being reemitted.  Also an assertion is added that these fields are
redefined only when reemitting the type context descriptor.
2020-08-15 09:54:54 -07:00
nate-chandler
6dddf96faf Merge pull request #33442 from nate-chandler/generic-metadata-prespecialization-components/record-canonical-prespecializations
[metadata prespecialization] Add canonical prespecialization to end of type descriptors.
2020-08-14 09:59:26 -07:00
Nate Chandler
5114f22e5e [metadata prespecialization] Reemit dependent values.
The metadata accessor and type context descriptor for a nominal type
both depend on canonical metadata--the former because it returns those
metadata, the latter because it has them as trailing objects.

Here, the work is done to reemit those values when new canonical
prespecialized metadata are encountered.
2020-08-13 17:44:05 -07:00
Nate Chandler
3ad2777a68 [IRGen] Erase nonoverride descriptor on emission.
Previously, emitting the descriptor for a nonoverride method always
simply emitted, even if it had previously been emitted.  That was not a
problem before, but is now that class type context descriptors can be
reemitted upon encountering metadata prespecializations.

Here, the behavior is changed to delete the old definition before
emitting the new definition.
2020-08-13 17:35:21 -07:00
Saleem Abdulrasool
fc164ce098 IRGen: be less aggressive about applying COMDAT
COMDAT can only be applied to definitions, not declarations.  This
manifested in builds of llbuild with SwiftPM on Windows.  The nominal
type descriptor accessor declaration was marked as COMDAT.
2020-08-13 10:42:03 -07:00
David Zarzycki
00f4700496 Handle expanded enums in upstream LLVM (ZOS and GOFF) 2020-08-12 09:05:38 -04:00
Joe Groff
d2bff927ef IRGen: Don't emit method descriptors for derivative functions.
The symbol mangling for the descriptors doesn't incorporate the derivative information, leading to symbol collisions.
2020-08-03 16:12:05 -07:00
Joe Groff
1a77850039 IRGen: Don't drop method descriptors for vtable-elided internal methods.
We still use the method descriptor for key path identity and other uses. Fixes rdar://problem/66280170.
2020-08-03 09:49:44 -07:00
Joe Groff
2dac5846ee IRGen: Keep vtables entries inherited from fragile base classes.
If a subclass is resilient, but has a fragile base class, we need to preserve the ABI-exposed vtable entries
inherited from the base class.
2020-07-24 14:16:23 -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
Slava Pestov
e6e9b6e352 Merge pull request #32887 from slavapestov/fixed-layout-protocols
AST: Allow @_fixed_layout protocols
2020-07-21 13:46:36 -04:00
Slava Pestov
4a47190335 AST: Allow @_fixed_layout protocols
A @_fixed_layout protocol exposes its witness table layout to
clients, which prevents re-ordering of requirements or adding
new requiremenst with a default.

When library evolution is enabled, we still emit method
descriptors even for @_fixed_layout protocols; this allows a
previously-resilient protocol to become @_fixed_layout as long
as the published layout matches the resilient layout in all
previously-shipped versions of the library.
2020-07-20 23:53:41 -04:00
Nate Chandler
d4b82bacca [metadata prespecialization] Cross-module: enums and structs.
When a generic type from a different module is not resilient within the
current module and at least one of its arguments is from the current
module, emit a non-canonical prespecialized record, and access that
metadata via a call to swift_getCanonicalSpecializedMetadata, passing in
the non-canonical record.

rdar://problem/56996727
rdar://problem/56997022
2020-07-16 14:14:01 -07:00
Davide Italiano
b0a419b297 [IRGen] Check if VTable isn't a nullptr.
Fixes a ubsan error on the lldb bots

runtime error: member call on null pointer of type 'swift::SILVTable'
undefined-behavior lib/IRGen/GenMeta.cpp:5107:24
2020-07-14 16:05:06 -07:00
Doug Gregor
454ccab9fb Merge pull request #32398 from keith/ks/unused-vars
Remove unused variables
2020-06-16 12:56:49 -07:00
Keith Smiley
134213852a Remove unused variables
These currently warn for being unused
2020-06-15 16:03:41 -07:00
Arnold Schwaighofer
abf65bb143 IRGen: Use the right descriminator for AutoDiffDerivativeFunctions
Fixes the failure in AutoDiff/validation-test/forward_mode.swift on
arm64e.

rdar://64192250
2020-06-15 15:28:41 -07:00
Joe Groff
04c8f0df42 IRGen: Don't reify internal vtable entries that are marked overridden.
Private and internal classes shouldn't have ABI constraints on their concrete vtable layout, so if methods
don't have overrides in practice, we can elide their vtable entries.
2020-06-12 11:59:24 -07:00
David Zarzycki
e077b6ffd9 [SIL] NFC: Make SILVTable follow C++ and LLVM best practices
1) Convert the `Entry` type to a class with getters/setters
2) Use llvm::TrailingObjects
3) Use llvm::PointerIntPair
2020-06-11 07:51:42 -04:00
Arnold Schwaighofer
825a2a259b Mark non-foreign entry points of @objc dynamic methods in generic classes dynamically_replaceable
```
class Generic<T> {
  @objc dynamic func method() {}
}

extension Generic {
  @_dynamicReplacement(for:method())
  func replacement() {}
}
```

The standard mechanism of using Objective-C categories for dynamically
replacing @objc methods in generic classes does not work.

Instead we mark the native entry point as replaceable.

Because this affects all @objc methods in generic classes (whether there
is a replacement or not) by making the native entry point
`[dynamically_replaceable]` (regardless of optimization mode) we guard this by
the -enable-implicit-dynamic flag because we are late in the release cycle.

* Replace isNativeDynamic and isObjcDynamic by calls to shouldUse*Dispatch and
  shouldUse*Replacement
  This disambiguates between which dispatch method we should use at call
  sites and how these methods should  implement dynamic function
  replacement.

* Don't emit the method entry for @_dynamicReplacement(for:) of generic class
  methods
  There is not way to call this entry point since we can't generate an
  objective-c category for generic classes.

rdar://63679357
2020-06-09 09:23:29 -07:00
Arnold Schwaighofer
3f903b4891 Merge pull request #31986 from aschwaighofer/irgen_inherit_clangs_fp_elim
IRGen: Default to clang's frame pointer elimination settings
2020-06-03 07:38:24 -07:00
Joe Groff
124808ddb6 Merge pull request #32088 from jckarter/final-keypath-methods
Make an internal KeyPath helper final.
2020-05-29 18:44:56 -07:00
Joe Groff
24336465c0 Add debug output for vtable layout 2020-05-29 14:30:02 -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
Arnold Schwaighofer
20f4ef93de IRGen: Default to clang's frame pointer elimination settings
Clang provides options to override that default value.
These options are accessible via the -Xcc flag.

Some Swift functions explicitly disable the frame pointer.

The clang options will not override those.
2020-05-28 12:21:42 -07: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
nate-chandler
c9912c5964 Merge pull request #31056 from nate-chandler/generic-metadata-prespecialization-components/rdar61465515
[metadata prespecialization] Zero trailing flags field.
2020-04-23 20:39:42 -07:00
Nate Chandler
2b50150e61 [metadata prespecialization] Zero trailing flags.
Previously, the trailing flags field of runtime instantiated generic
metadata for types which had prespecialization enabled were not zeroed.
Consequently, the field always contained garbage.  Often, metadata was
instantiated on new (and so, zeroed) pages, so the garbage happened to
be zero as is appropriate.  However, when the metadata was instantiated
on pages which had previously been dirtied, the garbage value would
sometimes indicate that the metadata was canonical statically
specialized.  When that occurred, swift_checkMetadataState would
incorrectly return a metadata state of complete, despite the fact that
the metadata might not in fact be complete.  As a result, the runtime
was trafficking in incomplete metadata as if it were complete, resulting
in various crashes that would arise from for example missing a witness
table or a value witness table.

Here the problem is corrected.  The trailing flags field of structs and
enums that have the field is set to 0.

For structs, this is accomplished by modifying the extra data pattern to
exist not only when there is fixed type info for the type but also when
the type is being prespecialized.  Specifically, the extra data for a
struct is, rather than an i32 array of field offsets, a struct
consisting of none, one, or both of the following: (1) the array of
field offsets, (2) the trailing flags.

Similarly, enums now have an extra data pattern which consists of none,
one, or both of the following: (1) the payload size, (2) the trailing
flags.  Enum metadata extra data setting was previously achieved by
customizing the metadata allocation function; that customization is now
eliminated, being replaced with the shared runtime code for copying
extra data into place, a modest code size savings.

rdar://problem/61465515
2020-04-23 18:18:40 -07:00
Robert Widmann
40d9cd8d3f [NFC] Give IRGenModule Exclusive Ownership of an LLVMContext Object 2020-04-16 11:57:44 -07:00
Nate Chandler
47943f8304 [Runtime] Fixed zeroing of extra data padding for values.
See also bcc309efa1 .
2020-04-15 17:22:26 -07:00
Artem Chikin
1b11e8798c [IRGen] Skip witness table query for protocols that do not require one
Some protocols, such as protocols marked with 'objc', do not have a Witness Table.
The code before this patch assumes all protocols do have a Witness Table when generating the layout of an OpaqueTypeDescriptor, causing an assert to be triggered for opaque return types that conform to an 'objc' protocol.

Fixes SR-12257 / rdar://problem/59740179
2020-03-31 10:56:20 -07:00
Dan Zheng
e5cb871428 [AutoDiff upstream] Add flag-gated AdditiveArithmetic derivation. (#30628)
Add `AdditiveArithmetic` derived conformances for structs, gated by the
`-enable-experimential-additive-arithmetic-derivation` flag.

Structs whose stored properties all conform to `AdditiveArithmetic` can derive
`AdditiveArithmetic`:
- `static var zero: Self`
- `static func +(lhs: Self, rhs: Self) -> Self`
- `static func -(lhs: Self, rhs: Self) -> Self`
- An "effective memberwise initializer":
  - Either a synthesized memberwise initializer or a user-defined initializer
    with the same type.

Effective memberwise initializers are used only by derived conformances for
`Self`-returning protocol requirements like `AdditiveArithmetic.+`, which
require memberwise initialization.

Resolves TF-844.
Unblocks TF-845: upstream `Differentiable` derived conformances.
2020-03-25 10:31:50 -07:00
marcrasi
025cb9a501 autodiff builtins (#30624)
Define type signatures and SILGen for the following builtins:

```
/// Applies the {jvp|vjp} of `f` to `arg1`, ..., `argN`.
func applyDerivative_arityN_{jvp|vjp}(f, arg1, ..., argN) -> jvp/vjp return type

/// Applies the transpose of `f` to `arg`.
func applyTranspose_arityN(f, arg) -> transpose return type

/// Makes a differentiable function from the given `original`, `jvp`, and
/// `vjp` functions.
func differentiableFunction_arityN(original, jvp, vjp)

/// Makes a linear function from the given `original` and `transpose` functions.
func linearFunction_arityN(original, transpose)
```

Add SILGen FileCheck tests for all builtins.
2020-03-25 02:36:42 -07:00
Fred Riss
259d78a350 Adapt to llvm.org StringRef API change 2020-03-13 19:08:22 +01:00
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
Nate Chandler
949029a788 [metadata prespecialization] Create enum records.
Extracted implementation of SpecializedGenericStructMetadataBuilder into
SpecializedGenericNominalMetadataBuilderBase, a CRTP with a template
template argument for the CRTP superclass and a template argument for
the implementation.  That new type is now subclassed by
SpecializedGenericStructMetadataBuilder.  Additionally, this new type is
also subclassed by the newly added SpecializedGenericEnumMetadataBuilder
which is responsible for build the prespecialization of generic enum
metadata.

rdar://problem/56960887
2020-02-11 09:57:22 -08:00
Owen Voorhees
166555c34f [Diagnostics] Better diagnostic for integer used as a boolean condition 2020-02-03 21:20:41 -08:00
Dan Zheng
1486d6b346 NFC: Add GenericSignature::getCanonicalSignature. (#29105)
Motivation: `GenericSignatureImpl::getCanonicalSignature` crashes for
`GenericSignature` with underlying `nullptr`. This led to verbose workarounds
when computing `CanGenericSignature` from `GenericSignature`.

Solution: `GenericSignature::getCanonicalSignature` is a wrapper around
`GenericSignatureImpl::getCanonicalSignature` that returns the canonical
signature, or `nullptr` if the underlying pointer is `nullptr`.

Rewrite all verbose workarounds using `GenericSignature::getCanonicalSignature`.
2020-01-12 12:17:41 -08:00
Nate Chandler
d78dc038c4 [metadata prespecialization] Specialize VWTs.
Prespecialized metadata records must refer to value witness tables that
have correct values for size and stride.  In order to do that, a
prespecialized value witness table must emitted and referred to.  Here,
a fully specialized value witness table is emitted.

For the moment, the value witness table is fully specialized.  Having it
be specialized, though, will likely cause serious code size problems,
since it results in specialized value witness functions being generated.

rdar://problem/58088270
2020-01-09 17:25:34 -08:00
Nate Chandler
9e2e090623 [IRGen] Emit metadata accessors last.
Metadata accessors are dependent on prespecializations of the metadata
of generic, in-module types.  Those prespecializations are themselves
dependent on usages of the types in functions.  Consequently, the
accessors must be emitted after all the functions are emitted.
2020-01-09 17:25:34 -08:00
Nate Chandler
7068141770 [IRGen] Emit prespecialized metadata records.
Prespecialized records contain direct references to the generic
arguments and protocol witnesses with which it is specialized for now.

Both prespecialized records and the records that are specialized at
runtime gain a trailing pointer-sized flagset.  For now, the flags in it
include whether the record was prespecialized and whether it was known
to be canonical at compile time (which is true for prespecialized
records within the module which defines the type whose metadata is
specialized since in those cases the metadata accessor can be modified).

rdar://problem/56960307
2020-01-09 17:25:33 -08:00
Nate Chandler
d9205fafd3 [IRGen] Prepare to emit prespecializations. 2020-01-09 17:25:33 -08:00
Nate Chandler
525e25603f [IRGen] Pass argument/table to builders.
Previously, the various generic builders implemented the methods
addGenericArgument and addGenericWitnessTable without being provided
what argument or witness table they were to add (because it was not
previously needed).  Now, the GenericRequirement is passed along to both
methods.
2020-01-09 17:25:31 -08:00
Doug Gregor
d59c23fa2c Merge pull request #28869 from DougGregor/assoc-type-witness-canon
[IRGen] Canonicalize associated type witnesses.
2019-12-19 00:27:25 -08:00
Doug Gregor
4e71ce53a9 [IRGen] Canonicalize associated type witnesses.
Associated type witnesses were not getting canonicalized with respect to
their appropriate generic signatures, causing types to be emitted into
the metadata that could not be properly demangled. Be consistent about
providing a generic signature for canonicalization.

Fixes SR-11642 / rdar://problem/56466693.
2019-12-18 22:21:50 -08:00
Xi Ge
1ebc78b22b [RemoteAST] Using module names specified by @_originallyDefinedIn for top-level decls marked as so
This should allow runtime de-mangling of those moved symbols.
2019-12-16 17:57:32 -08:00