Commit Graph

560 Commits

Author SHA1 Message Date
Mateus Rodrigues
013997dae7 Implement trailing comma for comma-separated lists 2024-06-18 14:01:38 -03:00
Meghana Gupta
470fa2f365 Remove resultDependsOn/resultDependsOnSelf 2024-06-05 11:36:16 -07:00
Michael Gottesman
88729b9e34 [sending] Make {Transferring,Sending}ArgsAndResults a LANGUAGE_FEATURE instead of an UPCOMING_FEATURE.
TLDR: This makes it so that we always can parse sending/transferring but changes
the semantic language effects to be keyed on RegionBasedIsolation instead.

----

The key thing that makes this all work is that I changed all of the "special"
semantic changes originally triggered on *ArgsAndResults to now be triggered
based on RegionBasedIsolation being enabled. This makes a lot of sense since we
want these semantic changes specifically to be combined with the checkers that
RegionBasedIsolation turns on. As a result, even though this causes these two
features to always be enabled, we just parse it but we do not use it for
anything semantically.

rdar://128961672
2024-06-01 23:25: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
Joe Groff
10f9289ef8 Enable 'BorrowingSwitch' feature. 2024-05-14 07:31:59 -07:00
Anthony Latsis
61bdbd2fe3 Move unsupported super use diagnosis form Parse to Sema 2024-04-19 16:57:04 +03:00
Joe Groff
7ff66fd023 Accept borrowing in pattern matches without underscore.
rdar://126305009
2024-04-11 18:06:08 -07:00
Alex Hoppen
d3511c1f00 [Parse] Disallow specifiers in front of parameter declarations
Lifetime specifiers before parameter names were disallowed in Swift 3 (SE-0031).
`isolated`, `transferring` and `_const` got added after Swift 3 without a diagnostic to disallow them before parameter names.
2024-03-15 06:59:37 -07: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
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
Michael Gottesman
1f0527d47f [ast] Rename ParamSpecifier::{Transferring,ImplicitlyCopyableConsuming}.
The reason why I am doing this is that I am going to be changing transferring to
not be a true ParamSpecifier. Instead, it is going to be a bit on Param that
changes the default ParamSpecifier used. That being said, I cannot use consuming
for this purpose since consuming today implies no implicit copy semantics, which
we do not want unless the user specifically asks for it by writing consuming.
2024-02-14 13:04:21 -08:00
Rintaro Ishizaki
b839718351 [AST] Use scoped enum for attribute kinds
Align with other kind enum e.g. DeclKind.
2024-02-02 09:36:48 -08:00
Rintaro Ishizaki
07bb0380a1 [AST] Use class names for type attribute kind enum
Align with DeclAttrKind.
2024-02-02 09:36:47 -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
John McCall
41cdfb04ad Introduce a proper TypeAttribute class hierarchy.
The old TypeAttributes reprsentation wasn't too bad for a small number of
simple attributes.  Unfortunately, the number of attributes has grown over
the years by quite a bit, which makes TypeAttributes fairly bulky even at
just a single SourceLoc per attribute.  The bigger problem is that we want
to carry more information than that on some of these attributes, which is
all super ad hoc and awkward.  And given that we want to do some things
for each attribute we see, like diagnosing unapplied attributes, the linear
data structure does require a fair amount of extra work.

I switched around the checking logic quite a bit in order to try to fit in
with the new representation better.  The most significant change here is the
change to how we handle implicit noescape, where now we're passing the
escaping attribute's presence down in the context instead of resetting the
context anytime we see any attributes at all.  This should be cleaner overall.

The source range changes around some of the @escaping checking is really a
sort of bugfix --- the existing code was really jumping from the @ sign
all the way past the autoclosure keyword in a way that I'm not sure always
works and is definitely a little unintentional-feeling.

