Commit Graph

24025 Commits

Author SHA1 Message Date
Slava Pestov
c26cafc47a AST: Remove bogus PackExpansionType logic in lookupConformance() 2023-08-09 18:28:22 -04:00
Slava Pestov
f219274e9b AST: Remove generic signature and conditional requirements from BuiltinProtocolConformance 2023-08-09 17:42:57 -04:00
Slava Pestov
bae8e69255 Sema: Availability checking needs to walk into PackConformances 2023-08-09 17:42:25 -04:00
Slava Pestov
7f9a71cd15 AST: Rename ASTContext::getConformance() to getNormalConformance() 2023-08-09 17:42:25 -04:00
Slava Pestov
1bccedaa5b Sema: Allow getInterfaceType() to be called on BuiltinTupleType 2023-08-09 17:42:25 -04:00
Slava Pestov
59bdf6630c Sema: Move tuple conformance diagnostic to TypeCheckDeclPrimary.cpp 2023-08-09 17:42:25 -04:00
Slava Pestov
971faebb61 Sema: Allow deriving hashValue witness in a tuple conformance to Hashable 2023-08-09 17:42:25 -04:00
Slava Pestov
fbd1f1acbd Sema: Fix a couple of problems in checkContextualRequirements()
The original bug was a crash-on-invalid with a missing '}', but it
actually exposed a bug with nested protocols (SE-0404) and another
long-time bug.

- Whatever we do, we should skip this for protocols because their 'Self'
  parameter is not bound from context.

- getTrailingWhereClause() is not the right proxy for "has a generic
  signature different than its parent", in particular it doesn't
  round-trip through serialization. Instead, just compare generic
  signatures for pointer equality in the early return check.

The second change is source-breaking because it was possible to
write a nested type with a `where` clause and use it contradicting
its requirements across a module boundary.

Fixes rdar://113103854.
2023-08-08 15:06:08 -04:00
Hamish Knight
bc31eb1595 [CS] Solve all conjunctions in source order
Previously we would only do source ordering for
ClosureExprs, but other conjunctions need to have
their source location taken into account too, in
order to make sure we don't try and type-check e.g
a TapExpr in a second closure before we type-check
the first closure.

Also while here, switch to `std::min_element`
instead of sorting, and treat invalid source
locations as incomparable.

rdar://113326835
2023-08-08 18:08:53 +01:00
Slava Pestov
6ae2a1deee Merge pull request #67739 from slavapestov/var-decl-type-in-context
AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
2023-08-04 21:44:22 -04:00
Slava Pestov
6c5074f6e8 Merge pull request #67749 from slavapestov/tuple-conformance-test
AST/Sema: Fix a couple of minor issues with tuple conformances and add a new test case
2023-08-04 21:43:53 -04:00
Pavel Yaskevich
27413f5624 [CSSimplify] Relax isBindable requirements for pack expansion variables
If type variable we are about to bind represents a pack
expansion type, allow the binding to happen regardless of
what the \c type is, because contextual type is just a hint
in this situation and type variable would be bound to its
opened type instead.

