Commit Graph

23610 Commits

Author SHA1 Message Date
Pavel Yaskevich
fe6cfe2d85 [CSDiagnostics] Diagnose conformance failures related to pack expansion patterns 2023-05-23 09:47:48 -07:00
Becca Royal-Gordon
6c08ff7289 [NFC] Change how @objcImpl async matching is done
apple/swift#65253 (79e26970) made it so that the async and completion-handler variants of a member would both be matched by the same implementation, but the technique used composes poorly with typechecking work later in this series of commits. Reimplement it so that async variants are filtered out of `ObjCImplementationChecker::unmatchedRequirements` and then async candidates are compared against async alternatives later, during matching.
2023-05-23 00:37:58 -07:00
Pavel Yaskevich
70e4cf0ac8 [ConstraintSystem] Limit assert in getFunctionArgApplyInfo to types without type parameter packs
If function type of some declaration has a at least on type parameter
pack it could mean that number of parameters in "applied" type could
be different from that of "interface" type.
2023-05-22 11:32:38 -07:00
Hamish Knight
58d6694783 Requestify ExportedSourceFile parsing
Avoid parsing the syntax tree up-front, and instead
only parse it when required, which happens when either:

1. ASTGen parsing is enabled (currently disabled
   by default)
2. Round trip checking is enabled for a primary
   file (enabled by default in a debug build,
   except when dep scanning or doing an IDE
   operation)
3. We need to evaluate a macro in that file

This change therefore means that we now no longer
need to parse the syntax tree for secondary files
by default unless we specifically need to evaluate
a macro in them (e.g if we need to lookup a member
on a decl with an attached macro). And the same
for primaries in release builds.

rdar://109283847
2023-05-22 14:55:19 +01:00
Michael Gottesman
d1dd4c164e Merge pull request #65935 from gottesmm/rdar101862423
[copy-operator] Add support for the copy operator in preparation for  making consuming and borrowing no implicit copy.
2023-05-19 14:50:45 -07:00
Konrad `ktoso` Malawski
181161cccc Merge pull request #66020 from ktoso/wip-distributed-dont-crash-compile-on-empty-system 2023-05-19 22:05:25 +02:00
Becca Royal-Gordon
2333ff5a20 Diagnose @objcImpl kind and settability errors
Sema now diagnoses @objcImpl implementations with:

• The wrong settability (i.e. a `let` used for a `readwrite` property)
• The wrong kind (i.e. a method used for a property)
2023-05-19 11:48:25 -07:00
Konrad `ktoso` Malawski
00243c6d8b [Distributed] Report error rather than crash no ad-hoc requirements are implemented 2023-05-19 16:06:53 +02:00
Pavel Yaskevich
3b1f392d0a Merge pull request #65785 from angela-laar/fix-covariant-erasure-for-constrained-existentials
Fix covariant erasure for constrained existentials
2023-05-18 16:58:45 -07:00
Rintaro Ishizaki
bb97dc625e Merge pull request #65978 from rintaro/macros-plugin-searchorder-rdar109163929
[Macros] Rearrange plugin search order
2023-05-18 09:48:38 -07:00
Michael Gottesman
67fcb1c86e [consume-operator] Change consume so that its result is not considered an lvalue.
Before this change it was possible to:

1. Call mutating methods on a consume result.
2. assign into a consume (e.x.: var x = ...; (consume x) = value.

From an implementation perspective, this involved just taking the logic I
already used for the CopyExpr and reusing it for ConsumeExpr with some small
tweaks.

rdar://109479440
2023-05-17 22:42:42 -07:00
Michael Gottesman
fd25cf379a Rename MoveExpr -> ConsumeExpr to reflect the final name.
NFC.
2023-05-17 22:42:42 -07:00
Michael Gottesman
e6f1691122 [copy-operator] Add support for the copy operator in preparation for making consuming and borrowing no implicit copy.
Some notes:

1. I implemented this as a contextual keyword that can only apply directly to
lvalues. This ensures that we can still call functions called copy, define
variables named copy, etc. I added tests for both the c++ and swift-syntax based
parsers to validate this. So there shouldn't be any source breaks.

2. I did a little bit of type checker work to ensure that we do not treat
copy_expr's result as an lvalue. Otherwise, one could call mutating functions on
it or assign to it, which we do not want since the result of copy_value is

3. As expected, by creating a specific expr, I was able to have much greater
control of the SILGen codegen and thus eliminate extraneous copies and other
weirdness than if we used a function and had to go through SILGenApply.

rdar://101862423
2023-05-17 22:42:42 -07:00
Angela Laar
a9f1096839 [Generic Signature] Unify generic upper bound functions
Opened existentials should be erased to the dependent upper bound
if the dependent member can be reduced to a concrete type. This
allows the generic signature to support parameterized protocol types
and bound generic class types by producing a more specific constraint
instead of just a plain protocol or class.
2023-05-17 15:33:50 -07:00
Rintaro Ishizaki
707f320b56 Merge pull request #65959 from rintaro/macros-typerefinement-context
[Macros] Create type refinement context for MacroExpansionDecl
2023-05-17 13:06:43 -07:00
Rintaro Ishizaki
3637885139 [Macros] Rearrange plugin search order
New ordring is:
1) `-load-plugin-library`
2) `-load-plugin-executable`
3) `-plugin-path`
4) `-external-plugin-path`