I tried to make the parser logic more consistent around recognizing these
parameter specifiers; it seems better now, at least.
2024-01-28 22:30:26 -05:00
Ben Barham
15bce77b79 Merge pull request #71021 from bnbarham/unnamed-warn-to-6
[Parse] Update error if closure has unnamed parameter to warning
2024-01-19 16:06:39 -08:00
Ben Barham
8bb1ac950b [Parse] Update error if closure has unnamed parameter to warning
This reverts commit 4ba4da45b9 and updates
the warning to a warning until Swift 6.
2024-01-19 12:42:27 -08:00
Michael Gottesman
9513d298ec [region-isolation] Add parsing/serialization/type system support for a transferring OwnershipSpecifier. 2024-01-18 13:20:28 -08:00
Anthony Latsis
96ee57b00b Merge pull request #70623 from AnthonyLatsis/init-sema
Move unqualified `init` diagnosis from Parse to Sema
2024-01-18 03:53:33 +03:00
Meghana Gupta
d3e921dc47 Make _resultDependsOn available on SILFunctionArgument 2023-12-29 01:57:19 -08:00
Anthony Latsis
bd2f48d9d2 [NFC] AST: Introduce and use Identifier::isConstructor 2023-12-25 21:09:17 +03:00
Andrew Trick
ace9937e95 Rename NonesapableTypes feature
Follow the feature flag convention for capitalization and be
consistent with the related NoncopyableGenerics feature.

This is a new feature that no wild Swift code has used it yet:

commit e99ce1cc5d
Author: Kavon Farvardin <kfarvardin@apple.com>
Date:   Tue Dec 5 23:25:09 2023

    [NCGenerics] add `~Escapable`

    Basic implementation of `~Escapable` in the type system.
2023-12-14 11:32:03 -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
Alex Hoppen
4ba4da45b9 [Parse] Error if closure has an unnamed parameter
We accepted unnamed closure parameters if the type was an array literal, dictionary literal, tuple or function (because the `[` or `(` starting the type was sufficient to disambiguate the type from the parameter’s name). This was never an accepted syntax and we should disallow it.
2023-11-28 11:07:57 -08:00
Kavon Farvardin
b55c4f1fc9 [nfc] allow ErrorTypeRepr to store a ZeroArgDiagnostic
There are sometimes parsing stuations where we don't want to
emit a parsing error, because of feature guarding. For
example, if a Feature involves new syntax for a type, we
must be able to parse both the true and false sides of an
ifdef guarding that new syntax based on a Feature flag.
2023-11-13 15:49:46 -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
Anthony Latsis
6293332cba ASTGen: Translate default arguments 2023-09-12 20:37:50 +03:00
Erik Eckstein
6b1697eb06 use new llvm::Optional APIs to fix deprecation warnings 2023-06-28 14:28:38 +02:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Doug Gregor
9d9f8326c8 [Macros] Allow macro parameters to have default arguments.
SE-0382 allows macro parameters to have default arguments. Enable these
default arguments, with the normal type checking rules. One
significant quirk to this implementation is that the actual default
argument values don't make it to the macro implementation. This is a
previously-unconsidered design problem we'll need to address.

Tracked by rdar://104043987.
2023-03-26 22:13:37 -07:00
Saleem Abdulrasool
b52fdb9d4b Apply suggestions from MSVC workaround 2023-03-18 14:11:31 -07:00
Alex Hoppen
024e2c93af [Parse] Add curly braces
Maybe this makes VSCode happy and resolves a Windows-only compilation failure `error C2059: syntax error: ')'`
2023-03-17 13:40:56 -07:00
Alex Hoppen
8a2cd86deb Split IDEInspectionCallbacks into CodeCompletionCallbacks and DoneParsingCallback
Cursor info only cares about the `doneParsing` callback and not about all the `complete` functions that are now defined in `CodeCompletionCallbacks`. To make the design clearer, split `IDEInspectionCallbacks`.

rdar://105120332
2023-03-17 10:31:13 -07:00
Hamish Knight
37b0a6074f [Sema] Introduce ExprPatternMatchRequest
This replaces `synthesizeTildeEqualsOperatorApplication`,
and synthesizes the match expression and var
on-demand.

