Commit Graph

593 Commits

Author SHA1 Message Date
Hamish Knight
738c70e8c8 [AST] Always walk folded SequenceExpr if available
Expand the special-cased ASTWalker behavior for folded SequenceExprs
such that we always walk the folded expression when available. This
ensures that we don't attempt to add the same node multiple times
when expanding ASTScopes during pre-checking.

rdar://147751795
2025-03-24 20:18:34 +00:00
Hamish Knight
f8ab391737 Introduce type sugar for InlineArray (#80087)
* [CS] Decline to handle InlineArray in shrink

Previously we would try the contextual type `(<int>, <element>)`,
which is wrong. Given we want to eliminate shrink, let's just bail.

* [Sema] Sink `ValueMatchVisitor` into `applyUnboundGenericArguments`

Make sure it's called for sugar code paths too. Also let's just always
run it since it should be a pretty cheap check.

* [Sema] Diagnose passing integer to non-integer type parameter

This was previously missed, though would have been diagnosed later
as a requirement failure.

* [Parse] Split up `canParseType` 

While here, address the FIXME in `canParseTypeSimpleOrComposition`
and only check to see if we can parse a type-simple, including
`each`, `some`, and `any` for better recovery.

* Introduce type sugar for InlineArray

Parse e.g `[3 x Int]` as type sugar for InlineArray. Gated behind
an experimental feature flag for now.
2025-03-23 15:31:37 -07:00
Amritpan Kaur
978a5215d5 [Expr/AST] Add apply component to handle resolved method arguments. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
0c614e09d1 [Expr/AST] Add unresolvedApply component to handle method arguments. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
2583da94b2 [NFC] Generalize subscript index handling. 2025-03-19 08:53:18 -07:00
Amritpan Kaur
811d54901b [NFC] Rename unresolvedProperty to unresolvedMember
to generalize for both properties and method members.
2025-03-19 08:53:18 -07:00
Amritpan Kaur
8f71f5c780 [NFC] Rename property to member to generalize
for both properties and method members.
2025-03-19 08:53:18 -07:00
Rintaro Ishizaki
5eac58e1e0 [AST] SwitchStmt only hold CaseStmt
Now that there is no way SwitchStmt to hold AST nodes other than
CaseStmt.
2025-03-08 09:14:40 -08:00
Rintaro Ishizaki
002d7d7cdf [Parse/AST] Remove PoundDiagnosticDecl
There is no reson to make a AST node for '#error' and '#warning'
directives. Parser knows the diagnostics should be emitted or not.
2025-03-07 21:48:01 -08:00
Artem Chikin
de26e960e2 Rename '_const' attribute to 'CompileTimeLiteral'
To pave the way for the new experimental feature which will operate on '@const' attribute and expand the scope of what's currently handled by '_const' without breaking compatibility, for now.
2025-03-04 07:30:02 -08:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Allan Shortlidge
87308e37f1 AST: Avoid creating duplicate AvailabilityScopes under SequenceExprs.
Since availability scopes may be built at arbitrary times, the builder may
encounter ASTs where SequenceExprs still exist and have not been folded, or it
may encounter folded SequenceExprs that have not been removed from the AST.

To avoid a double visit, track whether a SequenceExpr is folded and then
customize how ASTVisitor handles folded sequences.

Resolves rdar://142824799 and https://github.com/swiftlang/swift/issues/78567.
2025-01-17 10:21:22 -08:00
Slava Pestov
74f8960bd8 Sema: Remove OneWayExpr and Builtin.one_way 2024-12-21 00:42:13 -08:00
Doug Gregor
de4d4a4244 Teach the TypeRefinementContext not to skip declarations within macro expansions
The construction of type refinement contexts performs lazy expansion
for the contents of macro expansions, so that TRC creation doesn't
force all macros to be expanded. However, the logic that skips macro
expansions would *also* skip some declarations produced within a macro
expansion, even when building the TRC specifically for that macro
expansion buffer. This manifest as missing some availability
information within the TRC, rejecting some well-formed code.

Tune the logic for "don't visit macro expansions when building a TRC"
to recognize when we're building a TRC for that macro expansion.

Fixes rdar://128400301.
2024-11-10 07:32:00 -08:00
Doug Gregor
5b2520e379 Remove IfConfigDecl from the AST
The swift-syntax tree retains information about the parsed #if
regions. Drop it from the semantic AST.
2024-09-18 20:51:54 -07:00
Hamish Knight
1caaeeb83e Merge pull request #76295 from hamishknight/capturent
Remove `shouldWalkCaptureInitializerExpressions`
2024-09-06 21:39:51 +01:00
Alejandro Alonso
45d7ea39a5 Merge pull request #75518 from Azoy/integer-generics
Implement Value generics
2024-09-05 15:33:46 -07:00
Hamish Knight
f5557c4c10 Remove shouldWalkCaptureInitializerExpressions
There doesn't seem to be any reason we can't
walk the PatternBindingDecls directly here.
2024-09-05 22:27:15 +01:00
Alejandro Alonso
0df42e9841 Lower UDRE to TypeValue if it references a value generic 2024-09-04 15:13:29 -07:00
Alejandro Alonso
75c2cbf593 Implement value generics
Some requirement machine work

Rename requirement to Value

Rename more things to Value

Fix integer checking for requirement

some docs and parser changes

Minor fixes
2024-09-04 15:13:25 -07:00
Hamish Knight
9bd0d9b7e4 [Sema] Walk separately-checked closures normally in MiscDiagnostics
We no longer need to make any special affordances
for separately-checked closures, walk them normally.
2024-08-31 12:47:46 +01:00
Meghana Gupta
8137aed238 Rename LifetimeDependentReturnTypeRepr -> LifetimeDependentTypeRepr 2024-07-10 14:20:03 -07:00
Michael Gottesman
112071e57d [sending] Remove transferring.
Out of an abundance of caution, we:

1. Left in parsing support for transferring but internally made it rely on the
internals of sending.

2. Added a warning to tell people that transferring was going to
be removed very soon.

Now that we have given people some time, remove support for parsing
transferring.

rdar://130253724
2024-06-21 16:03:21 -07:00
Slava Pestov
1b9d80abc7 ASTWalker: getLazyInitializerWalkingBehavior() should not affect property wrappers 2024-06-20 21:34:54 -04:00
Tim Kientzle
1098054291 Merge branch 'main' into tbkka-assertions2 2024-06-18 17:52:00 -07: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
Anthony Latsis
1d3a5860e2 [NFC] ParamDecl: Extract write of type-checked default expr into its own method 2024-04-19 16:57:05 +03: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
Anthony Latsis
5b7a8b6705 [NFC] AST: Rename MemberTypeReprQualifiedIdentTypeRepr 2024-03-02 14:59:37 +03:00
Anthony Latsis
5d848e784f [NFC] AST: Merge SimpleIdentTypeRepr & GenericIdentTypeRepr into UnqualifiedIdentTypeRepr 2024-03-02 14:59:37 +03: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
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
ef931342ad AST/ASTWalker: Refactor for recursive MemberTypeRepr representation 2024-02-09 17:33:21 +03:00
Anthony Latsis
d6fd424560 [NFC] MemberTypeRepr: getBaseComponent()getRoot() 2024-02-09 17:22:05 +03:00
Hamish Knight
3b97fed6fa [ASTWalker] Re-introduce Action::SkipChildren
Now with the behavior of resuming at the post-walk.
2024-02-05 15:27:25 +00: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
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
Meghana Gupta
0cb805bccf Add Sema support for LifetimeDependence 2024-01-24 15:01:15 -08:00
Hamish Knight
990d15567d [AST] Split up PatternBindingDecl::setPattern
Most clients only want to set one of the two
parameters, split it into `setPattern` and
`setInitContext` (the latter of which now
handles calling `setBinding`).
2024-01-17 16:02:33 +00: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
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
Meghana Gupta
b6326f5f24 Add initial support for _resultDependsOn
These attributes are used to establish lifetime dependence between
argument and the result.

Add them under NonEscapableTypes experimental feature
2023-12-06 16:38:38 -08:00
Hamish Knight
f4e09c5531 [AST] Tighten up invariants around IfStmt
The 'then' statement must be a BraceStmt, and
the 'else' must either be a BraceStmt or an IfStmt.
2023-12-04 11:09:01 +00:00
Sima Nerush
f276bd2079 Support pack iteration in closures 2023-12-03 21:51:40 -08:00
Pavel Yaskevich
1f42585fdd [AST] NFC: Rename KeyPathExpr::{get, set}RootType to {get, set}ExplicitRootType 2023-11-28 13:01:43 -08:00
Doug Gregor
ef642098f2 [Typed throws] Parsing and AST representation for typed errors
Parse typed throw specifiers as `throws(X)` in every place where there
are effects specified, and record the resulting thrown error type in
the AST except the type system. This includes:
* `FunctionTypeRepr`, for the parsed representation of types
* `AbstractFunctionDecl`, for various function-like declarations
* `ClosureExpr`, for closures
* `ArrowExpr`, for parsing of types within expression context

This also introduces some serialization logic for the thrown error
type of function-like declarations, along with an API to extract the
thrown interface type from one of those declarations, although right
now it will either be `Error` or empty.
2023-09-29 10:51:51 -07:00
Kavon Farvardin
c01360d02e [Sema] reimplement ~C as an general inverse constraint 2023-09-20 09:34:06 -07:00
Allan Shortlidge
0dd8f4c492 AST: Introduce abstraction for extension/type decl inheritance clauses.
Wrap the `InheritedEntry` array available on both `ExtensionDecl` and
`TypeDecl` in a new `InheritedTypes` class. This class will provide shared
conveniences for working with inherited type clauses. NFC.
2023-09-06 10:41:57 -07:00