Commit Graph

1278 Commits

Author SHA1 Message Date
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07:00
Hamish Knight
a8c72617e4 [ASTDumper] Avoid parsing decl members
Previously we would call `getMembers`, which could
kick delayed member parsing. Instead, propagate a
`parseIfNeeded` flag through the ASTDumper logic,
and use it to determine whether to parse a
SourceFile, type/extension body, or function body.
This is needed for things like `-dump-parse` which
expects to dump the entire AST tree.
2024-06-14 10:54:47 +01:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Meghana Gupta
470fa2f365 Remove resultDependsOn/resultDependsOnSelf 2024-06-05 11:36:16 -07:00
Michael Gottesman
b780ff6696 [sending] Begin parsing 'sending' while still accepting 'transferring'.
A few things:

1. Internally except for in the parser and the clang importer, we only represent
'sending'. This means that it will be easy to remove 'transferring' once enough
time has passed.

2. I included a warning that suggested to the user to change 'transferring' ->
'sending'.

3. I duplicated the parsing diagnostics for 'sending' so both will still get
different sets of diagnostics for parsing issues... but anywhere below parsing,
I have just changed 'transferring' to 'sending' since transferring isn't
represented at those lower levels.

4. Since SendingArgsAndResults is always enabled when TransferringArgsAndResults
is enabled (NOTE not vis-a-versa), we know that we can always parse sending. So
we import "transferring" as "sending". This means that even if one marks a
function with "transferring", the compiler will guard it behind a
SendingArgsAndResults -D flag and in the imported header print out sending.

rdar://128216574
2024-05-16 21:43:50 -07:00
Michael Gottesman
e3e78ad6bb [sending] Change the internals of sending to be based around 'sending' instead of 'transferring'.
We still only parse transferring... but this sets us up for adding the new
'sending' syntax by first validating that this internal change does not mess up
the current transferring impl since we want both to keep working for now.

rdar://128216574
2024-05-16 12:20:45 -07:00
Slava Pestov
e342a38b87 Sema: Convert TypeChecker::computeCaptures() into two requests
We now compute captures of functions and default arguments
lazily, instead of as a side effect of primary file checking.

Captures of closures are computed as part of the enclosing
context, not lazily, because the type checking of a single
closure body is not lazy.

This fixes a specific issue with the `-experimental-skip-*` flags,
where functions declared after a top-level `guard` statement are
considered to have local captures, but nothing was forcing these
captures to be computed.

Fixes rdar://problem/125981663.
2024-04-20 22:16:25 -04:00
Slava Pestov
6e14999ee2 ASTDumper: Don't crash if capture info not computed yet 2024-04-16 12:34:55 -04:00
Becca Royal-Gordon
05e93da398 Simplify and test ASTGen support
Rather than adding custom parsing to SwiftSyntax, we can parse this as a custom attribute and convert it to a built-in one in ASTGen. Test that this works correctly (and fix a bug where it wasn’t).
2024-03-28 15:48:15 -07:00
Meghana Gupta
b5ca933002 Update lifetime dependence syntax and inference as per changes in the pitch
Pitch - https://github.com/apple/swift-evolution/pull/2305

Changes highlights:

dependsOn(paramName) and dependsOn(scoped argName) syntax

dependsOn(paramName) -> copy lifetime dependence for all parameters/self except
                         when we have Escapable parameters/self, we assign scope
                         lifetime dependence.

Allow lifetime dependence on parameters without ownership modifier.

Always infer copy lifetime dependence except when we have
Escapable parameters/self, we infer scope lifetime dependence.

Allow lifetime dependence inference on parameters without ownership modifier.
2024-03-23 18:19:47 -07:00
Sophia Poirier
95abb73e1a Merge pull request #72175 from sophiapoirier/explicitly-nonisolated-closure
[Concurrency] explicit nonisolated specification for closures
2024-03-14 17:17:00 -07:00
Sophia Poirier
5ce7be7e75 [Concurrency] explicit nonisolated specification for closures 2024-03-14 12:24:13 -07:00
Holly Borla
78384d596d [Concurrency] Add ExtractFunctionIsolationExpr to represent the isolation
of a dynamically isolated function value in the AST.
2024-03-13 19:55:15 -07:00
Rintaro Ishizaki
58e70e8535 Merge pull request #72103 from rintaro/astgen-stringliteral
[ASTGen] Generate interpolated string literal
2024-03-13 10:08:15 +09:00
Rintaro Ishizaki
cbae07e64e [Parse] Clean up Interpolated string literal parsing 2024-03-04 14:38:24 -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
Michael Gottesman
c65e10e36f [transferring] Improve how the AST dumps/prints transferring.
Specifically:

1. Previously when printing we would not put a space after transferring.
2. When a function type has a transferring result, we wouldn't print it when dumping.
2024-02-27 17:55:45 -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
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
Michael Gottesman
23ab974574 Merge pull request #71567 from gottesmm/transferring-param
[transferring] Implement transferring result and clean up transferring param support by making transferring a bit on param instead of a ParamSpecifier.
2024-02-14 17:54:48 -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
Michael Gottesman
bf2ec7eb85 [transferring] Change transferring to no longer be a ParamSpecifier.
Instead it is a bit on ParamDecl and SILParameterInfo. I preserve the consuming
behavior by making it so that the type checker changes the ParamSpecifier to
ImplicitlyCopyableConsuming if we have a default param specifier and
transferring is set. NOTE: The user can never write ImplicitlyCopyableConsuming.

NOTE: I had to expand the amount of flags that can be stored in ParamDecl so I
stole bits from TypeRepr and added some logic for packing option bits into
TyRepr and DefaultValue.