Additionally, it pushes the lookup logic into
pre-checking.
2023-03-07 15:16:35 +00:00
Michael Gottesman
25d5fff50b [reference-bindings] Put inout parsing behind a flag harder.
In my earlier commit that attempted to do this I wasn't aggressive enough. In
this commit, I was more aggressive in putting it behind a flag and as a result
we reject all of the patterns in the tests I added into tree.
2023-03-05 13:22:18 -08:00
Michael Gottesman
00d54ebaa8 [reference-binding] Add mark_unresolved_reference_binding to signal from SILGen to the pass to check.
Just the SIL part of this.
2023-03-03 17:14:41 -08:00
Michael Gottesman
78d57ea6be [reference-bindings] Put reference bindings support behind -enable-experimental-feature ReferenceBindings. 2023-03-03 17:14:16 -08:00
Michael Gottesman
c97121d3ee [reference-binding] Add support for inout binding parsing/serialization. 2023-03-01 20:48:54 -08:00
Michael Gottesman
4b354f6132 [reference-binding] Make InBindingState into a true type called PatternBindingState.
This cleans up the parser code a little bit around here and will make it easier
for me to add inout.
2023-03-01 20:48:33 -08:00
Michael Gottesman
ed57d882d3 [ast] Refactor BindingPattern to take a VarDecl::Introducer directly instead of a bool to mean a let.
I am going to be adding more VarDecl::Introducers so this is a small nice
cleanup that is cut off the larger patch.
2023-03-01 20:48:33 -08:00
Hamish Knight
9b8bc6033c [AST] NFC: Refactor ExprPattern construction
Introduce 3 separate factory constructors, and
remove the ability to specify the match expr and
var, as those should be synthesized on-demand.
2023-03-01 15:53:41 +00:00
Joe Groff
4bb68a36cf Update for rebase 2023-02-28 11:02:16 -08:00
Joe Groff
833c25c7d0 Parser: Generalize : lookahead to disambiguate all parameter specifiers as argument labels 2023-02-28 09:16:45 -08:00
Joe Groff
704a4363d7 C++ parser: support borrowing and consuming modifiers.
And adjust contextual parameter modifier parsing in general to be more
properly contextual, so we don't have to reserve `__shared` or `__owned`,
or their successor spellings, as argument labels anymore.
2023-02-28 09:16:45 -08:00
Joe Groff
655e9e681d Add ParamSpecifier cases for Borrowing and Consuming.
And do a first pass of auditing existing uses of the parameter specifiers to
make sure that we look at the ValueOwnership mapping in most cases instead of
individual modifiers.
2023-02-28 09:16:44 -08:00
Joe Groff
1311df6544 AST: Combine various ownership TypeReprs into one OwnershipTypeRepr.
This lets us consolidate code paths that mostly run in parallel over the
existing InOutTypeRepr/SharedTypeRepr/OwnedTypeRepr family of types. This
patch by itself is NFC but makes it easier to introduce new spellings,
particularly the newly-official `borrowing` and `consuming` modifiers
that were approved in SE-0377.
2023-02-28 09:15:43 -08:00
Kavon Farvardin
197a97621f require an ownership specifier for noncopyable parameters
Per the current proposal, these are to be specified
explicitly, as they form an important part of the API.

Bonus: This commit includes a fix to make
`CompileTimeConstTypeRepr` a proper `isa<>` subtype of
`SpecifierTypeRepr`, since we forgot to add it to
that type's `classof` function.

resolves rdar://105480354
2023-02-16 22:08:13 -08:00
Alex Hoppen
754e9d7d54 [CodeCompletion] Fix issue when completing inside a switch in a closure 2023-02-14 09:40:56 +01:00
Holly Borla
89fa17d74c [Parser] Replace postfix ellipsis with a prefix 'repeat' keyword for pack
expansion expressions, and create them in the parser instead of during
pre-checking in the constraint system.
2023-01-07 09:49:14 -08:00