Commit Graph

1945 Commits

Author SHA1 Message Date
Pavel Yaskevich
d8debe7a57 [Diagnostics] Make sure that fixes associated with function builders are found and diagnosed
Current logic in `applySolutionFixes` didn't actually look inside
of single-expression closures (because of brace statement) or
closures which are transformed by function builders.

Resolves: rdar://problem/51167632
2019-06-17 15:05:00 -07:00
Slava Pestov
8ea650043d Merge pull request #25408 from pschuh/s-8
Convert DictionaryExpr to not use tc.callWitness() or generate a SemanticExpr.
2019-06-17 18:01:54 -04:00
Parker Schuh
0b03721ce8 Convert DictionaryExpr to not use tc.callWitness() or generate a SemanticExpr.
For reference, everything else except string interpolation has been
migrated to this new form.
2019-06-13 15:58:03 -07:00
Pavel Yaskevich
26d0324318 [CSApply] Don't try to transform editor placeholder if it's type is invalid
CSDiag could re-typecheck closure or other expression which has editor
placeholder inside allowing type variables be bound to unresolved
type, which doesn't really form a valid solution to be applied to AST.
So we need to guard against trying to transform placeholder into a call
to `_undefined` in such case, otherwise in asserts build it's going to
crash with an assert but in release build it would crash in some other
place e.g. xSILGen or trying to type-check captures.

Resolves: rdar://problem/48937223
Resolves: rdar://problem/51599529
2019-06-13 10:55:43 -07:00
Pavel Yaskevich
59bc60eb20 [ConstraintSystem] Don't track captures if solver was in diagnostic mode
If solution application is attempted for one of the sub-expressions,
while diagnostics are trying to narrow down where the failure is
located, don't record that captures need to be computed for closures,
because that could fail later on as in such conditions expressions
are not guaranteed to have correct types (e.g. some types could be
set to "unresolved").
2019-06-13 00:56:06 -07:00
Doug Gregor
5d0d8d97ae [Constraint solver] Capture/roll back type mappings generated while solving.
When we perform constraint generation while solving, capture the
type mappings we generate as part of the solver scope and solutions,
rolling them back and replaying them as necessary. Otherwise, we’ll
end up with uses of stale type variables, expression/parameter/type-loc
types set twice, etc.

Fixes rdar://problem/50390449 and rdar://problem/50150314.
2019-06-11 17:34:45 -07:00
Doug Gregor
a4301cc95b [Type checker] Transform multi-statement closures via function builders.
When calling a function whose parameter specifies a function builder
with a multi-statement closure argument, transform the closure into
a single expression via the function builder. Should the result
type checker, replace the closure body with the single expression.
2019-06-11 17:34:44 -07:00
Doug Gregor
0494574706 Factor the computation of default arguments into ParameterListInfo.
Provide a place where we can capture more information about the parameters
from a declaration being called.
2019-06-11 17:34:44 -07:00
Parker Schuh
823ba0bb73 Convert ObjectLiteralExpr to not use tc.callWitness() or generate a SemanticExpr.
For reference, all other literal types except dictionaries and string
interpolation have been converted over to this form.
2019-06-11 02:47:32 -07:00
Slava Pestov
c84aad8bf1 Sema: TypeChecker::conformsToProtocol() is static 2019-06-11 02:47:32 -07:00
Luciano Almeida
bbf38c5541 Merge branch 'master' of https://github.com/apple/swift into attemp-fix-compiler-crash-28818 2019-06-10 00:14:56 -03:00
Luciano Almeida
7aaf71c216 Reverting to covertTypeCall and caching the type on the system 2019-06-02 23:32:03 -03:00
Luciano Almeida
f9fd006c30 Handling failed coercion 2019-05-31 22:28:57 -03:00
Luciano Almeida
8c30c46a03 Reverting covertToType extraction and using coerceToType on CSApply 2019-05-29 15:03:00 -03:00
Slava Pestov
4551230a8b Sema: Remove ConformanceCheckFlags::Used 2019-05-28 22:08:31 -04:00
Slava Pestov
dbea3bfb55 Sema: Remove calls to markConformanceUsed() when applying solution 2019-05-28 22:08:31 -04:00
Luciano Almeida
5c33156417 Reusing the constraint system to coerce to type. 2019-05-28 21:18:47 -03:00
Slava Pestov
2cfc459e1e Sema: Build fully type-checked AST for dynamic member lookups 2019-05-23 10:40:34 -04:00
Slava Pestov
73f1b10dab Sema: Remove useBridgedNSErrorConformances()
The walker in SILGenLazyConformance.cpp should be sufficient to catch
any conformances needed at runtime, and after all the recent changes
SILGen is now able to trigger lazy conformance checking and synthesis
of fully-checked function bodies for accessors, which is enough to
remove the explicit conformance checks from Sema in this case.
2019-05-18 11:35:05 -04:00
Hamish Knight
8aa7401ba5 [Sema] Add getDeclOrNull to OverloadChoice
This helps clean up a bunch of call sites.
2019-05-16 12:07:41 +01:00
Slava Pestov
86f9ca7245 AST: Add ProtocolConformanceRef::getWitnessByName() 2019-05-14 21:18:06 -04:00
Slava Pestov
e65161ea2e Sema: Build type checked bodies for lazy getters 2019-05-14 19:18:58 -04:00
Slava Pestov
548e292ad9 Sema: Fold Solution::convertOptionalToBool() into its only remaining caller 2019-05-14 19:18:57 -04:00
Slava Pestov
d22b3a7b0b Sema: Move the Optional-typed nil peephole to SILGen
When applying a solution to a nil literal of Optional type, we would
build a direct reference to Optional<T>.none instead of leaving the
NilLiteralExpr in place, because this would generate more efficient
SIL that avoided the call to the Optional(nilLiteral: ()) witness.

