Commit Graph

534 Commits

Author SHA1 Message Date
Doug Gregor
220e29d674 Reinstate "async let", with "spawn let" as an alias. 2021-05-07 00:13:56 -07:00
Doug Gregor
06dc77ddf3 Revert "[Concurrency] Resyntax 'async let' as 'spawn let'."
This reverts commit 41f42fabbf.
2021-05-06 22:18:36 -07:00
Kavon Farvardin
e17e09c294 Enable effectful properties (SE-310) by default.
1. Removes gating on -enable-experimental-concurrency.
2. Updates eff. prop tests to remove experimental flag,
   and also adjusts some tests slightly to avoid things
   that are still behind that flag.
2021-05-03 14:10:44 -07:00
Doug Gregor
1fa2d1656d [Concurrency] Don't complain about interpolation variables being mutated.
Implicitly-generated interpolation variables are mutated within the
autoclosures created by a `spawn let`. Don't complain about them being
concurrently accessed, because they aren't.

Fixes rdar://76020473.
2021-04-29 23:32:56 -07:00
Doug Gregor
41f42fabbf [Concurrency] Resyntax 'async let' as 'spawn let'.
This helps track the proposal.
2021-04-29 23:28:16 -07:00
Evan Wilde
3da0a540eb Update tests
This patch updates all the tests to accept the new error messages.
*Gack* so many things needed cleaning up.
2021-04-24 07:51:18 -07:00
Strieker
4e2b67cbae [NFC] Resolved merge conflict in CSSimplify.cpp after making changes to improve error handling for composed wrapped value mismatches 2021-04-22 11:49:21 -07:00
Strieker
b732319538 [NFC] Fixed and added property wrapper tests. 2021-04-22 11:31:41 -07:00
Doug Gregor
f8cb209c5a Only diagnose references to globals under -warn-concurrency.
Fixes rdar://75996222.
2021-04-02 00:06:48 -07:00
Holly Borla
71cd85c42b Merge pull request #36611 from hborla/property-wrapper-csgen-crash
[ConstraintSystem] Fix a property wrapper constraint generation crash.
2021-03-29 10:58:16 -07:00
David Zarzycki
8a0d68bbae [testing] Add missing REQUIRES: concurrency 2021-03-27 06:10:28 -04:00
Holly Borla
d23246568c [ConstraintSystem] Fix a property wrapper constraint generation crash. 2021-03-26 15:36:34 -07:00
Kavon Farvardin
7585f46085 [test] coverage for global effectful props 2021-03-26 07:58:28 -07:00
Kavon Farvardin
e94344593c [test] effectful properties + property wrappers
They're currently incompatible, but it should be
possible to enable this, with some care taken to
ensure that effectful wrappers are composed
correctly.
2021-03-26 07:58:28 -07:00
Slava Pestov
ed247a1fa1 Sema: Allow 'lazy' local variables 2021-02-06 08:56:38 -05:00
Slava Pestov
b053eae8fb Sema: Tweak assertion in CustomAttrTypeRequest to allow generic typealiases
If the typealias here is generic, we return an UnboundGenericType
where getAnyNominal() returns nullptr. This would fail by returning
an ErrorType to the caller without diagnosing anything.

This was a regression after some recent refactoring to remove code
duplication and some TypeLoc usages, because one of the copies of
this code did not have this check, so it happened to work for
property wrappers.

Relax the check by looking through a TypeAliasDecl explicitly.
I believe we can't end up here anyway, because if the type was
not a nominal we would fail earlier in CustomAttrNominalRequest, and
we wouldn't attempt to compute the type of the property wrapper at
all. However it's better to keep the assertion in place just in case.

Fixes https://bugs.swift.org/browse/SR-14143 / rdar://problem/73888684.
2021-02-02 23:10:38 -05:00
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
Pavel Yaskevich
ec31d77fa6 [Diagnostics] Allow integer cast fix-its for assignment mismatches 2020-12-11 20:49:54 -08:00
Doug Gregor
dd7ce8015d [Concurrency] Reject top-level asynchronous code for now.
We haven't implemented any support for top-level async code yet, so
reject it in effects checking rather than crashing in the SIL verifier.
Fixes rdar://71512818.
2020-12-03 22:28:58 -08:00
Slava Pestov
5808d9beb9 Parse: Remove parse-time name lookup 2020-11-16 22:39:44 -05:00
Robert Widmann
6b3872d7c6 Spruce Up Static/Class Diagnostics
Mention the let/var character of the property in addition to its static
spelling kind. Then drop the reference to "specifier". As icing on top,
offer to insert an initializer after any binding patterns.

