Commit Graph

1945 Commits

Author SHA1 Message Date
Alex Hoppen
3d2fd566cc Merge pull request #36523 from ahoppen/pr/revert-remove-unreachable-code
Revert "Sema: Remove some unreachable code from CSApply"
2021-03-22 13:05:02 +01:00
Holly Borla
3ca1292ec2 Merge pull request #36521 from hborla/property-wrapper-request-refactoring
[Property Wrappers] Rework the dependencies between property wrapper requests.
2021-03-19 21:27:31 -07:00
Holly Borla
21a86b5d2f [NFC][Property Wrappers] Split PropertyWrapperBackingPropertyInfoRequest into
two separate requests - one to synthesize the auxiliary declarations, and
another to compute how the backing storage is initialized.
2021-03-19 13:03:13 -07:00
Alex Hoppen
8f16139a8b Revert "Sema: Remove some unreachable code from CSApply"
This reverts commit 9d3c8ca396.
2021-03-19 19:38:52 +01:00
Doug Gregor
52096a640e SE-0302: Rename ConcurrentValue/@concurrent to Sendable/@Sendable. 2021-03-18 23:48:21 -07:00
Doug Gregor
0760739e18 Propagate global actor to a closure from its contextual type. 2021-03-17 00:51:58 -07:00
Pavel Yaskevich
000625f36b [CSApply] Use correct locator while converting expression to contextual type
This wasn't a problem before since locator wasn't really used by
`ExprRewritter:coerceToType` but with Double<->CGFloat conversion
it needs the locator to be anchored at a rewritten expression instead
of the original one to form a correct implicit initializer call.
2021-03-17 00:18:20 -07:00
Pavel Yaskevich
78ae8def65 [CSApply] Make sure to load value before attempting implicit conversion 2021-03-17 00:18:15 -07:00
Pavel Yaskevich
f9eb71ddad [ConstraintSystem] Attempt Double <-> CGFloat implicit conversion only once and re-use results 2021-03-17 00:18:11 -07:00
Pavel Yaskevich
8c6017687a [ConstraintSystem] Limit new implicit conversion to only Double <-> CGFloat 2021-03-17 00:18:10 -07:00
Pavel Yaskevich
491ba2c6f3 [CSApply] Implement restriction-to-AST application to support implicit CGFloat conversion
Insert an implicit call to an initializer into the AST
to model to/from CGFloat conversion and pass converted
value as an argument (left-hand side of the conversion).
2021-03-17 00:18:08 -07:00
Pavel Yaskevich
2b935bab7c [ConstraintSystem] Add conversion restriction to cover implicit conversion from/to CGFloat 2021-03-17 00:18:08 -07:00
David Zarzycki
b80ca8e8eb Merge pull request #36234 from davezarzycki/pr36234
[AST] NFC: Make ExtInfo param Optional<>
2021-03-12 13:47:22 -05:00
Anthony Latsis
79c0d93b86 Sema: Fix dynamic Self behavior for a «super» base expression 2021-03-09 19:20:43 +03:00
David Zarzycki
c0ec6c3235 [AST] NFC: Make ExtInfo param Optional<>
While it is very convenient to default the ExtInfo state when creating
new function types, it also make the intent unclear to those looking to
extend ExtInfo state. For example, did a given call site intend to have
the default ExtInfo state or does it just happen to work? This matters a
lot because function types are regularly unpacked and rebuilt and it's
really easy to accidentally drop ExtInfo state.

