Skip to content

NFC: Remove SILParserState from Subsystems #31950

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 1 commit into from
May 22, 2020
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
6 changes: 3 additions & 3 deletions include/swift/Parse/ParseSILSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ namespace swift {

/// Interface between the Parse and ParseSIL libraries, to avoid circular
/// dependencies.
class SILParserTUStateBase {
class SILParserStateBase {
virtual void anchor();
protected:
SILParserTUStateBase() = default;
virtual ~SILParserTUStateBase() = default;
SILParserStateBase() = default;
virtual ~SILParserStateBase() = default;
public:
virtual bool parseDeclSIL(Parser &P) = 0;
virtual bool parseDeclSILStage(Parser &P) = 0;
Expand Down
11 changes: 5 additions & 6 deletions include/swift/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace swift {
class Lexer;
class ParsedTypeSyntax;
class PersistentParserState;
class SILParserTUStateBase;
class SILParserStateBase;
class ScopeInfo;
class SourceManager;
class TupleType;
Expand Down Expand Up @@ -114,7 +114,7 @@ class Parser {
DiagnosticEngine &Diags;
SourceFile &SF;
Lexer *L;
SILParserTUStateBase *SIL; // Non-null when parsing SIL decls.
SILParserStateBase *SIL; // Non-null when parsing SIL decls.
PersistentParserState *State;
std::unique_ptr<PersistentParserState> OwnedState;
DeclContext *CurDeclContext;
Expand Down Expand Up @@ -396,14 +396,13 @@ class Parser {

public:
Parser(unsigned BufferID, SourceFile &SF, DiagnosticEngine* LexerDiags,
SILParserTUStateBase *SIL,
PersistentParserState *PersistentState,
SILParserStateBase *SIL, PersistentParserState *PersistentState,
std::shared_ptr<SyntaxParseActions> SPActions = nullptr);
Parser(unsigned BufferID, SourceFile &SF, SILParserTUStateBase *SIL,
Parser(unsigned BufferID, SourceFile &SF, SILParserStateBase *SIL,
PersistentParserState *PersistentState = nullptr,
std::shared_ptr<SyntaxParseActions> SPActions = nullptr);
Parser(std::unique_ptr<Lexer> Lex, SourceFile &SF,
SILParserTUStateBase *SIL = nullptr,
SILParserStateBase *SIL = nullptr,
PersistentParserState *PersistentState = nullptr,
std::shared_ptr<SyntaxParseActions> SPActions = nullptr);
~Parser();
Expand Down
12 changes: 0 additions & 12 deletions include/swift/Subsystems.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ namespace swift {
class SerializationOptions;
class SILOptions;
class SILModule;
class SILParserTUState;
class SourceFile;
enum class SourceFileKind;
class SourceManager;
Expand All @@ -74,17 +73,6 @@ namespace swift {
class TypeConverter;
}

/// Used to optionally maintain SIL parsing context for the parser.
///
/// When not parsing SIL, this has no overhead.
class SILParserState {
public:
std::unique_ptr<SILParserTUState> Impl;

explicit SILParserState(SILModule *M);
~SILParserState();
};

/// @{

/// \returns true if the declaration should be verified. This can return
Expand Down
3 changes: 1 addition & 2 deletions lib/Parse/ParseRequests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ BraceStmt *ParseAbstractFunctionBodyRequest::evaluate(
SourceFile &sf = *afd->getDeclContext()->getParentSourceFile();
SourceManager &sourceMgr = sf.getASTContext().SourceMgr;
unsigned bufferID = sourceMgr.findBufferContainingLoc(afd->getLoc());
Parser parser(bufferID, sf, static_cast<SILParserTUStateBase *>(nullptr),
nullptr, nullptr);
Parser parser(bufferID, sf, /*SIL*/ nullptr);
parser.SyntaxContext->disable();
auto body = parser.parseAbstractFunctionBodyDelayed(afd);
afd->setBodyKind(BodyKind::Parsed);
Expand Down
9 changes: 4 additions & 5 deletions lib/Parse/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void tokenize(const LangOptions &LangOpts, const SourceManager &SM,
using namespace swift;
using namespace swift::syntax;

void SILParserTUStateBase::anchor() { }
void SILParserStateBase::anchor() { }

void swift::performCodeCompletionSecondPass(
SourceFile &SF, CodeCompletionCallbacksFactory &Factory) {
Expand Down Expand Up @@ -379,14 +379,14 @@ static LexerMode sourceFileKindToLexerMode(SourceFileKind kind) {
llvm_unreachable("covered switch");
}

Parser::Parser(unsigned BufferID, SourceFile &SF, SILParserTUStateBase *SIL,
Parser::Parser(unsigned BufferID, SourceFile &SF, SILParserStateBase *SIL,
PersistentParserState *PersistentState,
std::shared_ptr<SyntaxParseActions> SPActions)
: Parser(BufferID, SF, &SF.getASTContext().Diags, SIL, PersistentState,
std::move(SPActions)) {}

Parser::Parser(unsigned BufferID, SourceFile &SF, DiagnosticEngine* LexerDiags,
SILParserTUStateBase *SIL,
SILParserStateBase *SIL,
PersistentParserState *PersistentState,
std::shared_ptr<SyntaxParseActions> SPActions)
: Parser(
Expand Down Expand Up @@ -521,8 +521,7 @@ class TokenRecorder: public ConsumeTokenReceiver {
} // End of an anonymous namespace.

Parser::Parser(std::unique_ptr<Lexer> Lex, SourceFile &SF,
SILParserTUStateBase *SIL,
PersistentParserState *PersistentState,
SILParserStateBase *SIL, PersistentParserState *PersistentState,
std::shared_ptr<SyntaxParseActions> SPActions)
: SourceMgr(SF.getASTContext().SourceMgr),
Diags(SF.getASTContext().Diags),
Expand Down
51 changes: 22 additions & 29 deletions lib/SIL/Parser/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ using namespace swift::syntax;
// SILParserState implementation
//===----------------------------------------------------------------------===//

namespace swift {
// This has to be in the 'swift' namespace because it's forward-declared for
// SILParserState.
class SILParserTUState : public SILParserTUStateBase {
namespace {
class SILParserState : public SILParserStateBase {
public:
explicit SILParserTUState(SILModule &M) : M(M) {}
~SILParserTUState();
explicit SILParserState(SILModule &M) : M(M) {}
~SILParserState();

SILModule &M;

Expand Down Expand Up @@ -80,9 +78,9 @@ class SILParserTUState : public SILParserTUStateBase {
bool parseSILProperty(Parser &P) override;
bool parseSILScope(Parser &P) override;
};
} // end namespace swift
} // end anonymous namespace

SILParserTUState::~SILParserTUState() {
SILParserState::~SILParserState() {
if (!ForwardRefFns.empty()) {
for (auto Entry : ForwardRefFns) {
if (Entry.second.Loc.isValid()) {
Expand All @@ -101,11 +99,6 @@ SILParserTUState::~SILParserTUState() {
}
}

SILParserState::SILParserState(SILModule *M)
: Impl(M ? std::make_unique<SILParserTUState>(*M) : nullptr) {}

SILParserState::~SILParserState() = default;

std::unique_ptr<SILModule>
ParseSILModuleRequest::evaluate(Evaluator &evaluator,
SILGenDescriptor desc) const {
Expand All @@ -117,8 +110,8 @@ ParseSILModuleRequest::evaluate(Evaluator &evaluator,

auto silMod = SILModule::createEmptyModule(desc.context, desc.conv,
desc.opts);
SILParserState parserState(silMod.get());
Parser parser(*bufferID, *SF, parserState.Impl.get());
SILParserState parserState(*silMod.get());
Parser parser(*bufferID, *SF, &parserState);
PrettyStackTraceParser StackTrace(parser);

auto hadError = parser.parseTopLevelSIL();
Expand Down Expand Up @@ -157,11 +150,11 @@ namespace {
};

class SILParser {
friend SILParserTUState;
friend SILParserState;
public:
Parser &P;
SILModule &SILMod;
SILParserTUState &TUState;
SILParserState &TUState;
SILFunction *F = nullptr;
GenericEnvironment *ContextGenericEnv = nullptr;

Expand Down Expand Up @@ -193,8 +186,8 @@ namespace {

public:
SILParser(Parser &P)
: P(P), SILMod(static_cast<SILParserTUState *>(P.SIL)->M),
TUState(*static_cast<SILParserTUState *>(P.SIL)),
: P(P), SILMod(static_cast<SILParserState *>(P.SIL)->M),
TUState(*static_cast<SILParserState *>(P.SIL)),
ParsedTypeCallback([](Type ty) {}) {}

/// diagnoseProblems - After a function is fully parse, emit any diagnostics
Expand Down Expand Up @@ -5638,7 +5631,7 @@ bool SILParser::parseSILBasicBlock(SILBuilder &B) {
/// 'sil' sil-linkage '@' identifier ':' sil-type decl-sil-body?
/// decl-sil-body:
/// '{' sil-basic-block+ '}'
bool SILParserTUState::parseDeclSIL(Parser &P) {
bool SILParserState::parseDeclSIL(Parser &P) {
// Inform the lexer that we're lexing the body of the SIL declaration. Do
// this before we consume the 'sil' token so that all later tokens are
// properly handled.
Expand Down Expand Up @@ -5806,7 +5799,7 @@ bool SILParserTUState::parseDeclSIL(Parser &P) {

/// decl-sil-stage: [[only in SIL mode]]
/// 'sil_stage' ('raw' | 'canonical')
bool SILParserTUState::parseDeclSILStage(Parser &P) {
bool SILParserState::parseDeclSILStage(Parser &P) {
SourceLoc stageLoc = P.consumeToken(tok::kw_sil_stage);
if (!P.Tok.is(tok::identifier)) {
P.diagnose(P.Tok, diag::expected_sil_stage_name);
Expand Down Expand Up @@ -5887,7 +5880,7 @@ static Optional<VarDecl *> lookupGlobalDecl(Identifier GlobalName,

/// decl-sil-global: [[only in SIL mode]]
/// 'sil_global' sil-linkage @name : sil-type [external]
bool SILParserTUState::parseSILGlobal(Parser &P) {
bool SILParserState::parseSILGlobal(Parser &P) {
// Inform the lexer that we're lexing the body of the SIL declaration.
Lexer::SILBodyRAII Tmp(*P.L);

Expand Down Expand Up @@ -5944,7 +5937,7 @@ bool SILParserTUState::parseSILGlobal(Parser &P) {
/// decl-sil-property: [[only in SIL mode]]
/// 'sil_property' sil-decl-ref '(' sil-key-path-pattern-component ')'

bool SILParserTUState::parseSILProperty(Parser &P) {
bool SILParserState::parseSILProperty(Parser &P) {
Lexer::SILBodyRAII Tmp(*P.L);

auto loc = P.consumeToken(tok::kw_sil_property);
Expand Down Expand Up @@ -6017,7 +6010,7 @@ bool SILParserTUState::parseSILProperty(Parser &P) {
/// '{' sil-vtable-entry* '}'
/// sil-vtable-entry:
/// SILDeclRef ':' SILFunctionName
bool SILParserTUState::parseSILVTable(Parser &P) {
bool SILParserState::parseSILVTable(Parser &P) {
P.consumeToken(tok::kw_sil_vtable);
SILParser VTableState(P);

Expand Down Expand Up @@ -6545,7 +6538,7 @@ static bool parseSILVTableEntry(
/// associated_type_protocol (AssocName: ProtocolName):
/// protocol-conformance|dependent
/// base_protocol ProtocolName: protocol-conformance
bool SILParserTUState::parseSILWitnessTable(Parser &P) {
bool SILParserState::parseSILWitnessTable(Parser &P) {
P.consumeToken(tok::kw_sil_witness_table);
SILParser WitnessState(P);

Expand Down Expand Up @@ -6648,7 +6641,7 @@ bool SILParserTUState::parseSILWitnessTable(Parser &P) {
/// sil-default-witness-entry:
/// sil-witness-entry
/// 'no_default'
bool SILParserTUState::parseSILDefaultWitnessTable(Parser &P) {
bool SILParserState::parseSILDefaultWitnessTable(Parser &P) {
P.consumeToken(tok::kw_sil_default_witness_table);
SILParser WitnessState(P);

Expand Down Expand Up @@ -6715,7 +6708,7 @@ bool SILParserTUState::parseSILDefaultWitnessTable(Parser &P) {
///
/// index-subset ::=
/// [0-9]+ (' ' [0-9]+)*
bool SILParserTUState::parseSILDifferentiabilityWitness(Parser &P) {
bool SILParserState::parseSILDifferentiabilityWitness(Parser &P) {
auto loc = P.consumeToken(tok::kw_sil_differentiability_witness);
auto silLoc = RegularLocation(loc);
SILParser State(P);
Expand Down Expand Up @@ -6865,7 +6858,7 @@ llvm::Optional<llvm::coverage::Counter> SILParser::parseSILCoverageExpr(
/// StartLine ':' StartCol '->' EndLine ':' EndCol
/// sil-coverage-expr:
/// ...
bool SILParserTUState::parseSILCoverageMap(Parser &P) {
bool SILParserState::parseSILCoverageMap(Parser &P) {
P.consumeToken(tok::kw_sil_coverage_map);
SILParser State(P);

Expand Down Expand Up @@ -6956,7 +6949,7 @@ bool SILParserTUState::parseSILCoverageMap(Parser &P) {
/// scope-parent ::= sil-function-name ':' sil-type
/// scope-parent ::= sil-scope-ref
/// debug-loc ::= 'loc' string-literal ':' [0-9]+ ':' [0-9]+
bool SILParserTUState::parseSILScope(Parser &P) {
bool SILParserState::parseSILScope(Parser &P) {
P.consumeToken(tok::kw_sil_scope);
SILParser ScopeState(P);

Expand Down