Commit Graph

2195 Commits

Author SHA1 Message Date
Alex Hoppen
c6e425a559 [Parse] Disallow space between attribute name and '(' in Swift 6 mode
This allows us to resolve disambiguities of whether a parenthesis belong to an argument to the attribute or if it is eg. the start of a tuple.
2024-01-31 18:24:42 -08:00
Alex Hoppen
cc5e79b521 [Parse] Disallow space between @ and attribute name in Swift 6 mode 2024-01-29 22:54:29 -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
Rintaro Ishizaki
170336721d Merge pull request #71128 from rintaro/ast-nonmodifiers
[AST] Remove unused decl modifiers
2024-01-26 01:14:49 -08:00
Meghana Gupta
36f43fe760 Follow up for C++ parser changes in #71069 2024-01-25 00:40:34 -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
d37b0cf10d Add support for LifetimeDependence in C++ parser 2024-01-24 15:01:10 -08:00
Rintaro Ishizaki
e8f79a068a [AST] Remove unused decl modifiers
_resultDependsOn and transferring are - at least currently - only used
as type specifiers, not decl modifiers. And if they are actually
specified as a decl modifiers, they're just accepted and ignored, which
is not ideal.
2024-01-24 14:36:38 -08:00
Hamish Knight
71d8a9cf53 Unset the return location for an implicit return nil
The `return` keyword here doesn't have a source
location, so unset it. This matches the other
implicit single expression returns.
2024-01-23 21:33:55 +00:00
Hamish Knight
c97d80b1c3 [AST] NFC: Add convenience constructors for ReturnStmt
Add `ReturnStmt::createParsed` and `createImplict`.
2024-01-23 19:30:18 +00:00
Hamish Knight
12af066f5b Mark a couple of ReturnStmts implicit
These are both synthesized returns, so they ought
to be marked implicit.
2024-01-23 19:29:14 +00:00
Alex Hoppen
695e69e09e [CodeComplete] Suggest single argument labels if code completion is invoked at start of function call with exiting parameters
This removes the distinction between argument completions and postfix expr paren completions, which was meaningless since solver-based completion.

It then determines whether to suggest the entire function call pattern (with all argument labels) or only a single argument based on whether there are any existing arguments in the call.

For this to work properly, we need to improve parser recovery a little bit so that it parsers arguments after the code completion token properly.

This should make call pattern heuristics obsolete.

rdar://84809503
2024-01-22 12:21:04 -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
Hamish Knight
0b18d287e0 [Parse] Avoid re-using attribute context for non-first entry
This could result in us changing the binding
index after-the-fact.
2024-01-17 16:02:33 +00:00
Hamish Knight
848574080a [CS] Use correct DeclContext when solving initializations
Use the PatternBindingInitializer context if we
have one. This also uncovered a parser issue where
we would mistakenly create a
PatternBindingInitializer in top-level code after
parsing the initializers.
2024-01-17 16:02:33 +00:00
Hamish Knight
fb0a75fe55 [AST] NFC: Introduce PatternBindingInitializer::create 2024-01-17 16:02:32 +00:00
Allan Shortlidge
72e0fc2af1 NFC: Remove an unused variable in ParseDecl.cpp. 2024-01-16 13:27:55 -08:00
Allan Shortlidge
cd8c99fe26 NFC: Remove an unused variable in ParseDecl.cpp. 2024-01-12 18:03:11 -08:00
Rintaro Ishizaki
f7e35cb835 [AST] Requestify local type declarations
Instead of recording local type declarations while parsing, make a
request to collect them from the AST. This reduces the side effect of
parsing.
2024-01-05 13:26:55 -08:00
Michael Gottesman
799ab69c11 [parser] Introduce a helper struct for parsing type attributes rather than passing around a bunch of state.
Just refactoring before adding /another/ field to these APIs. It hurt to do so
so I needed to refactor.

