Commit Graph

1476 Commits

Author SHA1 Message Date
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
b3f0442faa [ConstraintSystem] Modified CSGen.cpp in order to resolve a failing test in property_wrappers.swift 2021-04-22 11:31:42 -07:00
Strieker
c9b53ec66f [ConstraintSystem] Created a locator in CSGen to store the location where the wrappedValue type of a property wrapper was determined and added necessary logic so that a constraint locator can recognize a composed property wrapper’s wrapped value type in CSFix.cpp, CSFix.h, and CSSimplify.cpp. 2021-04-22 11:31:41 -07:00
Azoy
9ed732f0ab Introduce isDecl and getDeclType
fix enum logic issue

fix tests

guard against null types
2021-04-20 02:22:16 -04:00
Nathan Hawes
f75f5fe78d Merge pull request #36879 from nathawes/track-match-call-result
[ConstraintSystem] Record parameter bindings in solutions (NFC)
2021-04-18 06:10:23 +10:00
Nathan Hawes
c57c403ffa [ConstraintSystem] Record parameter bindings in solutions (NFC)
This saves us from needing to re-match args to params in CSApply and is also
useful for a forthcoming change migrating code completion in argument position
to use the solver-based typeCheckForCodeCompletion api.

rdar://76581093
2021-04-16 18:32:06 +10:00
Pavel Yaskevich
e507bcfc44 Merge pull request #36792 from LucianoPAlmeida/failure-diagnostics-left
[CSGen] Removing code that was only necessary for failure diagnostics
2021-04-12 11:04:34 -07:00
Luciano Almeida
a028a0dc2c [CSGen] Removing code that was only necessary for failure diagnostics 2021-04-06 23:40:23 -03:00
Alex Hoppen
fd8e34913a Merge pull request #36551 from ahoppen/pr/internal-labels-in-closures
[CodeComplete] Default parameter names of completed closure to internal names
2021-04-06 15:30:26 +02:00
Alex Hoppen
865e80f9c4 [CodeComplete] Default parameter names of completed closure to internal names
If have a function that takes a trailing closure as follows
```
func sort(callback: (_ left: Int, _ right: Int) -> Bool) {}
```
completing a call to `sort` and expanding the trailing closure results in
```
sort { <#Int#>, <#Int#> in
  <#code#>
}
```

We should be doing a better job here and defaulting the trailing closure's to the internal names specified in the function signature. I.e. the final result should be
```
sort { left, right in
  <#code#>
}
```

This commit does exactly that.

Firstly, it keeps track of the closure's internal names (as specified in the declaration of `sort`) in the closure's type through a new `InternalLabel` property in `AnyFunctionType::Param`. Once the type containing the parameter gets canonicalized, the internal label is dropped.

Secondly, it adds a new option to `ASTPrinter` to always try and print parameter labels. With this option set to true, it will always print external paramter labels and, if they are present, print the internal parameter label as `_ <internalLabel>`.

Finally, we can use this new printing mode to print the trailing closure’s type as
```
<#T##callback: (Int, Int) -> Bool##(_ left: Int, _ right: Int) -> Bool#>
```

This is already correctly expanded by code-expand to the desired result. I also added a test case for that behaviour.
2021-04-01 19:14:19 +02:00
Holly Borla
ad3568e52e Merge pull request #36344 from hborla/property-wrapper-parameter-revision
[SE-0293] Implement revision #3 of property wrapper parameters
2021-03-31 15:49:01 -07:00
Pavel Yaskevich
f00c578761 Merge pull request #34401 from xedin/implicit-cgfloat-conversion
[DNM][TypeChecker] Implement Double <-> CGFloat implicit conversion
2021-03-31 10:20:28 -07:00
Holly Borla
a15f4233a2 [Property Wrappers] Implement implementation-detail property wrappers for
parameters.
2021-03-31 09:29:46 -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
Holly Borla
d23246568c [ConstraintSystem] Fix a property wrapper constraint generation crash. 2021-03-26 15:36:34 -07:00
Pavel Yaskevich
a51e3da285 [CSGen] Avoid failing due to invalid explicit closure parameters
If closure parameter has an explicit type, type resolution
would diagnose the issue and cache the resulting error type for
future use. Invalid types currently fail constraint generation,
which doesn't play well with result builders because constraint
generation for their bodies happens during solving.

Let's handle invalid parameters gracefully, replace them with
placeholders and let constraint generation proceed.

