Skip to content

Commit 087a7da

Browse files
committed
Remove remaining references to gyb
1 parent 9dff225 commit 087a7da

File tree

8 files changed

+32
-199
lines changed

8 files changed

+32
-199
lines changed

CodeGeneration/README.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22

33
This directory contains file to generate source code that is part of the SwiftSyntax package. If you are looking to generate Swift code yourself, you might be interested in [SwiftSyntaxBuilder](../Sources/SwiftSyntaxBuilder).
44

5-
SwiftSyntax currently uses two mechanisms to generate source code: gyb and SwiftSyntaxBuilder. Both can be run using
6-
7-
```bash
8-
./build-script.py generate-source-code --toolchain /path/to/toolchain.xctoolchain/usr
9-
```
10-
11-
## `gyb`
12-
13-
Files generated using `gyb` have a `.gyb` suffix. [ChangingSwiftSyntax.md](../Sources/SwiftSyntax/Documentation.docc/ChangingSwiftSyntax.md) contains documentation how `gyb` works. This directory contains the definitions that back most of gyb-generation in `gyb_syntax_support`.
14-
15-
## `SwiftSyntaxBuilder`
16-
175
Some source code inside SwiftSyntax is generated using [SwiftSyntaxBuilder](../Sources/SwiftSyntaxBuilder), a Swift library whose purpose is to generate Swift code using Swift itself. This kind of code generation is performed by the Swift package defined in this directory.
186

19-
This directory is a standalone package that uses a pinned version of SwiftSyntaxBuilder. It is thus NOT using SwiftSyntaxBuilder of the parent directory. This guarantees that when `generate-swiftsyntaxbuilder` is run, it can't break its own build.
7+
This directory is a standalone package that uses a pinned version of SwiftSyntaxBuilder. It is thus NOT using SwiftSyntaxBuilder of the parent directory. This guarantees that when `generate-swiftsyntaxbuilder` is run, it can't break its own build.

