Commit Graph

1350 Commits

Author SHA1 Message Date
swift-ci
9f29b005b5 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-25 18:52:44 -08:00
Philippe Hausler
6e05240426 AsyncSequence and protocol conformance rethrows (#35224)
* Initial draft of async sequences

* Adjust AsyncSequence associated type requirements

* Add a draft implementation of AsyncSequence and associated functionality

* Correct merge damage and rename from GeneratorProtocol to AsyncIteratorProtocol

* Add AsyncSequence types to the cmake lists

* Add cancellation support

* [DRAFT] Implementation of protocol conformance rethrowing

* Account for ASTVerifier passes to ensure throwing and by conformance rethrowing verifies appropriately

* Remove commented out code

* OtherConstructorDeclRefExpr can also be a source of a rethrowing kind function

* Re-order the checkApply logic to account for existing throwing calculations better

* Extract rethrowing calculation into smaller functions

* Allow for closures and protocol conformances to contribute to throwing

* Add unit tests for conformance based rethrowing

* Restrict rethrowing requirements to only protocols marked with @rethrows

* Correct logic for gating of `@rethrows` and adjust the determinates to be based upon throws and not rethrows spelling

* Attempt to unify the async sequence features together

* Reorder try await to latest syntax

* revert back to the inout diagnosis

* House mutations in local scope

* Revert "House mutations in local scope"

This reverts commit d91f1b25b59fff8e4be107c808895ff3f293b394.

* Adjust for inout diagnostics and fall back to original mutation strategy

* Convert async flag to source locations and add initial try support to for await in syntax

* Fix case typo of MinMax.swift

* Adjust rethrowing tests to account for changes associated with @rethrows

* Allow parsing and diagnostics associated with try applied to for await in syntax

* Correct the code-completion for @rethrows

* Additional corrections for the code-completion for @rethrows this time for the last in the list

* Handle throwing cases of iteration of async sequences

* restore building XCTest

* First wave of feedback fixes

* Rework constraints checking for async sequence for-try-await-in checking

* Allow testing of for-await-in parsing and silgen testing and add unit tests for both

* Remove async sequence operators for now

* Back out cancellation of AsyncIteratorProtocols

* Restructure protocol conformance throws checking and cache results

* remove some stray whitespaces

* Correct some merge damage

* Ensure the throwing determinate for applying for-await-in always has a valid value and adjust the for-await-in silgen test to reflect the cancel changes

* Squelch the python linter for line length
2021-01-25 18:48:50 -08:00
swift_jenkins
7f84c7b706 Merge remote-tracking branch 'origin/main' into next 2020-12-15 22:15:55 -08:00
John McCall
bad16fd105 Do dynamic layout of generic/resilient default actors properly.
Since these types have an implicit stored property, this requires
adding an abstraction over fields to IRGen, at least throughout
the class code.  In some ways I think this significantly improves
the code, especially in how we approach missing members.

Fixes rdar://72202671.
2020-12-15 20:10:46 -05:00
swift_jenkins
09c50eb369 Merge remote-tracking branch 'origin/main' into next 2020-12-04 21:53:19 -08:00
Slava Pestov
379d7522a1 IRGen: Nonoverridden method descriptors should be true-const
Fixes <rdar://problem/70685173>.
2020-12-04 21:56:33 -05:00
swift_jenkins
f1eec97e9d Merge remote-tracking branch 'origin/main' into next 2020-12-02 19:33:30 -08:00
John McCall
945011d39f Handle default actors by special-casing layout in IRGen instead
of adding a property.

This better matches what the actual implementation expects,
and it avoids some possibilities of weird mismatches.  However,
it also requires special-case initialization, destruction, and
dynamic-layout support, none of which I've added yet.

In order to get NSObject default actor subclasses to use Swift
refcounting (and thus avoid the need for the default actor runtime
to generally use ObjC refcounting), I've had to introduce a
SwiftNativeNSObject which we substitute as the superclass when
inheriting directly from NSObject.  This is something we could
do in all NSObject subclasses; for now, I'm just doing it in
actors, although it's all actors and not just default actors.
We are not yet taking advantage of our special knowledge of this
class anywhere except the reference-counting code.

I went around in circles exploring a number of alternatives for
doing this; at one point I basically had a completely parallel
"ForImplementation" superclass query.  That proved to be a lot
of added complexity and created more problems than it solved.
We also don't *really* get any benefit from this subclassing
because there still wouldn't be a consistent superclass for all
actors.  So instead it's very ad-hoc.
2020-12-02 18:47:13 -05:00
swift_jenkins
7b00d6e238 Merge remote-tracking branch 'origin/main' into next 2020-11-19 11:57:20 -08:00
Nate Chandler
8b6ff9cb67 [NFC] Assert that extra data size matches extra data pattern and offset.
To prevent the fix for rdar://problem/68997282 from regressing, assert
that the size of the extra data patterns for generic enums and structs
combined with the corresponding offsets matches the size passed from the
generic metadata instantiation function to
swift_allocateGenericValueMetadata.
2020-11-19 00:59:53 -08:00
Nate Chandler
4dfaa77935 [IRGen] Pack extra data pattern structs.
Previously, the extra data pattern structs for struct and enums were not
packed.

On 32 bit, this resulted in an extra data pattern struct which was 4
bytes too large whenever there was an odd number of fields in the
struct.  The result was writing past the end of the allocated struct.
That bug only caused occasional crashes because (1) for the most part
there was additional space beyond the end of the allocation intended for
the struct metadata in the bump allocator and (2) while half of the
trailing flags field would be overwritten, because those bits of the
trailing flags being nonzero did not have an observable effect since
those bits of the trailing flags field are not yet used.

Here, the structs are marked packed, resulting in the appropriate size
for the extra data pattern structs on 32 bit platforms.

rdar://problem/68997282
2020-11-19 00:59:53 -08:00
swift_jenkins
db4e02556a Merge remote-tracking branch 'origin/main' into next 2020-11-16 14:23:23 -08:00
Slava Pestov
2390b959e1 IRGen: Emit class stubs in more instances so that objc_copyClassList() can find them
We would like it if objc_copyClassList() would find non-generic
classes with generic ancestry, as long as they ultimately inherit
from an @objc class. Make this so by emitting class stubs in a
few more cases.

Fixes <rdar://problem/71194117>.
2020-11-16 15:10:12 -05:00
swift_jenkins
c3c8e6dd18 Merge remote-tracking branch 'origin/main' into next 2020-11-13 09:58:56 -08:00
Nate Chandler
660f74b68a [Async CC] Add AsyncFunctionPointer to vtable. 2020-11-12 18:20:10 -08:00
Nate Chandler
2d21932672 [Async CC] Add constant "pointer" for async func.
An AsyncFunctionPointer, defined in Task.h, is a struct consisting of
two i32s: (1) the relative address of the async function and (2) the
size of the async context to be allocated when calling that function.

Here, such structs are emitted for every async SILFunction that is
emitted.
2020-11-12 18:20:10 -08:00
swift_jenkins
00d5035939 Merge remote-tracking branch 'origin/main' into next 2020-11-04 19:36:54 -08:00
nate-chandler
5c59babfeb Merge pull request #34490 from nate-chandler/generic-metadata-prespecialization-components/special-entry
[metadata prespecialization] Add canonical records to cache.
2020-11-04 19:35:40 -08:00
Arnold Schwaighofer
97e5e01fe2 Merge remote-tracking branch 'origin/main' into next 2020-11-04 12:20:35 -08:00
Slava Pestov
bfee5fb800 IRGen: Emit list of Objective-C resilient class stubs in __objc_stublist section
Part of <rdar://problem/55000892>.
2020-11-02 17:01:42 -05:00
Nate Chandler
a68fcb155b [prespecialized metadata] Add token for caching.
Emit a once token when adding canonical prespecialized metadata records
to a nominal type descriptor and add the token itself as a trailing
object to the type descriptor.  The new token will, in subsequent
commits, enable the canonical prespecialized metadata records attached
to the type descriptor to be added to the metadata cache exactly once.
2020-11-01 13:34:22 -08:00
swift_jenkins
ac24c24279 Merge remote-tracking branch 'origin/main' into next 2020-10-13 08:06:23 -07:00
Arnold Schwaighofer
d6d79c66aa Merge two fields into a PointerUnion in SILDeclRef to save space 2020-10-12 09:19:29 -07:00
swift_jenkins
55b4adb819 Merge remote-tracking branch 'origin/main' into next 2020-09-30 13:52:43 -07:00
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