Resolves: rdar://75409111
2021-03-26 10:38:18 -07:00
Holly Borla
6f4b62a93c Merge pull request #36568 from hborla/property-wrapper-constraint
[ConstraintSystem] Add a property-wrapper constraint to allow for inference of implicit property wrappers
2021-03-24 17:13:51 -07:00
Holly Borla
7cd8add885 [ConstraintSystem] Add a property wrapper constraint to delay checking
if an inferred wrapper type is a property wrapper until that type is
resolved.
2021-03-24 11:24:21 -07:00
Holly Borla
f05589f6c4 [Diagnostics] Improve diagnostics for passing an invalid projected
value argument.
2021-03-24 11:24:21 -07:00
Pavel Yaskevich
d0f675d52b [CSGen] Stop unsound recycling of type variables used for editor placeholders
This prevents solver from deducing correct solutions.
2021-03-24 10:19:36 -07:00
Pavel Yaskevich
6e628c4874 [CSGen] Fallback to a type variable if preferred type for placeholder is invalid
Type inside of an editor placeholder is more of a hint than anything else,
so if it's incorrect let's diagnose that and use type variable instead to
allow solver to make forward progress.

Resolves: SR-14213
Resolves: rdar://74356736
2021-03-23 18:56:21 -07:00
Pavel Yaskevich
a559ca8c53 [TypeChecker/SE-0307] NFC: Fix typos and clarify a couple of comments
Thanks Xiaodi Wu!
2021-03-17 14:11:53 -07:00
Doug Gregor
dbc63ebdca Synchronous closures can have global actors as part of their type 2021-03-17 00:51:58 -07:00
Pavel Yaskevich
307caf2848 [CSGen] Don't favor overload choices that could require an implicit conversion
Doing so resulted in performance impact due to the number of partial
solutions increase.
2021-03-17 00:18:29 -07:00
Pavel Yaskevich
dbf401effb [CSGen] Tweak favoring hacks to avoid favoring overloads that require narrowing conversions (Double -> CGFloat) 2021-03-17 00:18:20 -07:00
Pavel Yaskevich
0567900a99 [CSGen] Favor overload choices that support Double/CGFloat conversions (argument or result) 2021-03-17 00:18:20 -07:00
Pavel Yaskevich
cf8005b765 [CSGen] Favor CGFloat operator overloads for floating-pointer literal arguments
If argument is a floating-point literal, with newly introduced implicit
Double<->CGFloat conversion, sometimes it's better to choose a concrete
function/operator overload on `CGFloat` even if it's not a default literal
type e.g. `let _: CGFloat = min(1.0, log(<CGFloat value>))` shouldn't form
solutions with `Double` arguments since it would result in multiple
implicit conversions, it's better to use a `CGFloat` type for the arguments.
2021-03-17 00:18:18 -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
8242d843cd NFC, Sema: Further propagate the locator through to doesStorageProduceLValue 2021-03-09 17:01:50 +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
Holly Borla
b7a170cd77 [NFC][ConstraintSystem] Rename applyPropertyWrapperParameter. 2021-02-25 18:35:14 -08:00
Holly Borla
db387273f6 [ConstraintSystem] Don't allow dollar prefixes in argument labels unless
the parameter has an attached property wrapper.
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
aa0da03d2a [CSGen] Move generateWrappedPropertyTypeConstraints back to its original
position in CSGen. This effectively reverts 6caca26014.
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
522eedcfd1 [ConstraintSystem] Emit an error message when trying to pass a property
wrapper projection argument to a wrapped parameter with arguments in the
wrapper attribute.
2021-02-25 18:35:14 -08:00
Holly Borla
ea3fe03c98 [Property Wrappers] Add a constraint fix and diagnostic for the case
where the programmer tries to pass a projection argument to a wrapped
parameter without 'var projectedValue'.
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
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
Pavel Yaskevich
5b55ea1312 [CSGen] Use new UnresolvedMemberChainBase constraint 2021-02-23 11:33:10 -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
Frederick Kellison-Linn
8539782c9a [Sema] Rename convertInferableTypes to replaceInferableTypesWithTypeVars 2021-02-19 14:35:03 -05:00
Pavel Yaskevich
64323a0149 Revert "[SR-12033] [Sema] Do not allow inferring defaultable closure () -> $T for autoclosure arguments result" 2021-02-17 10:28:30 -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
Frederick Kellison-Linn
40122dfecd [Sema] Add support for folding placeholders into TypeExprs
Move markAcceptableDiscardExprs into PreCheckExpr so that we can perform this analysis before we convert expressions like `_? = <value>` into `_ = <value>` since `_?` is now an expression with meaning, and we only want to perform this transformation when `_?` is on the LHS of an assignment
2021-02-16 22:59:19 -05:00
Frederick Kellison-Linn
a79e7b59f0 [Sema] Convert placeholder types in expression conversion types 2021-02-16 22:59:19 -05:00
Frederick Kellison-Linn
fbb78cd006 [Sema] Convert placeholder types to type vars wherever we open generics
Rename `openUnboundGenericTypes` to `convertInferableTypes`. In addition to unbound generics, this method also converts placeholder types to fresh type variables.
2021-02-16 22:59:19 -05:00