Commit Graph

672 Commits

Author SHA1 Message Date
Pavel Yaskevich
888ab81c1e [ConstraintSystem] Connect closure to outer pack expansions it appears in
Type variable reference collector needs to be augmented to collect
type variables associated with pack expansions that a closure references
elements of, otherwise it would get disconnected from the context.
2024-05-22 14:42:39 -07:00
Doug Gregor
39f4e38027 Diagnose inout uses of 'lets' in constructors in the type checker.
Stored `let` properties of a struct, class, or actor permit
'inout' modification within the constructor body after they have been
initialized. Tentatively remove this rule, only allowing such `let`
properties to be initialized (assigned to) and not treated as `inout`.

Fixes rdar://127258363.
2024-05-14 15:59:50 -07:00
Slava Pestov
da31c59bcb Sema: Track active pack expansions across closure boundaries 2024-04-30 21:38:45 -04:00
Anthony Latsis
d18a7fd073 Sema: Require CS to certify conversions associated w/ existential member accesses 2024-04-18 22:54:19 +03:00
Alex Hoppen
278ecef284 [CodeCompletion] Don’t report a call pattern as convertible if its result type doesn’t match
To compute the expected type of a call pattern (which is the return type of the function if that call pattern is being used), we called `getTypeForCompletion` for the entire call, in the same way that we do for the code completion token. However, this pattern does not generally work. For the code completion token it worked because the code completion expression doesn’t have an inherent type and it inherits the type solely from its context. Calls, however, have an inherent return type and that type gets assigned as the `typeForCompletion`.

Implement targeted checks for the two most common cases where an expected type exists: If the call that we suggest call patterns for is itself an argument to another function or if it is used in a place that has a contextual type in the constraint system (eg. a variable binding or a `return` statement). This means that we no longer return `Convertible` for call patterns in some more complex scenarios. But given that this information was computed based on incorrect results and that in those cases all call patterns had a `Convertible` type relation, I think that’s acceptable. Fixing this would require recording more information in the constraints system, which is out-of-scope for now.
2024-04-10 16:06:47 -07:00
Pavel Yaskevich
a7f9a689fc [ConstraintSystem] Move @Sendable inference for partially applied members to adjustFunctionTypeForConcurrency 2024-03-22 09:02:32 -07:00
Pavel Yaskevich
eb9755367c [ConstraintSystem] NFC: Switch adjustFunctionTypeForConcurrency to use FunctionType
This method is always called after the type is opened by the solver
which means that we never end up with `GenericFunctionType`.
2024-03-20 13:16:18 -07:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Doug Gregor
81ffafdc6a Merge pull request #70602 from ApolloZhu/macro/expression-as-default-argument
[Macros] Expression macro as caller-side default argument
2024-02-14 16:10:11 -08:00
Pavel Yaskevich
0db22316a2 [ConstraintSystem] Record conformances synthesized for ad-hoc distributed requirements 2024-02-12 14:26:30 -08:00
Pavel Yaskevich
29a086d8ec [ConstraintSystem] NFC: Pass an underlying declaration to Solution::computeSubstitutions
This is going to be used to determine whether the substitutions are
computed for `DistributedActorSystem::remoteCall` and adjust the
generic signature with witness conformance requirements.
2024-02-12 13:23:51 -08:00
Hamish Knight
2c77947000 Merge pull request #71006 from hamishknight/implicit-last-expression
Introduce implicit last expression results
2024-02-08 10:15:01 +00:00
Hamish Knight
33cdd33f9e [CS] Account for implicit returns in closures
Avoid defaulting to Void if we have an implicit
return from which we can infer the result type.
2024-02-07 18:14:23 +00:00
Hamish Knight
1003b2f30b [CS] Remove CTP_ImpliedReturnStmt
Unify with `CTP_ReturnStmt`, and have the
SyntacticElementTarget carry the ReturnStmt for
regular type-checking, which we can use to record
implied returns.
2024-02-07 18:14:23 +00:00
Hamish Knight
61a4148925 [CS] Generalize implied result handling
Track the implied result exprs in the constraint
system, and allow arbitrary propagation of
implied results down if/switch expression
branches. This is required for allowing implied
results in non-single-expression closures.
2024-02-07 18:14:22 +00:00
John McCall
2f8a33cf0a Experimental type-checking support for @isolated(any) function types. 2024-02-06 22:54:27 -05:00
Apollo Zhu
b09a22a9a0 Somewhat working
Test shadowed variable of same type