NFCI.
2024-01-02 12:15:37 -08:00
Michael Gottesman
aad2669bd6 [parse] Generalize "Need experimental feature flag" parser error to work for general experimental features instead of just NonEscapableTypes. 2024-01-02 12:13:32 -08:00
Hamish Knight
2f25d8fa58 [AST] Compute SubscriptDecl EndLoc
Instead of having the parser set it, compute it
using the recorded brace location for the accessor
record.
2023-12-15 21:44:31 +00:00
Hamish Knight
8fdb48d910 [AST] Rename SubscriptDecl::create -> createParsed
And generate the DeclName using the argument labels
on the ParameterList.
2023-12-15 21:44:31 +00:00
Hamish Knight
526dcfbe11 [AST] Factor out AccessorDecl::createParsed
Move the logic for splicing together the
accessor's parameter list out of the parser so
that ASTGen will be able to use it too.
2023-12-15 21:44:30 +00:00
Hamish Knight
e1d35d90aa [AST] Introduce TypedPattern::createPropagated 2023-12-15 21:44:30 +00:00
Hamish Knight
b04d5d5abc [ASTGen] Better handle pattern binding entries
Generate all entries, and ensure we introduce a
PatternBindingInitializer context for non-local
cases. Also use this opportunity to cleanup
`PatternBindingDecl::create`.
2023-12-15 21:44:30 +00: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
Sophia Poirier
d319404e16 [Concurrency] unguard nonisolated(unsafe) attribute from GlobalConcurrency experimental feature 2023-12-13 15:06:07 -08:00
Hamish Knight
a68c2ac714 [Parse] Restore accidentally deleted code 2023-12-11 12:00:47 +00:00
Hamish Knight
5e7854f46b [AST] Remove static loc and spelling kind from AccessorDecl
The spelling kind was only ever set to
`StaticSpellingKind::None`, and the static location
was never used for anything (and should be queried
on the storage anyway). This doesn't affect the
computation of `isStatic` since `IsStaticRequest`
already takes the static-ness from the storage for
accessors.
2023-12-08 17:59:44 +00: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
Doug Gregor
36a2dcd927 Implement function body macros
Function body macros allow one to introduce a function body for a
particular function, either providing a body for a function that
doesn't have one, or wholesale replacing the body of a function that
was written with a new one.
2023-11-27 17:04:55 -08:00
Doug Gregor
89bda715ce Merge pull request #69840 from DougGregor/macro-role-metaprogramming
[Macros] Macro-metaprogram macro roles
2023-11-14 11:51:50 -08:00
Doug Gregor
ffa5ba7ce3 More macro metaprogramming for macro roles 2023-11-14 09:20:15 -08:00
Kavon Farvardin
dbd17c538a [NCGenerics] allow feature-guarded uses of ~Copyable
We need to delay the pre-NCGenerics errors about
illegal uses of ~Copyable from Parse until Sema.
Otherwise, such uses can't appear within a false
2023-11-13 15:51:41 -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
Sophia Poirier
3d89295736 Merge pull request #69796 from sophiapoirier/nonisolated-unsafe-globals-corrected
corrected implementation of parsing nonisolated(unsafe) as decl contextual keyword in top-level global scope
2023-11-13 14:31:40 -08:00
Rintaro Ishizaki
fb08a92f48 [ASTGen] Infrastructure to implment ASTGen Incrementally
* 'ASTGenVisitor' has a reference to a legacy C++ Parser configured for
  ASTGen.
* If 'ASTGenVisitor' encounters a AST node that hasn't been migrated,
  call parse(Decl|Stmt|Expr|Type) to parse the position using the legacy
  parser.
* The legacy parser calls ASTGen's
  'swift_ASTGen_build(Decl|Stmt|Expr|Type)' for each ASTNode "parsing"
  (unless the call is not directly from the ASTGen.)

rdar://117151886
2023-11-12 21:43:08 -08:00
Sophia Poirier
f65b157058 corrected implementation of parsing nonisolated(unsafe) as decl contextual keyword in top-level global scope (follow up to 5a8825705) 2023-11-11 11:28:55 -08:00
Meghana Gupta
3db420a45f Merge pull request #69176 from meg-gupta/resultdependson
Add initial support for  _resultDependsOnSelf
2023-11-08 18:55:51 -08:00
Sophia Poirier
5a88257052 Merge pull request #69624 from sophiapoirier/nonisolated-unsafe-globals-temp
parse nonisolated(unsafe) as decl contextual keyword in top-level global scope rather than as function invocation
2023-11-08 07:45:11 -08:00
Meghana Gupta
5658deae27 Add initial support for _resultDependsOnSelf
This is used to establish lifetime dependence between self and the result.

Add under NonEscapableTypes experimental feature
2023-11-08 01:48:59 -08:00
Sophia Poirier
e10504f8f7 parse nonisolated(unsafe) as decl contextual keyword in top-level global scope rather than as function invocation (temporary solution) 2023-11-07 16:15:29 -08:00
Yuta Saito
70a1ac2139 Merge pull request #69683 from kateinoigakukun/katei/underscore-extern
Add underscore prefix to extern attribute
2023-11-07 06:00:27 -05:00
Yuta Saito
79b3d2d626 Add underscore prefix to extern attribute
It's already guarded by a feature flag, but it would be nice to signal
users that it's not stable yet by adding an underscore prefix.
2023-11-07 02:01:02 +00:00
Rintaro Ishizaki
7e27d99075 [Parse] Remove 'Flags' from 'PersistentParserState'
This is not used anymore.
2023-11-02 23:13:59 -07:00
Rintaro Ishizaki
5862d347e6 [Parse] Remove 'ParseDeclOptions' parameter from 'parseDecl' function
'ParseDeclOptions' can be trivially calculated solely from the current
decl context. To reduce the number of the contextual parameters,
calculate it inside the function.
2023-11-02 16:50:33 -07:00
Hamish Knight
6afde8a6d2 Remove CBasicBridging and CASTBridging
Merge with BasicBridging and ASTBridging
respectively. The changes here should be pretty
uncontroversial, I tried to keep it to just moving
code about.
2023-10-30 23:49:56 +00:00
Sophia Poirier
77e7dc2c19 Merge pull request #69280 from sophiapoirier/globals_strict_concurrency_opt_out_nonisolated_unsafe
nonisolated(unsafe) to opt out of strict concurrency static checking for global variables
2023-10-26 22:34:22 -07:00
Sophia Poirier
4c9a726183 nonisolated(unsafe) to opt out of strict concurrency static checking for global variables 2023-10-26 16:22:28 -07:00