Skip to content

Commit

Permalink
Enable NoBlockComments and remove existing block comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
allevato committed Oct 2, 2024
1 parent 3390fcf commit 0db13de
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"rules": {
"AlwaysUseLowerCamelCase": false,
"AmbiguousTrailingClosureOverload": false,
"NoBlockComments": false,
"NoBlockComments": true,
"OrderedImports": true,
"UseLetInEveryBoundCaseVariable": false,
"UseSynthesizedInitializer": true
Expand Down
12 changes: 5 additions & 7 deletions CodeGeneration/Sources/SyntaxSupport/Child.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,11 @@ public class Child: NodeChoiceConvertible {
} else if choices.allSatisfy(\.isKeyword) {
return .keyword
} else {
/*
FIXME: Technically, returning `.unknown` is not correct here.
The old string-based implementation returned "Token" to ensure that `tokenKind` is not nil
and that `isToken` computed-property will return true, but the value "Token" had never been
used in other cases. We should try to remove this computed property altogether in the issue:
https://github.com/swiftlang/swift-syntax/issues/2010
*/
// FIXME: Technically, returning `.unknown` is not correct here.
// The old string-based implementation returned "Token" to ensure that `tokenKind` is not nil
// and that `isToken` computed-property will return true, but the value "Token" had never been
// used in other cases. We should try to remove this computed property altogether in the issue:
// https://github.com/swiftlang/swift-syntax/issues/2010
return .unknown
}
default:
Expand Down
82 changes: 38 additions & 44 deletions Sources/SwiftCompilerPluginMessageHandling/JSON/JSONDecoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,50 +35,44 @@ func decodeFromJSON<T: Decodable>(json: UnsafeBufferPointer<UInt8>) throws -> T
}
}

/*
JSONMap is inspired by swift-foundation's JSONMap.
For JSON payload such as:
```
{"foo": [-1.3, true], "barz": 42}
```
will be scanned by 'JSONScanner' into a map like:
```
<OM> == Object Marker
<AM> == Array Marker
<SS> == Simple String (a variant of String that can has no escapes and can be passed directly to a UTF-8 parser)
<NM> == Number Marker
<TL> == NULL Marker
map: [
0: <OM>, -- object marker
1: 17, | `- number of *map* elements this object occupies
2: <SS>, | --- key 1: 'foo'
3: <int_ptr>, | | |- pointer in the payload
4: 3, | | `- length
5: <AM>, | --- value 1: array
6: 6, | | `- number of *map* elements this array occupies
7: <NM>, | | -- arr elm 1: '-1.3'
8: <int_ptr>, | | |
9: 4, | | |
10: <TL>, | | -- arr elm 2: 'true'
11: <SS>, | --- key 2: 'barz'
12: <int_ptr>, | |
13: 4, | |
14: <NM> | --- value 2: '42'
15: <int_ptr>, | |
16: 2, | |
]
```
To decode '<root>.barz' value:
1. Index 0 indicates it's a object.
2. Parse a key string at index 2, which is "foo", not a match for "barz"
3. Skip the key and the value by advancing the index by 'mapSize' of them, 3 and 6.
4. Parse a key string at index 11, matching "barz"
5. Parse a value number at the pointer of index 15, length at index 16
*/
// JSONMap is inspired by swift-foundation's JSONMap.
// For JSON payload such as:
// ```
// {"foo": [-1.3, true], "barz": 42}
// ```
// will be scanned by 'JSONScanner' into a map like:
// ```
// <OM> == Object Marker
// <AM> == Array Marker
// <SS> == Simple String (a variant of String that can has no escapes and can be passed directly to a UTF-8 parser)
// <NM> == Number Marker
// <TL> == NULL Marker
// map: [
// 0: <OM>, -- object marker
// 1: 17, | `- number of *map* elements this object occupies
// 2: <SS>, | --- key 1: 'foo'
// 3: <int_ptr>, | | |- pointer in the payload
// 4: 3, | | `- length
// 5: <AM>, | --- value 1: array
// 6: 6, | | `- number of *map* elements this array occupies
// 7: <NM>, | | -- arr elm 1: '-1.3'
// 8: <int_ptr>, | | |
// 9: 4, | | |
// 10: <TL>, | | -- arr elm 2: 'true'
// 11: <SS>, | --- key 2: 'barz'
// 12: <int_ptr>, | |
// 13: 4, | |
// 14: <NM> | --- value 2: '42'
// 15: <int_ptr>, | |
// 16: 2, | |
// ]
// ```
// To decode '<root>.barz' value:
// 1. Index 0 indicates it's a object.
// 2. Parse a key string at index 2, which is "foo", not a match for "barz"
// 3. Skip the key and the value by advancing the index by 'mapSize' of them, 3 and 6.
// 4. Parse a key string at index 11, matching "barz"
// 5. Parse a value number at the pointer of index 15, length at index 16

