Skip to content

[libSyntax] Store data of RecoredeOrDeferredNode as PointerIntPair #36420

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/swift/Parse/ParsedRawSyntaxNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

namespace swift {

typedef const void *OpaqueSyntaxNode;
class SyntaxParsingContext;

/// Represents a raw syntax node formed by the parser.
Expand Down
13 changes: 6 additions & 7 deletions include/swift/Parse/SyntaxParseActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#include "swift/Basic/LLVM.h"
#include "swift/Basic/SourceLoc.h"
#include "swift/Subsystems.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/Support/Allocator.h"

namespace swift {
Expand All @@ -34,8 +36,6 @@ class SourceFileSyntax;
enum class SyntaxKind : uint16_t;
}

typedef const void *OpaqueSyntaxNode;

// MARK: - Helper types

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

private:
OpaqueSyntaxNode Opaque;
Kind NodeKind;
llvm::PointerIntPair<OpaqueSyntaxNode, 2, Kind> Data;

public:
RecordedOrDeferredNode(OpaqueSyntaxNode Node, Kind NodeKind)
: Opaque(Node), NodeKind(NodeKind) {}
: Data(Node, NodeKind) {}

OpaqueSyntaxNode getOpaque() const { return Opaque; }
Kind getKind() const { return NodeKind; }
OpaqueSyntaxNode getOpaque() const { return Data.getPointer(); }
Kind getKind() const { return Data.getInt(); }
};

/// Data returned from \c getDeferredChild. This is enough data to construct
Expand Down
6 changes: 6 additions & 0 deletions include/swift/Subsystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ namespace swift {
class IRGenOptions;
class LangOptions;
class ModuleDecl;
/// A opaque syntax node created by a \c SyntaxParseAction, whose contents
/// must be interpreted by the \c SyntaxParseAction which created it.
/// Requires the two low bits to be 0, so that it can be stored in an
/// \c llvm::PointerIntPair. This is in particular guaranteed for pointers
/// to C/C++ objects and for pointers that were generated by Swift and passed
/// to the compiler via a C API (in particular \c CLibParseActions ).
Comment on lines +59 to +61
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably true, but just in case could you add an assertion in the RecordedOrDeferredNode constructor?

https://github.com/apple/llvm-project/blob/28c70a0e/llvm/include/llvm/Support/PointerLikeTypeTraits.h#L73-L74

  /// All clients should use assertions to do a run-time check to ensure that
  /// this is actually true.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PointerIntPairInfo already does this check. I suppose that it is considered the client of PointerLikeTypeTraits and we are just using PointerIntPairInfo.

https://github.com/apple/llvm-project/blob/apple/main/llvm/include/llvm/ADT/PointerIntPair.h#L178

typedef const void *OpaqueSyntaxNode;
class Parser;
class SerializationOptions;
Expand Down