CodeGeneration/Sources/Utils/SyntaxBuildableType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct SyntaxBuildableType: Hashable {
2626
public init(syntaxKind: String, isOptional: Bool = false) {
2727
self.isOptional = isOptional
2828
if syntaxKind.hasSuffix("Token") {
29-
// There are different token kinds but all of them are represented by `Token` in the Swift source (see `kind_to_type` in `gyb_syntax_support`).
29+
// There are different token kinds but all of them are represented by `Token` in the Swift source (see `kindToType` in `SyntaxSupport/Utils.swift`).
3030
self.syntaxKind = "Token"
3131
self.tokenKind = syntaxKind
3232
} else {

CodeGeneration/Sources/Utils/Utils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public func dedented(string: String) -> String {
2222
}
2323

2424
/// Creates a single-line documentation string from indented
25-
/// documentation as written in `gyb_syntax_support`.
25+
/// documentation as written in `CodeGeneration`.
2626
public func flattened(indentedDocumentation: String) -> String {
2727
dedented(string: indentedDocumentation)
2828
.replacingOccurrences(of: "\n", with: "")

CodeGeneration/Sources/generate-swiftsyntax/templates/swiftsyntax/SyntaxNodeFile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import SwiftSyntaxBuilder
1515
import SyntaxSupport
1616
import Utils
1717

18-
/// This gyb-file generates the syntax nodes for SwiftSyntax. To keep the generated
18+
/// This file generates the syntax nodes for SwiftSyntax. To keep the generated
1919
/// files at a managable file size, it is to be invoked multiple times with the
2020
/// variable `emitKind` set to a base kind listed in
2121
/// It then only emits those syntax nodes whose base kind are that specified kind.

Sources/SwiftParser/README.md

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,3 @@ assert(sourceFile.description == sourceText)
2727
// Visualize the complete syntax tree.
2828
dump(sourceFile)
2929
```
30-
31-
## Implementation Status
32-
33-
There are a number of implementation tasks involved in realizing the parser, which include:
34-
35-
* [ ] Parsing
36-
* [x] Rough parse of full grammar
37-
* [x] Recovery from unexpected syntax
38-
* [x] Insert missing syntax where needed
39-
* [ ] SIL syntax
40-
* [ ] [Regular expression literals](https://github.com/apple/swift-experimental-string-processing)
41-
* [x] Parse into raw syntax nodes
42-
* [ ] Diagnostics
43-
* [ ] Render diagnostics to a terminal with color, highlights, etc.
44-
* [ ] Fix-Its to add/remove/replace syntax
45-
* [ ] Emit diagnostics in the same binary format that the Swift compiler/driver do
46-
* [x] Syntax visitor to emit diagnostics for all missing and unexpected syntax
47-
* [ ] Tooling and automation
48-
* [ ] Improve test harness to easily check the expected parse trees + diagnostics
49-
* [ ] Migrate [attribute definitions](https://github.com/apple/swift/blob/main/include/swift/AST/Attr.def) from C++ to Swift
50-
* [x] Migrate [grammar definition](https://github.com/apple/swift/tree/main/utils/gyb_syntax_support) to the swift-syntax repository
51-
* [ ] Migrate grammar definition from Python to Swift
52-
* [ ] Replace uses of gyb with SwiftSyntax-based generation
53-
* [ ] Auditing the grammar to ensure that it accurately represents the Swift grammar
54-
* [ ] Attributes
55-
* [ ] Declarations
56-
* [ ] Statements
57-
* [ ] Expressions
58-
* [ ] AST generation within the Swift compiler itself
59-
60-
### Testing methodology
61-
62-
We'll employ a number of different techniques to help test the new parser at each phase, including:
63-
64-
* [x] Unit tests for specific parser behaviors, added as we implement pieces and uncover bugs.
65-
66-
* [ ] Self-parse test to ensure that all Swift files in the package can be parsed, that the syntax tree is well-formed, and that it always reproduces the input source.
67-
68-
* [ ] Parsing tests from the Swift compiler repository to check that the parsers accept the same code.
69-
70-
* [ ] Fuzzing tests that ensure that the parser does not crash, and always reproduces the input source.

Sources/SwiftSyntax/Documentation.docc/ChangingSwiftSyntax.md

Lines changed: 26 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,18 @@ Discover the steps necessary to add, remove, and update syntax nodes
66

77
The surface area of the entire Swift programming language is represented in the
88
Swift Syntax API and its associated data structures. In order to keep these
9-
structures in sync, this project makes use of a code generation utility called
10-
[gyb][GYB] - short for "Generate Your Boilerplate".
11-
12-
## Introduction to GYB
13-
14-
The gyb utility allows for [literate metaprogramming][LiterateProgramming] of
15-
files in any human-editable format. The standard convention is to attach the
16-
`.gyb` suffix to a file. For example, this repository uses `.swift.gyb` files
17-
that generate `.swift` code. The metaprogramming language that gyb uses is
18-
python. Templating code is delimited by `%` and can be used inline with `${...}`
19-
blocks.
20-
21-
Here is the gyb definition for all of the cases of the <doc:TokenKind> enum.
22-
23-
```swift
24-
public enum TokenKind: Hashable {
25-
case eof
26-
% for token in SYNTAX_TOKENS:
27-
% kind = token.swift_kind()
28-
%
29-
% # Tokens that don't have a set text have an associated value that
30-
% # contains their text.
31-
% if not token.text:
32-
% kind += '(String)'
33-
% end
34-
case ${kind}
35-
% end
36-
}
37-
```
38-
39-
- Note: gyb files act as the source of truth in this repository. Always edit
40-
gyb files instead of the corresponding Swift files, or your changes will
41-
be overwritten the next time those files are regenerated.
9+
structures in sync, this project makes generates the code using the Swift package
10+
`CodeGeneration`, located in the root of this repository.
4211

4312
## Regenerating Files
4413

45-
While working on gyb files, it can be helpful to regenerate the files in this
46-
repository to see the effects of local changes. SwiftSyntax comes with a script
47-
called `build-script.py` that automates the process of regenerating, validating,
48-
and building all of the files in this repository.
49-
50-
To invoke `build-script.py` to regenerate source code, run
51-
52-
```
53-
$ ./build-script.py generate-source-code --toolchain /path/to/toolchain/usr
54-
```
55-
56-
where `/path/to/toolchain` can point either to the `XcodeDefault.xctoolchain`
57-
installed with Xcode, or to a [toolchain downloaded from swift.org][SwiftToolchains].
58-
59-
- Note: To see the raw commands that `build-script.py` is running, use the `-v`
60-
flag. This can be used to dump the command(s) necessary to regenerate
61-
one file at a time.
62-
63-
This script also comes with a verification command that is run by Swift's
64-
CI/CD systems to ensure that you regenerate files before they are checked into
65-
the version control system.
66-
67-
To invoke `build-script.py` in verification mode, run
68-
69-
```
70-
$ ./build-script.py verify-source-code --toolchain /path/to/toolchain/usr
71-
```
14+
To re-generate the files after changing `CodeGeneration` run the `generate-swiftsyntax`
15+
target of `CodeGeneration` and pass `path/to/swift-syntax/Sources` as the argument.
7216

7317
## Adding and Removing Syntax Nodes
7418

7519
The files containing the definition of all of the syntax nodes are available
76-
under the [gyb_syntax_support][gyb_syntax_support] directory. These files
20+
under the [SyntaxSupport][SyntaxSupport] directory. These files
7721
are roughly divided according to broad syntactic categories in the Swift
7822
programming language. That is, the syntax nodes for classes, structs, and actors
7923
are defined in `DeclNodes.py`, while the syntax nodes for string literals,
@@ -92,74 +36,29 @@ nodes among these categories for easier processing.
9236

9337
The node for a source file is reproduced below:
9438

95-
```python
96-
Node('SourceFile', name_for_diagnostics='source file', kind='Syntax',
97-
traits=['WithStatements'],
98-
children=[
99-
Child('Statements', kind='CodeBlockItemList',
100-
collection_element_name='Statement'),
101-
Child('EOFToken', kind='EOFToken')
102-
]),
103-
```
104-
105-
Notice that the `Statements` child node contains a `collection_element_name`
106-
field. This is because it is defining a syntax collection with the type
107-
`CodeBlockItemList` with elements that are `Statement` nodes.
108-
109-
- Warning: Always remember to run `build-script.py` to regenerate files after
110-
you make changes to the syntax nodes.
111-
112-
113-
## Adding and Removing Attributes
114-
115-
The file that defines all of the attributes respected by the Swift compiler
116-
is available under the [gyb_syntax_support][gyb_syntax_support] directory
117-
in AttributedKinds.py.
118-
119-
### Type Attributes
120-
121-
To define a new attribute that applies to types, add a new `TypeAttribute` to
122-
the `TYPE_ATTR_KINDS` list with the name of the attribute spelled without the
123-
leading '@' sign.
124-
125-
```python
126-
TypeAttribute('_myAttribute'), # Becomes @_myAttribute in the compiler
127-
```
39+
```swift
40+
Node(
41+
name: "SourceFile",
42+
nameForDiagnostics: "source file",
43+
kind: "Syntax",
44+
traits: [
45+
"WithStatements"
46+
],
47+
parserFunction: "parseSourceFile",
48+
children: [
49+
Child(
50+
name: "Statements",
51+
kind: .collection(kind: "CodeBlockItemList", collectionElementName: "Statement")
52+
),
53+
Child(
54+
name: "EOFToken",
55+
kind: .node(kind: "EOFToken")
56+
),
57+
]
58+
),
12859

129-
### Declaration Attributes
130-
131-
To define a new attribute that applies to declarations, add a new
132-
`DeclAttribute` to the `DECL_ATTR_KINDS` list. Declaration attributes are
133-
richer than type attributes, and require a bit more metadata to define them.
134-
A `DeclAttribute` consists of the attribute's name, the name of the
135-
corresponding C++ class, a series of metadata tags, and a stable serialization
136-
code.
137-
138-
To add an attribute, identify an unused serialization code and place the
139-
attribute in the correct position in the `DECL_ATTR_KINDS` list. Then,
140-
fill out the corresponding metadata and tags. At a minimum, every attribute
141-
should come with ABI and API stability tags. But there are also tags that
142-
alter the behavior of the AST printer and the parser that may be desirable.
143-
144-
The definition of the `_silgen_name` declaration attribute is reproduced below
145-
as it provides a good example of many of these tags:
146-
147-
```python
148-
DeclAttribute('_silgen_name', 'SILGenName', # Spelled @_silgen_name, becomes SILGenNameAttr in C++
149-
OnAbstractFunction, # Only applies to functions - parser will diagnose other usages automatically
150-
LongAttribute, UserInaccessible, # Attribute should be printed on its own line since it's long.
151-
ABIStableToAdd, ABIStableToRemove, APIStableToAdd, APIStableToRemove, # Stability tags
152-
code=0), # Serialization code
15360
```
15461

155-
Once a new attribute has been added, you will need to regenerate SwiftSyntax to
156-
account for it. If the attribute includes a non-trivial set of arguments,
157-
consider adding a dedicated syntax node for it as well. To use the new attribute
158-
with the Swift compiler, ensure that swift-syntax and swift are checked out
159-
alongside each other and invoke the appropriate build tool to rebuild the Swift
160-
compiler. The compiler's build system automatically detects changes to the
161-
Attr.def.gyb gyb file and the python defined here.
162-
16362
## Committing Changes
16463

16564
When it is time to commit changes to the Swift Syntax repository, most cases
@@ -186,10 +85,9 @@ and is a much more involved process. [The Swift Forums][CompilerDev] are a
18685
great source for guidance on how to extend the C++ compiler to accomodate new
18786
syntax and semantics for the Swift programming language.
18887

189-
[GYB]: https://github.com/apple/swift/blob/main/utils/gyb.py
19088
[LiterateProgramming]: https://en.wikipedia.org/wiki/Literate_programming
19189
[SwiftToolchains]: https://www.swift.org/download/
192-
[gyb_syntax_support]: https://github.com/apple/swift-syntax/tree/main/Sources/generate-swift-syntax-builder/gyb_syntax_support
90+
[SyntaxSupport]: https://github.com/apple/swift-syntax/tree/main/CodeGeneration/Sources/SyntaxSupport
19391
[swift-stress-tester]: https://github.com/apple/swift-stress-tester
19492
[Swiftc]: https://github.com/apple/swift
19593
[ParserBasics]: https://github.com/apple/swift-syntax/tree/main/Sources/SwiftParser/SwiftParser.docc/ParsingBasics.md

build-script.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def realpath(path: Optional[str]) -> Optional[str]:
118118

119119

120120
# -----------------------------------------------------------------------------
121-
# Generating gyb Files
121+
# Generating Files
122122

123123

124124
def run_code_generation(
@@ -515,16 +515,6 @@ def test_command(args: argparse.Namespace) -> None:
515515
_DESCRIPTION = """
516516
Build and test script for SwiftSyntax.
517517
518-
Build SwiftSyntax by generating all necessary files form the corresponding
519-
.swift.gyb files first. For this, SwiftSyntax needs to be check out alongside
520-
the main swift repo (http://github.com/apple/swift/) in the following structure
521-
522-
- (containing directory)
523-
- swift
524-
- swift-syntax
525-
526-
It is not necessary to build the compiler project.
527-
528518
The build script can also drive the test suite included in the SwiftSyntax
529519
repo. This requires a custom build of the compiler project since it accesses
530520
test utilities that are not shipped as part of the toolchains. See the Testing

format.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ def get_files_to_format() -> List[Path]:
8989
files_to_format = package_dir.glob('**/*.swift')
9090

9191
def should_exclude(path: Path) -> bool:
92-
if 'gyb_generated' in path.parts:
93-
return True
94-
elif 'lit_tests' in path.parts:
92+
if 'lit_tests' in path.parts:
9593
return True
9694
elif 'generated' in path.parts:
9795
return True

0 commit comments

Comments
 (0)