private struct JSONMap {
enum Descriptor: Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class SourceManager {

var node = syntaxRegistry.get(source: syntaxInfo.source, kind: syntaxInfo.kind)
if let operatorTable {
node = operatorTable.foldAll(node, errorHandler: { _ in /*ignore*/ })
node = operatorTable.foldAll(node, errorHandler: { _ in }) // ignore
}

// Copy the location info from the plugin message.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public struct StandardIOMessageConnection: MessageConnection {
while ptr != endPtr {
switch write(outputFileDescriptor, ptr, numericCast(endPtr - ptr)) {
case -1: throw IOError.systemError(function: "write(_:_:_:)", errno: _errno)
case 0: throw IOError.systemError(function: "write", errno: 0) /* unreachable */
case 0: throw IOError.systemError(function: "write", errno: 0) // unreachable
case let n: ptr += Int(n)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@ private func _findAnyType(_ moduleName: String, _ typeName: String) -> Any.Type?
// actual symbol name doesn't match with it. i.e. We don't need to perform
// punycode encodings or word substitutions.
// FIXME: This is process global. Can we limit it to a specific .dylib ?
for suffix in [ /*struct*/"V", /*enum*/ "O", /*class*/ "C"] {
for suffix in [
"V", // struct
"O", // enum
"C", // class
] {
let mangled = "\(moduleName.utf8.count)\(moduleName)\(typeName.utf8.count)\(typeName)\(suffix)"
if let type = _typeByName(mangled) {
return type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ import Foundation
}

func formatImports(in file: String) -> SourceFileSyntax {
/* Formatter here */
// Formatter here
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ import SwiftSyntax
}

func formatImports(in file: String) -> SourceFileSyntax {
/* Formatter here */
// Formatter here
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import SwiftSyntax

func formatImports(in file: String) -> SourceFileSyntax {
let sourceFile = Parser.parse(source: file)
/* format source file */
// format source file
return sourceFile
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ import SwiftSyntax
}

func classifyItems(in file: SourceFileSyntax) -> [Item] {
/* Classify items here */
// Classify items here
}
}
2 changes: 1 addition & 1 deletion Sources/SwiftSyntax/SyntaxArena.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public class ParsingSyntaxArena: SyntaxArena {
public func internSourceBuffer(_ buffer: UnsafeBufferPointer<UInt8>) -> UnsafeBufferPointer<UInt8> {
let allocated = allocator.allocate(
UInt8.self,
count: buffer.count + /* for NULL */ 1
count: buffer.count + 1 // +1 for NULL
)
precondition(sourceBuffer.baseAddress == nil, "SourceBuffer should only be set once.")
_ = allocated.initialize(from: buffer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ extension BasicMacroExpansionContext {
/// Fold all operators in `node` and associated the ``KnownSourceFile``
/// information of `node` with the original new, folded tree.
func foldAllOperators(of node: some SyntaxProtocol, with operatorTable: OperatorTable) -> Syntax {
let folded = operatorTable.foldAll(node, errorHandler: { _ in /*ignore*/ })
let folded = operatorTable.foldAll(node, errorHandler: { _ in }) // ignore
if let originalSourceFile = node.root.as(SourceFileSyntax.self),
let newSourceFile = folded.root.as(SourceFileSyntax.self)
{
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftSyntaxMacroExpansion/MacroSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ private extension SyntaxProtocol {
if let basicContext = context as? BasicMacroExpansionContext {
folded = basicContext.foldAllOperators(of: self, with: operatorTable)
} else {
folded = operatorTable.foldAll(self, errorHandler: { _ in /*ignore*/ })
folded = operatorTable.foldAll(self, errorHandler: { _ in }) // ignore
}
} else {
folded = Syntax(self)
Expand Down

0 comments on commit 0db13de

Please sign in to comment.