Fully type check caller side macro expansion

Skip macro default arg caller side expr at decl primary

Test macro expand more complex expressions

Set synthesized expression as implicit

Add test case for with argument, not compiling currently

Test with swiftinterface

Always use the string representation of the default argument

Now works across module boundary

Check works for multiple files

Make default argument expression work in single file

Use expected-error

Disallow expression macro as default argument

Using as a sub expression in default argument still allowed as expression macros behave the same as built-in magic literals
2024-02-06 15:02:11 -08:00
Hamish Knight
16cfca4186 [ASTWalker] NFC: Rename SkipChildren -> SkipNode
This better describes what the action currently
does, and allows us to re-introduce `SkipChildren`
with the correct behavior.
2024-02-05 15:27:25 +00:00
Frederick Kellison-Linn
0735629c8d Merge pull request #39612 from Jumhyn/keypath-function-conversion
[ConstraintSystem] Allow function-function conversions for keypath literals
2024-02-03 10:26:13 -08:00
Hamish Knight
d9fd4c75b1 [CS] Remove isInputExpression parameter
This wasn't consistently used, and consequently
could result in some expressions getting their
parents invalidated. Instead, replace it with a
query to make sure we don't try and add an
expression we've already computed the parent info
for.
2024-01-31 20:26:20 +00:00
Sima Nerush
066f253d2e Merge pull request #70196 from simanerush/nested-pack-iteration
[SE-0408] Enable nested iteration
2024-01-27 10:18:12 -08:00
Sima Nerush
0b167b55b1 [ConstraintSystem] Cache pack element generic environments associated withfor-in loops over parameter packs to apply in getPackElementEnvironment. 2024-01-27 00:12:33 -08:00
Frederick Kellison-Linn
0d79f4523a Allow function-function conversions for keypath literals
Remove keypath subtype asserts; always use cached root type

Add tests for keypaths converted to funcs with inout param

Add unit test for overload selection
2024-01-23 08:51:44 -05:00
Alex Hoppen
dd5486cda8 [Sema] Remove ConjunctionElement::mightContainCodeCompletionToken
Isn’t used anymore (I think it stopped being used after the new result builder transform was enabled).
2024-01-22 19:52:33 -08:00
Pavel Yaskevich
60c20536ee [ConstraintSystem] NFC: Extract isResultBuilderMethodReference into a namespace method 2024-01-19 15:11:41 -08:00
Sima Nerush
7aa3c26bec [Docs] Add details for addMaterializePackExpansionConstraint 2023-12-25 11:57:55 -08:00
Pavel Yaskevich
a288b1eb76 [CSBindings] Key path cannot be bound to typ erased type even if its existential
Extend existing check to handle type erased versions when they
are wrapped in an existential.
2023-12-19 13:36:46 -08:00
Sima Nerush
2fd5843a79 Merge pull request #70355 from simanerush/pack-iteration-fixes
[SE-0408] Pack iteration review feedback!
2023-12-16 09:50:31 -08:00
Sima Nerush
0482bd3652 [Sema] Refactor code and improve documentation pertaining to SE-0408. 2023-12-15 20:39:40 -08:00
Doug Gregor
ae5f66ac11 Record throwing property accesses as potential throw sites 2023-12-13 16:36:14 -08:00
Doug Gregor
8ad137fb51 [Typed throws] Infer thrown error type for do..catch blocks within closures.
Start classifying all potential throw sites within a constraint
system and associate them with the nearest enclosing catch node. Then,
determine the thrown error type for a given catch node by taking the
union of the thrown errors at each potential throw site. Use this to
compute the error type thrown from the body of a `do..catch` block
within a closure.

