Skip to content

[libSyntax] Don't reference count RawSyntax #36165

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 2 commits into from
Mar 2, 2021
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
8 changes: 5 additions & 3 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -1817,10 +1817,12 @@ bool isKeywordPossibleDeclStart(const Token &Tok);

/// Lex and return a vector of `TokenSyntax` tokens, which include
/// leading and trailing trivia.
std::vector<std::pair<RC<syntax::RawSyntax>, syntax::AbsoluteOffsetPosition>>
std::vector<
std::pair<const syntax::RawSyntax *, syntax::AbsoluteOffsetPosition>>
tokenizeWithTrivia(const LangOptions &LangOpts, const SourceManager &SM,
unsigned BufferID, unsigned Offset = 0,
unsigned EndOffset = 0, DiagnosticEngine *Diags = nullptr);
unsigned BufferID, const RC<SyntaxArena> &Arena,
unsigned Offset = 0, unsigned EndOffset = 0,
DiagnosticEngine *Diags = nullptr);
} // end namespace swift

#endif
26 changes: 13 additions & 13 deletions include/swift/Syntax/AbsoluteRawSyntax.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ class SyntaxIndexInTree {

/// Assuming that this index points to the start of \p Raw, advance it so that
/// it points to the next sibling of \p Raw.
SyntaxIndexInTree advancedBy(const RC<RawSyntax> &Raw) const;
SyntaxIndexInTree advancedBy(const RawSyntax *Raw) const;

/// Assuming that this index points to the next sibling of \p Raw, reverse it
/// so that it points to the start of \p Raw.
SyntaxIndexInTree reversedBy(const RC<RawSyntax> &Raw) const;
SyntaxIndexInTree reversedBy(const RawSyntax *Raw) const;

/// Advance this index to point to its first immediate child.
SyntaxIndexInTree advancedToFirstChild() const;
Expand Down Expand Up @@ -84,14 +84,14 @@ class SyntaxIdentifier {

/// Assuming that this identifier points to the start of \p Raw, advance it so
/// that it points to the next sibling of \p Raw.
SyntaxIdentifier advancedBy(const RC<RawSyntax> &Raw) const {
SyntaxIdentifier advancedBy(const RawSyntax *Raw) const {
auto NewIndexInTree = IndexInTree.advancedBy(Raw);
return SyntaxIdentifier(RootId, NewIndexInTree);
}

/// Assuming that this identifier points to the next sibling of \p Raw,
/// reverse it so that it points to the start of \p Raw.
SyntaxIdentifier reversedBy(const RC<RawSyntax> &Raw) const {
SyntaxIdentifier reversedBy(const RawSyntax *Raw) const {
auto NewIndexInTree = IndexInTree.reversedBy(Raw);
return SyntaxIdentifier(RootId, NewIndexInTree);
}
Expand Down Expand Up @@ -138,11 +138,11 @@ class AbsoluteSyntaxPosition {

/// Assuming that this position points to the start of \p Raw, advance it so
/// that it points to the next sibling of \p Raw.
AbsoluteSyntaxPosition advancedBy(const RC<RawSyntax> &Raw) const;
AbsoluteSyntaxPosition advancedBy(const RawSyntax *Raw) const;

/// Assuming that this position points to the next sibling of \p Raw, reverse
/// it so that it points to the start of \p Raw.
AbsoluteSyntaxPosition reversedBy(const RC<RawSyntax> &Raw) const;
AbsoluteSyntaxPosition reversedBy(const RawSyntax *Raw) const;

/// Get the position of the node's first immediate child.
AbsoluteSyntaxPosition advancedToFirstChild() const {
Expand Down Expand Up @@ -189,15 +189,15 @@ class AbsoluteSyntaxInfo {

/// Assuming that this info points to the start of \p Raw, advance it so
/// that it points to the next sibling of \p Raw.
AbsoluteSyntaxInfo advancedBy(const RC<RawSyntax> &Raw) const {
AbsoluteSyntaxInfo advancedBy(const RawSyntax *Raw) const {
auto NewNodeId = NodeId.advancedBy(Raw);
auto NewPosition = Position.advancedBy(Raw);
return AbsoluteSyntaxInfo(NewPosition, NewNodeId);
}

/// Assuming that this info points to the next sibling of \p Raw, reverse
/// it so that it points to the start of \p Raw.
AbsoluteSyntaxInfo reversedBy(const RC<RawSyntax> &Raw) const {
AbsoluteSyntaxInfo reversedBy(const RawSyntax *Raw) const {
auto NewNodeId = NodeId.reversedBy(Raw);
auto NewPosition = Position.reversedBy(Raw);
return AbsoluteSyntaxInfo(NewPosition, NewNodeId);
Expand All @@ -214,20 +214,20 @@ class AbsoluteSyntaxInfo {
/// A \c RawSyntax node that is enrichted with information of its position
/// within the syntax tree it lives in.
struct AbsoluteRawSyntax {
const RC<RawSyntax> Raw;
const RawSyntax *Raw;
const AbsoluteSyntaxInfo Info;

public:
AbsoluteRawSyntax(const RC<RawSyntax> &Raw, AbsoluteSyntaxInfo Info)
AbsoluteRawSyntax(const RawSyntax *Raw, AbsoluteSyntaxInfo Info)
: Raw(Raw), Info(Info) {}

/// Construct a \c AbsoluteRawSyntax for a \c RawSyntax node that represents
/// the syntax tree's root.
static AbsoluteRawSyntax forRoot(const RC<RawSyntax> &Raw) {
static AbsoluteRawSyntax forRoot(const RawSyntax *Raw) {
return AbsoluteRawSyntax(Raw, AbsoluteSyntaxInfo::forRoot());
}

const RC<RawSyntax> &getRaw() const { return Raw; }
const RawSyntax *getRaw() const { return Raw; }

AbsoluteSyntaxInfo getInfo() const { return Info; }

Expand All @@ -245,7 +245,7 @@ struct AbsoluteRawSyntax {
/// - the \p NewRaw as the backing storage
/// - the \p NewRootId as the RootId
AbsoluteRawSyntax
replacingSelf(const RC<RawSyntax> &NewRaw,
replacingSelf(const RawSyntax *NewRaw,
SyntaxIdentifier::RootIdType NewRootId) const {
SyntaxIdentifier NewNodeId(NewRootId, Info.getNodeId().getIndexInTree());
AbsoluteSyntaxInfo NewInfo(Info.getPosition(), NewNodeId);
Expand Down
Loading