Commit Graph

1476 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
d673ed0989 Merge pull request #30519 from xedin/rdar-52204414
[ConstraintSystem] Don't allow explicit closure result to be implicitly converted to `Void`
2020-03-20 09:36:17 -07:00
Pavel Yaskevich
4876996b8c Merge pull request #30510 from HassanElDesouky/SR-12309-FollowUp
[CSGen] Diagnose `nil` with any number of parentheses
2020-03-20 00:13:50 -07:00
Robert Widmann
21cfcfef2c Merge pull request #30505 from CodaFi/ligated-legacy
[NFC] Remove the Legacy Semantic Queries Bit
2020-03-19 13:45:27 -07:00
Hassan El Desouky
5ff6fe20a9 Remove incorrect comment 2020-03-19 22:31:01 +02:00
Hassan El Desouky
a72ea640e6 Handle nil with any number of parentheses 2020-03-19 21:41:22 +02:00
Robert Widmann
6d60d01420 [NFC] Remove the Legacy Semantic Queries Bit
Clients that wish to avoid semantic requests should decline to register
those requests.
2020-03-19 11:04:12 -07:00
Doug Gregor
f2e581c7fc [Type checker] Look through reference storage types for typed patterns.
Fixes a regression caused by properly setting the context for checking
the type in a typed pattern.
2020-03-19 11:01:56 -07:00
Doug Gregor
3abea6be65 [Constraint system] Use the PatternBindingDecl context when possible.
Make sure that we're resolving types and patterns using the
PatternBindingDecl context, both for the type resolver context and the
contextual pattern used for pattern resolution.

Fixes a regression with implicitly-unwrapped options reported as
SR-11998 / rdar://problem/58455441.
2020-03-18 21:09:06 -07:00
Pavel Yaskevich
c72940f2c7 [ConstraintSystem] Default multi-statement closure result to Void only after resolving
Let's remove a side-effect from `ConstraintGenerator::inferClosureType`
and default result type to `Void` for multi-statement closures after
closure has been resolved.
2020-03-18 17:48:56 -07:00
Pavel Yaskevich
2d6170b847 [TypeChecker] Requestify check to determine if closure has explicit result
Determine whether closure body has any explicit `return`
statements which could produce a non-void result.
2020-03-18 17:06:15 -07:00
Robert Widmann
70b6bbcb13 Remove swift::createTypeChecker
Replace it with the "legacy semantic queries" bit. The remaining client
of this bit is SourceKit, which appears to require this bit be set
conditionally so certain semantic property wrapper requests return
a sentinel value.

We should migrate these requests to a syntactic interface as soon as
possible.

rdar://60516325
2020-03-16 19:20:22 -07:00
Robert Widmann
c3c490efb0 Remove the ability to reference instances of TypeChecker 2020-03-16 19:19:02 -07:00
HassanElDesouky
e747dc25b1 Resolve issues 2020-03-14 08:02:23 +02:00
HassanElDesouky
8d5a33ee89 Move to visitNilLiteralExpr 2020-03-14 07:39:44 +02:00
HassanElDesouky
ceb3f3842f [SR-12309] Add more tests 2020-03-14 03:06:10 +02:00
HassanElDesouky
8195cce1d3 [SR-12309] Cannot force unwrap 'nil' 2020-03-14 01:28:28 +02:00
Pavel Yaskevich
f1f3b60713 [CSGen] Clarify locators for some of the patterns
- optional object type of `.some` pattern ends with `OptionalPayload`
- type of sub-pattern used in a cast points to underlying sub-pattern declaration
- Enum element:
  - parent type locator ends with `ParentType`
  - member lookup constraint locator ends at `Member`
2020-03-10 13:56:32 -07:00
Doug Gregor
1a981f917c [Constraint system] Clean up constraints associated with patterns.
Wherever we have constraints that involve pattern matching, use the
PatternMatch locator element. Additionally, don't use the TupleElement
locator element for tuple patterns, because it violates assumptions used
for diagnostics.

The new test was crashing; now it has a terrible diagnostic for which I
need to think harder about a fix.
2020-03-05 23:06:21 -08:00
Doug Gregor
8191aa4924 Merge pull request #30174 from DougGregor/function-builder-switch
[Constraint system] Implement switch support for function builders.
2020-03-03 12:34:08 -08:00
Doug Gregor
4b43573693 [Constraint system] Implement switch support for function builders.
Implement support for switch statements within function builders. Cases can
perform arbitrary pattern matches, e.g.,

    tuplify(true) { c in
      "testSwitchCombined"
      switch e {
      case .a:
        "a"
      case .b(let i, _?), .b(let i, nil):
        i + 17
      }
    }

subject to the normal rules of switch statements. Cases within function
builders cannot, however, include “fallthrough” statements, because those
(like “break” and “continue”) are control flow.

The translation of performed for `switch` statements is similar to that of
`if` statements, using `buildEither(first:)` and `buildEither(second:)` on
the function builder type.

This is the bulk of switch support, tracked by rdar://problem/50426203.
2020-03-02 17:25:25 -08:00
Doug Gregor
13b200ddd5 [Constraint system] Generalize saved ASTNode -> solution target mapping.
We are currently only using the “solution targets” map for statement
conditions, but we will need it for more entities soon. Start generalizing
now.
2020-03-02 08:43:55 -08:00