rdar://121324715
2024-02-14 13:04:46 -08:00
Anthony Latsis
d9777a06b6 [NFC] AST/ASTDumper: Refactor for recursive MemberTypeRepr representation 2024-02-09 17:22:56 +03:00
Anthony Latsis
d6fd424560 [NFC] MemberTypeRepr: getBaseComponent()getRoot() 2024-02-09 17:22:05 +03: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
Pavel Yaskevich
4debaf2c5d [AST] Introduce a new conversion expression - ActorIsolationErasure
To be used in situations when a global actor isolation is stripped
from a function type in argument positions and could be extended in
the future to cover more if needed.
2024-02-01 13:28:25 -08:00
Slava Pestov
80205ecf9c Merge pull request #71241 from slavapestov/ncgenerics-fixes
Non-copyable generics fixes
2024-02-01 07:18:29 -05:00
Slava Pestov
d8f85a3bf6 AST: Remove ProtocolDecl::getRequirementSignatureAsGenericSignature() 2024-01-31 21:56:57 -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
0a4c029cfc [AST] Introduce UnreachableExpr
This models the conversion from an uninhabited
value to any type, and allows us to get rid of
a couple of places where we'd attempt to drop
the return statement instead.
2024-01-30 14:08:54 +00:00
Hamish Knight
840d52f5ad [ASTDumper] Remove special case for single expr functions
We don't do the same for closures, and I don't see
any reason why we should obscure the real AST from
the dump.
2024-01-30 14:08:54 +00:00
Meghana Gupta
ab71c1ea8a Implement LifetimeDependentReturnTypeRepr::printImpl 2024-01-29 14:55:52 -08:00
Meghana Gupta
28f27c3da1 Merge pull request #71069 from meg-gupta/lifetimedependencelangattr
Initial language support for lifetime dependence
2024-01-25 00:39:13 -08:00
Meghana Gupta
0cb805bccf Add Sema support for LifetimeDependence 2024-01-24 15:01:15 -08:00
Holly Borla
d60a06760b Merge pull request #71050 from hborla/global-actor-unsafe
[Concurrency] Deprecate `@GlobalActor(unsafe)` in favor of `@preconcurrency @GlobalActor`
2024-01-22 16:52:56 -08:00
Holly Borla
47afd21d85 [Concurrency] Remove ActorIsolation::GlobalActorUnsafe. 2024-01-21 21:05:33 -08:00
Hamish Knight
3f4b45b012 [AST] Remove SerializedLocalDeclContext
It's not clear that its worth keeping this as a
base class for SerializedAbstractClosure and
SerializedTopLevelCodeDecl, most clients are
interested in the concrete kinds, not only whether
the context is serialized.
2024-01-18 12:03:52 +00:00
Doug Gregor
8b514ec029 Merge pull request #70902 from DougGregor/isolation-macro
Implement `#isolation` macro to produce the isolation of the current context
2024-01-16 14:27:00 -08:00
Doug Gregor
255009dddb Implement #isolation macro to produce the isolation of the current context
Introduce a new expression macro that produces an value of type
`(any AnyActor)?` that describes the current actor isolation. This
isolation will be `nil` in non-isolated code, and refer to either the
actor instance of shared global actor in other cases.

This is currently behind the experimental feature flag
OptionalIsolatedParameters.
2024-01-16 14:25:51 -08:00
Anthony Latsis
a48dc87f86 Merge pull request #70855 from AnthonyLatsis/dump-archetype-addr
ASTDumper: Fix archetype address dumping
2024-01-16 18:04:33 +03:00
Anthony Latsis
bd933029f0 ASTDumper: Fix archetype address dumping 2024-01-11 23:32:21 +03:00
Joe Groff
4011b2f53c Add methods to determine the ownership behavior of patterns.
When matching against a noncopyable value, whether the match operation can
borrow the value in-place or needs to take ownership of it is significant.
This can generally be determined from the kind of pattern being used, except
in the case of expr patterns, where it depends on type-checking the `~=`
operator that was used.
2024-01-08 18:21:33 -08:00
Doug Gregor
7a3e3aea15 Merge pull request #70353 from DougGregor/error-union-type
[Typed throws] Add an ErrorUnion type to the type system
2023-12-11 22:04:10 -08:00
Kavon Farvardin
e99ce1cc5d [NCGenerics] add ~Escapable
Basic implementation of `~Escapable` in the type system.

rdar://119216918
2023-12-10 01:25:43 -08:00
Doug Gregor
b080b5f3d8 [Typed throws] An ErrorUnion type to the type system
The errorUnion type operation specifies how thrown error types are
combined when multiple errors are thrown in the same context. When
thrown error types can have type variables in them, we sometimes cannot
resolve the errorUnion until the type variables have substitutions. In
such cases, we need to persist the result of errorUnion in the
constraint solver.

Introduce the ErrorUnionType to do exactly that, and update the core
errorUnion operation to produce an ErrorUnionType when needed. At
present, this code is inert, because any errorUnion operation today
involves only concrete types. However, inference of thrown errors in
closures will introduce type variables, and depend on this.
2023-12-08 22:30:37 -08:00
Kavon Farvardin
338d426b3d Merge pull request #70278 from kavon/refactor-InverseType
[NCGenerics] fold InverseType into PCT
2023-12-08 02:44:45 -08:00
Kavon Farvardin
63b3e7624d [NCGenerics] fold InverseType into PCT
We already need to track the inverses separate from the members in a
ProtocolCompositionType, since inverses aren't real types. Thus, the
only purpose being served by InverseType is to be eliminated by
RequirementLowering when it appears in a conformance requirement.

Instead, we introduce separate type InverseRequirement just to keep
track of which inverses we encounter to facilitate cancelling-out
defaults and ensuring that the inverses are respected after running
the RequirementMachine.
2023-12-07 22:14:23 -08:00