Commit Graph

50 Commits

Author SHA1 Message Date
Hamish Knight
35a98f3828 [ASTGen] Allow querying of enabled features
For now this is using C interop, we ought to be
using C++ interop, but that's a much bigger
change.
2023-08-09 19:35:50 +01:00
Allan Shortlidge
f9a93a55d7 NFC: Fix duplicate definition of macro warnings.
Centralize the `SWIFT_{BEGIN/END}_NULLABILITY_ANNOTATIONS` definitions in a new
Nullability.h header to share.
2023-07-27 13:02:22 -07:00
John McCall
1a7d44a11d Diagnose attempts to reabstract variadic function types in unimplementable ways. 2023-07-18 13:22:35 -04:00
Rintaro Ishizaki
eefe9dc7ef [Macros] Attached macro expansions return single string
* Move collapse(expansions:for:attachedTo:) to SwiftSyntaxMacroExpansion
* SwiftSyntaxMacroExpansion.expandAttachedMacro() now perform collapsing
* SwiftSyntaxMacroExpansion.expandAttachedMacroWithoutCollapsing()
  to keep old behavior
* IPC request 'getCapability' now sends the host protocol version
* Unified IPC response 'macroExpansionResult' that returns single string
  for both 'expandFreestandingMacro' and 'expandAttachedMacro'
* Compiler accepts old 'expandFreestandingMacroResult' and
  'expandAttachedMacroResult' to keep compatibility
* Plugins check the compiler's protcol version to see if it suppports
  'macroExpansionResult', and fall back to old behavior if necessary
2023-06-26 11:04:59 -07:00
Ben Barham
18f56c9de5 [NFC][ASTGen] Add wrapping structs for commonly bridged types
Adds wrapping structs for a bunch of commonly bridged types (but not all
the AST nodes yet).
2023-06-02 10:11:46 -07:00
Doug Gregor
4188dca07a [ASTGen] Handle composition types parsed through parseType().
Protocol composition types such as `P & Q` are similar to nested types
like `A.B` because the innermost type syntax node at the given position
doesn't cover the whole type. Adjust by looking back up the tree.
This all feels like a hack, and there should be a better way.

While here, fix the source ranges passed in to create
`CompositionTypeRepr`. We were tripping assertions due to missing
source-location information.
2023-05-22 21:39:59 -07:00
Doug Gregor
e935ebb682 [ASTGen] Handle simple type attributes.
Bridge the simple type attributes like `@autoclosure` into an
`AttributedTypeRepr`. We don't validate the arguments, and we don't
handle more complicated attributes like `@convention(c)` just yet.
2023-05-22 21:39:59 -07:00
Doug Gregor
3dad575e89 [ASTGen] Handle variadic parameters in functions and function types
There is a modeling difference between the swift-syntax tree and the
C++ type representation (TypeRepr) that is a little odd here, so we
end up parsing the ellipsis on the C++ side rather than looking "up"
the syntax tree to find it.
2023-05-22 21:39:59 -07:00
Doug Gregor
b50d5fe438 [ASTGen] Handle the 'Any' type 2023-05-22 21:39:59 -07:00
Doug Gregor
1340124a96 [ASTGen] Support specifiers on types such as inout and consuming 2023-05-22 21:39:59 -07:00
Rintaro Ishizaki
e181a4d39c [Macros] Improve error handling for plugin errors 2023-05-04 14:40:28 -07:00
Rintaro Ishizaki
fe1eb469e4 [ASTGen] Avoid including C standard libary headers in brigdging headers
C stdlib headers are part of "Darwin"/"Glibc" clang module.
If a Swift file imports a bridging headers and that has '#include'
C stdlib headers, Swift compiler implicitly imports "Darwin"/"Glibc"
overlay modules. That violates dependency layering. I.e. Compiler
depends on Darwin overlay, Darwin overlay is created by the compiler.

rdar://107957117
2023-04-12 17:22:32 -07:00
Doug Gregor
49277f7e89 [Macros] Move most macro definition checking into ASTGen
In preparation for supporting macros that are defined in terms of other
macros, adopt macro definition checking provided by the
`MacroDeclSyntax.checkDefinition` operation (implemented in
swift-syntax). Use this in lieu of the checking on the C++ side.

This required me to finally fix an issue with the source ranges for
Fix-Its, where we were replacing the leading/trailing trivia of nodes
along with the node itself, even though that's incorrect: we should
only replce the node itself, and there are other Fix-It kinds for
replacing leading or trailing trivia.
2023-03-29 16:30:42 -07:00
Rintaro Ishizaki
a49ab25ae8 [Macros] Recovery after executable plugin crash
When executable plugins crashed or somehow decided to exit, the compiler
should relaunch the plugin executable before sending another message.
2023-03-23 22:26:42 -07:00
Sophia Poirier
70cffb06f3 [Variadic Generics] type parameter pack syntax change: T... -> each T 2023-03-02 14:42:28 -08:00
Doug Gregor
0d6de9e4a1 [Diagnostics] Switch swift-syntax diagnostic style to grouped diagnostics
Use the new "grouped diagnostics" feature of the swift-syntax
diagnostic rendering to emit printed diagnostics under the
swift-syntax diagnostic style. This emits macro expansion buffers as
text to the terminal, inset in a box where the macro was expanded, so
that there is more context for understanding how the macro was
expanded and what went wrong inside it.
2023-02-27 08:56:21 -08:00
Rintaro Ishizaki
396c227765 [CASTBridging] Typedefs for opaque pointer types 2023-02-22 17:11:31 -08:00
Rintaro Ishizaki
0e31393024 [Macros] Add executable plugin support
Executable compiler plugins are programs invoked by the host compiler
and communicate with the host with IPC via standard IO (stdin/stdout.)
Each message is serialized in JSON, prefixed with a header which is a
64bit little-endian integer indicating the size of the message.

