Commit Graph

63 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
Tony Allevato
79935f9720 Add explicit ctors for aggregation for types that default or delete ctors.
In C++20, types that declare or delete their default/copy/move constructors are no longer aggregates, so the aggregate uses of these types will not compile under C++20. Adding them fixes this, without affecting older language modes.
2023-08-02 14:22:32 -04:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -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
fb8f71e8ce [ASTGEn] Handle _ identifier as the empty identifier 2023-05-22 21:39:59 -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
3c1867ffee [ASTGen] Handle back-ticked names as identifiers 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
Holly Borla
35fcc37136 Merge pull request #65134 from hborla/parameter-pack-revision
[SE-0393] Require the `repeat` keyword for generic requirement expansions.
2023-04-13 08:33:25 -07:00
Holly Borla
234b5dc660 [SE-0393] Require the repeat keyword for generic requirement expansions. 2023-04-12 22:04:01 -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
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
Rintaro Ishizaki
93aabfff01 Merge pull request #64006 from rintaro/macros-plugin-errhandling
[Macros] Improve error handling for executable macro plugins
2023-03-02 22:10:51 -08:00
Rintaro Ishizaki
a6e0191bc0 [Macros] Improve error handling for executable macro plugins
* Handle broken pipe
* Handle invalid response (malformed message, unexpected message kind)
2023-03-02 17:40:55 -08: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
138934ed64 [PluginRegistry] Error handling tweaks 2023-02-23 10:32:21 -08:00
Rintaro Ishizaki
c5a737f9ba [AST] PluginRegistry returns Error/Expected instead of errorMsg out 2023-02-22 17:35:56 -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
1bb407ac8c [NFC] AST: Rename ComponentIdentTypeReprIdentTypeRepr 2023-01-07 07:15:36 +03:00
Anthony Latsis
ad5d55c36e [NFC] AST: Rename IdentTypeReprDeclRefTypeRepr 2023-01-07 07:14:44 +03:00
Anthony Latsis
746c7aff7d [NFC] AST: Rename CompoundIdentTypeReprMemberTypeRepr 2023-01-07 07:14:41 +03:00
Anthony Latsis
8935acdd5b [NFC] AST: Remove IdentTypeRepr::create 2023-01-07 07:11:29 +03:00
Doug Gregor
402ba1492f Set closure descriminators via a request.
Rather than set closure discriminators in both the parser (for explicit
closures) and then later as part of contextualizing closures (for
autoclosures), do so via a request that sets all of the discriminators
for a given context.
2022-12-19 15:23:45 -08: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
Zoe Carver
1ae1c43bf4 Merge pull request #62298 from zoecarver/fix-warning-astgen
[nfc][astgen] Ignore deprecation warning around bridged dump methods.
2022-11-30 10:10:28 -07:00
zoecarver
20deaba67e [nfc][astgen] Ignore deprecation warning around bridged dump methods. 2022-11-29 10:13:20 -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
8beda688bc [astgen] Use empty param list for closures to fix crash (this will eventually need to be implemented proprly). 2022-11-01 09:32:41 -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
06d6c9219b [astgen] Fix two use-after-frees. 2022-10-31 15:01:28 -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
37ef2d7834 [astgen] Correctly thread 'name' through VarDecl visitor. 2022-10-30 11:50:15 -07:00
zoecarver
799463b81e [astgen] Add ASTNodeKind; support decls in code-blocks. 2022-10-30 11:42:55 -07:00
zoecarver
f05302b58a [astgen] Use 'arg name' as 'param name' if there is no 'param name'. 2022-10-30 11:32:43 -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