Commit Graph

1147 Commits

Author SHA1 Message Date
Anthony Latsis
267e32dcd8 Merge pull request #32118 from AnthonyLatsis/post-increment-cleanup
[NFC] Pre- increment and decrement where possible
2020-06-02 20:10:29 +03:00
Varun Gandhi
2419112469 Merge pull request #32080 from varungandhi-apple/vg-tidying-up-without-marie-kondo
Get rid of #includes that do not spark joy
2020-06-01 19:51:01 -07:00
Anthony Latsis
9fd1aa5d59 [NFC] Pre- increment and decrement where possible 2020-06-01 15:39:29 +03:00
Varun Gandhi
c14e934563 [NFC] Remove redundant includes for llvm/ADT/SmallSet.h. 2020-05-31 13:07:45 -07:00
Doug Gregor
451e3cc480 [Constraint system] Move closure type checking to a separate file. 2020-05-29 21:05:02 -07:00
Doug Gregor
6def0303a9 [Constraint system] Separate out constraint generation for closures. 2020-05-29 20:51:17 -07:00
Robert Widmann
afe8f2b63f Drop TypeCheckerDebugConsumer 2020-05-18 22:49:55 -07:00
Pavel Yaskevich
b5568e0c20 [CSGen] Allow closure parameters to become holes by default
That helps when there is no context around a closure and parameters
used in the body are untyped.
2020-05-15 01:13:06 -07:00
Rintaro Ishizaki
b8f6471096 Merge pull request #31774 from rintaro/ide-completion-rdar60982638
[CodeCompletion] Avoid re-typechecking pre-checked expressions
2020-05-14 12:48:12 -07:00
Rintaro Ishizaki
32bd37756e [CodeCompletion] Handle "KeyPath as function" thunk in SanitizeExpr
rdar://problem/60982638
2020-05-13 16:59:06 -07:00
Robert Widmann
2bca013457 Move "isDebugMode" into ConstraintSystem
This eliminates the final source of mutation of the TypeCheckerFlags on the ASTContext.
2020-05-13 09:13:44 -07:00
Luciano Almeida
02c454c976 [Diagnostics] Diagnose that we cannot infer the key path type when binding to a hole 2020-05-11 18:08:40 -03:00
Pavel Yaskevich
4b91ff7f0a Merge pull request #31604 from xedin/rdar-60534522
[ConstraintSystem] Always verify computed/resolved pattern types befo…
2020-05-07 00:05:23 -07:00
Pavel Yaskevich
f22ca7216b [ConstraintSystem] Always verify computed/resolved pattern types before use
While trying to infer type for pattern always take result of
`getTypeForPattern` and `resolveTypeInExpressionContext` with
a grain of salt because both of these methods produce empty type
if type as-written or one of the sub-pattern types is incorrect.

Resolves: rdar://problem/60534522
2020-05-06 15:58:12 -07:00
John McCall
6a0bd67dfb Merge pull request #31052 from apple/unbraced-multiple-trailing-closures
[SE-0279] Add support for an unbraced syntax for multiple trailing closures
2020-05-06 15:54:13 -04:00
John McCall
a518e759d9 WIP for a different syntax for multiple trailing closures
that allows arbitrary `label: {}` suffixes after an initial
unlabeled closure.

Type-checking is not yet correct, as well as code-completion
and other kinds of tooling.
2020-05-06 01:56:40 -04:00
Pavel Yaskevich
4c259acedc [CSGen] Allow typed pattern to propagate its type to sub-pattern
Currently we always generate a new type variable for any pattern
(represented as `_` in the source), but in cases where it's a
sub-pattern of a typed pattern e.g. `let _: Foo = ...` it makes
more sense to pass a type to it directly otherwise type variable
allocated for any pattern gets disconnected from the rest of
the constraint system.
2020-05-05 15:14:21 -07:00
Robert Widmann
b68540f9c4 [NFC] Remove Non-Mutating Usages of Typechecker::validateType 2020-04-30 16:10:25 -07:00
Robert Widmann
ab908f0151 [Gardening] Remove the ASTContext parameter from TypeChecker::validateType 2020-04-30 16:10:25 -07:00
Robert Widmann
31d23303e1 [NFC] Strip all remaining TypeResolutionOptions parameters
Now that these are stored in the TypeResolution object itself, and all callers that mutate flags create a new resolution object, this data can be derived from the resolution itself.
2020-04-30 10:58:40 -07:00
Robert Widmann
4130170bf2 [NFC] Internalize TypeCheckerOptions in a TypeResolution Object
Add the appropriate assertions to ensure that the now-redundant options parameters are being kept in sync so they can be retracted.