rdar://109163929
2023-05-17 10:53:36 -07:00
Rintaro Ishizaki
7c2a73ebbd [Macros] Create type refinement context for MacroExpansionDecl 2023-05-16 20:47:12 -07:00
Pavel Yaskevich
1728cca5f0 [CSBindings] Mark type variables that represent type parameter packs as "involving type variables"
Such type variables are always dependent on pack expansion type variables
which should be bound first.
2023-05-16 16:32:24 -07:00
Pavel Yaskevich
ce826c2137 Revert "[CSBindings] Mark type variables that represent packs as involving type variables"
This reverts commit 8a39f3f38d.
2023-05-16 14:48:32 -07:00
Pavel Yaskevich
a987861d1c Merge pull request #65806 from xedin/rdar-108977234
[CSSimplify] Detect and diagnose conformance failures related to AnyHashable conversion
2023-05-16 09:56:41 -07:00
Pavel Yaskevich
fdf6d62ece Merge pull request #65830 from xedin/rdar-108904190
[CSSimplify] Allow converting pack expansion types and tuples with pack expansions to Void for closure result
2023-05-16 09:56:27 -07:00
Slava Pestov
31bfa4b78c Merge pull request #65936 from slavapestov/se-0398-accepted
Unconditionally enable variadic generic types now that SE-0398 has been accepted
2023-05-16 07:34:31 -04:00
Kavon Farvardin
7816138cf4 Merge pull request #65931 from kavon/discard-generics-v2
more `discard` fixes in Sema
2023-05-15 21:17:07 -07:00
Slava Pestov
e9e6a51c82 Unconditionally enable variadic generic types now that SE-0398 has been accepted 2023-05-15 23:32:52 -04:00
Anthony Latsis
3f629315a9 Merge pull request #65731 from AnthonyLatsis/always-print-any
ASTPrinter: Turn on explicit `any` printing for everything and remove the option to disable it
2023-05-16 03:27:36 +03:00
Pavel Yaskevich
96cbc01822 Merge pull request #65861 from xedin/rdar-109160060
[CSSimplify] Allow conversions between tuples with pack expansions and `Any`
2023-05-15 16:20:50 -07:00
Pavel Yaskevich
dc4ee4b61a [CSSimplify] Allow converting tuple with pack expansions to Void for closure result
Maintains existing rule where single-expression closure is allowed
to convert to contextual function type with `Void` result.
2023-05-15 16:20:01 -07:00
Pavel Yaskevich
effa261266 [CSSimplify] Move invalid pack expansion check to enable closure result conversion
Checking for pack expansion type mismatch impedes non-Void-to-Void
conversion allowed for single-expression closures.

Resolves: rdar://108904190
2023-05-15 16:19:59 -07:00
Pavel Yaskevich
406b7a62c7 Merge pull request #65718 from xedin/diagnose-missing-each-in-expr-context
[ConstraintSystem] Detect and diagnose missing 'each' and provide a fix-it
2023-05-15 16:18:55 -07:00
Angela Laar
5c818b3fd4 [Constraint System] Fix covariant erasure for constrained existentials
Constrained existentials should be type erased to an upper bound that is dependent on other type parameters.
2023-05-15 16:17:59 -07:00
Kavon Farvardin
1c9ed33fba ensure you cannot discard a local called self
previous checking for the expr being `self`
was checking for the decl being named `self`.

that meant you could do naughty things like:

```
let `self` = Self()
discard `self`
```

rdar://109376381
2023-05-15 16:14:35 -07:00
Kavon Farvardin
da9847a841 fix typechecking for discard in generics
Don't use `getDeclaredTypeInContext` it gives
the wrong types for generic params.