rdar://19827674
2020-11-10 15:14:27 -08:00
Slava Pestov
7b00d52e18 Merge pull request #34571 from slavapestov/fix-astscope-assert
ASTScope: Fix assertion with pattern bindings that don't introduce any variables
2020-11-05 17:22:37 -05:00
Doug Gregor
290f9a5626 [Concurrency] Add an async let example with multiple initializer clauses 2020-11-05 00:09:26 -08:00
Doug Gregor
58b590aa3d [Concurrency] Wrap the initializer of 'async let' in an autoclosure call.
The initializer of an 'async let' is executed as a separate child task
that will run concurrently with the main body of the function. Model
the semantics of this operation by wrapping the initializer in an
async, escaping autoclosure (representing the evaluation of the child
task), and then a call to that autoclosure (to

This is useful both for actor isolation checking, which needs to treat
the initializer as executing in concurrent code, and also (eventually)
for code generation, which needs to have that code in a closure so
that it can be passed off to the task-creation functions.

There are a number of issues with this implementation producing
extraneous diagnostics due to this closure transformation, which will
be addressed in a follow-up commit.
2020-11-04 17:32:04 -08:00
Doug Gregor
9722df86e8 [Concurrency] Require references to 'async let' to have an 'await'.
Extend effects checking to ensure that each reference to a variable
bound by an 'async let' is covered by an "await" expression and occurs
in a suitable context.
2020-11-04 17:32:04 -08:00
Doug Gregor
7f738778b8 [Concurrency] Parse 'async let' declarations.
Perform very basic semantic analysis for their well-formedness.
2020-11-04 17:31:31 -08:00
Slava Pestov
6599bef24a ASTScope: Fix assertion with pattern bindings that don't introduce any variables
We would get confused if we saw a PatternBindingDecl where
one entry introduced a binding, and the other did not.

Thanks to @DougGregor for the test case!
2020-11-04 03:12:38 -05:00
Doug Gregor
6d41524fe6 [SE-0289] Finish renaming source code, tests to "result builders" 2020-10-20 22:18:51 -07:00
Doug Gregor
0d568a93d4 [SE-0289] Update diagnostics & many other strings to "result builders" 2020-10-20 21:44:09 -07:00
Doug Gregor
6a40a3a8aa [SE-0289] Add support for @resultBuilder.
"Function builders" are being renamed to "result builders". Add the
corresponding `@resultBuilder` attribute, with `@_functionBuilder` as
an alias for it, Update test cases to use @resultBuilder.
2020-10-20 13:24:51 -07:00
Slava Pestov
bd36100cb3 Update tests in preparation for disabling parser lookup
I created a second copy of each test where the output changes
after disabling parser lookup. The primary copy now explicitly
calls the frontend with -disable-parser-lookup and expects the
new diagnostics; the *_parser_lookup.swift version calls the
frontend with -enable-parser-lookup and has the old expectations.

This allows us to turn parser lookup on and off by default
without disturbing tests. Once parser lookup is completely
removed we can remove the *_parser_lookup.swift variants.
2020-10-03 09:37:55 -04:00
Slava Pestov
4f1ab9d8e5 ASTScope: Directly calculate end location of GuardStmtScope and PatternEntryDeclScope
Today, the reported source range of a GuardStmtScope is just that of
the statement itself, ending after the 'else' block. Similarly, a
PatternEntryDeclScope ends immediately after the initializer
expression.

Since these scopes introduce names until the end of the parent
BraceStmt (meaning they change the insertion point), we were
relying on the addition of child scopes to extend the source
range.

While we still need the hack for extending source ranges to deal
with string interpolation, at least in the other cases we can
get rid of it.

Note that this fixes a bug where a GuardStmtScope would end
before an inactive '#if' block if the inactive '#if' block was
the last element of a BraceStmt.
2020-10-02 23:49:59 -04:00
Holly Borla
355fbb3a8b Merge pull request #34109 from hborla/local-property-wrappers
[Property Wrappers] Support local property wrappers
2020-10-01 22:45:41 -07:00
Holly Borla
af71c5dfbd [Property Wrappers] Ban non-member property wrappers with observers,
just like we do for regular non-member properties.
2020-10-01 19:34:43 -07:00
Holly Borla
d8df6217d3 [Property Wrappers] Allow property wrappers on local variables. 2020-09-28 18:43:13 -07:00
Slava Pestov
1a860cc99e Sema: Simplify adjustSelfTypeForMember() a little bit to avoid a cycle
We used to wrap the base expression in an InOutExpr when accessing a
computed property. This was a vestigial remnant of differences in the
SILGen code paths for stored vs computed property access.

These days SILGen doesn't care and is perfectly happy to call getters
and setters with an LValueType base as well.

This allows us to remove the call to getAccessSemantics(), which for
a 'didSet', had to kick off type checking of the body.

Fixes <rdar://problem/69532933>.
2020-09-26 00:02:42 -04:00
Slava Pestov
641469e5b3 Sema: Don't consider if 'didSet' references 'oldValue' when computing if setter is mutable
Previously this would depend on whether the 'didSet' referenced
'oldValue'. This introduces a request cycle once parse-time name
lookup is disabled, and was also an ABI break from Swift 5.2.

See https://forums.swift.org/t/clarify-behavior-of-se-0268-with-a-mutating-getter/40324.
2020-09-15 22:03:58 -04: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
Frederick Kellison-Linn
b82c57a800 [Sema] Require function builders to have at least one buildBlock method
If the supplied method is not static, offer a fix-it to make it static
2020-09-05 01:46:42 -04:00
Slava Pestov
6d84c18ba4 Sema: Check 'where' clause requirements on type witnesses
In the included test case, conformance checking of Wrapper : B would
pick up typealias Foo as a witness for the associated type B.Foo.

However, this typealias Foo is defined in a constrained extension where
T : A, and the underlying type references the associated type A.Foo
on T.

The resulting substitution is invalid when the conformance Wrapper : B
is used in a context where T does not conform to A.

Instead, we should ignore this typealias entirely, since it appears
in an unusable constrained extension.

Fixes <rdar://problem/60219705>, <https://bugs.swift.org/browse/SR-12327>,
<https://bugs.swift.org/browse/SR-12663>.
2020-08-15 01:43:13 -04:00
Suyash Srijan
d3b5996b05 [Sema] Diagnose explicit access to a lazy variable's underlying storage (#33144) 2020-07-28 19:12:53 +01:00
Suyash Srijan
db53fc7eb8 [Sema] Diagnose wrapped property if its projected value property conflicts with lazy variable storage property (#33152) 2020-07-28 15:39:49 +01:00
Hamish Knight
da998bae6d Merge pull request #33037 from hamishknight/to-no-avail 2020-07-22 12:19:06 -07:00
Holly Borla
bd03c47506 Merge pull request #33025 from hborla/repair-via-unwrap-typevar
[Property Wrappers] Fix property wrapper initialization type checking when `wrappedValue` is an optional of a generic parameter.
2020-07-22 11:54:17 -07:00
Hamish Knight
be607d15b3 [CS] Introduce performSyntacticDiagnosticsForTarget
Add a function that deals with invoking syntactic
diagnostics for all the expressions involved in
a SolutionApplicationTarget.

Resolves SR-13260
Resolves rdar://65903005
2020-07-21 15:51:07 -07:00
Holly Borla
3b917729dc [Property Wrappers] Always anchor the equality constraint between
the property type and wrapped value type at the wrapped VarDecl.
2020-07-21 15:23:24 -07:00
Robert Widmann
8a7a1d98f5 Teach the VarDeclUsageChecker About Variables Bound in Patterns
The VDUC was missing a class of AST nodes that can bind variables:
patterns in switch statements. For these, it was falling back to
requesting a simple replacement of the bound variable name with _. But
for patterns, this means there's a two-step dance the user has to go
through where the first fixit does this:

.pattern(let x) -> .pattern(let _)

Then a second round of compilation would emit a fixit to do this:

.pattern(let _) -> .pattern(_)

Instead, detect "simple" variable bindings - for now, variable patterns
that are immediately preceded by a `let` or `var` binding pattern - and
collapse two steps into one.

Resolves rdar://47240768
2020-07-21 12:33:14 -07:00
Holly Borla
7dffff79da [Property Wrappers] Let PropertyWrapperBackingPropertyTypeRequest
handle all errors with a property wrapper backing type.
2020-07-02 14:47:45 -07:00
Holly Borla
f555bfefc9 [Property Wrappers] Add new contextual type purposes for property wrappers
to produce better diagnostics when there's a 'wrappedValue' type mismatch.
2020-07-02 14:47:45 -07:00
Holly Borla
238637408c [Property Wrappers] Type check out-of-line initialized property wrappers
via SolutionApplicationTarget. This allows fixes to be applied and diagnosed
for better error messages in the case of failures, and removes code
duplication for generating property wrapper constraints.
2020-07-02 14:47:45 -07:00