Resolves: rdar://112617922
2023-08-04 16:49:20 -07:00
Holly Borla
3d1310a8ab Merge pull request #67730 from hborla/non-sendable-base
[Concurrency] Diagnose non-sendable 'self' arguments crossing isolation boundaries.
2023-08-04 16:17:35 -07:00
Hamish Knight
7e2cdf813c Merge pull request #67626 from hamishknight/try-without-completion-drop 2023-08-04 22:24:08 +01:00
Slava Pestov
979acd9025 AST/Sema: Fix a couple of minor issues with tuple conformances and add a new test case
The progress on variadic generics means we can now implement useful
witnesses in a tuple conformance. The feature remains very incomplete
though, today we crash in SILGen.
2023-08-04 16:33:47 -04:00
Pavel Yaskevich
3dff3e5a49 [CSSimplify] Avoid eager matching between pack expansion and its contextual type
This is effectively a premature optimization. Contextual type might
not be fully resolved yet, so let's give solver a chance to do it for us.
2023-08-04 11:21:16 -07:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04:00
Doug Gregor
c251b3cf56 Merge pull request #67732 from DougGregor/trc-attributes
Expand type refinement contexts to encompass attributes
2023-08-04 10:12:02 -07:00
Pavel Yaskevich
44cb14f849 Merge pull request #67441 from xedin/fix-overly-eager-closure-resolving
[CSBindings] Prefer conjunctions over closure variables without bindings
2023-08-04 09:42:50 -07:00
Holly Borla
6a4c7891b8 [Concurrency] Diagnose non-sendable 'self' arguments crossing isolation boundaries. 2023-08-04 09:32:41 -07:00
Doug Gregor
0e80b4e710 Expand type refinement contexts to encompass attributes 2023-08-03 23:44:50 -07:00
Pavel Yaskevich
043d2aa3dd [CSSimplify] NFC: Straighten checking of type variable passed to resolvePackExpansion
The type variable should always be one for pack expansion type which
implies that locator always ends at `PackExpansionType`.
2023-08-03 14:11:09 -07:00
Hamish Knight
6ede5e050f [CodeComplete] Avoid dropping "is for code completion" bit
This should no longer be needed now that we check for a code
completion token when increasing the score. It should also
allow us to skip more conjunction elements, as that requires
the bit being set.
2023-08-03 21:16:10 +01:00
Doug Gregor
300d04a2d4 Merge pull request #67642 from DougGregor/lazy-type-refinement-context
Eliminate Observable circular reference errors via lazier TypeRefinementContext building
2023-08-03 12:47:19 -07:00
Pavel Yaskevich
f1f74f0b0b Merge pull request #67663 from amritpan/kp-root-value-tv-inference
[ConstraintSystem] Allow inference to bind AnyKeyPath as a KeyPath
2023-08-03 09:36:32 -07:00
Pavel Yaskevich
b8bbc8a9ce Merge pull request #67679 from xedin/fix-distributed-actor-init-synthesis
[TypeChecker] Make sure that distributed actors always get "default" init
2023-08-03 09:35:49 -07:00
swift-ci
bb6df83b63 Merge pull request #67701 from hamishknight/small-fixes
A couple of small fixes
2023-08-03 08:26:58 -07:00
Doug Gregor
f62c6c062e Merge pull request #67698 from DougGregor/macro-reference-availability
[Macros] Emit deprecation warnings for uses of macros.
2023-08-03 07:08:42 -07:00
Hamish Knight
e22180ba2e [CS] Add missing break 2023-08-03 13:00:12 +01:00
Doug Gregor
c3af8cbe42 [Macros] Diagnose availability of attached macros 2023-08-02 23:23:38 -07:00
Doug Gregor
0a1fbe7f30 [Macros] Emit deprecation warnings for uses of freestanding macros.
Fixes rdar://113138432.
2023-08-02 22:58:11 -07:00
Doug Gregor
37959de29e Establish type refinement contexts for pattern binding decls directly
The type refinement context builder had a bunch of logic to try to
model type refinement contexts for the first variable declaration that
shows up within a pattern binding declaration. Instead, model this
more syntactically by creating a type refinement context for the
pattern binding declaration itself. This both addresses a regression
in the handling of `if #available` within a closure that's part of an
initializer, and fixes a bug in the same area where similar code has
explicit availability annotations.
2023-08-02 15:07:09 -07:00
Doug Gregor
7f031dfdd4 Drop unnecessary "parent context" state from TypeRefinementContextBuilder
This state is a holdover from when accessors we stored "alongside"
their variable declarations, rather than contained within them. That's
no longer the case, so we don't need to track this information any
more.
2023-08-02 15:07:09 -07:00
Doug Gregor
0d779dfd10 [Type refinement context] Avoid creating implicit contexts with bad ranges 2023-08-02 15:07:08 -07:00
Doug Gregor
3079f3d074 [Type refinement context] Lazily expand TRCs for pattern bindings
Eager expansion of type refinement contexts (TRCs) for variables
within pattern binding declarations is causing cyclic references in
some places involving macros. Make this expansion lazy, triggered by
walking into these pattern binding declarations as part of (e.g.)
availability queries.

