Commit Graph

43937 Commits

Author SHA1 Message Date
Doug Gregor
a554ad632b [Concurrency] Diagnose mutating accesses to locals from concurrent code.
Replace the existing warning about any access to a local variable from
concurrently-executing code with a more tailored error:
concurrently-executing code may read a mutable varable, but cannot
modify it. This is safe so long as we either always do by-value
captures in concurrent closures or we ensure that no mutation of that
variable can occur after the point of capture.

We'll follow up with one of those. For now... be careful out there.

Since we're promoting this to an error, narrow it down to concurrent
closures and local functions, dropping the assumption that escaping
closures "may execute concurrently."
2021-01-29 14:27:24 -08:00
Doug Gregor
99f8d7a5e8 [SIL] Add @concurrent function types to SIL
Add @concurrent to SIL function types, mirroring what's available on
AST function types. @concurrent function types will have by-value
capture semantics.
2021-01-29 11:16:17 -08:00
Doug Gregor
1f1f703afe Drop @concurrent from parameter to @asyncHandler entry point.
The async handler code doesn't really run concurrently with where it is
launched, despite the implementation currently using `runDetached`
internally. Drop the @concurrent and bitcase it back on when needed.
2021-01-29 09:53:22 -08:00
Doug Gregor
f4c5a267b7 @concurrent functions are actor-independent
Concurrent functions need to be actor-independent because they wouldn't
ever be safe to run concurrently while isolated on an actor. This
allows us to elimate the "may execute concurrently with" check related
to actor isolation, which is a cleaner overall story.
2021-01-28 22:07:54 -08:00
Doug Gregor
8eae527ca6 Tighten up actor isolation checking for closures and local functions.
Make sure that we check the isolation of the context in which a reference
to `self` is made, rather than the context in which `self` is declared,
when checking whether we are within actor-isolated code. This ensures
that we report errors as actor-isolation errors rather than falling
back to the "may execute concurrently with" checking.
2021-01-28 21:56:07 -08:00
Doug Gregor
1d082e1fb4 Require that concurrently-executed local functions be @concurrent. 2021-01-28 13:03:13 -08:00
Doug Gregor
75f4fb1823 Mark async let closures as @concurrent.
This ensures that they enable concurrency-related checks.
2021-01-28 12:30:18 -08:00
Doug Gregor
9efb44fde8 Adopt @concurrent in Task APIs 2021-01-28 10:03:09 -08:00
Doug Gregor
6d086d4d9c Add support for @concurrent on function declarations 2021-01-28 00:50:40 -08:00
Doug Gregor
5129d82c5b Add more tests for @concurrent function types 2021-01-27 21:05:50 -08:00
Doug Gregor
99040262ba [Concurrency] Teach data race & isolation checking about @concurrent functions.
@concurrent functions are, of course, concurrent. Treat them that way.
2021-01-27 16:30:07 -08:00
Doug Gregor
b77ba9a77f [Concurrency] Infer @concurrent on closures from contextual type 2021-01-27 16:00:39 -08:00
Doug Gregor
ba8819eb58 [Concurrent] Introduce concurrent function types.
Introduce `@concurrent` attribute on function types, including:
* Parsing as a type attribute
* (De-/re-/)mangling for concurrent function types
* Implicit conversion from @concurrent to non-@concurrent
- (De-)serialization for concurrent function types
- AST printing and dumping support
2021-01-27 14:22:32 -08:00
Saleem Abdulrasool
ae7e1b5ee2 Merge pull request #35599 from eeckstein/fix-llt-checker
SIL: support dealloc_ref and dealloc_partial_ref in LoadBorrowImmutabilityChecker
2021-01-26 11:48:13 -08:00
Doug Gregor
dba2726ba3 Merge pull request #35593 from DougGregor/objc-async-conformance-verify
[AST Verifier] Handle ObjC requirements satisfied by alternative requirements
2021-01-26 08:48:11 -08:00
Erik Eckstein
4cd3171f35 SIL: support dealloc_ref and dealloc_partial_ref in LoadBorrowImmutabilityChecker
It fixes a verifier crash.