By changing the ExtInfo state to an optional, we can track when it is
actually needed.
2021-03-09 05:57:39 -05:00
Zoe Carver
f64b7c4d75 Merge pull request #35819 from zoecarver/cxx/fix-full-inst
[cxx-interop] Fix class template instantiation.
2021-02-26 12:14:41 -08:00
Holly Borla
c29eecd0b6 [Property Wrappers] Store the callee in AppliedPropertyWrapperExpr to use
the correct substitution map when emitting the property wrapper generator
application in SILGen.
2021-02-25 18:35:14 -08:00
Holly Borla
99e066683c [ConstraintSystem] Inject implicit applied property wrapper expressions
around arguments to property wrapper parameters.
2021-02-25 18:35:14 -08:00
Holly Borla
b821c8d76b [Sema] Add an implicit applied property wrapper expression and a new
dedicated initializer context for this expressions.
2021-02-25 18:35:14 -08:00
Holly Borla
133dec0e05 [ConstraintSystem] Implement implicit property wrapper attribute
inference for closure parameters.
2021-02-25 18:35:14 -08:00
Holly Borla
31f7b1ac75 [ConstraintSystem] Change the type of an unapplied function reference
when it has property wrapper parameters.

The property wrapper type will be replaced with either the wrapped-value
or projected-value type, depending on the argument label/parameter name,
and CSApply will build a thunk to construct the property wrapper and call
the function.
2021-02-25 18:35:13 -08:00
Holly Borla
6aee012d84 [CSApply] Add buildPropertyWrapperFnThunk, which builds a thunk around
a reference to a function with property wrapper parameters and initializes
each backing property wrapper from a wrapped or projected value.
2021-02-25 18:35:13 -08:00
Holly Borla
8bdc8f9dde [Property Wrappers] Use the TypeExpr instead of the TypeRepr of the
property wrapper custom attribute to get the backing wrapper type
in CSApply.

This is necessary because implicit custom attributes do not have
TypeReprs, but they always have TypeExprs.
2021-02-25 18:35:13 -08:00
Holly Borla
4bdeed570b [ConstraintSystem] Use a wrapped value placeholder when matching property
wrapper arguments in the constraint system in order to avoid generating
constraints for the argument multiple times.
2021-02-25 18:35:13 -08:00
Holly Borla
8325a52b41 [ConstraintSystem] Teach the constraint system about property wrapper
parameters.
2021-02-25 18:35:13 -08:00
zoecarver
b280d26a7b [cxx-interop] Fix class template instantiation.
Lazily instantiate class template members. This means we no longer
reject some programs that clang accepts, such as the following:

```
template<class T> struct Foo { void fail(T value) { value.fail(); } };
using Bar = Foo<int>;
```

The above program will not error so long as `Bar::fail` isn't called.
(Previously, we'd fail to import `Bar`.)
2021-02-24 11:25:45 -08:00
Pavel Yaskevich
a2ee7f2e6b [CSApply] Simplify handling of static member refs on protocol metatype 2021-02-23 11:33:11 -08:00
Pavel Yaskevich
5758ae2bcc [ConstraintSystem] Filtering for static member lookup on protocol metatypes
Detect and filter some of the overload choices which can't possibly
match because their result type cannot conform to the expected protocol.
2021-02-23 11:33:10 -08:00
Pavel Yaskevich
b05678f18e [ConstraintSystem] Allow static member references on protocol metatypes 2021-02-23 11:31:43 -08:00
Holly Borla
11028350a7 Merge pull request #35589 from Jumhyn/placeholder-types
[AST, Sema] Replace HoleType with PlaceholderType
2021-02-22 08:35:37 -08:00
Doug Gregor
077d96c68e Merge pull request #36012 from DougGregor/explicit-concurrent-closure
Add support for @Concurrent attribute on closures.
2021-02-17 21:16:08 -08:00
Slava Pestov
9d3c8ca396 Sema: Remove some unreachable code from CSApply
I believe these code paths could only be reached by re-typechecking
invalid code in the old CSDiag implementation.
2021-02-17 18:27:08 -05:00
Doug Gregor
8448e61b3a Add support for attributes on closures. 2021-02-16 22:19:43 -08:00
Frederick Kellison-Linn
e4ea1678dc Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
2021-02-16 22:59:19 -05:00
Anthony Latsis
a223d37ae7 Merge pull request #34140 from AnthonyLatsis/coself-array
AST, Sema: Teach findProtocolSelfReferences that some stdlib collections preserve variance
2021-02-13 19:45:15 +03:00
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