Commit Graph

2224 Commits

Author SHA1 Message Date
John McCall
976f1494f5 [NFC] Introduce DiagRef and use it throughout the parser
The goal is to have a lightweight way to pass an unapplied
diagnostic to general routines.  Constructing a Diagnostic
is quite expensive as something we're potentially doing in
hot paths, as opposed to just when we're actually emitting
the diagnostic.  This design allows the expense to be delayed
until we need it.

I've also optimized the Diagnostic constructor to avoid
copying arguments unnecessarily; this is a relatively small
expense, since arguments are POD, but there's really no good
reason not to do it.
2024-03-01 22:09:47 -05:00
Hamish Knight
5d39788331 [Parse] Fix a couple more attribute SourceRanges 2024-03-01 12:23:49 +00:00
Hamish Knight
cbcfb37f96 [Parse] Fix a couple of SourceRanges
These should point to the last token of the
attribute, not the token that follows.

rdar://123405070
2024-02-28 22:21:43 +00:00
Ben Barham
1306f2b32a Merge pull request #71863 from bnbarham/remove-makearrayref
Use the new template deduction guides rather than `makeArrayRef`
2024-02-25 21:06:51 -08:00
Ben Barham
f292ec9784 Use the new template deduction guides rather than makeArrayRef
LLVM has removed `make*ArrayRef`, migrate all references to their
constructor equivalent.
2024-02-23 20:04:51 -08:00
Alex Hoppen
a836195e97 Revert "Merge pull request #71238 from ahoppen/ahoppen/source-location-parser-changes"
This reverts commit 12fe866470, reversing
changes made to 956d6d23f2.
2024-02-23 11:09:10 -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
Konrad `ktoso` Malawski
e9c7f3c382 [Distributed] Target identifiers for protocol calls (#70928) 2024-02-16 07:19:20 -08: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
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
Hamish Knight
2c77947000 Merge pull request #71006 from hamishknight/implicit-last-expression
Introduce implicit last expression results
2024-02-08 10:15:01 +00:00
Hamish Knight
7b4c9fef02 Allow implicit last expressions for functions and closures
Gated behind the experimental feature
`ImplicitLastExprResults`.
2024-02-07 18:14:23 +00: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
Andrew Trick
e738b8a77e Merge pull request #71353 from meg-gupta/initlifetimedep
Support for lifetime dependence specifiers on initializers
2024-02-05 08:55:54 -08:00
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