The eventual goal is to have TypeResolution requestified.
2020-04-30 10:35:02 -07:00
Robert Widmann
1319b53528 Hide the TypeExpr in ClosureExpr 2020-04-29 13:40:39 -07:00
Robert Widmann
f9a506d799 [NFC] Strip EditorPlaceholderExpr of its TypeLoc 2020-04-28 20:10:10 -07:00
Robert Widmann
19ab68db98 [NFC] Strip UnresolvedSpecializeExpr of its TypeLoc
No caller needed the type
2020-04-28 20:10:10 -07:00
Robert Widmann
5b3060318e [NFC] Strip ClosureExpr of its TypeLoc 2020-04-28 20:10:10 -07:00
Robert Widmann
a6fc9b3679 Merge pull request #31253 from CodaFi/casting-call
Strip TypeExpr of its TypeLoc
2020-04-28 09:45:53 -07:00
Slava Pestov
e8a736a952 Merge pull request #31226 from slavapestov/check-generic-arguments-refactoring
Refactor checkGenericArguments() and related code
2020-04-25 12:04:47 -04:00
Slava Pestov
742bd98402 Sema: Remove ConformanceCheckOptions::SkipConditionalRequirements
All callers can trivially be refactored to use ModuleDecl::lookupConformance()
instead. Since this was the last flag in ConformanceCheckOptions, we can remove
that, too.
2020-04-25 00:14:24 -04:00
Hamish Knight
2070b2cfcd [CS] Connect closure to referenced vars
Previously we were only connecting a closure
constraint to type variables from param decls that
it referenced. This worked fine up until we
started type-checking for-in statements entirely
in the constraint system, meaning that closures
can now reference type variables from the element
pattern.

Tweak the collection logic to consider vars too.

Resolves rdar://62339835
2020-04-24 17:26:21 -07:00
Robert Widmann
09db2902d2 Strip TypeExpr of its TypeLoc
Remove duplication in the modeling of TypeExpr. The type of a TypeExpr
node is always a metatype corresponding to the contextual
type of the type it's referencing. For some reason, the instance type
was also stored in this TypeLoc at random points in semantic analysis.

Under the assumption that this instance type is always going to be the
instance type of the contextual type of the expression, introduce
a number of simplifications:

1) Explicit TypeExpr nodes must be created with a TypeRepr node
2) Implicit TypeExpr nodes must be created with a contextual type
3) The typing rules for implicit TypeExpr simply opens this type
2020-04-23 17:04:38 -07:00
Pavel Yaskevich
cbdb98049d [ConstraintSystem] Fix new "empty" locator in resolveValueMember 2020-04-23 01:15:05 -07:00
Pavel Yaskevich
5dfd51a692 [ConstraintSystem] Switch getConstraintLocator variants to use TypedNode for anchor 2020-04-23 01:13:13 -07:00
nate-chandler
a41a2ffb7e Merge pull request #30693 from nate-chandler/main-attribute
@main: Attribute to add an entry point to a type.
2020-04-22 15:42:49 -07:00
Robert Widmann
48a5432cb7 [NFC] Remove ConformanceCheckFlags::InExpression
The last read of this bit was removed when the legacy referenced name tracker was deleted in the last commit.
2020-04-20 10:22:58 -07:00
Nate Chandler
df99de804d Added executable entry-point via @main type.
When a type (class, enum, or struct) is annotated @main, it is required
to provide a function with the following signature:

  static func main() -> ()

