Commit Graph

214 Commits

Author SHA1 Message Date
Pavel Yaskevich
65126b7dac [ResultBuilders] Make sure that case body variables get types
Solution application needs to set interface types for variables
declared in a `case` statement, otherwise this would lead to crashes
in SILGen.
2021-10-04 13:12:59 -07:00
Pavel Yaskevich
55b0373caa [BuilderTransform] NFC: Print out a function to which builder is being applied 2021-09-22 12:28:20 -07:00
Hamish Knight
47754822c7 [CodeSynthesis] Adopt ArgumentList
Most of this should be fairly mechanical, the
changes in PlaygroundTransform are a little more
involved though.
2021-09-01 18:40:26 +01:00
Pavel Yaskevich
1509accca2 [ConstraintSystem] Open only directly declared opaque types related to return statements (#38762)
* [ConstraintSystem] NFC: Rename `openOpaqueTypeRec` and make `openOpaqueType` private for individual types

* [ConstraintSystem] Require a contextual purpose for `openOpaqueType(Type, ...)`

Some of the contexts require special handling e.g. return type of a function
can only open directly declared opaque result type(s), this would be
implemented in a follow-up commit.

* [ConstraintSystem] Open only directly declared opaque types related to return statements

Re-establish a check which would only open opaque types directly
declared in the return type of a function/accessor declaration,
otherwise constraint system would end up with type variables it
has no context for if the type had generic parameters.

Resolves: rdar://81531010
2021-08-05 20:45:46 -04:00
willtunnels
319b3e64aa Add support for opaque result types in structural positions (#38392)
* [TypeResolver][TypeChecker] Add support for structural opaque result types

* [TypeResolver][TypeChecker] Clean up changes that add structural opaque result types
2021-08-03 23:45:02 -04:00
Hamish Knight
f69ca410fa [CS] Better handle null in BuilderClosureRewriter
There were a couple of places where we weren't
handling a nullptr return from one of the visitor
methods. Change the methods to return NullablePtr
and add the missing null checks.

rdar://81228221
2021-07-30 18:08:11 +01:00
Bruno Rocha
adfb983e2b [SE-0290] Cleanup BuilderTransform for #unavailable 2021-07-02 13:35:12 +02:00
Bruno Rocha
1fe3857735 [SE-0290] Add #unavailable 2021-07-02 13:35:11 +02:00
Pavel Yaskevich
ccc0c8b6e3 Merge pull request #38177 from xedin/rdar-79746785
[ResultBuilders] Allow pre-check to look into single-statement closures
2021-07-01 09:40:22 -07:00
Pavel Yaskevich
3374500da8 [ResultBuilders] Allow pre-check to look into single-statement closures
While determining whether result builder body is correct, allow
pre-check phase to look into single-statement closures because
their bodies participate in type-check and would fail constraint
generation if they contain `ErrorExpr`s, so it's better to determine
that the body is invalid early and skip result builder application.

Resolves: rdar://79746785
2021-06-30 11:49:27 -07:00
Pavel Yaskevich
c2767d2b14 [BuilderTransform] Remove unused skipPrecheck from PreCheckResultBuilderRequest::evaluate 2021-06-29 16:21:57 -07:00
Becca Royal-Gordon
769ea4aa78 Share diagnoseAndRemoveAttr()
Merge together several helpers and code patterns for “diagnose/fix-it/invalidate bad attribute” into helper functions in TypeChecker.h.

This requires minor test changes in some places where we’re testing ObjC interop without importing Foundation; it’s otherwise NFC.
2021-05-21 16:10:11 -07:00
Pavel Yaskevich
4b0d9a2509 [ResultBuilders] Diagnose pre-check errors inline
Not all of the pre-check errors could be diagnosed by re-running
`PreCheckExpression` e.g. key path expressions are mutated to
a particular form after an error has been produced.

To make the behavior consistent, let's allow pre-check to emit
diagnostics and unify pre-check and constraint generation fixes.

Resolves: rdar://77466241
2021-05-10 11:06:58 -07:00
Pavel Yaskevich
51ff12d06e [ConstraintLocator] Augment ContextualType element to carry its purpose
Having purpose attached to the contextual type element makes it much
easier to diagnose contextual mismatches without involving constraint
system state.
2021-04-26 09:51:21 -07:00
Pavel Yaskevich
22a231e4d8 [Diagnostics] Allow result build to detect ErrorExprs in the body
We assume that presence of `ErrorExpr` means that the problem has
been diagnosed early (i.e. by parser), so the fix is going to return
`true` if diagnostic engine has emitted an error.

Resolves: rdar://76246526
2021-04-09 16:42:59 -07:00
Nathan Hawes
c4b0983a81 [Sema][CodeCompletion] Allow empty case statement bodies in the result builder transform...
..when typechecking for code completion.

They were disallowed to give better diagnostics, but code completion suppresses
diagnostics and can't provide any completions at all when the transform fails as
it doesn't get any types.

Resolves rdar://problem/74028722
2021-02-17 16:09:52 +10:00
Slava Pestov
671472362a Sema: Reject invalid attributes on local variables in result builders
Fixes <rdar://problem/73545981>.
2021-02-06 23:37:51 -05:00
Slava Pestov
c0ca9ad3ea Sema: Reject non-stored local variables in result builders
We would previously reject properties without an initializer expression,
but this is not quite sufficient, because of 'lazy', property wrappers,
and observers.

We could probably support all three in result builder contexts, but
for now, let's diagnose them like other computed properties, instead of
crashing.

Fixes part of <rdar://problem/73545981>.
2021-02-06 23:37:51 -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
Pavel Yaskevich
d912e12ba7 [ResultBuilders] Use new fix to detect and diagnose use of return statements in a result builder body 2020-11-19 17:21:00 -08:00
Pavel Yaskevich
057e836c13 [ResultBuilders] Split diagnostic about return statements into error and warning versions 2020-11-19 17:21:00 -08:00
Pavel Yaskevich
1d3f3204ca [ResultBuilders] Account of a fact that re-write of a statement can fail
If one of the statements in the result builder body fails to
apply solution, let's fail entire rewrite attempt, otherwise
type-checker would end up with AST that has null pointers for
some child nodes.

Resolves: rdar://problem/70256351
2020-11-05 16:29:58 -08:00
Slava Pestov
d5ee1da9bb Sema: Put the AvailabilityContext inside the ExportContext 2020-10-28 23:55:17 -04:00
Pavel Yaskevich
1683fb91b6 [ConstraintSystem] Remove RValueAdjustment locator element
It was used for unresolved member and `.dynamicType` references
as well as a couple of other places, but now unresolved member
references no longer need that due to new implicit "chain result"
AST node and other places could use more precise locators
e.g. new `.dynamicType` locator or `sequence element` for `for in`
loops.
2020-10-26 00:40:45 -07: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
Pavel Yaskevich
461eafff54 [ConstraintSystem] NFC: Move ConstraintSystem.h to include/swift/Sema 2020-10-08 10:45:47 -07:00
Pavel Yaskevich
767c1a0ed6 [ConstraintSystem] NFC: Move SolutionResult.h to include/swift/Sema 2020-10-08 10:42:08 -07:00
Doug Gregor
f07c7d15fe [Type checker] Eliminate a use-after-free due to C++ temporaries.
Found by Brent using ASan, thank you!
2020-09-25 11:17:19 -07:00
Slava Pestov
51a4a91a13 Sema: Mark a PatternBindingDecl as implicit in the builder transform 2020-09-22 00:16:54 -04:00
Slava Pestov
d7f4b1a1bd AST: Capture list bindings now point back to their parent CaptureListExpr
We'll need this to get the right 'selfDC' when name lookup
finds a 'self' declaration in a capture list, eg

class C {
  func bar() {}
  func foo() {
    _ = { [self] in bar() }
  }
}
2020-09-18 02:59:15 -04:00
Doug Gregor
3b8656dc6f [Function builders] Add stubs for missing buildBlock and buildLimitedAvailability
The lack of these functions in a function builder is diagnosed in
different places in the type checker. Extend these diagnostics to
provide stubs in the function builder.

Thanks to Suyash for the suggestion!
2020-09-16 16:31:03 -07:00
Doug Gregor
23b6b409ce [Code completion] Fix incorrect addition of '{' in function builder results.
Noticed by Rintaro, thank you!
2020-09-16 14:18:22 -07:00
Doug Gregor
20ab640e56 [Function builders] Add code completion for build* functions.
When performing code completion inside the declaration of a type with
the function builder attribute, also include completions for all of
the possible "build" functions.
2020-09-16 11:55:09 -07: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
Pavel Yaskevich
dadf2b47cc [ConstraintSystem] Track invalid function builder bodies to avoid duplicate diagnostics 2020-09-02 11:15:40 -07:00
Pavel Yaskevich
c17bdaf715 [AST] Adjust Diagnostic transaction to only track pending errors 2020-09-01 13:57:03 -07:00
Pavel Yaskevich
1bfb0b0747 [ConstraintSystem] Extend invalid function body fix to cover constraint generation failures
Ignore function builder body if it emits at least one diagnostic
during constraint generation.

Resolves: rdar://problem/65983237
2020-09-01 12:23:50 -07:00
swift-ci
7daed3cf08 Merge pull request #33570 from DougGregor/function-builders-throw 2020-08-20 17:16:27 -07:00
swift-ci
316475c4ff Merge pull request #33564 from DougGregor/function-builders-remove-build-do 2020-08-20 14:13:54 -07:00
Doug Gregor
d46c4ec5c5 [Function builders] Add support for 'throw' statement. 2020-08-20 12:11:45 -07:00
Doug Gregor
9ffddc9ba6 [Function builders] Remove buildDo.
"do" blocks will always go through buildBlock().
2020-08-20 11:31:07 -07:00
Pavel Yaskevich
a12ac414a1 Merge pull request #33509 from xedin/rdar-65320500
[FunctionBuilders] Implement graceful handling of pre-check failures
2020-08-18 00:58:15 -07:00
Doug Gregor
9ef0fce7b0 [Function builders] Allow build functions to be declared elsewhere.
Make the lookup of the various `build` functions for function builders
normal, qualified name lookup. This allows (e.g.) the implementation
of many of the 'build' functions to come from a protocol extension,
making function builders more composable. Thank you to @anreitersimon
on the Swift forums for the example!
2020-08-17 15:41:33 -07:00
Pavel Yaskevich
56ef379fb8 [ConstraintSystem] Integrate IgnoreInvalidFunctionBuilderBody into the solver 2020-08-17 12:39:29 -07:00
Pavel Yaskevich
b2982fa0e5 [TypeChecker] Add a flag PreCheckFunctionBuilderRequest to suppress diagnostics 2020-08-17 12:39:29 -07:00
Pavel Yaskevich
bc319779d5 [TypeChecker] Replace invalid refs with ErrorExpr only when explicitly allowed
Add a flag to `ConstraintSystem::preCheckExpression` and subsequently
to `TypeChecker::resolveDeclRefExpr` to indicate whether it's allowed
to replace invalid member refs with `ErrorExpr`.

It is useful for diagnostics and code completion to preserve AST
in it's original state otherwise it's impossible to diagnose errors
post factum or extract `CodeCompletionExpr` when it's a child of an
invalid reference.
2020-08-17 12:39:29 -07:00
Pavel Yaskevich
fddfd6d782 [BuilderTransform] Suppress diagnostics produced by preCheckExpression 2020-08-17 12:37:17 -07:00
Pavel Yaskevich
9b33ffa828 Merge pull request #33272 from xedin/rdar-65254452
[Diagnostics] Do more checking before recording `force downcast` fix
2020-08-04 10:22:47 -07:00
Doug Gregor
f787e1bd3b [Statement checker] Simplify checkUnknownAttrRestrictions().
This routine can compute the fallthrough destination on its own. When
it does, we start correctly checking @unknown cases in function
builders, so update and expand the test accordingly.
2020-08-03 22:13:10 -07:00