This behavior is limited to the upcoming feature `FullTypedThrows`.
2023-12-13 14:59:23 -08:00
Sima Nerush
b6d0afba1f Merge pull request #67594 from simanerush/simanerush/pack-iteration-impl
[SE-0408] Enable Pack Iteration
2023-12-07 17:09:48 -08:00
Pavel Yaskevich
911ba101e7 [CSBindings] Extend early array literal favoring to cover dictionaries
Follow-up to https://github.com/apple/swift/pull/70148

Just like with arrays it's advantageous to favor dictionary
literals over disjunctions to bind the elements together and
enable inference across elements and, as a consequence,
type pruning.

Resolves: rdar://119040159
2023-12-04 15:01:27 -08:00
Holly Borla
48cb3309bd [Constraint System] Fix the shape class and context substitiutions for
opened element generic environments containing same-element requirements.
2023-12-03 21:51:41 -08:00
Pavel Yaskevich
dde501485e [CSBinding] Prefer array literal type over a disjunction in certain cases
If array literal type is not delayed and doesn't have any type variables
associated with it, let's prefer it over a disjunction to facilitate
type propagation through its `Element` type to element expressions.

Resolves: rdar://118993030
2023-11-30 17:43:13 -08:00
Pavel Yaskevich
c5d393f04f [ConstraintSystem] NFC: Adjust comment for isKnownKeyPath to cover all currently checked types 2023-11-28 13:02:17 -08:00
Pavel Yaskevich
2e1ca0a32a [ConstraintSystem] Extend KeyPathCapability to support sendability 2023-11-28 13:02:14 -08:00
Pavel Yaskevich
bd4ee4681b Merge pull request #70007 from xedin/keypath-application-improvements
[ConstraintSystem] Modernization of key path application handling
2023-11-28 12:44:42 -08:00
Slava Pestov
f89b9817e7 Merge pull request #69950 from slavapestov/clean-up-open-existentials
Cleanups and fixes for opened existentials
2023-11-28 10:45:19 -05:00
Slava Pestov
c0f9d290fa AST: Move TypeBase::typeEraseOpenedArchetypesWithRoot() into ConstraintSystem.cpp 2023-11-27 14:05:36 -05:00
Alex Hoppen
b603a5e9a0 [Sema] Remove LeaveClosureBodiesUnchecked
This shouldn’t be needed anymore since we migrated code completion to be solver-based.

rdar://91403086
2023-11-23 11:41:29 -08:00
Pavel Yaskevich
f440dd8e37 [ConstraintSystem] Update key path subscript index type variable to use new locator element 2023-11-17 15:47:44 -08:00
Pavel Yaskevich
e67dfc182b [CSSimplify] Remove obsolete key path capability inference and matching
The capability inference is now handled by the binding inference
and that makes resolved key path matching to bound type is no longer
necessary.
2023-11-08 19:54:31 -08:00
Pavel Yaskevich
8292c7d68f [ConstraintSystem] Add a way to check whether type variable represents a key path root type 2023-11-08 19:54:31 -08:00
Angela Laar
eb277d9ee7 Merge pull request #67498 from angela-laar/implicit-sendable-for-methods
[Sema] Implicitly add @Sendable attribute to partial methods
2023-11-07 16:46:16 -08:00
Angela Laar
c09ec72e85 [Constraint System] Always add Sendable to unapplied function applications 2023-11-07 13:37:24 -08:00
Pavel Yaskevich
b129d92937 Merge pull request #69549 from xedin/rdar-117227549
[ConstraintSystem] Rework overload ranking based on Sendable conformances
2023-11-02 09:42:49 -07:00
Pavel Yaskevich
dff578638a [ConstraintSystem] Move SK_MissingSynthesizableConformance before SK_UnappliedFunction
This would make sure that if property is non-Sendable we'd pick
a method if it's Sendable instead.
2023-11-01 10:50:39 -07:00
Pavel Yaskevich
d74c4723dc [ConstraintSystem] De-duplicate key path constraint simplification
Move some of the checks from the constraint simplification into
`inferKeyPathLiteralCapability` and start using it for both
inference and constraint simplification.
2023-11-01 09:15:14 -07:00