Another step toward fixing the cyclic references in rdar://112079160.
2023-08-02 15:07:07 -07:00
Doug Gregor
b5d3e0b6f7 [Type refinement context] Don't query property wrappers just for range info
Querying property wrappers involves semantic analysis that can cause
cyclic references while building the type refinement context, and it's
unnecessary: we need only know that these are custom attributes to
incorporate their source ranges. Switch to the simpler/cheaper query.

A small part of fixing the cyclic references in rdar://112079160.
2023-08-02 15:07:05 -07:00
Pavel Yaskevich
e2bac24023 [TypeChecker] Make sure that distributed actors always get "default" init
Default initialization of stored properties doesn't play a role
in default init synthesis for distributed actors.
2023-08-02 10:30:44 -07:00
Pavel Yaskevich
c659323598 Merge pull request #67597 from amritpan/kp-value-mismatch-diagnostic
[ConstraintSystem] Delay Contextual Type Fix record for key paths
2023-08-02 09:26:31 -07:00
Hamish Knight
63cc9260c1 Merge pull request #67563 from hamishknight/complete
[CodeComplete] Properly handle `if`/`switch` expressions
2023-08-02 09:56:46 +01:00
Amritpan Kaur
e8425bf4c8 [CSGen] Update LocatorPathElt::KeyPathType usage. 2023-08-01 09:18:15 -07:00
Amritpan Kaur
1384ff0038 [CSBinding] Allow inference to bind AnyKeyPath as a KeyPath
that can be converted to AnyKeyPath later.
2023-08-01 09:15:04 -07:00
Hamish Knight
c48b77f486 [CodeComplete] Don't skip single-expression AssignExpr bodies of an if/switch expr
Fix an issue uncovered by the stress tester where
the brace element skipping logic could still attempt
to skip a single-expression body of an if/switch
expr.
2023-08-01 15:21:30 +01:00
Hamish Knight
1dd86fccdb [CodeComplete] More efficient skipping for completions in if/switch exprs
Skip type-checking multi-statement branches if the
completion is in a single-expression branch, and
skip type-checking the expression as a whole if
the completion is in a multi-statement branch.
2023-08-01 15:21:29 +01:00
Hamish Knight
d8d8db987b [CodeComplete] Properly handle if/switch exprs
Run PreCheckFunctionBodyRequest to ensure we insert
an implicit return for an if/switch if needed, and
ensure we don't try and type-check an element in a
SingleValueStmtExpr separately, as it should be
type-checked as a whole by the constraint system.
This ensures we can propagate a contextual type from
outside an if/switch expression for code completion.
2023-08-01 15:21:29 +01:00
Hamish Knight
bf3c807c27 [Sema] Introduce PreCheckFunctionBodyRequest
Split out the part of TypeCheckFunctionBodyRequest
that inserts and removes implicit returns.
2023-08-01 15:21:29 +01:00
Allan Shortlidge
e4810f5304 Sema: Fix unavailable enum element cases in derived hashable/equatable impls.
When deriving the `hash(into:)` and `==` witnesses for `Hashable`/`Equatable`
enums, call `_diagnoseUnavailableCodeReached()` in the case bodies for
unavailable enum elements. This is needed because the previously derived code
would operate on the values associated with unavailable enum elements, which is
illegal if the types of those associated values are also unavailable (these
case bodies would have failed typechecking had they been hand-written). The new
structure also more explicitly documents that reaching these cases is
unexpected, since unavailable enum elements should not be instantiated at run
time.
2023-07-31 22:44:52 -07:00
Allan Shortlidge
7ea0723f5b NFC: Clarify comment in TypeCheckSwitchStmt.cpp.
Unavailable cases _can_ be written in switch statements. However, they should
not be required to be written for exhaustive matching.
2023-07-31 17:26:34 -07:00
Allan Shortlidge
903e68b289 NFC: Test derived Comparable conformances for enums with unavailable cases.
Also, add a FIXME to track improving the diagnostics when derivation of a
Comparable conformance is blocked by unavailable enum cases.
2023-07-31 17:26:34 -07:00
Amritpan Kaur
3604551172 [CSSimplify] Handle keypathvalue constraint locator 2023-07-31 09:50:32 -07:00
Amritpan Kaur
36031f3b3d [CSSimplify] Prevent contextual type failure fix record 2023-07-31 09:50:27 -07:00