Thanks to @compnerd, who found this by experiment.
2021-01-26 17:47:10 +01:00
swift-ci
fb70ab4279 Merge pull request #35598 from davezarzycki/pr35598 2021-01-26 06:04:07 -08:00
Arnold Schwaighofer
b0d31730de Merge pull request #35303 from aschwaighofer/introduce_swiftasync_lowering
Add llvm::Attribute::SwiftAsync to the context parameter
2021-01-26 06:03:19 -08:00
David Zarzycki
05a8cbe047 [testing] Add missing REQUIRES 2021-01-26 06:42:14 -05: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
Doug Gregor
83e8588977 [AST Verifier] Handle ObjC requirements satisfied by alternative requirements.
With 'async' imports of Objective-C protocol requirements, a single
Objective-C method will produce two different requirements in the
protocol, with the same Objective-C selector. Teach the AST verifier
that it is sufficient for just one of the requirements with that
Objective-C selector to be satisfied by a witness.

Fixes rdar://72742910.
2021-01-25 15:20:29 -08:00
Rintaro Ishizaki
ba23002716 Merge pull request #35567 from rintaro/parse-rdar73159041
[Parse] Diagnose default argument for subscript in protocols
2021-01-25 13:11:49 -08:00
Saleem Abdulrasool
0f47bd3e19 Merge pull request #35562 from rmaz/concurrency_fixes
[Testing] Add missing REQUIRES: concurrency
2021-01-24 20:03:22 -08:00
Robert Widmann
c2163703fd Merge pull request #35465 from mininny/objc-override-hash-warning
[Diagnostics] Add specific warning for overriden `NSObject.hash(into:)`
2021-01-24 14:37:03 -08:00
Michael Gottesman
329f03d675 Merge pull request #35558 from gottesmm/pr-8546814ec14114ba6e9d76c03a8ab15aabc4ad2b
[sil-optimizer] Compile in SIL verifiers when NDEBUG is enabled and enable them only when -sil-verify-all is enabled.
2021-01-24 10:27:32 -08:00
Michael Gottesman
eb641f039d [sil-optimizer] Compile in SIL verifiers when NDEBUG is enabled and enable them only when -sil-verify-all is enabled. 2021-01-23 21:04:27 -08:00
Rintaro Ishizaki
8a58107123 [Parse] Diagnose default argument for subscript in protocols
Protocol requirements don't support default arguments. Although this is
a "semantic" diagnostics, we currently do this for 'func' and 'init' in
Parser. So for fixing a crash, let's to it for 'subscript' in Parser
too.

