Commit Graph

13545 Commits

Author SHA1 Message Date
Doug Gregor
3c38ffe0ea [Concurrency] await try -> try await
The `try await` ordering is both easier to read and indicates the order
of operations better, because the suspension point occurs first and
then one can observe a thrown error.
2020-12-23 13:21:59 -08:00
Kavon Farvardin
179474e185 Merge pull request #35153 from kavon/warn-unqualified-await
[concurrency] warn about future reservation of 'await' as contextual keyword
2020-12-23 09:20:18 -08:00
Kavon Farvardin
463003194e add warning that 'await' will become contextual keyword 2020-12-22 15:46:24 -08:00
Slava Pestov
161d832140 AST: Refactor request evaluator dependency tracking a bit
Other than simplifying some code, the big improvement here is
that we 'freeze' the reference dependencies for a request down
to a simple vector. We only use a DenseSet to store dependencies
of active requests.
2020-12-22 16:12:04 -05:00
Slava Pestov
f5e47ea5d2 AST: Add AnyRequest::isDependencySource() 2020-12-22 01:42:04 -05:00
Slava Pestov
d1a2a612b1 AST: Change some writeDependencySink() methods to take the result by const reference 2020-12-22 01:42:04 -05:00
Slava Pestov
b1f9c10d07 ASTScope: Small optimization to ASTScopeImpl memory layout
Combine the wasExpanded flag with the parent pointer, and remove
the haveAddedCleanup flag since it's no longer necessary now that
"re-expansion" is gone.
2020-12-18 15:43:33 -05:00
Slava Pestov
0fa84c14a0 ASTScope: Remove the ExpandASTScopeRequest
This doesn't really fit the request evaluator model since the
result of evaluating the request is the new insertion point,
but we don't have a way to get the insertion point of an
already-expanded scope.

Instead, let's change the callers of the now-removed
expandAndBeCurrentDetectingRecursion() to instead call
expandAndBeCurrent(), while checking first if the scope was
already expanded.

Also, set the expanded flag before calling expandSpecifically()
from inside expandAndBeCurrent(), to ensure that re-entrant
calls to expandAndBeCurrent() are flagged by the existing
assertion there.

Finally, replace a couple of existing counters, and the
now-gone request counter with a single ASTScopeExpansions
counter to track expansions.
2020-12-18 15:43:33 -05:00
Evan
d48393bd10 Merge pull request #35108 from etcwilde/ewilde/fixit-actor-protocol-conformance
[Concurrency] Emit fixit to add actorIndependent attribute
2020-12-18 08:59:00 -08:00
Evan Wilde
1d53d748d3 Cleanup actor protocol conformance error
This patch cleans up how we emit the errors for disallowing the
properties and methods of an actor to be applied to the protocol
conformance. Rather than having multiple error messages for each case,
we keep one error message saying that the actor-isolated
method/variable/what-have-you cannot be used to satisfy a protocol
requirement, then allow multiple notes with fix-its to allow the
programmer to choose what they want to do. The notes have a better
description of what each option does.
2020-12-17 16:12:41 -08:00
John McCall
fcb1864a89 Merge pull request #35116 from rjmccall/builtin-synthesis-1
[NFC] Switch a bunch of builtins over to use ASTSynthesis
2020-12-16 22:34:55 -05:00
Dan Liew
8e95189d24 Merge pull request #35074 from apple/dliew/rdar-69335186
Disable "UseOdrIndicator" ASan instrumentation mode by default.
2020-12-16 19:19:40 -08:00
Slava Pestov
bf23faa3ed Merge pull request #35112 from slavapestov/request-evaluator-caching-optimization
Hacks to avoid request evaluator caching overhead
2020-12-16 19:15:50 -05:00
John McCall
2422e0342c [NFC] Switch a bunch of builtins over to use ASTSynthesis 2020-12-16 17:12:01 -05:00
John McCall
d68d406dae Merge pull request #35094 from rjmccall/actor-dynamic-layout
Do dynamic layout of generic/resilient default actors properly
2020-12-16 01:05:00 -05:00
Slava Pestov
008a97ef4e AST: Convert IsAsyncHandlerRequest to use separate caching 2020-12-15 23:43:05 -05: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
Rintaro Ishizaki
4c38ec5a4a Merge pull request #35069 from rintaro/ide-completion-rdar72199413
[Parse/CodeCompletion] Implement effects specifier completion
2020-12-15 13:11:18 -08:00
Arnold Schwaighofer
b9407099fd Merge pull request #35060 from aschwaighofer/fix_prespec_import_perf_problem
Serialize decls with `_specialize(exported:true, target: somefunc(_:), ...)` in a list for fast lookup
2020-12-15 12:59:17 -08:00
eeckstein
7c78207407 Merge pull request #35082 from eeckstein/concurrency-ptrauth
[concurrency] IRGen:: do ptrauth for hop_to_executor
2020-12-15 21:32:54 +01:00
Dan Liew
9208b52de1 Disable "UseOdrIndicator" ASan instrumentation mode by default.
Previously Swift enabled the "UseOdrIndicator" ASan instrumentation mode
and gave no option to disable this. This probably wasn't intentional but
happened due to the fact the
`createModuleAddressSanitizerLegacyPassPass()` function has a default
value for the `UseOdrIndicator` parameter of `true` and in Swift we
never specified this parameter explicitly.