However, a few places in the type checker build type-checked AST, and
they build NilLiteralExpr directly. Moving the peephole to SILGen's
lowering of NilLiteralExpr allows us to simplify generated SIL even
further by eliding an unnecessary metatype value. Furthermore, it
allows SILGen to accept NilLiteralExprs that do not have a
ConcreteDeclRef set, which makes type-checked AST easier to build.
2019-05-13 17:25:49 -04:00
swift-ci
00af9c9d9a Merge pull request #22156 from Azoy/cache-money 2019-05-10 19:07:49 -07:00
Pavel Yaskevich
ce406fca04 Merge pull request #24615 from xedin/fix-autoclj-returning-fn-type
[ConstraintSystem] Allow arguments to be passed by value to `@autoclo…
2019-05-09 00:48:53 -07:00
Pavel Yaskevich
860cddfd34 [ConstraintSystem] Allow arguments to be passed by value to @autoclosure parameters
Instead of always requiring a call to be made to pass argument
to `@autoclosure` parameter, it should be allowed to pass argument
by value to `@autoclosure` parameter which can return a function
type.

```swift
func foo<T>(_ fn: @autoclosure () -> T) {}
func bar(_ fn: @autoclosure @escaping () -> Int) { foo(fn) }
```
2019-05-08 19:41:35 -07:00
Slava Pestov
1dedba1f12 Sema: Pass argument match kind down to matchCallArguments() 2019-05-07 23:10:48 -04:00
Azoy
9789b2504f add typealias to known types
formatting

underscore
2019-05-07 15:13:28 -05:00
Azoy
33ed2076f6 Cache _MaxBuiltinFloatType
period
2019-05-07 14:54:48 -05:00
Slava Pestov
324e36f47f Sema: Remove useObjectiveCBridgeableConformances()
THere is no longer any reason to complete ClangImporter-synthesized _ObjectiveCBridgeable
conformances in Sema. SILGen will determine the ones that it needs and will trigger
conformance checking as needed automatically.
2019-04-25 22:33:23 -04:00
nate-chandler
155a155000 Merge pull request #23251 from nate-chandler/nate/omit-return
Allow return to be omitted from single expression functions.
2019-04-25 08:36:34 -07:00
Nate Chandler
b2ad56223f Eliminated conversion from uninhabited. 2019-04-24 10:09:17 -07:00
Pavel Yaskevich
ca6cf0c022 [ConstraintSystem] Use special locator for expr representing return of single expr function 2019-04-24 10:06:44 -07:00
Nate Chandler
0143ce25c2 Implicitly convert single exprs from uninhabited.
When type-checking a return statement's result, pass a new
ContextualTypePurpose when that return statement appears in a function
with a single expression.  When solving the corresponding constraint
system, the conversion constraint will have a new ConstraintKind.  When
matching types, check whether the constraint kind is this new kind,
meaning that the constraint is between a function's single expression
and the function's result.  If it is, allow a conversion from
an uninhabited type (the expression's type) to anything (the function's
result type) by adding an uninhabited upcast restriction to the vector
of conversions.  Finally, at coercion time, upon encountering this
restriction, call coerceUninhabited, replacing the original expression
with an UninhabitedUpcastExpr.  Finally, at SILGen time, treat this
UninhabitedUpcastExpr as a ForcedCheckedCastExpr.

Eliminates the bare ConstraintSystem usage from
typeCheckFunctionBodyUntil, ensuring that the same code path is followed
for all function bodies.
2019-04-24 10:04:17 -07:00
Doug Gregor
cc68b12d1a [SILGen] Initialization of instance properties with property delegates
The initialization of an instance property that has an attached
property delegate involves the initial value written on the property
declaration, the implicit memberwise initializer, and the default
arguments to the implicit memberwise initializer. Implement SILGen
support for each of these cases.

There is a small semantic change to the creation of the implicit
memberwise initializer due to SE-0242 (default arguments for the
memberwise initializer). Specifically, the memberwise initializer will
use the original property type for the parameter to memberwise
initializer when either of the following is true:

  - The corresponding property has an initial value specified with the
    `=` syntax, e.g., `@Lazy var i = 17`, or
  - The corresponding property has no initial value, but the property
    delegate type has an `init(initialValue:)`.

The specific case that changed is when a property has an initial value
specified as a direct initialization of the delegate *and* the
property delegate type has an `init(initialValue:)`, e.g.,

```swift
struct X {
  @Lazy(closure: { ... })
  var i: Int
}
```

Previously, this would have synthesized an initializer:

```swift
init(i: Int = ???) { ... }
```

However, there is no way for the initialization specified within the
declaration of i to be expressed via the default argument. Now, it
synthesizes an initializer:

```swift
init(i: Lazy<Int> = Lazy(closure: { ... }))
```
2019-04-23 11:31:59 -07:00
Pavel Yaskevich
d6a3a31ae9 [ConstraintSystem] Detect and fix use of method references in key path
Referencing (instance or static) methods in the key path is not
currently allowed, solver should be responsible for early detection
and diagnosis of both standalone e.g. `\.foo` and chained
e.g. `\.foo.bar` (where foo is a method) references in key path
components.

```swift
struct S {
  func foo() -> Int { return 42 }
}