* Basic/ExecuteWithPipe: External program invocation. Lik
  llvm::sys::ExecuteNoWait() but establishing pipes to the child's
  stdin/stdout
* Basic/Sandbox: Sandboxed execution helper. Create command line
  arguments to be executed in sandbox environment (similar to SwiftPM's
  pluging sandbox)
* AST/PluginRepository: ASTContext independent plugin manager
* ASTGen/PluginHost: Communication with the plugin. Messages are
  serialized by ASTGen/LLVMJSON

rdar://101508815
2023-02-22 10:22:14 -08:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Anthony Latsis
56a1809f82 ASTGen: Handle member types with non-identifier qualifiers 2023-01-26 21:22:24 +03:00
Holly Borla
74bf2f3e7a [AST] Introduce a syntactic distinction betweek vararg type reprs and
pack expansion type reprs.

Classic variadic parameters still use the postfix ellipsis syntax, and
pack expansion types now use a prefix 'repeat' keyword.
2023-01-07 09:50:11 -08:00
Anthony Latsis
ad5d55c36e [NFC] AST: Rename IdentTypeReprDeclRefTypeRepr 2023-01-07 07:14:44 +03:00
Doug Gregor
14aebcab1b Bridge swift-syntax diagnostics to the C++ diagnostic engine's diagnostics.
Implement an ASTGen operation to bridge swift-syntax diagnostics, as
produced by the parser, operator folding, and macros, over to the C++
diagnostic engine infrastructure. Use this to wire up macro expansion
diagnostics.
2022-12-05 11:49:42 -08:00
zoecarver
cae1a2b7d1 [astgen] Support labeled tuples. 2022-11-03 13:54:34 -07:00
zoecarver
1e08317d3a Format sources. 2022-11-01 10:59:26 -07:00
zoecarver
b6b7224d50 [astgen] Correctly represent FuncDecl as a DeclContect. 2022-11-01 09:33:44 -07:00
zoecarver
42f4b750a9 [astgen] Add '.rawValue' to map operation. 2022-11-01 09:32:41 -07:00
Zoe Carver
60c8b4b178 Merge pull request #61834 from zoecarver/astgen-array-literal 2022-11-01 07:49:28 -07:00
zoecarver
0801d478b8 [astgen] Add support for ArrayExpr. 2022-10-31 15:20:10 -07:00
zoecarver
88dfb83d76 Address a comments post-commit. 2022-10-31 13:51:14 -07:00
zoecarver
dd4a0ec405 [nfc] Format changes. 2022-10-30 12:01:31 -07:00
zoecarver
f85d687278 [astgen] Correctly thread initializer through VarDecl visitor. 2022-10-30 12:00:58 -07:00
zoecarver
799463b81e [astgen] Add ASTNodeKind; support decls in code-blocks. 2022-10-30 11:42:55 -07:00
zoecarver
3447dd7baa [astgen] Set TypeRepr when visiting ParamDecls. 2022-10-30 11:32:02 -07:00
zoecarver
b81cb5042f [nfc] Run clang-format over CASTBridging sources. 2022-10-30 11:07:04 -07:00
zoecarver
371eb9143d [astgen] Add ReturnStmt visitor. 2022-10-30 10:55:17 -07:00
zoecarver
bec4ff77f3 [astgen] Use ASTNode to implement BraceStmt correctly. 2022-10-30 10:50:13 -07:00
Robert Widmann
b29d4673e6 Conditionalize Enum Extensibility 2022-10-27 11:11:12 -07:00
Robert Widmann
822fd47b8a Add Utilities to Retrieve the (Opened) Type of a Macro Reference 2022-10-27 11:11:11 -07:00
Robert Widmann
032e8d5e1d Start Lowering Generic ASTs
Lower generic argument lists and generic parameter lists, then expand the lowering for identifiers to take generic arguments into account.
2022-10-27 11:11:11 -07:00
Robert Widmann
f4f7f7f2ce Finish Off ASTGen Implementation for Types
Complete the lowering for the type ASTs present in SwiftSyntax to C++ TypeReprs
2022-10-27 11:11:11 -07:00
Doug Gregor
2f61489543 Don't try to bridge diagnostics from C++ to Swift
We'll be going the other way, with diagnostics existentials.
2022-10-07 10:19:06 -07:00
Doug Gregor
7483373326 [ASTGen] Use UTF-8 rather than C char, and use BridgedIdentifier consistently 2022-10-07 10:19:06 -07:00
Doug Gregor
9c00a0f549 Fix CASTBridging.h for non-Clang host compilers 2022-10-07 10:19:06 -07:00
Doug Gregor
4da85ea091 Clean up build logic for ASTGen library.
Only introduce it and its dependency when the new Swift parser is being
built, and rely more on existing logic to make sure we get the right
build/link flags.
2022-10-07 10:19:05 -07:00
zoecarver
73fe41373b Support functions with statements in their body.
(cherry picked from commit 5935670931)
2022-10-07 10:19:05 -07:00
zoecarver
93f1505e8a Add support for bool literals.
(cherry picked from commit d58a01db95)
2022-10-07 10:19:05 -07:00
zoecarver
f7d501d770 Add support for structs/classes.
(cherry picked from commit 1b1944ea48)
2022-10-07 10:19:05 -07:00
zoecarver
bed2742ba8 Make ASTGen a swift package
(cherry picked from commit 4e9e5fe6a8)
2022-10-07 10:19:05 -07:00
zoecarver
80200ec23a Add Swift-side infrastructure for ASTGen.
(cherry picked from commit 7bc67c9f12)
2022-10-07 10:18:40 -07:00