Commit Graph

2410 Commits

Author SHA1 Message Date
Ben Barham
9de5afd92e Merge pull request #35846 from bnbarham/walk-pdb
[IDE] SourceEntityWalker should walk all explicit declarations
2021-02-12 07:41:13 +10:00
Ben Barham
33bc38cdb8 [IDE] SourceEntityWalker should walk all explicit declarations
`SourceEntityWalker` had an unbalanced `walkToDeclPre` and
`walkToDeclPost`, ie. `walkToDeclPost` could be called even though
`walkToDeclPre` was not. Specifically, this would occur for both
`OperatorDecl` and `PrecedenceGroupDecl` declarations.

These could both be added to the `if` in `walkToDeclPost`, but this
seems fairly errorprone in general - especially as new decls are added.
Indeed, there's already declarations that are being skipped because they
aren't explicitly tested for in `walkToDeclPre`, ie.
`PatternBindingDecl`.

Instead of skipping if not explcitly handled, only skip running the
`SEWalker` walk methods if the declaration is implicit (and not a
constructor decl, see TODO). This should probably also always visit
children, with various decls changed to become implicit (eg.
TopLevelCodeDecl), but we can do that later - breaks too many tests for
now.

This change exposed a few parameter declarations that were missing their
implicit flag, as well as unbalanced walk methods in `RangeResolver`.
2021-02-11 10:34:07 +10:00
Anthony Latsis
3d317938ad AST, Sema: Teach findProtocolSelfReferences that some stdlib collections preserve variance
* Swift.Array preserves variance in its 'Element' type
* Swift.Dictionary preserves variance in its 'Value' type
2021-02-11 03:22:20 +03:00
Luciano Almeida
d55eed46e8 [Sema][CSApply] Moving some checked cast diagnostics to a fix format (#34980)
* [Sema] Implementing is runtime check always true diagnostic as a fix

* [AST] Implement getWithoutThrows on function type

* [CSSimplify] Detect that checked cast types conversion is always true and record warning fix

* [test] Some additional test cases for SR-13789

* [Sema] Fixing typo on fix name

* [Sema] Move and adjust the ConditionalCast diagnostics to the fix format

* [Sema] Remove some checked cast diagnostics from check constraints and move to fix

* [Sema] Renaming checked cast coercible types fix

* [Sema] Some adjustments and rewrite on the logic for downcast record fix

* [Sema] Move logic of runtime function type to AllowUnsupportedRuntimeCheckedCast::attempt

* [Sema] Abstract checked cast fix logic to static function and minor adjustments

* [Sema] Renamings from review
2021-02-10 08:31:06 -03:00
Richard Wei
af8942d940 [AutoDiff] Rename '@differentiable' to '@differentiable(reverse)'.
Compiler:
- Add `Forward` and `Reverse` to `DifferentiabilityKind`.
- Expand `DifferentiabilityMask` in `ExtInfo` to 3 bits so that it now holds all 4 cases of `DifferentiabilityKind`.
- Parse `@differentiable(reverse)` and `@differentiable(_forward)` declaration attributes and type attributes.
- Emit a warning for `@differentiable` without `reverse`.
- Emit an error for `@differentiable(_forward)`.
- Rename `@differentiable(linear)` to `@differentiable(_linear)`.
- Make `@differentiable(reverse)` type lowering go through today's `@differentiable` code path. We will specialize it to reverse-mode in a follow-up patch.

ABI:
- Add `Forward` and `Reverse` to `FunctionMetadataDifferentiabilityKind`.
- Extend `TargetFunctionTypeFlags` by 1 bit to store the highest bit of differentiability kind (linear). Note that there is a 2-bit gap in `DifferentiabilityMask` which is reserved for `AsyncMask` and `ConcurrentMask`; `AsyncMask` is ABI-stable so we cannot change that.

_Differentiation module:
- Replace all occurrences of `@differentiable` with `@differentiable(reverse)`.
- Delete `_transpose(of:)`.

Resolves rdar://69980056.
2021-02-07 14:09:46 -08:00
zoecarver
02b5118199 [cxx-interop] Correctly import static function templates.
Handle static members the same way we handle other member function
templates. Also, set the "static"ness of the new (specialized) function decl.
2021-01-31 15:49:33 -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
b77ba9a77f [Concurrency] Infer @concurrent on closures from contextual type 2021-01-27 16:00:39 -08: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
Varun Gandhi
d9cd7e73cd Merge pull request #35457 from varungandhi-apple/vg-cleanup-rep-matching
[docs] Tidy and document permissible conversions based on calling conventions
2021-01-20 13:28:54 -08:00
Varun Gandhi
aac0a9a9ed [doc] Document function representation conversions inline. 2021-01-19 10:48:13 -08:00
Varun Gandhi
02c4ad3850 [SILGen] Branch on result of next() before conversion.
Fixes SR-8688 (rdar://problem/47162940).
2021-01-12 09:09:48 -08:00
Pavel Yaskevich
c3ff4d40b7 Merge pull request #35319 from xedin/remove-checked-conformances-cache
[ConstraintSystem] Remove used/checked conformances cache
2021-01-11 11:42:40 -08:00
Holly Borla
80a9df2bff Merge pull request #35218 from hborla/assign-by-wrapper-crash
[Property Wrappers] Fix a few corner cases where property wrappers with nonmutating setters fail in DI
2021-01-11 08:57:35 -08:00
Pavel Yaskevich
2a6f279b45 [ConstraintSystem] NFC: Remove obsolete used/checked conformances cache 2021-01-08 12:55:49 -08:00
Pavel Yaskevich
87cc597d19 [ConstraintSystem] Stop using CheckedConformances cache
It was necessary only for `applySolutionToForEachStmt` in `CSApply`,
diagnostic can avoid it and use information stored in the locator
instead.
2021-01-08 11:36:34 -08:00
Pavel Yaskevich
33f34d15f6 Merge pull request #35281 from xedin/rdar-72819046
[Diagnostics] Special case requirement failures related to `return` statement/expression
2021-01-07 08:56:15 -08:00
Pavel Yaskevich
4917d4314b [ConstraintSystem] Use new ConformanceRequirement to record checked conformances and conditional requirements 2021-01-06 11:01:35 -08:00
Holly Borla
e75b7ef08a [Property Wrappers] Clarify the description of property wrapper handling
in adjustSelfTypeForMember in CSApply.
2020-12-23 11:02:32 -05:00
Slava Pestov
e675bee26c AST: Split off DependencyCollector.h from EvaluatorDependencies.h
Also remove some unnecessary #includes from DependencyCollector.h,
which necessitated adding #includes in various other files.
2020-12-23 00:00:25 -05:00
Luciano Almeida
3189d5c8b8 [CSApply] Removing warning diagnostic that will be moved to a fix format 2020-12-05 22:48:09 -03:00
zoecarver
24aa9ac75e [cxx-interop] Add support for templated member functions.
Essentially applying the same change as for supporting templated
constructors.
2020-12-04 13:07:22 -08:00
zoecarver
08e7160cec [cxx-interop] Support templated C++ constructors. 2020-11-11 09:38:10 -08:00
Pavel Yaskevich
6a753acd1e Merge pull request #34619 from xedin/autoclosure-application-loc
[CSApply] Adjust @autoclosure locator to point to argument expression…
2020-11-07 23:32:58 -08:00
Pavel Yaskevich
d675c7471b [CSApply] Adjust @autoclosure locator to point to argument expression being coerced to result type
While applying type inferred for autoclosure to argument use locator
that records argument/param indices to make it possible for
`coerceToType` to simplify it down to underlying argument expression
if necessary.
2020-11-06 17:56:22 -08:00
Doug Gregor
33cfbbdd72 [Concurrency] Don't diagnose missing "self." in async let autoclosures. 2020-11-04 23:18:51 -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
Zoe Carver
f0f2246793 [cxx-interop] Support C++ function templates in Swift. (#33053)
This patch adds rudimentary support for C++ template functions in swift.
2020-10-21 20:42:25 -07:00
Pavel Yaskevich
64d446582b Merge pull request #34132 from Interfere/SR-12022-LiteralExpr-refactoring
SR-12022: refactor LiteralExpr to combine common initializer code
2020-10-12 12:10:40 -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
Pavel Yaskevich
4175a01987 Merge pull request #34206 from xedin/decouple-cs-tc-headers
[Sema] Decouple ConstraintSystem and TypeChecker headers
2020-10-07 10:51:53 -07:00
Slava Pestov
d01e1ddd53 Sema: Fix type of MemberRefExpr for a VarDecl with DynamicSelfType
This fixes a regression from 33401ae147.

Fixes <rdar://problem/69804933>.
2020-10-06 15:36:00 -04:00
Pavel Yaskevich
05b223aa0b [Sema] Switch typeCheckExpression to use ContextualTypeInfo 2020-10-06 12:21:07 -07:00
Alexey Komnin
4fa17bf597 SR-12022: refactor LiteralExpr to combine common initializer code 2020-10-01 15:45:16 +03:00
Slava Pestov
2fb3c7c975 Merge pull request #34092 from slavapestov/didset-access-semantics-cycle
Sema: Simplify adjustSelfTypeForMember() a little bit to avoid a cycle
2020-09-26 10:15:52 -04:00
Slava Pestov
71a281c68e Sema: Rename coerceObjectArgumentToType() to coerceSelfArgumentToType()
Also remove the unused AccessSemantics parameter.
2020-09-26 00:02:42 -04: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
6a82f242ac Sema: Don't trigger ImplInfoRequest from TypeChecker::buildRefExpr()
It's too early to do that here, because we may be building a reference
to a ParamDecl that is not yet known to be inout, because the constraint
solver has not run yet.

Instead, always compute the access semantics in CSApply.
2020-09-25 17:59:20 -04:00
Anthony Latsis
d953fa646d Merge pull request #34005 from AnthonyLatsis/coself
Sema: Allow non-final classes to satisfy properties and subscripts with covariant Self
2020-09-25 05:23:34 +03:00
Doug Gregor
fc426405b7 [Concurrency] Prohibit partial application of actor-isolated methods. 2020-09-23 14:50:53 -07:00
Anthony Latsis
33401ae147 CS: Use the curried opened type when building a VarDecl member ref
This ensures that we erase opened archetypes before closing an existential result
2020-09-23 21:16:12 +03:00
Doug Gregor
ec72db1d8a Merge pull request #34019 from DougGregor/curry-thunk-dot-syntax-call-source-locs
[Type checker] Use DotSyntaxCallExpr consistently for instance members.
2020-09-21 22:11:10 -07:00
Doug Gregor
6ce4eb2390 [Type checker] Use DotSyntaxCallExpr consistently for instance members.
When building a curry thunk for unapplied references to instance
methods, the type checker would build a CallExpr rather than a
DotSyntaxCallExpr to work around various issues with source locations.
Fix the underlying issues with source locations in DotSyntaxCallExpr
so we can consistently build DotSyntaxCallExpr here, and assert that
we don't do this again:

* DotSyntaxCallExpr wasn't able to reason about having just one of its
children having source location information; fix it.
* @dynamicCallable support was passing the declaration source location
for the call expression, which was nowhere in the expression itself.
The above mistake was covering for this one.
2020-09-21 16:57:25 -07: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
Nathan Hawes
a1ef6e4dac Merge pull request #33749 from nathawes/new-member-completion
[CodeCompletion] Update member completion to handle ambiguous and invalid base expressions
2020-09-09 18:51:22 -07:00
tbkka
82c43a8ac7 [Dynamic Casting] Allow casts to "more optional" types (#33684)
Generally, casting consistency demands that we be able
to extract anything from an existential that can be put
into that existential.  (Which is why the casting spec
requires that casting permit arbitrary injection and
projection of optionals.)

This particular diagnostic prevented optionals from being
projected back out of existentials:
   let i: Int?
   let a: Any = i  // Inject Int? into Any
   // Error prevents projecting Int? back out of Any
   a as? Int?

This also broke certain uses of Mirror (weak variables get reflected as
optionals stored in Any existentials).
2020-08-31 17:52:22 -07:00
Doug Gregor
b62328be4f Merge pull request #33721 from DougGregor/forward-scan-unresolved-member
[Constraint solver] Fix backward trailing closures with ".member" expressions
2020-08-31 16:20:45 -07:00
Doug Gregor
cabcbc9270 [Constraint application] Find trailing closure direction more carefully.
Rather than trying to include each expression kind, which leaves us
open to errors of omission, exclude only the case where we don't record
locators for trailing closure directions.
2020-08-31 13:53:37 -07:00
Doug Gregor
0b2b7b58e8 [Constraint solver] Fix backward trailing closures with ".member" expressions
The introduction of forward-scan matching for trailing closures
(SE-0286) failed to account for unresolved member expressions,
sometimes causing a crash in SILGen. Fixes rdar://problem/67781123.
2020-08-31 11:18:27 -07:00