Commit Graph

1659 Commits

Author SHA1 Message Date
Slava Pestov
703c39d3fa Merge pull request #23845 from Azoy/sr-10313
[CSApply] Restructure the implicit AST when applying @dynamicCallable
2019-07-06 13:48:27 -04:00
Slava Pestov
4c499fd4ac AST: Stop passing around LazyResolvers in various places 2019-07-06 00:43:22 -04:00
Azoy
d0c727dd36 Restructure implicit AST for @dynamicCallable
add tests

dont assume dict type

dont assume member ref ast

formatting

more formatting

Update getTypeWitnessByName
2019-07-05 20:46:12 -04:00
Slava Pestov
c889ca5a14 Sema/SILGen: Move invalid @convention(c) conversion check to SILGen
This removes a bit of global state from the TypeChecker class, and
allows C function pointers to be formed to closures that capture
local functions, but have no transitive captures.
2019-07-02 22:03:30 -04:00
Slava Pestov
d475546eb8 Merge pull request #24511 from LucianoPAlmeida/attemp-fix-compiler-crash-28818
[TypeChecker] Attempt fix a compiler crasher: Expecting a type set
2019-06-27 23:32:16 -04:00
Slava Pestov
5826db5d56 AST: Add AbstractFunctionDecl::hasDynamicSelfResult() and use it
This calculates a result directly from the function's result type
instead of checking a bit that was previously set by the type
checker. Also, always returns true for constructors to simplify
some callers.
2019-06-26 01:10:12 -04:00
John Holdsworth
c1c1801448 CovariantReturnConversionExpr required. 2019-06-26 01:10:11 -04:00
John Holdsworth
bd4f49c1b5 Revert some tidy-ups. 2019-06-26 01:10:11 -04:00
John Holdsworth
f3e2282f65 Tidy-up 2019-06-26 01:10:11 -04:00
John Holdsworth
b3512298f1 Remove debug messages 2019-06-26 01:10:11 -04:00
John Holdsworth
498280d324 Seems to work 2019-06-26 01:10:11 -04:00
John Holdsworth
444027667c Some progress 2019-06-26 01:10:11 -04:00
John Holdsworth
97f102c74b Story so far 2019-06-26 01:10:11 -04:00
Pavel Yaskevich
4d6a18a0cf Merge pull request #25518 from xedin/rdar-51167632
[Diagnostics] Make sure that fixes associated with function builders …
2019-06-18 00:46:45 -07:00
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