Commit Graph

359 Commits

Author SHA1 Message Date
Kuba (Brecka) Mracek
2d5f33e2e3 Add @_used and @_section attributes for global variables and top-level functions (#65901)
* Add @_used and @_section attributes for global variables and top-level functions

This adds:
- @_used attribute that flags as a global variable or a top-level function as
  "do not dead-strip" via llvm.used, roughly the equivalent of
  __attribute__((used)) in C/C++.
- @_section("...") attribute that places a global variable or a top-level
  function into a section with that name, roughly the equivalent of
  __attribute__((section("..."))) in C/C++.
2023-05-26 14:02:32 -07:00
Kavon Farvardin
3e4bc82aa8 rename _forget to discard; deprecate _forget
SE-390 concluded with choosing the keyword discard rather than forget for
the statement that disables the deinit of a noncopyable type. This commit
adds parsing support for `discard self` and adds a deprecation warning for
`_forget self`.

rdar://108859077
2023-05-08 21:42:19 -07:00
Xi Ge
9a98766df2 ABIChecker: consider adding @_predatesConcurrency ABI-safe
We shouldn't diagnose adding @_predatesConcurrency without considering the context because the attribute itself is for ABI-preserving purposes.

rdar://90738915
2023-03-14 17:26:01 -07:00
Doug Gregor
1c37ee5a1d [Macros] Support @discardableResult on macro declarations.
The result of an expansion of such macros can be silently ignored.
2023-03-04 22:21:02 -08:00
Joe Groff
17c803724f Implement consuming and borrowing declaration-level modifiers from SE-0377.
`borrowing func`/`consuming func` control the ownership convention of `self` for
methods.
2023-03-01 11:58:59 -08:00
Kavon Farvardin
f41ed5926b implement the forget statement
Currently, this is staged in as `_forget`,
as part of SE-390. It can only be used on
`self` for a move-only type within a consuming
method or accessor. There are other rules, see
Sema for the details.

A `forget self` really just consumes self and
performs memberwise destruction of its data.
Thus, the current expansion of this statement
just reuses what we inject into the end of a
deinit.

Parsing of `forget` is "contextual".
By contextual I mean that we do lookahead to
the next token and see if it's identifier-like.
If so, then we parse it as the `forget` statement.
Otherwise, we parse it as though "forget" is an
identifier as part of some expression.

This way, we won't introduce a source break for
people who wrote code that calls a forget
function.

This should make it seamless to change it from
`_forget` to `forget` in the future.

resolves rdar://105795731
2023-02-28 21:15:17 -08:00
Alexis Laferrière
1afc6af739 Merge pull request #63912 from xymus/access-level-import-parsing
[Parser|Sema] Accept access level on imports with experimental flag
2023-02-27 09:27:26 -08:00
Alexis Laferrière
08895657cb [Parser] Intro parser support and flag for access level on imports 2023-02-25 09:47:19 -08:00
Nate Chandler
ec1a5e0911 Add attr to enable lexical lifetime per function.
Enables modules to migrate to the new lifetime rules incrementally.
2023-02-18 11:59:54 -08:00
Pavel Yaskevich
61ab4d539d [Frontend] Remove TypeWrappers flag and associated attributes 2023-02-08 09:27:07 -08:00
Allan Shortlidge
d2524a6de8 AST: Implement parsing support for the accepted spelling of @backDeployed for SE-0376.
For source compatibility `@_backDeploy` continues to be accepted as a spelling.

rdar://102792909
2023-02-01 22:04:33 -08:00
Richard Wei
dbbf6aa4f1 Merge branch 'main' into freestanding-macro-attr-cleanup 2023-01-26 18:09:45 +08:00
Doug Gregor
af7ce9e945 [Macros] Remove the @declaration attribute.
We have @freestanding working appropriately now.
2023-01-25 17:07:38 -08:00
Doug Gregor
c188ab4f91 Remove the "@expression" attribute now that it has a better spelling 2023-01-25 17:07:38 -08:00
Doug Gregor
d74f235eb9 Generalize @attached parsing and representation to also include @freestanding.
The attached and freestanding macro attributes use the same parsing
logic and representation, so generalize the "attached" attribute into
a more general "macro role" attribute.
2023-01-25 17:07:38 -08:00
Pavel Yaskevich
477a54a145 [AST] RuntimeMetadata: Allow using enums as custom runtime metadata types 2023-01-24 14:16:36 -08:00
Ellie Shin
37af51dc4c Merge branch 'main' into es-pkg-acl 2023-01-19 16:18:17 -08:00
Ellie Shin
1c66d02f92 Add package access level to enum AccessLevel
Resolves rdar://104198440
2023-01-19 15:54:18 -08:00
Doug Gregor
de16b47875 [Macros] Introduce the @attached attribute for declaring attached macros.
Describe attached macros with the `@attached` attribute, providing the
macro role and affected names as arguments to the macro. The form of
this macro will remain the same as it gains other kinds of attached
macro roles beyond "accessor".

Remove the "accessors" role from `@declaration`, which will be going
away.
2023-01-13 22:47:59 -08:00
Richard Wei
f17b7c48bf [Macros] Freestanding declaration macros
Add support for freestanding declaration macros.

- Parse `@declaration` attribute.
- Type check and expand `MacroExpansionDecl`.

Known issues:
- Generic macros are not yet handled.
- Expansion does not work when the parent decl context is `BraceStmt`. Need to parse freestanding declaration macro expansions in `BraceStmt` as `MacroExpansionDecl`, and add expanded decls to name lookup.
2023-01-10 19:09:11 -08:00
Doug Gregor
3e2bafc2f2 [Macro] Add the expression attribute for macro declarations 2022-12-22 09:10:01 -08:00
Alex Hoppen
160518430f Format AttributeKinds.py to appease the linter
I added quite a few noqa: E501 because I think having similar properties on the same line is more important than having a strict column-limit
2022-12-15 16:40:28 +01:00
Alex Hoppen
3b2a5700e1 Remove properties from Token.py that are not relevant for the compiler 2022-12-15 16:40:28 +01:00
Alex Hoppen
1ebe7ef6a2 Copy files from SwiftSyntax’s gyb_syntax_support that are relevant to the compiler to this repo
This allows us to evolve e.g. token kinds and how attributes are modelled independently between SwiftSyntax and the compiler. It also makes it easier to e.g. add an attribute because you don’t need to create PRs for two repositories.
2022-12-15 16:40:28 +01:00
Robert Widmann
f9cff13604 Move All the Gyb Support for Syntax out of Swift
Make libSyntax depend on swift-syntax: the new home for all
of this infrastructure. This greatly simplifies the addition and
amending of syntax nodes as only the swift-syntax paired with a
swift checkout will need to be changed. This is in contrast to
the existing build flow where a paired PR to both repos must be
made to change anything here.

Note that a paired PR may still be required if the legacy parser
needs to be adjusted in response to syntax nodes changing, but I
anticipate this to be a much more infrequent event now that
the C++ end of libSyntax is deprecated.
2022-08-31 13:10:24 -07:00
Alex Hoppen
a4bd91a57f [SwiftSyntax] Add a human readable name for diagnostics to all nodes 2022-08-30 09:58:29 +02:00
YOCKOW
c1e154a9cb [Gardening] Remove trailing whitespaces in Python scripts. (W291)
That has been marked as 'FIXME' for three years.
This commit fixes it.
2022-08-25 16:08:36 +09:00
Rintaro Ishizaki
ed34dfc637 [Syntax] Introduce UnresolvedIsExpr/UnresolvedAsExpr
SequenceExprSyntax should have odd number elements. Previously 'a as b'
was parsed like:
```
(sequence_expr
  (identifier_expr "a"),
  (as_expr
    'as'
    (typeidentifier "b")))
```
So it had even number elements. Now it's parsed
```
(sequence_expr
  (identifier_expr "a"),
  (unresolved_as_expr 'as')
  (type_expr
    (typeidentifier "b")))
```
2022-08-23 13:03:18 -07:00
YOCKOW
d10381557b [NFC] Python Lint: Fix E275(missing whitespace after keyword) issues. 2022-08-21 16:07:07 +09:00
Alex Hoppen
613ef8cd47 [SwiftSyntax] Adjustment for changed RawSyntax API 2022-08-19 08:35:23 +02:00
Rintaro Ishizaki
c09ef05433 [Syntax] Add 'UnresolvedTernaryExpr'
that resembles `IfExpr` before folding in AST parsing.
2022-08-18 10:37:18 -07:00
Rintaro Ishizaki
a673043737 Terminology change: 'garbage' -> 'unexpected'
There are no "garbage" characters in Swift code. They are just
"unexpected."
2022-08-15 14:32:28 -07:00
Robert Widmann
72cef81d3b Merge pull request #60513 from CodaFi/running-on-empty
MissingDeclSyntax Can Have Attributes and Modifiers
2022-08-11 23:06:33 -07:00
Robert Widmann
ddd876614e MissingDeclSyntax Can Have Attributes and Modifiers
Strange as it sounds, we parse

@foo public

in item position as a decl that has a hanging attribute and access
control modifier. We need to be able to stick... something in the
tree here so we don't just drop these tokens on the floor.
2022-08-11 11:06:26 -07:00
fwcd
afe412f4b8 Remove trailing space from some expr keywords 2022-08-11 03:42:37 +02:00
Michael Gottesman
e9d8f363cc Bump node serialization code for MoveExpr due to subsequent commit landing. 2022-08-08 12:51:12 -07:00
Michael Gottesman
c10c0f6285 [move-function] Add a new context sensitive move expr.
It doesn't do anything yet.
2022-08-08 12:50:41 -07:00
Doug Gregor
addffbbd9c Add InfixOperatorExpr. 2022-08-05 22:15:12 -07:00
Robert Widmann
845a4e4541 Formalize Labeled Syntax
This represents labeled statements as an explicit kind of statement and removes the Labeled trait. Any kind of statement is allowed to be labeled in the tree, but we specifically diagnose the syntax elements that aren't allowed to have labels. This homogenizes the way clients deal with statement labels and also makes parser recovery quite a bit easier in the case where we have a label but no actual statement following it.
2022-08-05 15:01:02 -07:00
Eugene Berdnikov
65e38ec044 Leading/trailing spaces are updated for do and related statements 2022-08-04 19:16:11 -07:00
Alex Hoppen
c2695f0ffc [libSyntax] Allow adding garbage nodes in between any two children of a syntax node
When the source code is invalid, this allows us to represent tokens that could not be used to form a valid syntax tree with more fidelity.

This commit does not start using GarbageNodes yet, it just sets everything up for them.
2022-08-04 09:20:31 +02:00
Robert Widmann
d2143981ed Merge pull request #60344 from CodaFi/aligned-alloc
Add Layout Requirements To AST
2022-08-02 17:04:07 -07:00
Robert Widmann
8fbe69f698 Add Layout Requirements To AST
Layout Requirements aren't a fully-exposed part of the language, but
we do need some representation for them.
2022-08-01 17:11:07 -07:00
Alex Hoppen
e643fb14b5 Introduce a new syntax kind to represent missing base nodes
In the future, we only want to attach a source presence to tokens, not to nodes. All concreate nodes which are missing can be represented by creating the node and marking all tokens as missing, but if a syntax node carries a child, that has a base kind (like `Decl`), we can’t decide which concrete node to instantiate. Introduce `MissingDecl` etc. node for this purpose.

rdar://97908258
rdar://97775360
2022-08-01 16:22:47 +02:00
Alex Hoppen
83380f2682 [SourceKit] Register await as a contextual keyword
`await` in an expresssion should be marked as a contextual keyword, not as an identifier

Resolves apple/sourcekit-lsp#591
2022-07-25 10:26:44 +02:00
Alex Hoppen
5494161ddd Merge pull request #60196 from ahoppen/pr/misc-libsyntax-improvements
[libSyntax] Small improvements
2022-07-24 17:14:20 +02:00
Alex Hoppen
4b45f05aa6 [SwiftSyntax] Move error function to standalone Utils.py 2022-07-23 09:28:03 +02:00
Eugene Berdnikov
4e10086608 Add leading space for arrow token 2022-07-20 21:11:33 -07:00
Doug Gregor
3e53290187 Merge pull request #60052 from DougGregor/syntax-decl-cleanup
[Syntax] Clean up syntax grammar for declaration nodes
2022-07-20 16:09:28 -07:00
Alex Hoppen
fadee9c13f Merge pull request #59980 from evnik/LeftBraceTrivia
Add leading space for left brace
2022-07-15 15:00:55 +02:00