rdar://108975216
2023-05-15 15:37:23 -07:00
Slava Pestov
b6a2791de9 Merge pull request #65899 from slavapestov/variadic-type-availability
Variadic type availability
2023-05-15 17:09:21 -04:00
Rintaro Ishizaki
ee5b3b134b Merge pull request #65815 from rintaro/macros-attributes-rdar107386648
[Macros/Parse] Attributes on MacroExpansionDecl
2023-05-15 13:28:53 -07:00
Hamish Knight
4cafd90c01 [Sema] Allow if/switch expressions in optional chain assignments
Make sure we look through a wrapping
`OptionalEvaluationExpr` and its injections when
looking for an assignment to mark a valid if/switch
source expression.

rdar://109305454
2023-05-15 11:58:28 +01:00
Slava Pestov
4318a36be6 Sema: Availability checking for variadic generic types 2023-05-12 22:50:25 -04:00
swift-ci
187f823683 Merge pull request #65898 from kavon/subscript-ownership-fixit
improve error when using noncopyable type with subscript
2023-05-12 19:16:15 -07:00
Slava Pestov
0901790dca Sema: Clean up some duplicated code in availability checking 2023-05-12 22:05:28 -04:00
swift-ci
7c3e480218 Merge pull request #65896 from kavon/discard-generic-noncopyable
allow `discard` in generic noncopyable type
2023-05-12 18:36:05 -07:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Kavon Farvardin
3ce82442fd improve error when using noncopyable type with subscript
Subscripts today don't support any form of ownership specifier
for its parameters Since noncopyable types require such a
specifier, it's not helpful to emit an error suggesting to add
the specifier.

rdar://109233314
2023-05-12 16:39:56 -07:00
Kavon Farvardin
20b060b893 allow discard in generic noncopyable type
A bug was preventing you from writing `discard self`
in a consuming method of a generic noncopyable type.

The main cause was the `isPureMoveOnly` ignored
unbound generic types, claiming none of them are
noncopyable. Then I also needed to pass the contextual
type with the vars bound to the type checker.

rdar://108975216
2023-05-12 16:11:38 -07:00
swift-ci
bc9acf98d8 Merge pull request #65840 from kavon/async-requirement-matching
Witness selection should pick exact matches for effect overloads
2023-05-12 14:14:42 -07:00
Kavon Farvardin
3ae2ce5a7f Witness selection should pick exact matches for effect overloads
You can overload a function based on its `async`-ness, and
resolution is carried out based on async-ness of calling
context.

But during protocol conformance checking, for an `async`
requirement we were accidentally choosing the non-`async
overload instead of the `async` one. The `async` one is
the choice people would expect, since the `async` requirement
is in essence the "context" that forwards to the underlying
witness. This intended behavior is also inferred from:

https://github.com/apple/swift/pull/40088

The problem boiled down to a bad check when categorizing the
witness matches prior to ranking them.

Resolves rdar://109135488 / https://github.com/apple/swift/issues/60318
2023-05-12 11:03:48 -07:00
Rintaro Ishizaki
9fc1521aeb [Macros/Parser] Attributes on MacroExpansionDecl
* Parse `#<identifier>` attribute list as a `MacroExpansionDecl`
  regardless of the position
* Diagnose whitespaces between `#` and the macro name.
* Correctly attach attributes to `MacroExpansionDecl`
* Fix `OrigDeclAttributes` to handle modifiers (use `getLocation()`
  instead of `AtLoc`.)

Type checking is a TODO

rdar://107386648
2023-05-11 12:04:35 -07:00
Pavel Yaskevich
181d2d1371 [CSSimplify] Allow conversions between tuples with pack expansions and Any
Don't attempt to wrap `Any` into a single-element tuple to match
against a tuple with pack expansions, this conversion would be
handled by existential promotion if it's allowed, otherwise it
would produce an error.

Resolves: rdar://109160060
2023-05-11 10:05:15 -07:00
Pavel Yaskevich
c9c631109b [CSDiagnostics] NFC: Move FailureDiagnostic::resolveType out of header 2023-05-09 14:11:45 -07:00
Pavel Yaskevich
440bc39207 [Diagnostics] Don't print pack element archetypes in diagnostics 2023-05-09 14:11:45 -07:00
Pavel Yaskevich
58ffca8f74 [ConstraintSystem] Don't produce partially matching note if none of the overloads matched 2023-05-09 14:11:38 -07:00
Kavon Farvardin
511eb44025 Merge pull request #65787 from kavon/forget-to-discard
rename `_forget` to `discard`; deprecate `_forget`
2023-05-09 07:30:49 -07:00