Skip to content

Commit 6764366

Browse files
committed
Add SILGenSourceFileRequest
Replace SILGenModule::emitSourceFile with SILGenSourceFileRequest so we have an explicit source file to associate any lookups with.
1 parent 0c0018f commit 6764366

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

include/swift/AST/SILGenRequests.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class SourceFile;
3131

3232
namespace Lowering {
3333
class TypeConverter;
34+
class SILGenModule;
3435
}
3536

3637
/// Report that a request of the given kind is being evaluated, so it
@@ -96,6 +97,30 @@ void simple_display(llvm::raw_ostream &out, const SILGenDescriptor &d);
9697

9798
SourceLoc extractNearestSourceLoc(const SILGenDescriptor &desc);
9899

100+
class SILGenSourceFileRequest :
101+
public SimpleRequest<SILGenSourceFileRequest,
102+
bool(Lowering::SILGenModule *, SourceFile *),
103+
CacheKind::Uncached> {
104+
public:
105+
using SimpleRequest::SimpleRequest;
106+
107+
private:
108+
friend SimpleRequest;
109+
110+
// Evaluation.
111+
llvm::Expected<bool>
112+
evaluate(Evaluator &evaluator,
113+
Lowering::SILGenModule *SGM, SourceFile *SF) const;
114+
115+
public:
116+
bool isCached() const { return true; }
117+
};
118+
119+
inline void
120+
simple_display(llvm::raw_ostream &out, const Lowering::SILGenModule *SGM) {
121+
// No-op
122+
}
123+
99124
/// The zone number for SILGen.
100125
#define SWIFT_TYPEID_ZONE SILGen
101126
#define SWIFT_TYPEID_HEADER "swift/AST/SILGenTypeIDZone.def"

include/swift/AST/SILGenTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@
1717
SWIFT_REQUEST(SILGen, GenerateSILRequest,
1818
std::unique_ptr<SILModule>(SILGenDescriptor),
1919
Uncached, NoLocationInfo)
20+
SWIFT_REQUEST(SILGen, SILGenSourceFileRequest,
21+
bool(Lowering::SILGenModule *, SourceFile *),
22+
Uncached, NoLocationInfo)

lib/SILGen/SILGen.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,22 +1669,24 @@ class SourceFileScope {
16691669

16701670
} // end anonymous namespace
16711671

1672-
void SILGenModule::emitSourceFile(SourceFile *sf) {
1673-
SourceFileScope scope(*this, sf);
1674-
FrontendStatsTracer StatsTracer(getASTContext().Stats, "SILgen-file", sf);
1672+
llvm::Expected<bool>
1673+
SILGenSourceFileRequest::evaluate(Evaluator &evaluator,
1674+
SILGenModule *SGM, SourceFile *sf) const {
1675+
SourceFileScope scope(*SGM, sf);
16751676
for (Decl *D : sf->getTopLevelDecls()) {
1676-
FrontendStatsTracer StatsTracer(getASTContext().Stats, "SILgen-decl", D);
1677-
visit(D);
1677+
FrontendStatsTracer StatsTracer(SGM->getASTContext().Stats, "SILgen-decl", D);
1678+
SGM->visit(D);
16781679
}
16791680

16801681
for (TypeDecl *TD : sf->LocalTypeDecls) {
1681-
FrontendStatsTracer StatsTracer(getASTContext().Stats, "SILgen-tydecl", TD);
1682+
FrontendStatsTracer StatsTracer(SGM->getASTContext().Stats, "SILgen-tydecl", TD);
16821683
// FIXME: Delayed parsing would prevent these types from being added to the
16831684
// module in the first place.
16841685
if (TD->getDeclContext()->getInnermostSkippedFunctionContext())
16851686
continue;
1686-
visit(TD);
1687+
SGM->visit(TD);
16871688
}
1689+
return true;
16881690
}
16891691

16901692
//===----------------------------------------------------------------------===//
@@ -1708,7 +1710,8 @@ SILModule::constructSIL(ModuleDecl *mod, TypeConverter &tc,
17081710

17091711
if (SF) {
17101712
if (auto *file = dyn_cast<SourceFile>(SF)) {
1711-
SGM.emitSourceFile(file);
1713+
(void)evaluateOrDefault(file->getASTContext().evaluator,
1714+
SILGenSourceFileRequest{&SGM, file}, false);
17121715
} else if (auto *file = dyn_cast<SerializedASTFile>(SF)) {
17131716
if (file->isSIB())
17141717
M->getSILLoader()->getAllForModule(mod->getName(), file);
@@ -1718,7 +1721,8 @@ SILModule::constructSIL(ModuleDecl *mod, TypeConverter &tc,
17181721
auto nextSF = dyn_cast<SourceFile>(file);
17191722
if (!nextSF || nextSF->ASTStage != SourceFile::TypeChecked)
17201723
continue;
1721-
SGM.emitSourceFile(nextSF);
1724+
(void)evaluateOrDefault(nextSF->getASTContext().evaluator,
1725+
SILGenSourceFileRequest{&SGM, nextSF}, false);
17221726
}
17231727

17241728
// Also make sure to process any intermediate files that may contain SIL

lib/SILGen/SILGen.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,6 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
208208

209209
void emitAbstractFuncDecl(AbstractFunctionDecl *AFD);
210210

211-
/// Generate code for a source file of the module.
212-
void emitSourceFile(SourceFile *sf);
213-
214211
/// Generates code for the given FuncDecl and adds the
215212
/// SILFunction to the current SILModule under the name SILDeclRef(decl). For
216213
/// curried functions, curried entry point Functions are also generated and

0 commit comments

Comments
 (0)