rdar://problem/73159041
2021-01-22 17:21:17 -08:00
Konrad `ktoso` Malawski
80ee936a72 Revert "[Concurrency] isCanceled spelling to follow guidance" 2021-01-23 07:27:34 +09:00
Richard Howell
6b6e5b84a6 [Testing] Add missing REQUIRES: concurrency 2021-01-22 14:16:15 -08:00
Arnold Schwaighofer
12e6ec1daf Fix one more test 2021-01-22 10:52:34 -08:00
Rintaro Ishizaki
a69bf4e509 [Tests] Fix a test failing in simulator target (#35555)
rdar://problem/73501226
2021-01-22 12:14:56 -06:00
Arnold Schwaighofer
daa72d3cc5 Add llvm::Attribute::SwiftAsync to the context parameter
* Adds support for generating code that uses swiftasync parameter lowering.

* Currently only arm64's llvm lowering supports the swift_async_context_addr intrinsic.

* Add arm64e pointer signing of updated swift_async_context_addr.

This commit needs the PR llvm-project#2291.

* [runtime] unittests should use just-built compiler if the runtime did

This will start to matter with the introduction of usage of swiftasync parameters which only very recent compilers support.

rdar://71499498
2021-01-22 10:01:55 -08:00
Minhyuk Kim
5c21cdf4a6 Modify override_decl_extension error to be more descriptive 2021-01-23 01:04:40 +09:00
Konrad `ktoso` Malawski
45ce10a4f1 Merge pull request #35549 from ktoso/wip-task-canceled-spelling
[Concurrency] isCanceled spelling to follow guidance
2021-01-22 19:18:41 +09:00
Robert Widmann
a89c882bdb Merge pull request #35269 from CodaFi/hash-brown
Replace llvm::MD5 with SipHash-2-4
2021-01-21 21:00:56 -08:00
Meghana Gupta
8d7ac53290 Merge pull request #35545 from meg-gupta/looprotateossa
Enable LoopRotate on OSSA
2021-01-21 19:55:01 -08:00
Konrad `ktoso` Malawski
8b37455774 [Concurrency] isCanceled spelling to follow guidance 2021-01-22 12:09:19 +09:00
Robert Widmann
73ac8d3531 Replace llvm::MD5 with StableHasher 2021-01-21 17:19:38 -08:00
Rintaro Ishizaki
b3bbf0c070 Merge pull request #35544 from rintaro/astprinter-async-rdar73426591
[ASTPrinter] Print 'async' as a keyword
2021-01-21 16:59:10 -08:00
Meghana Gupta
6c32cac98e Enable LoopRotate on OSSA 2021-01-21 16:27:51 -08:00
swift-ci
9ef7b2ac3c Merge pull request #35530 from meg-gupta/dceossapr 2021-01-21 14:29:26 -08:00
Rintaro Ishizaki
969ca0c1b2 [ASTPrinter] Print 'async' as a keyword
rdar://problem/73426591
2021-01-21 14:10:06 -08:00
Andrew Trick
47a4ad267d Merge pull request #35531 from atrick/ossa-enforcementopts
Enable AccessEnforcementOpts with OSSA
2021-01-21 11:27:12 -08:00
Meghana Gupta
f2760bbea3 Enable DCE on OSSA 2021-01-21 11:12:00 -08:00
Arnold Schwaighofer
f9a25bac7a Merge pull request #35516 from aschwaighofer/constant_fold_availability
Constant fold known availability checks
2021-01-21 09:30:50 -08:00
Minhyuk Kim
f138ce0b19 Add specific warning for overriden NSObject.hash(into:) 2021-01-21 23:23:00 +09:00
swift-ci
13ffb8b181 Merge pull request #35534 from meg-gupta/loopunrolltest 2021-01-21 01:50:33 -08:00
scentini
0b3990c141 [cxx-interop] Generate IR for decls called from members (#35056)
Currently the following code doesn't work when `callConstructor()` is called from Swift:
```cc
inline int increment(int value) {
  return value + 1;
}

struct Incrementor {
  int incrementee;
  Incrementor(int value) : incrementee(increment(value)) {}
}

int callConstructor(int value) {
  return Incrementor(value).incrementee;
}
```

The issue is that we don't generate `IR` for the `increment()` function when it's only called from a constructor or a method.
Swift is aware of the existence of `increment()` and we see it in `IR` as `declare incrementEi`, however, as we don't to emit a definition, we get the following error:
```
Incrementor::Incrementor(int): error: undefined reference to 'increment(int)'
```

This PR fixes this by visiting constructors and methods in `IRGen` and calling `HandleTopLevelDecl()` with all used declarations, which results in emitting definitions for the used declarations.

Co-authored-by: Marcel Hlopko <hlopko@google.com>
2021-01-21 10:16:25 +01:00
Egor Zhdan
daa134f9d6 Merge pull request #35427 from egorzhdan/sk-self-imports
SourceKit: avoid self-imports in generated Swift interfaces
2021-01-21 12:11:21 +03:00
Meghana Gupta
3b60184f53 "[NFC] Add tests for LoopUnroll on OSSA""
Reland #35423
2021-01-20 22:26:18 -08:00