Commit Graph

754 Commits

Author SHA1 Message Date
Alex Hoppen
b31398215d Don’t include SourceLoc.h when USED_IN_CPP_SOURCE is not set 2023-11-27 19:34:27 -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
Alex Hoppen
f408619ddc Address Hamish’s review comments 2023-11-27 14:17:04 -08:00
Alex Hoppen
330ed60401 [SourceKit] Don't use C++ interop to append elements to a ResolvedLocVector
This was causing build issues on Linux with Swift 5.8. Instead, wrap the `std::vector` in a `BridgedResolvedLocVector` that has a pointer to a heap-allocated `std::vector`
2023-11-22 16:41:07 -08:00
Alex Hoppen
d224549030 [SourceKit] Don’t use C++ to Swift interop to run NameMatcher 2023-11-20 11:30:18 -08:00
Alex Hoppen
8fd025625b [SourceKit] Use NameMatcher that is rewritten in Swift for syntactic rename 2023-11-17 09:30:04 -08:00
Rintaro Ishizaki
e395df3ef3 Merge pull request #69930 from rintaro/astgen-regex-cleanup
[Parse] Remove RegexParserBridging.h
2023-11-16 19:04:24 -08:00
Rintaro Ishizaki
49f28c8651 Merge pull request #69894 from rintaro/astgen-choice-optional
[ASTGen] Several improvements to generalize node handling
2023-11-16 16:25:54 -08:00
Rintaro Ishizaki
986415a4af [Parse] Remove RegexParserBridging.h
This is not used anymore
2023-11-16 14:01:41 -08:00
Rintaro Ishizaki
24b44e371c Revert "ASTGen: add a workaround for CSC conformance visibility"
This reverts commit 5d0c5a643f.
2023-11-16 11:02:52 -08:00
Rintaro Ishizaki
47f18d492e [ASTGen] Move regex literal parsing from SwiftCompilerSources to ASTGen
ASTGen always builds with the host Swift compiler, without requiring
bootstrapping, and is enabled in more places. Move the regex literal
parsing logic there so it is enabled in more host environments, and
makes use of CMake's Swift support. Enable all of the regex literal
tests when ASTGen is built, to ensure everything is working.

Remove the "AST" and "Parse" Swift modules from SwiftCompilerSources,
because they are no longer needed.
2023-11-16 10:59:23 -08:00
Rintaro Ishizaki
aeb7a215fd [ASTGen] Add back specialized generate() functions for optional nodes 2023-11-15 13:43:20 -08:00
Rintaro Ishizaki
db4a2a4e02 [ASTGen] Generalize Optional node handling
Defining `generate(_: XXXSyntax?) -> BridgedXXX` for each node kind is too
much boilerplate.

  self.generate(optional: optionalXXXNode).asNullable

is now:

  self.map(optionalXXXNode, generate(xxx:))
2023-11-15 11:04:12 -08:00
Rintaro Ishizaki
91fa051a37 [ASTGen] Remove TypeRepr from ASTGen.ASTNode
Now that ASTNode is used only for codeBlockItem generation. That align
with C++ ASTNode where it represent code items.

Since TypeRepr is not an ASTGen in C++, remove it from ASTGen too.
2023-11-15 10:59:10 -08:00
Rintaro Ishizaki
d95d7e526e [ASTGen] Generate ConditionElement using switch
Generating ConditionElement using generate(_:) wouldn't work when we
implemnt other condition kinds e.g. patterns because they are not
ASTNode kinds.
Remove generate(choices:) and generate(_:) as they weren't used anymore.
2023-11-15 10:59:10 -08:00
Rintaro Ishizaki
1d558ebe52 [ASTGen] Don't use generate(_: Syntax) -> ASTNode for partial gen
We already know the type of the node. There's no reason switch over
again and wrap the result with ASTNode.
2023-11-15 10:59:10 -08:00
Rintaro Ishizaki
94c6987c97 [ASTGen] Reduce usage of generate(choices:)
`generate(choices:)` is not good because it expects "ASTNode". Not all
`SyntaxChildChoices` can generate ASTNode.

* `generate(codeBlockItem:)` to manually switch over the cases
* switch on `IfExpr.ElseBody` insdie `makeIfStmt()`, now supports `else
  if` case
2023-11-15 10:59:08 -08:00
Rintaro Ishizaki
07a432d2a5 [ASTGen] Soft deprecate generate(choices:) 2023-11-14 19:49:10 -08:00
Rintaro Ishizaki
5fdeabd045 [ASTGen] Give argument labels to all generate(_:) functions
Explicit argument labels are useful for "Open Quickly..." in Xcode,
reduce the fear of miss overload resolution, and better crash
backtrace as they might not show parameter types.
2023-11-14 19:49:10 -08:00
Rintaro Ishizaki
215abe6d40 [ASTGen] Start generating Patterns 2023-11-14 10:47:31 -08:00
Rintaro Ishizaki
038597c80f [ASTGen] Use kind specific SyntaxEnum 2023-11-14 10:47:16 -08:00
Rintaro Ishizaki
b3991732c7 Merge pull request #69761 from rintaro/astgen-incremental-develop
[ASTGen] Infrastructure for implementing ASTGen incrementally
2023-11-13 14:10:28 -08:00
Rintaro Ishizaki
f3f4b19776 [ASTGen] Remove ASTGenTypes experimental feature
There's no reason to generate only TypeRepr using ASTGen anymore.
Use ParserASTGen feature to test test/ASTGen/types.swift because
ASTGen now can generate the whole test file for type checking.
2023-11-12 21:43:09 -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
Sophia Poirier
353d04fd73 Merge pull request #69725 from sophiapoirier/nonisolated-unsafe-experimental-feature-flag-mapping
map nonisolated(unsafe) experimental feature for SwiftParser
2023-11-10 19:30:52 -08:00
Rintaro Ishizaki
2c8d7f2550 [ASTGen] Generalize findSyntaxNodeInSourceFile(wantOutermost:true)
When 'wantOutermost' is true, traverse the parent as long as the
position is the same as the target position.
2023-11-10 12:59:19 -08:00
Rintaro Ishizaki
da9813e517 [ASTGen] Add copyright headers 2023-11-09 23:33:01 -08:00
Sophia Poirier
6690d57465 map nonisolated(unsafe) experimental feature for SwiftParser 2023-11-09 11:05:34 -08:00
Alejandro Alonso
16cbb76fc6 Merge pull request #69710 from Azoy/stdlib-warning-cleanup
[stdlib] Silence some standard library warnings
2023-11-08 20:09:13 -08:00
Alejandro Alonso
e41fe5a173 Special case some unknown builtin macros 2023-11-08 16:02:31 -08:00
Meghana Gupta
5658deae27 Add initial support for _resultDependsOnSelf
This is used to establish lifetime dependence between self and the result.