Clang disables the "UseOdrIndicator" mode by default but allows it to be
enabled using the `-fsanitize-address-use-odr-indicator` flag.
Having "UseOdrIndicator" off by default is probably the right
default choice because it bloats the binary. So this patch changes the
Swift compiler to match Clang's behavior.

This patch disables the "UseOdrIndicator" mode by default but adds a
hidden driver and frontend flag (`-sanitize-address-use-odr-indicator`)
to enable it. The flag is hidden so that we can remove it in the future
if needed.

A side effect  of disabling "UseOdrIndicator" is that by we will no
longer use private aliases for poisoning globals. Private aliases were
introduced to avoid crashes
(https://github.com/google/sanitizers/issues/398) due to ODR violations
with non-instrumented binaries. On Apple platforms the use of two-level
namespaces probably means that using private aliases wasn't ever really
necessary to avoid crashes. On platforms with a flat linking namespace
(e.g. Linux) using private aliases might matter more but should users
actually run into problems they can either:

* Fix their environment to remove the ODR, thus avoiding the crash.
* Instrument the previously non-instrumented code to avoid the crash.
* Use the new `-sanitize-address-use-odr-indicator` flag

rdar://problem/69335186
2020-12-15 11:09:30 -08:00
Evan
f3da35a75f Merge pull request #34688 from etcwilde/ewilde/disallow-passing-actor-state-inout
[Concurrency] Ban passing actor state via inout

Resolves: rdar://70635479
2020-12-15 10:59:42 -08:00
Erik Eckstein
e697e49582 [concurrency] IRGen:: do ptrauth for hop_to_executor
Sign the resume-function pointer which is stored in AsyncTask.ResumeTask
2020-12-15 15:23:20 +01:00
swift-ci
1eb810f566 Merge pull request #35048 from kavon/typechecking-unspecified-isolation-contexts-71548470 2020-12-14 17:43:15 -08:00
Evan Wilde
66d307e4af Improve implicit async error message
At the declaration, the implicitly async functions appear to be
synchronous, so it isn't clear why the error message is being emitted.
This patch updates the error message to indicate that the function is
implicitly asynchronous.
2020-12-14 17:13:33 -08:00
Rintaro Ishizaki
31595e3b2b [Parse] Adjust diagnostics message for duplicated effects specifiers 2020-12-14 14:58:30 -08:00
Evan Wilde
a09224d9c4 [Concurrency] Ban passing actor state via inout
Passing actor statte to async functions via inout parameters violates
automicity. This patch bans passing actor state via inout parameter to
async functions.

This removes the warning when passing a sub-property of a property of an
actor class and replaces it with an error message since passing actor
state inout is not allowed.
2020-12-14 14:56:49 -08:00
Richard Wei
8d8614058b [AudoDiff] NFC: Replace 'SILAutoDiffIndices' with 'AutoDiffConfig'. (#35079)
Resolve rdar://71678394 / SR-13889.
2020-12-14 14:32:40 -08:00
Rintaro Ishizaki
c72f9e5c92 [Parse] Adjust diagnostics for effects specifiers in closure signature 2020-12-14 12:43:50 -08:00
Rintaro Ishizaki
4284a51589 [Parse/CodeCompletion] Implement effects specifier completion
Rewrote and rename 'parseAsyncThrows' to 'parseEffectsSpecifiers'.
Implemented 'CodeCompletionCallbacks::completeEffectsSpecifier()'
2020-12-14 12:38:15 -08:00
Kavon Farvardin
e23f0abbe8 [concurrency] patch hole in typechecking ordinary functions for global actor references
Non-actor isolated synchronous functions were previously
allowed to call & reference global-actor isolated declarations.
This patch puts a stop to that.

Resolves rdar://71548470
2020-12-14 12:23:59 -08:00
Arnold Schwaighofer
2b6ba2830c Serialize decls with _specialize(exported:true, target: somefunc(_:), ...) in a list for fast lookup
rdar://71430641
2020-12-11 09:58:32 -08:00
martinboehme
f4e74f7907 When qualifying Clang types with a module, make sure we choose a visible module (#32465)
Clang types need special treatment because multiple Clang modules can contain the same type declarations from a textually included header, but not all of these modules may be visible.

This fixes
https://bugs.swift.org/browse/SR-13032

The newly added test breaks without this fix.
2020-12-11 08:15:05 +01:00
John McCall
1177cde4e3 Use current public Dispatch API to schedule global work.
We expect to iterate on this quite a bit, both publicly
and internally, but this is a fine starting-point.

I've renamed runAsync to runAsyncAndBlock to underline
very clearly what it does and why it's not long for this
world.  I've also had to give it a radically different
implementation in an effort to make it continue to work
given an actor implementation that is no longer just
running all work synchronously.

The major remaining bit of actor-scheduling work is to
make swift_task_enqueue actually do something sensible
based on the executor it's been given; currently it's
expecting a flag that IRGen simply doesn't know to set.
2020-12-10 19:18:53 -05:00
John McCall
b22407ef0c Add a builtin to convert a Task* to a Job*. 2020-12-10 17:06:14 -05:00
John McCall
10e0dfc1cf [NFC] Add a header library to simplify generating synthetic types
I'm going to use this in Builtins.cpp.
2020-12-10 17:06:14 -05:00
Joe Groff
291b75fcc4 Merge pull request #34953 from jckarter/async-native-to-foreign-thunk
[WIP] SILGen: Implement native-to-foreign thunks for async methods.
2020-12-09 17:00:36 -08:00
Joe Groff
5087e411c2 SILGen: Implement native-to-foreign thunks for async methods.
Bridging an async Swift method back to an ObjC completion-handler-based API requires
that the ObjC thunk spawn a task on which to execute the Swift async API and pass
its results back on to the completion handler.
2020-12-08 10:04:40 -08:00
eeckstein
daa85e18a9 Merge pull request #34986 from eeckstein/fix-generic-spec
GenericSpecializer: use an alternative mangling if the function has re-abstracted resilient type parameters.
2020-12-08 11:05:33 +01:00
nate-chandler
af8cf15e22 Merge pull request #34928 from nate-chandler/concurrency/irgen/ptrauth
[Async CC] Pointer authentication.
2020-12-07 08:28:48 -08:00
Erik Eckstein
9e43f493f3 GenericSpecializer: use an alternative mangling if the function has re-abstracted resilient type parameters.
If the specialized function has a re-abstracted (= converted from indirect to direct) resilient argument or return types, use an alternative mangling: "TB" instead of "Tg".
Resilient parameters/returns can be converted from indirect to direct if the specialization is created within the type's resilience domain, i.e. in its module (where the type is loadable).
In this case we need to generate a different mangled name for the specialized function to distinguish it from specializations in other modules, which cannot re-abstract this resilient type.

This fixes a miscompile resulting from ODR-linking specializations from different modules, which in fact have different function signatures.

https://bugs.swift.org/browse/SR-13900
rdar://71914016
2020-12-07 17:23:46 +01:00
Nate Chandler
d4be3e88e4 [PtrAuth] Adopt AsyncContextResume schema. 2020-12-04 16:36:36 -08:00
Doug Gregor
06a712bff6 Merge pull request #34957 from rjmccall/partial-async-task-is-a-job
Freeze PartialAsyncTask as a Job*
2020-12-04 15:43:44 -08:00
Doug Gregor
4957a5e8b4 Merge pull request #34969 from DougGregor/swift_get_jobflags
[Concurrency] Traffic in underlying C type rather than JobFlags.
2020-12-04 15:39:58 -08:00
Luciano Almeida
ab71104fa9 Merge pull request #34954 from LucianoPAlmeida/nfc-typo
[NFC][Sema] Fix init diagnostic typo
2020-12-04 08:54:57 -03:00
Doug Gregor
18ef1869f3 [Concurrency] Diagnose "try await" with a Fix-It 2020-12-04 00:57:18 -08:00
John McCall
ee0bb0a2d5 Freeze PartialAsyncTask as a Job*.
Also fix the extra inhabitants of Builtin.RawUnsafeContinuation
and try to make adding types like this a little less boiler-plate
in the future.
2020-12-04 01:06:29 -05:00
Doug Gregor
41f74e48d5 Merge pull request #34952 from DougGregor/convert-sync-to-async
[Concurrency] Allow synchronous functions to be a subtype of 'async' functions
2020-12-03 20:18:53 -08:00
Luciano Almeida
5423da20f0 [Sema] Fix init_not_instance_member_use_assignment diagnostic typo 2020-12-03 23:45:28 -03:00
Doug Gregor
ac9ee94dbe Merge pull request #34940 from DougGregor/async-nonasync-redecl-checking
[Concurrency] Disallow 'async' and non-async overloading.
2020-12-03 15:23:04 -08:00