Skip to content

Commit 74ed2ac

Browse files
committed
[libSyntax] Store data of RecoredeOrDeferredNode as PointerIntPair
This furthere reduces the size of ParsedRawSyntaxNode, as well as for intermediate data structures using in SyntaxParseActions, improving syntax parsing performance.
1 parent e1e0f54 commit 74ed2ac

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

include/swift/Parse/ParsedRawSyntaxNode.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
namespace swift {
3535

36-
typedef const void *OpaqueSyntaxNode;
3736
class SyntaxParsingContext;
3837

3938
/// Represents a raw syntax node formed by the parser.

include/swift/Parse/SyntaxParseActions.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#include "swift/Basic/LLVM.h"
2222
#include "swift/Basic/SourceLoc.h"
23+
#include "swift/Subsystems.h"
24+
#include "llvm/ADT/PointerIntPair.h"
2325
#include "llvm/Support/Allocator.h"
2426

2527
namespace swift {
@@ -34,8 +36,6 @@ class SourceFileSyntax;
3436
enum class SyntaxKind : uint16_t;
3537
}
3638

37-
typedef const void *OpaqueSyntaxNode;
38-
3939
// MARK: - Helper types
4040

4141
/// A syntax node that can either be deferred or recorded. The actual data is
@@ -51,15 +51,14 @@ class RecordedOrDeferredNode {
5151
};
5252

5353
private:
54-
OpaqueSyntaxNode Opaque;
55-
Kind NodeKind;
54+
llvm::PointerIntPair<OpaqueSyntaxNode, 2, Kind> Data;
5655

5756
public:
5857
RecordedOrDeferredNode(OpaqueSyntaxNode Node, Kind NodeKind)
59-
: Opaque(Node), NodeKind(NodeKind) {}
58+
: Data(Node, NodeKind) {}
6059

61-
OpaqueSyntaxNode getOpaque() const { return Opaque; }
62-
Kind getKind() const { return NodeKind; }
60+
OpaqueSyntaxNode getOpaque() const { return Data.getPointer(); }
61+
Kind getKind() const { return Data.getInt(); }
6362
};
6463

6564
/// Data returned from \c getDeferredChild. This is enough data to construct

include/swift/Subsystems.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ namespace swift {
5353
class IRGenOptions;
5454
class LangOptions;
5555
class ModuleDecl;
56+
/// A opaque syntax node created by a \c SyntaxParseAction, whose contents
57+
/// must be interpreted by the \c SyntaxParseAction which created it.
58+
/// Requires the two low bits to be 0, so that it can be stored in an
59+
/// \c llvm::PointerIntPair. This is in particular guaranteed for pointers
60+
/// to C/C++ objects and for pointers that were generated by Swift and passed
61+
/// to the compiler via a C API (in particular \c CLibParseActions ).
5662
typedef const void *OpaqueSyntaxNode;
5763
class Parser;
5864
class SerializationOptions;

0 commit comments

Comments
 (0)