let _: KeyPath<S, Int> = \.foo
```

Resolves: rdar://problem/49413561
2019-04-22 14:56:15 -07:00
Joe Groff
a8c2b50bd8 Merge pull request #22072 from jckarter/opaque-type-runtime
Opaque types with resilience
2019-04-18 14:52:31 -07:00
Brent Royal-Gordon
334b76a237 Merge pull request #24084 from brentdax/whos-that-key-path-component
Improve `-debug-constraints` output for key path components
2019-04-18 14:12:43 -07:00
Brent Royal-Gordon
44a472766d [ConstraintSystem] Add KeyPathComponentTypes map
Avoids digging through the long list of type vars to find the ones related to key path components when dumping an expression.
2019-04-17 21:15:16 -07:00
Joe Groff
f008019bda Sema: Infer the underlying type for opaque return types from function bodies. 2019-04-17 14:43:32 -07:00
Pavel Yaskevich
2e93165040 [ConstraintSystem] Detect use of declaration with mutating getter as a key path component
Such use is currently not allowed so variables or subscripts with
mutating getters should be rejected and diagnosed.
2019-04-16 17:56:13 -07:00
Robert Widmann
f192b92799 Merge pull request #23785 from Azoy/context-cleanups
AST NFC: Minor cleanups around ASTContext
2019-04-16 13:50:35 -04:00
Pavel Yaskevich
03ea5dce5a [ConstraintSystem] Detect and fix use of static members in a key path in the solver
Previously it was possible to create an invalid solution where
static members would be referenced in a key path, which is not
currently supported and would only be diagnosed while applying
such solution to AST e.g.

```swift
struct S {
  static var foo: Int = 42
}

_ = \S.Type.foo
```
2019-04-15 23:42:34 -07:00
Slava Pestov
7fe577fddb Sema: Clean up modeling of non-member VarDecl references
Give them substitutions just like with everything else, which
eliminates some special cases from SILGen.
2019-04-14 23:28:14 -04:00
Slava Pestov
a3c15f2f6b Sema: References to TypeDecls should always be TypeExpr
In a few corner cases we built DeclRefExpr and MemberRefExpr
for references to types. These should just be TypeExpr so that
SILGen doesn't have to deal with it.

This also fixes a bug where a protocol typealias with an
unbound generic type could not be accessed properly from
expression context, but that is just so incredibly obscure.
2019-04-14 23:28:13 -04:00
Suyash Srijan
072e84acd6 [CSSimplify] Reject key path if root type is AnyObject (#23820)
Detect situations where `AnyObject` is attempted to be used as a root type of the key path
early and diagnose via new diagnostics framework.
2019-04-14 12:18:35 -07:00
Brent Royal-Gordon
def1af6049 Merge pull request #23358 from brentdax/a-type-is-a-set-of-its-instances
Add static and class subscripts
2019-04-11 12:58:32 -07:00
Pavel Yaskevich
34960788aa Merge pull request #23741 from xedin/verify-kp-subscript-hashable-via-solver
[CSSolver] Move keypath subscript index Hashable conformance verification to solver
2019-04-11 00:48:26 -07:00
Brent Royal-Gordon
e42939d9bb Correctly apply typechecking solutions with subscripts on type instances 2019-04-10 23:09:44 -07:00