That function will be called when the executable the type is defined
within is launched.
2020-04-17 09:53:46 -07:00
Holly Borla
66e85721cb Merge pull request #30807 from hborla/property-wrapper-refactoring
[Property Wrappers] Refactor property wrappers so the synthesized backing init is only type checked once
2020-04-14 10:48:22 -07:00
Doug Gregor
6999c318b7 Merge pull request #30924 from DougGregor/for-each-solution-application-target
[Constraint solver] Migrate for-each statement checking into SolutionApplicationTarget
2020-04-10 07:28:21 -07:00
Holly Borla
65105f3a26 [Property Wrappers] Introduce a new Expr node for the property wrapper
wrapped value placeholder in an init(wrappedValue:) call that was previously
injected as an OpaqueValueExpr. This commit also restores the old design of
OpaqueValueExpr.
2020-04-09 16:00:57 -07:00
Doug Gregor
87d86f3545 [Constraint solver] Migrate for-each statement checking into SolutionApplicationTarget.
Pull the entirety of type checking for for-each statement headers (i.e., not the
body) into the constraint system, using the normal SolutionApplicationTarget-based
constraint generation and application facilities. Most of this was already handled
in the constraint solver (although the `where` filtering condition was not), so
this is a smaller change than it looks like.
2020-04-09 11:02:56 -07:00
Doug Gregor
78880ffc1a Merge pull request #27776 from owenv/catch_revamp_take_4
[SE-0276] Support multiple patterns in catch clauses
2020-04-07 12:31:33 -07:00
Pavel Yaskevich
bd44fb3ef3 Merge pull request #30838 from xedin/rdar-61347993
[ConstraintSystem] Don't bind result type of an empty closure too early
2020-04-07 10:40:12 -07:00
Pavel Yaskevich
04e2795a03 [ConstraintSystem] Don't bind result type of an empty closure too early
Instead of setting empty closure (`{}`) result type to be `Void`
while generating constraints, let's allocate a new type variable
instead and let it be bound to `Void` once the body is opened.

This way we can support an interaction with function builders which
would return a type different from `Void` even when applied to empty closure.

Resolves: rdar://problem/61347993
2020-04-06 15:55:55 -07:00
Owen Voorhees
43e2d107e1 [SE-0276] Implement multi-pattern catch clauses
Like switch cases, a catch clause may now include a comma-
separated list of patterns. The body will be executed if any
one of those patterns is matched.

This patch replaces `CatchStmt` with `CaseStmt` as the children
of `DoCatchStmt` in the AST. This necessitates a number of changes
throughout the compiler, including:
- Parser & libsyntax support for the new syntax and AST structure
- Typechecking of multi-pattern catches, including those which
  contain bindings.
- SILGen support
- Code completion updates
- Profiler updates
- Name lookup changes
2020-04-04 09:28:26 -07:00
Pavel Yaskevich
5c58bb8432 [CSGen] Bring back performance hack for named patterns with an initializer expression
Unfortunately we still need this performance hack because otherwise
e.g. if initializer returns a tuple its type is going to be connected
to a type variable representing a pattern type, which means all of the
tuple element types are going to form a single constraint system component.

Resolves: rdar://problem/60961087
2020-04-03 15:56:27 -07:00
Pavel Yaskevich
80ac793ecd [CSGen] Adjust locators for some patterns
In each of the following situations `getTypeForPattern` would
add a new pattern element to the path:

- Element of a tuple pattern
- Sub-pattern of a typed pattern
- Sub-pattern of optional .some
2020-04-03 15:56:27 -07:00
Robert Widmann
92c8a65f09 Drop references to name binding as a phase
A lot of places appear to mean "name lookup".  A few places meant "import resolution".
2020-03-29 18:51:09 -07:00
Hamish Knight
234270c941 [CS] NFC: Tweak addExplicitConversionConstraint
Have it take a RememberChoice_t instead of an
'allowFixes' bool, as the parameter no longer
really corresponds to fixes.
2020-03-27 15:13:24 -07:00
Pavel Yaskevich
7410c09c56 [CSGen] No longer allow _ allow to be a hole directly
Problems related to incorrect use of `_` where previously diagnosed
by syntactic diagnostics which meant that it could only happen on
type-checked AST. This is no longer a case so we don't have to allow
incorrect uses of `_` to form solution without any fixes.
2020-03-25 08:33:36 -07:00
Pavel Yaskevich
16c1f50eda [ConstraintSystem] Diagnose incorrect use of _ during constraint generation
`_` or discard assignment expression should only be used on the left-hand
side of the assignment expression. Incorrect uses are easy to detect during
constraint generation which also allows us to avoid complications related
to other diagnostics when `_` is used incorrectly.
2020-03-24 16:51:44 -07:00
Pavel Yaskevich
465b0e193a [ConstraintSystem] Diagnose more cases of invalid nil use during constraint generation
Move check for `nil` destination of conditional casts to `visitNilLiteral` and
add support for `nil?` which wasn't previously detected.
2020-03-24 14:57:27 -07:00