Commit Graph

2357 Commits

Author SHA1 Message Date
Meghana Gupta
c8ece100ba Handle explicit lifetime dependence specifiers in initializers 2024-02-02 11:50:10 -08:00
Rintaro Ishizaki
92e70ef80a [AST] Remove DeclAttrKind::Count
Introduce NumDeclAttrKinds for number of enum values. Use optional for
invalid attribute kind. This align with `TypeAttrKind`.
2024-02-02 09:36:49 -08:00
Rintaro Ishizaki
8fdc4cc225 [AST] Split Attr.def to DeclAttr.def and TypeAttr.def 2024-02-02 09:36:49 -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
Rintaro Ishizaki
cd7a31cddc [ASTGen] Cleanup type attribute generation
Use similar scheme as DeclAttribute.
* Create `BridgedTypeAttribute.createSimple()` and
  `BridgedTypeAttributes.add()`, instead of
  `BridgedTypeAttributes.addSimple()`
* Create `DeclAttributes::createSimple()` to align with `TypeAttribute`
2024-02-01 15:45:50 -08:00
Alex Hoppen
b3f9e08255 Merge pull request #71237 from ahoppen/ahoppen/attribute-parser-changes
Disallow spaces between `@`, attribute name and `(` in Swift 6
2024-01-31 20:53:34 -08:00
Alex Hoppen
12fe866470 Merge pull request #71238 from ahoppen/ahoppen/source-location-parser-changes
Disallow multi-line filenames and non-decimal line numbers in `#sourceLocation` directive in Swift 6 mode
2024-01-31 18:31:29 -08:00
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
4a386d40a6 [Parse] Disallow multiline string literals for filename in #sourceLocation and similar locations
This should allow us to eventually simplify parsing of simple string literals in the new parse by not having to handle indentation of multiline string literals.
2024-01-31 16:03:20 -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
Hamish Knight
f4a6b95d24 Move single-expr return transform from Parse to Sema
Rather than doing the transform in the parser, and
then potentially undoing it in Sema, move the
entire transform into Sema. This also lets us
unify the logic between function decls and
closures, and allows ASTGen to benefit from it.
2024-01-30 14:08:53 +00:00
Alex Hoppen
0e2430be08 [Parse] Disallow non-decimal line numbers to #sourceLocation directive
Non-decimal line numbers in a `#sourceLocation` directive are simply confusing in my opinion and should be banned.
2024-01-29 23:02:38 -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