Add under NonEscapableTypes experimental feature
2023-11-08 01:48:59 -08:00
Hamish Knight
9216672db7 Improve some bridging interfaces
Migrate a bunch of structs to classes, and
uppercase field names.
2023-10-31 11:06:41 +00:00
Hamish Knight
2a6d93f505 [Basic] Improve API of BridgedArrayRef + BridgedData
Remove the default constructor footgun present with
the struct implementations, and sprinkle some
`SWIFT_NAME` and bridging utilities to make them
nicer to work with.
2023-10-30 23:49:59 +00:00
Hamish Knight
dc899c53de [AST] Use consistent naming for bridging functions
Add a `Bridged` prefix to match the name being
exposed to Swift, and to match the other bridging
functions. Also while here, use `SWIFT_NAME` for
some bridging functions that were missing it.
2023-10-30 23:49:58 +00:00
Hamish Knight
6afde8a6d2 Remove CBasicBridging and CASTBridging
Merge with BasicBridging and ASTBridging
respectively. The changes here should be pretty
uncontroversial, I tried to keep it to just moving
code about.
2023-10-30 23:49:56 +00:00
Hamish Knight
fce1cb54d5 [AST] Merge BridgedDiagnosticEngine + BridgedDiagEngine
Introduce a macro that can stamp out wrapper
classes for underlying C++ pointers, and use
it to define BridgedDiagnosticEngine in
ASTBridging. Then, migrate users of
BridgedDiagEngine onto it.
2023-10-30 23:49:55 +00:00
Hamish Knight
fe0ad60fe8 [ASTGen] Fix a couple of @_cdecl param types
These are `void *` on the C side.
2023-10-30 23:49:54 +00:00
Hamish Knight
356cf31d83 [ASTGen] Migrate onto some BasicBridging types
Migrate onto BridgedStringRef, and the
BasicBridging equivalents of BridgedSourceLoc
and BridgedArrayRef.
2023-10-30 23:49:53 +00:00
Hamish Knight
e5442fea50 [ASTGen] Enable C++ interop 2023-10-30 23:49:52 +00:00
Hamish Knight
d1fa767c84 Merge pull request #69326 from hamishknight/null-and-void 2023-10-23 23:54:50 +01:00
Hamish Knight
9da66906d5 [ASTGen] NFC: Fixup formatting 2023-10-23 18:41:10 +01:00
Hamish Knight
4a4a04888c [ASTGen] Introduce nullable variants of bridging wrappers
For nullable nodes, introduce both a non-null and
nullable variant of the bridging wrapper. This
allows us to annotate the necessary parameters
as nullable, but keep the returns of the bridged
`createParsed` methods non-null.
2023-10-23 18:00:13 +01:00
Hamish Knight
5d105f175d [ASTGen] NFC: Format with swift-format
This uses the same formatting configuration as
sourcekit-lsp.
2023-10-23 10:51:23 +01:00
Hamish Knight
11b8549442 Merge pull request #69229 from hamishknight/boxing-match
[ASTGen] Introduce wrapper types for AST nodes
2023-10-21 15:08:24 +01:00
Hamish Knight
3639d866cb Address review feedback 2023-10-20 22:57:14 +01:00
Hamish Knight
2ad64f1a40 [ASTGen] Use SWIFT_NAME in some more places 2023-10-20 22:57:13 +01:00
Hamish Knight
6d3c0c88a7 [ASTGen] Introduce wrapper types for AST nodes
Stamp out wrapper types for all the AST nodes,
and use them for ASTGen, with members being
imported on those types.
2023-10-20 22:57:12 +01:00
Harlan Haskins
4ac34a40ea @retroactive conformance syntax and checking (#36068) 2023-10-20 14:27:03 -07:00
Rintaro Ishizaki
bce5eeb78d [ASTGen] Null-terminate error messsages from ASTGen
Always null-terminate `BridgedString` by  `allocateBridgedString()`.
It had `nullTerminated: Bool` option, but allocating one extra byte
doesn't harm anything. Always null-terminate the string just for
client's convenience.

rdar://117205829
2023-10-19 13:29:57 -07:00
Rintaro Ishizaki
37a637447f Merge pull request #69027 from rintaro/macro-resolveerror-rdar115571427
[Macros] Improve macro plugin loading macro definition resolution diagnostics
2023-10-16 17:35:48 -07:00