Commit Graph

950 Commits

Author SHA1 Message Date
Joe Groff
10f9289ef8 Enable 'BorrowingSwitch' feature. 2024-05-14 07:31:59 -07:00
Cal Stephens
da144f71ad Fix outdated usage of isKnownNoEscape 2024-05-04 14:08:43 -07:00
Cal Stephens
6b36f78f67 Remove unused validateOutermostCapture param 2024-05-04 12:37:43 -07:00
Cal Stephens
b525b9c7da Merge tag 'swift-DEVELOPMENT-SNAPSHOT-2024-05-01-a' of github.com:apple/swift into cal--fix-70089
Tag build swift-DEVELOPMENT-SNAPSHOT-2024-05-01-a
2024-05-04 12:19:16 -07:00
Cal Stephens
7d897fd383 Fix validation for async let thunks 2024-05-04 11:25:24 -07:00
Cal Stephens
d17bc35a93 Refactor and simplify shouldOnlyWarn logic 2024-05-04 10:10:53 -07:00
Cal Stephens
7e95f9b15a Fix unexpected error by simplifying outermost capture validation 2024-05-04 09:25:24 -07:00
Slava Pestov
c11beb5d2f Sema: Make wonky logic explicit in diagnoseImplicitSelfUseInClosure()
We walk up the DeclContext hierarchy looking for closures, but they might
not have had their types set yet because they're currently being type
checked.
2024-04-30 16:10:36 -04:00
Cal Stephens
e4e80787ac Simplify autoclosure check in shouldOnlyWarn 2024-04-25 07:36:32 -07:00
Cal Stephens
985e8d9941 Update DeclContext::getInnermostClosureForSelfCapture to return a ClosureExpr 2024-04-25 06:44:54 -07:00
Cal Stephens
74a33eb420 Improve 'shouldOnlyWarn' logic 2024-04-25 06:26:50 -07:00
Nate Chandler
23e7c36c5f [NoncopyablePartialConsumption] Ungate feature.
Remove all checks for the feature flag.  It's on all the time.
2024-04-19 12:37:34 -07:00
Cal Stephens
3fcc5a8f46 Always validate self capture 2024-03-31 19:50:44 -07:00
Pavel Yaskevich
6a5bd1042a Merge pull request #72527 from xedin/rdar-119593407-alternative
[TypeChecker] InferSendableFromCaptures: Infer `@Sendable` on adjusted types
2024-03-29 09:54:50 -07:00
Konrad `ktoso` Malawski
6132386371 [Distributed] Complete handling of protocol calls and witnesses using adjusted mangling scheme (#72416) 2024-03-23 23:54:23 +09:00
Pavel Yaskevich
64a200ab07 [MiscDiagnostics] Make sure that diagnostics look through function conversions
None of the diagnostics in MiscDiagnostics make a distinction between
sendable or actor-isolated function references which means that we can
skip conversions while reaching for a declaration used in an application.
2024-03-21 15:35:03 -07:00
Cal Stephens
3315cab336 Merge branch 'main' into cal--fix-70089 2024-03-18 16:44:09 -07:00
Kavon Farvardin
149c052ec5 use new noncopyable types infrastructure
The infrastructure underpinning the new feature NoncopyableGenerics is
mature enough to be used.
2024-03-14 23:10:44 -07:00
Cal Stephens
97178b2494 Look up the outer self decl via the capture's parent initializer instead of ASTScope::lookupSingleLocalDecl 2024-03-13 20:18:48 -07:00
Pavel Yaskevich
93fabf05ea Merge pull request #72239 from xedin/infersendablefromcaptures-fixes
[Sema] A few minor fixes for `InferSendableFromCaptures` feature
2024-03-13 14:12:01 -07:00
Kavon Farvardin
01864d9af4 Sema: replace legacy Copyable containment check
We can use part of the new infrastructure if we simply handle abstract
conformances to Copyable, which is what we'd get upon lookup for a
nominal in the old world. This means that we can merge diagnostics for
the containment test together, and fix differences with deinit
diagnostics.
2024-03-12 11:05:25 -07:00
Cal Stephens
f21aee7baa Improve quality of 'capture self explicitly to enable implicit self in this closure' and 'variable other than self captured here under the name self does not enable implicit self' diagnostics 2024-03-12 10:45:17 -07:00
Pavel Yaskevich
3376d03079 [MiscDiagnostics] KeyPath KVO diagnostics should handle existential opening
Sendable key path literals are represented as an existential
protocol composition with `Sendable` protocol which has to be
opened in certain scenarios i.e. to pass it to non-Sendable version.
2024-03-11 13:48:32 -07:00
Cal Stephens
94dcf9bc70 Fix edge cases related to nested autoclosures, invalid weak self unwrapping 2024-03-11 07:42:44 -07:00
Cal Stephens
8c5f783f5b [SE-0365] Fix issue where implicit self was unexpectedly disallowed in nested closures 2024-03-10 07:57:51 -07:00
Nate Chandler
74ab0f616c [NoncopyablePartialConsumption] Hone diagnostics.
Only noncopyable fields of noncopyable aggregates may be partially
consumed with the `consume` keyword.
2024-03-07 13:27:40 -08:00
Nate Chandler
fb0ae6ecbb [NoncopyablePartialConsumption] Allow consume.
Allow a noncopyable value to be partially consumed via the `consume`
keyword.
2024-03-06 18:58:38 -08:00
Anthony Latsis
5b7a8b6705 [NFC] AST: Rename MemberTypeReprQualifiedIdentTypeRepr 2024-03-02 14:59:37 +03:00
Anthony Latsis
68746a0579 [NFC] AST: Rename IdentTypeReprUnqualifiedIdentTypeRepr 2024-03-02 08:28:47 +03: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
Slava Pestov
1c24b880ec Merge pull request #70467 from AnthonyLatsis/recursive-member-typerepr
AST: Remodel `MemberTypeRepr` to be recursive
2024-02-16 11:36:31 -05: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
Anthony Latsis
d6fd424560 [NFC] MemberTypeRepr: getBaseComponent()getRoot() 2024-02-09 17:22:05 +03: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
d73e394ea7 Allow implicit last expression results for if/switch expressions
Allow implicitly treating the last expression of
the branch as the result, behind the experimental
feature `ImplicitLastExprResults`.
2024-02-07 18:14:22 +00: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
Hamish Knight
94c4d117a1 Remove some redundant post walks 2024-02-05 15:27:25 +00:00
Slava Pestov
9820d38f7f Sema: Use GenericSignature::getUpperBound() 2024-02-01 23:35:33 -05:00
Joe Groff
a52e96e358 Merge pull request #71263 from jckarter/borrowing-switch-3
Parse `_borrowing x` in patterns as a borrow binding.
2024-01-31 07:08:32 -08:00
Joe Groff
6706feaf5e Parse _borrowing x in patterns as a borrow binding.
Treat it as a contextual keyword when followed by an identifier, like our
other ownership-related declarations and operators.
2024-01-30 17:33:42 -08:00
Hamish Knight
9b64990d24 [AST] Remove the "single expression body" bit
Remove this bit from function decls and closures.
Instead, for closures, infer it from the presence
of a single return or single expression AST node
in the body, which ought to be equivalent, and
automatically takes result builders into
consideration. We can also completely drop this
query from AbstractFunctionDecl, replacing it
instead with a bit on ReturnStmt.
2024-01-30 14:08:54 +00:00
Doug Gregor
bb7a563e6c Switch async for-each loop over to _nextElement and drop @rethrows.
This couples together several changes to move entirely from
`@rethrows` over to typed throws:

* Use the `Failure` type to determine whether an async for-each loop
will throw, rather than depending on rethrows checking

* Introduce a special carve-out for `rethrows` functions that have a
generic requirement on an `AsyncSequence` or `AsyncIteratorProtocol`,
which uses that requirement's `Failure` type as potentially being part
of the thrown error type. This allows existing generic functions like
the following to continue to work:

    func f<S: AsyncSequence>(_: S) rethrows

* Switch SIL generation for the async for-each loop from the prior
`next()` over to the typed-throws version `_nextElement`.

* Remove `@rethrows` from `AsyncSequence` and `AsyncIteratorProtocol`
entirely. We are now fully dependent on typed throws.
2024-01-25 16:04:43 -08:00
Kavon Farvardin
3e03c674c7 [NCGenerics] remove arg from isNoncopyable(DC)
It should be the responsibility of callers to map the type to a
contextual type, as needed. When it's not possible or repetitive to do
so, there is a special-purpose function `isInterfaceTypeNoncopyable` for
 Sema.
2024-01-23 22:42:38 -08:00
Kavon Farvardin
b4985f7fde [NFC] replace canBeNoncopyable
First, "can have an absence of Copyable" is a rather confusing notion,
so the query is flipped to "can be Copyable". Next, it's more robust to
ask if a conformance exists for the TypeDecl to answer that question,
rather than trying to replicate what happens within that conformance
lookup.

Also renames `TypeDecl::isEscapable` to match.
2024-01-23 22:42:38 -08:00
Joe Groff
960938f87e SILGen: Always match noncopyable values by borrowing.
Even if the final pattern ends up consuming the value, the match itself
must be nondestructive, because any match condition could fail and cause
us to have to go back to the original aggregate. For copyable values,
we can always copy our way out of consuming operations, but we don't
have that luxury for noncopyable types, so the entire match operation
has to be done as a borrow.

For address-only enums, this requires codifying part of our tag layout
algorithm in SIL, namely that an address-only enum will never use
spare bits or other overlapping storage for the enum tag. This allows
us to assume that `unchecked_take_enum_data_addr` is safely non-side-
effecting and match an address-only noncopyable enum as a borrow.
I put TODOs to remove defensive copies from various parts of our
copyable enum codegen, as well as to have the instruction report
its memory behavior as `None` when the projection is nondestructive,
but this disturbs SILGen for existing code in ways SIL passes aren't
yet ready for, so I'll leave those as is for now.

This patch is enough to get simple examples of noncopyable enum switches
to SILGen correctly. Additional work is necessary to stage in the binding
step of the pattern match; for a consuming switch, we'll need to end
the borrow(s) and then reproject the matched components so we can
consume them moving them into the owned bindings. The move-only checker
also needs to be updated because it currently always tries to convert
a switch into a consuming operation.
2024-01-19 13:59:04 -08:00
Hamish Knight
72cbea678a [Sema] Avoid mentioning then in a diagnostic
This is still an experimental feature, so avoid
mentioning it in this diagnostic.
2024-01-18 14:52:20 +00:00
Slava Pestov
14d1fcb51a AST: TypeChecker::conformsToProtocol() => ModuleDecl::checkConformance() 2024-01-16 17:08:00 -05:00
Kavon Farvardin
778a413745 [NCGenerics] ensure ExistentialLayout is minimal
Instead of injecting Copyable & Escapable protocols into every
ExistentialLayout, only add those protocols if the existing protocols
don't already imply them. This simplifies things like `any Error`
protocol, so it still only lists one protocol in its existential layout.
But existentials like `any NoCopyP` still end up with a Copyable in its
layout.
2024-01-10 19:37:21 -08:00
Hamish Knight
29dac4380e [Sema] Correctly re-contextualize if/switch exprs in lazy vars
With `if`/`switch` expressions, we may now have
local bindings within lazy initializers, and
therefore need to ensure we correctly
re-contextualize them. Adjust the walker to set
the DeclContext for all decls it encounters,
and make sure it handles some cases that the
ASTWalker does not currently visit.

rdar://119158202
2023-12-08 14:38:40 +00:00