Commit Graph

46922 Commits

Author SHA1 Message Date
Slava Pestov
c52affbd68 Merge pull request #37440 from slavapestov/clean-up-generic-requirement-checking
Clean up duplicate logic for checking if generic requirements are satisfied
2021-05-17 19:28:18 -04:00
Ben Barham
ccd39760cf Merge pull request #37441 from bnbarham/serialization-crashes
[Serialization] Do not assert when inherited type is null
2021-05-18 09:14:06 +10:00
Xi Ge
0d4d98eeb0 Merge pull request #37458 from nkcsgexi/string-as-version
CanImport: allow using string literal to indicate desired version
2021-05-17 14:26:55 -07:00
Ben Langmuir
006e78e672 Merge pull request #37320 from fwcd/sourcekit-diagnostic-ids
[SourceKit] Add id and category to diagnostics
2021-05-17 14:25:40 -07:00
Slava Pestov
b556cb5d70 IDE: Refactor SynthesizedExtensionAnalyzer to use Requirement::isSatisfied() 2021-05-17 16:34:18 -04:00
Xi Ge
e0b8de4d49 Merge pull request #37455 from nkcsgexi/user-module-subminor
Serialization: embed subminor and build version in the user module version entry
2021-05-17 13:15:25 -07:00
Xi Ge
ebfa459b3e CanImport: allow using string literal to indicate desired version 2021-05-17 11:10:41 -07:00
Ben Rimmington
ff12adf62b [test] Update get_simulator_command for macOS 11 (#37446) 2021-05-17 18:37:00 +01:00
Xi Ge
5c5715f626 Serialization: embed subminor and build version in the user module version entry 2021-05-17 10:15:47 -07:00
Arnold Schwaighofer
b0c977f149 This test fails on windows 2021-05-16 07:24:15 -07:00
Arnold Schwaighofer
9b4f7d62cd Make sure we tail call optimize a call in concurrency runtime's switch_task_impl.
Without this hack the call will leave a stack frame around (not tail
call optimized) and blow the stack if we call switch_task often enough.

Ideally, clang would emit this call as `musttail` but currently it does
not.

rdar://76652421
2021-05-15 08:07:55 -07:00
Ben Barham
c1e4362dfd [Serialization] Do not assert when inherited type is null
When compiling with allow errors, it's possible to have invalid
inherited types - both null and ErrorType.

Cleaned up the tests a little - moved the majority of
Frontend/allow-errors.swift into separate files in
Serialization/AllowErrors and use split_file.py instead of #defines.

Resolves rdar://78048470
2021-05-15 16:35:23 +10:00
Slava Pestov
760d7997de Merge pull request #37434 from slavapestov/fix-generic-override-crash
Sema: Fix a couple of issues with implicit overrides of generic designated initializers
2021-05-14 23:19:04 -04:00
Andrew Trick
4d7321edba Merge pull request #37429 from nkcsgexi/78027229
test: specify touch time to ensure mod time difference
2021-05-14 17:40:59 -07:00
Slava Pestov
379220b9e2 Sema: Fix a couple of issues with implicit overrides of generic designated initializers
If a base class initializer was not generic but had a contextual 'where'
clause, we would unconditionally inherit the 'where' clause in the override as
part of the fix for another issue (https://bugs.swift.org/browse/SR-14118).

However, it is possible that some of those requirements are satisfied by
the derived class itself. For example:

    class Base<T> {
        init() where T : AnyObject {}
    }

    class Derived : Base<AnyObject> {}

In this case, the implicit override Derived.init() has no generic requirements
at all. We used to assert because we would create a GSB with no generic
parameters.

It was also possible for a base class initializer to have generic
requirements that are not satisfied by the derived class. In this case,
we need to drop the initializer from consideration altogether.

While I'm here, I improved the comments in computeDesignatedInitOverrideSignature(),
which is the new name for configureGenericDesignatedInitOverride().

Fixes rdar://problem/77285618.
2021-05-14 19:02:57 -04:00
Xi Ge
ae4781dd90 test: specify touch time to ensure mod time difference
rdar://78027229
2021-05-14 13:04:44 -07:00
Xi Ge
e24eef4b35 driver: emit a warning when user specified flags to disable the new driver
rdar://78021402
2021-05-14 11:00:36 -07:00
Alex Hoppen
b0bade6711 Merge pull request #37417 from bnbarham/add-completionhandler-attribute
[Refactoring] Add @completionHandlerAsync to sync function
2021-05-14 17:09:58 +02:00
Hamish Knight
5b2f40a006 Merge pull request #37411 from hamishknight/returning-so-soon 2021-05-14 13:37:17 +01:00
Ben Barham
762337cc9b [Refactoring] Add @completionHandlerAsync to sync function
When adding an async alternative, add the @completionHandlerAsync
attribute to the sync function. Check for this attribute in addition to
the name check, ie. convert a call if the callee has either
@completionHandlerAsync or a name that is completion-handler-like name.

The addition of the attribute is currently gated behind the experimental
concurrency flag.

Resolves rdar://77486504
2021-05-14 20:19:02 +10:00
Hamish Knight
87703a0716 [test] Add test for async completion handler call in parens
We don't currently handle this, but arguably we
should be able to.
2021-05-14 11:17:59 +01:00
Hamish Knight
7ab5915750 [Refactoring] Don't drop returns with expressions
Previously we were unconditionally dropping a
return statement if it was the last node, which
could cause us to inadvertently drop the result
expression as well. Instead, only drop bare
'return' statements.

rdar://77789360
2021-05-14 11:17:59 +01:00
Hamish Knight
aa189f2fe9 [Refactoring] Avoid duplicating return statements
It's possible the user has already written an
explicit return for the call to the completion
handler. In that case, avoid adding another return.

rdar://77789360
2021-05-14 11:17:59 +01:00
swift-ci
2074057785 Merge pull request #37415 from DougGregor/remove-asynchandler 2021-05-13 19:47:46 -07:00
swift-ci
e0eff4885e Merge pull request #37287 from plotfi/cxx-interop-anon-union 2021-05-13 19:47:37 -07:00
Doug Gregor
2b9ca315fe [Concurrency] Remove asyncHandler attribute.
The `asyncHandler` attribute turned out to be the wrong solution
to the problem of creating a sync->async bridge. Remove it.
2021-05-13 17:01:39 -07:00
Joe Groff
8e1dcb481f Merge pull request #37393 from jckarter/disable-flaky-objc-async-test
Disable flaky test/Concurrency/Runtime/objc_async.swift test.
2021-05-13 16:13:02 -07:00
Pavel Yaskevich
3823966e01 Merge pull request #37395 from xedin/rdar-75849035
[Concurrency] Actor cannot conform to global actor isolated protocol
2021-05-13 13:44:07 -07:00
Hamish Knight
ef318a16cb Merge pull request #37387 from hamishknight/any-comments 2021-05-13 21:09:26 +01:00
Xi Ge
42a89af00c Merge pull request #37355 from nkcsgexi/77676064-flag
Frontend: teach the compiler to use a backup directory to find .swiftinterface files to compile
2021-05-13 11:45:32 -07:00
Puyan Lotfi
7d7a6c6bcc [cxx-interop] Detect IndirectFields nested in non-importable anon-unions
This patch to the Clang Importer avoids an assert by detecting when an
IndirectField belongs to an anonymous union that is not importable. How
it does this is by determining if an IndirectFieldDecl's anonymous
parent field is non-importable (based on isCxxRecordImportable) and if
so skips importing the IndirectFieldDecl.

This avoids the mentioned assert because makeIndirectFieldAccessors
expects a FieldDecl of __Unnamed_union___Anonymous_field that is only
populated when the top-level union is imported from an
IndirectFieldDecl's parent. IndirectFieldDecls for the members of an
anonymous union are dependent on their parent and should not be imported
if their parent can not also be imported.

This corner case can happen in cases when an anonymous union contains an
ARC pointer, which results in a non-trivial but also inaccessible dtor.
2021-05-13 07:31:33 -10:00
Xi Ge
b6cd513534 Frontend: teach the compiler to use a backup directory to find .swiftinterface files to compile
This mechanism allows the compiler to use a backup interface file to build into a binary module when
a corresponding interface file from the SDK is failing for whatever reasons. This mechansim should be entirely opaque
to end users except several diagnostic messages communicating backup interfaces are used.

Part of rdar://77676064
2021-05-13 09:11:45 -07:00
QuietMisdreavus
51c96a4df0 Merge pull request #37351 from apple/QuietMisdreavus/protocol-req-sourceOrigin
[SymbolGraph] add sourceOrigin field for symbols implementing remote protocol requirements
2021-05-13 09:06:37 -07:00
Arnold Schwaighofer
f82edf72c7 Mark test async_stream as executable_test
It fails on non_executable bots.

rdar://77963528
2021-05-13 06:26:10 -07:00
Hamish Knight
8cb319b640 [Refactoring] Preserve comments in async transform
Previously we would drop comments between nodes in
a BraceStmt, as we printed each node out individually.
To remedy this, always make sure we scan backwards
to find any preceding comments attached to a node,
and also keep track of any SourceLocs which we
don't print, but may have comments attached which
we want to preserve.

rdar://77401810
2021-05-13 14:16:27 +01:00
Ben Barham
a2ce02a639 Merge pull request #37302 from bnbarham/async-shadowing
[Refactoring] Avoid redeclarations or shadowing in async refactored code
2021-05-13 22:23:30 +10:00
Ben Barham
8569c8a51b [Refactoring] Avoid redeclarations or shadowing in async refactored code
When converting a call or function, rename declarations such that
redeclaration errors and shadowing are avoided. In some cases this will
be overly conservative, but since any renamed variable can be fixed with
edit all in scope, this is preferred over causing redeclaration errors
or possible shadowing.

Resolves rdar://73973517
2021-05-13 17:48:41 +10:00
Robert Widmann
724e015dae Merge pull request #37386 from CodaFi/ir-ony
Delete Flaky IR Hash Test
2021-05-12 19:11:03 -07:00
Pavel Yaskevich
ecfff76552 [Concurrency] Actor cannot conform to global actor isolated protocol
Attempting to conform an actor to a global actor isolated protocol
creates a clash in isolation when members are accessed so, let's
detect and diagnose that.

Resolves: rdar://75849035
2021-05-12 16:00:25 -07:00
Artem Chikin
364f154fff Merge pull request #37350 from artemcm/DeployTargetIndependentAvailabilityDiagnostic
Warn about unnecessary availability independently from the deployment target
2021-05-12 15:39:45 -07:00
Joe Groff
74736c75ba Disable flaky test/Concurrency/Runtime/objc_async.swift test.
We need to introduce some proper synchronization between the @main task and the ObjC
completion handler to make this reliably deterministic. rdar://77934626
2021-05-12 15:24:40 -07:00
Artem Chikin
5146bd5191 Report unnecessary availability warnings independently from the deployment target
This change separates emission of the diagnostics like:
```
unnecessary check for 'Platform'; enclosing scope ensures guard will always be true
```
from the deployment target of the current compilation. Instead, these diagnostics will only be emitted if the enclosing scope guard is explicitly specified by the user with an `#availability` attribute.

This fixes cases like the following:
```
@available(macOS 11.0, *)
class Foo {
    func foo() {
        if #available(macOS 11.1, *) {}
    }
}
```
Compiling this with `-target x86_64-apple-macos11.2` results in:
```
warning: unnecessary check for 'macOS'; enclosing scope ensures guard will always be true
        if #available(macOS 11.1, *) {}
.../test.swift:2:7: note: enclosing scope here
class Foo {
```
Even though in source-code the enclosing scope (`Foo`) of this guard does not ensure it will always be true.
This happens because availability range is propagated by intersecting ranges top-down from the root `TypeRefinementContext`, which is defined by the deployment target, causing the availability range on class `Foo` to become `11.2`.

Users may be sharing the same piece of source-code across different projects with their own respective deployment targets which makes such target-dependent warnings confusing at some times, and not-useful at others.
We should rather have the warning simply reflect what is in the source.

Resolves rdar://77607488
2021-05-12 11:57:57 -07:00
Robert Widmann
7c360ff1d8 Delete Flaky IR Hash Test
Our LLVM backend is supposed to have a build-time optimization where we
hash the IR and do not proceed with LLVM code generation if the hash
matches the one we last used to emit any products. This has never quite
worked for a variety of reasons - we fixed a number of those reasons in
https://github.com/apple/swift/pull/31106 but this test remained flaky
for its entire lifetime.

It's really not worth all the trouble to keep investigating this, so I'm
removing this test.

rdar://77654695
2021-05-12 10:02:48 -07:00
Holly Borla
e1591314cf Merge pull request #37380 from hborla/property-wrapper-inference-crash
[ConstraintSystem] Fix a constraint system crash with property wrapper inference using the $ syntax.
2021-05-12 08:55:51 -07:00
Alex Hoppen
65b9a1c1fc Merge pull request #37314 from ahoppen/pr/refactor-to-async-variable-callback
[Refactoring] Support refactoring calls to async if a variable or function is used as completion handler
2021-05-12 16:57:34 +02:00
Pavel Yaskevich
d500f9cc8a Merge pull request #37373 from xedin/rdar-76058892
[CSSimplify] Increase fix impact when passing closure to a non-function type parameter
2021-05-12 00:30:17 -07:00
Alex Hoppen
f1455c29bf [Refactoring] Check that code compiles after refatorings in variable_as_callback.swift 2021-05-12 09:26:42 +02:00
Alex Hoppen
effae5f2a9 [Refactoring] Remove the VARIABLE-COMPLETION-HANDLER suffix from checks in variable_as_callback.swift
These were a legacy from when the tests lived in `basic.swift`. They are no longer needed.
2021-05-12 09:26:42 +02:00
Alex Hoppen
32ceb24b6c [Refactoring] Promote call to refactored completion handlers to return
When a function’s completion handler is being passed to another function and the function that the completion handler is being declared in is converted to async, replace the call to the completion handler by a `return` statement.

For example:
```swift
func foo(completion: (String) -> Void) {
  bar(completion)
}
```

becomes
```swift
func foo() async -> String {
  return await bar()
}
```

Previously, we were calling the completion handler, which no longer exists in the newly created `async` function.
2021-05-12 09:26:25 +02:00
Philippe Hausler
4886bd56e4 [Concurrency] AsyncStream and AsyncThrowingStream
* Rework YieldingContinuation to service values in a buffered fashion

* Fix word size calculation for locks

* Handle terminal states and finished/failed storage

* Wrap yielding continuation into a more featureful type for better ergonomics

* Hope springs eternal, maybe windows works with this?

* Prevent value overflows at .max limits

* Add a cancellation handler

* Fix series tests missing continuation parameters

* Fix series tests for mutable itertaors

* Rename to a more general name for Series's inner continuation type

* Whitespace fixes and add more commentary about public functions on Series

* Restore YieldingContinuation for now with deprecations to favor Series

* Ensure onCancel is invoked in deinit phases, and eliminate a potential for double cancellation

* Make sure ThrowingSeries has the same nonmutating setter for onCancel as Series

* Add a swath of more unit tests that exersize cancellation behavior as well as throwing behaviors

* Remove work-around for async testing

* Fixup do/catch range to properly handle ThrowingSeries test

* Address naming consistency of resume result function

* Adopt the async main test setup

* More migration of tests to new async mechanisms

* Handle the double finish/throw case

* Ensure the dependency on Dispatch is built for the series tests (due to semaphore usage)

* Add import-libdispatch to run command for Series tests

* Use non-combine based timeout intervals (portable to linux) for dispatch semaphore

* Rename Series -> AsyncStream and resume functions to just yield, and correct a missing default Element.self value

* Fix missing naming change issue for yielding an error on AsyncThrowingStream

* Remove argument label of buffering from tests

* Extract buffer and throwing variants into their own file

* Slightly refactor for only needing to store the producer instead of producer and cancel

* Rename onCancel to onTermination

* Convert handler access into a function pair

* Add finished states to the termination handler event pipeline and a disambiguation enum to identify finish versus cancel

* Ensure all termination happens before event propigation (and outside of the locks) and warn against requirements for locking on terminate and enqueue

* Modified to use Deque to back the storage and move the storage to inner types; overall perf went from 200kE/sec to over 1ME/sec

* Update stdlib/public/Concurrency/AsyncStream.swift

Co-authored-by: Doug Gregor <dgregor@apple.com>

* Update stdlib/public/Concurrency/AsyncThrowingStream.swift

Co-authored-by: Doug Gregor <dgregor@apple.com>

* Update stdlib/public/Concurrency/AsyncStream.swift

Co-authored-by: Joseph Heck <heckj@mac.com>

* Update stdlib/public/Concurrency/AsyncThrowingStream.swift

Co-authored-by: Joseph Heck <heckj@mac.com>

* Update stdlib/public/Concurrency/AsyncThrowingStream.swift

Co-authored-by: Joseph Heck <heckj@mac.com>

* Update stdlib/public/Concurrency/AsyncThrowingStream.swift

Co-authored-by: Joseph Heck <heckj@mac.com>

* Update stdlib/public/Concurrency/AsyncStream.swift

Co-authored-by: Joseph Heck <heckj@mac.com>

* Update stdlib/public/Concurrency/AsyncThrowingStream.swift

Co-authored-by: Joseph Heck <heckj@mac.com>

* Remove local cruft for overlay disabling

* Remove local cruft for Dispatch overlay work

* Remove potential ABI impact for adding Deque

Co-authored-by: Doug Gregor <dgregor@apple.com>
Co-authored-by: Joseph Heck <heckj@mac.com>
2021-05-11 21:41:33 -07:00