Skip to content

Commit 28103df

Browse files
authored
Merge pull request swiftlang#32043 from hamishknight/better-late-than-never
2 parents 828720c + bccdc0e commit 28103df

File tree

13 files changed

+68
-64
lines changed

13 files changed

+68
-64
lines changed

include/swift/AST/SILGenRequests.h

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,38 +40,39 @@ template<typename Request>
4040
void reportEvaluatedRequest(UnifiedStatsReporter &stats,
4141
const Request &request);
4242

43-
struct SILGenDescriptor {
43+
/// Describes a file or module to be lowered to SIL.
44+
struct ASTLoweringDescriptor {
4445
llvm::PointerUnion<FileUnit *, ModuleDecl *> context;
4546
Lowering::TypeConverter &conv;
4647
const SILOptions &opts;
4748

48-
friend llvm::hash_code hash_value(const SILGenDescriptor &owner) {
49+
friend llvm::hash_code hash_value(const ASTLoweringDescriptor &owner) {
4950
return llvm::hash_combine(owner.context, (void *)&owner.conv,
5051
(void *)&owner.opts);
5152
}
5253

53-
friend bool operator==(const SILGenDescriptor &lhs,
54-
const SILGenDescriptor &rhs) {
54+
friend bool operator==(const ASTLoweringDescriptor &lhs,
55+
const ASTLoweringDescriptor &rhs) {
5556
return lhs.context == rhs.context &&
5657
&lhs.conv == &rhs.conv &&
5758
&lhs.opts == &rhs.opts;
5859
}
5960

60-
friend bool operator!=(const SILGenDescriptor &lhs,
61-
const SILGenDescriptor &rhs) {
61+
friend bool operator!=(const ASTLoweringDescriptor &lhs,
62+
const ASTLoweringDescriptor &rhs) {
6263
return !(lhs == rhs);
6364
}
6465

6566
public:
66-
static SILGenDescriptor forFile(FileUnit &sf, Lowering::TypeConverter &conv,
67-
const SILOptions &opts) {
68-
return SILGenDescriptor{&sf, conv, opts};
67+
static ASTLoweringDescriptor
68+
forFile(FileUnit &sf, Lowering::TypeConverter &conv, const SILOptions &opts) {
69+
return ASTLoweringDescriptor{&sf, conv, opts};
6970
}
7071

71-
static SILGenDescriptor forWholeModule(ModuleDecl *mod,
72-
Lowering::TypeConverter &conv,
73-
const SILOptions &opts) {
74-
return SILGenDescriptor{mod, conv, opts};
72+
static ASTLoweringDescriptor forWholeModule(ModuleDecl *mod,
73+
Lowering::TypeConverter &conv,
74+
const SILOptions &opts) {
75+
return ASTLoweringDescriptor{mod, conv, opts};
7576
}
7677

7778
/// For a single file input, returns a single element array containing that
@@ -83,13 +84,17 @@ struct SILGenDescriptor {
8384
SourceFile *getSourceFileToParse() const;
8485
};
8586

86-
void simple_display(llvm::raw_ostream &out, const SILGenDescriptor &d);
87+
void simple_display(llvm::raw_ostream &out, const ASTLoweringDescriptor &d);
8788

88-
SourceLoc extractNearestSourceLoc(const SILGenDescriptor &desc);
89+
SourceLoc extractNearestSourceLoc(const ASTLoweringDescriptor &desc);
8990

90-
class SILGenerationRequest
91+
/// Lowers a file or module to SIL. In most cases this involves transforming
92+
/// a file's AST into SIL, through SILGen. However it can also handle files
93+
/// containing SIL in textual or binary form, which will be parsed or
94+
/// deserialized as needed.
95+
class ASTLoweringRequest
9196
: public SimpleRequest<
92-
SILGenerationRequest, std::unique_ptr<SILModule>(SILGenDescriptor),
97+
ASTLoweringRequest, std::unique_ptr<SILModule>(ASTLoweringDescriptor),
9398
RequestFlags::Uncached | RequestFlags::DependencySource> {
9499
public:
95100
using SimpleRequest::SimpleRequest;
@@ -98,8 +103,8 @@ class SILGenerationRequest
98103
friend SimpleRequest;
99104

100105
// Evaluation.
101-
std::unique_ptr<SILModule>
102-
evaluate(Evaluator &evaluator, SILGenDescriptor desc) const;
106+
std::unique_ptr<SILModule> evaluate(Evaluator &evaluator,
107+
ASTLoweringDescriptor desc) const;
103108

104109
public:
105110
// Incremental dependencies.
@@ -110,7 +115,7 @@ class SILGenerationRequest
110115
/// Parses a .sil file into a SILModule.
111116
class ParseSILModuleRequest
112117
: public SimpleRequest<ParseSILModuleRequest,
113-
std::unique_ptr<SILModule>(SILGenDescriptor),
118+
std::unique_ptr<SILModule>(ASTLoweringDescriptor),
114119
RequestFlags::Uncached> {
115120
public:
116121
using SimpleRequest::SimpleRequest;
@@ -119,8 +124,8 @@ class ParseSILModuleRequest
119124
friend SimpleRequest;
120125

121126
// Evaluation.
122-
std::unique_ptr<SILModule>
123-
evaluate(Evaluator &evaluator, SILGenDescriptor desc) const;
127+
std::unique_ptr<SILModule> evaluate(Evaluator &evaluator,
128+
ASTLoweringDescriptor desc) const;
124129
};
125130

126131
/// The zone number for SILGen.

include/swift/AST/SILGenTypeIDZone.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17-
SWIFT_REQUEST(SILGen, SILGenerationRequest,
18-
std::unique_ptr<SILModule>(SILGenDescriptor),
17+
SWIFT_REQUEST(SILGen, ASTLoweringRequest,
18+
std::unique_ptr<SILModule>(ASTLoweringDescriptor),
1919
Uncached, NoLocationInfo)
2020
SWIFT_REQUEST(SILGen, ParseSILModuleRequest,
21-
std::unique_ptr<SILModule>(SILGenDescriptor),
21+
std::unique_ptr<SILModule>(ASTLoweringDescriptor),
2222
Uncached, NoLocationInfo)

include/swift/Subsystems.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@ namespace swift {
172172
/// The module must contain source files. The optimizer will assume that the
173173
/// SIL of all files in the module is present in the SILModule.
174174
std::unique_ptr<SILModule>
175-
performSILGeneration(ModuleDecl *M, Lowering::TypeConverter &TC,
176-
const SILOptions &options);
175+
performASTLowering(ModuleDecl *M, Lowering::TypeConverter &TC,
176+
const SILOptions &options);
177177

178178
/// Turn a source file into SIL IR.
179179
std::unique_ptr<SILModule>
180-
performSILGeneration(FileUnit &SF, Lowering::TypeConverter &TC,
181-
const SILOptions &options);
180+
performASTLowering(FileUnit &SF, Lowering::TypeConverter &TC,
181+
const SILOptions &options);
182182

183183
using ModuleOrSourceFile = PointerUnion<ModuleDecl *, SourceFile *>;
184184

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ bool ModuleInterfaceBuilder::buildSwiftModuleInternal(
209209
SILOptions &SILOpts = subInvocation.getSILOptions();
210210
auto Mod = SubInstance.getMainModule();
211211
auto &TC = SubInstance.getSILTypes();
212-
auto SILMod = performSILGeneration(Mod, TC, SILOpts);
212+
auto SILMod = performASTLowering(Mod, TC, SILOpts);
213213
if (!SILMod) {
214214
LLVM_DEBUG(llvm::dbgs() << "SILGen did not produce a module\n");
215215
return true;

lib/FrontendTool/FrontendTool.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ static bool performCompileStepsPostSema(CompilerInstance &Instance,
10841084
if (!opts.InputsAndOutputs.hasPrimaryInputs()) {
10851085
// If there are no primary inputs the compiler is in WMO mode and builds one
10861086
// SILModule for the entire module.
1087-
auto SM = performSILGeneration(mod, Instance.getSILTypes(), SILOpts);
1087+
auto SM = performASTLowering(mod, Instance.getSILTypes(), SILOpts);
10881088
const PrimarySpecificPaths PSPs =
10891089
Instance.getPrimarySpecificPathsForWholeModuleOptimizationMode();
10901090
return performCompileStepsPostSILGen(Instance, std::move(SM), mod, PSPs,
@@ -1096,8 +1096,8 @@ static bool performCompileStepsPostSema(CompilerInstance &Instance,
10961096
if (!Instance.getPrimarySourceFiles().empty()) {
10971097
bool result = false;
10981098
for (auto *PrimaryFile : Instance.getPrimarySourceFiles()) {
1099-
auto SM = performSILGeneration(*PrimaryFile, Instance.getSILTypes(),
1100-
SILOpts);
1099+
auto SM = performASTLowering(*PrimaryFile, Instance.getSILTypes(),
1100+
SILOpts);
11011101
const PrimarySpecificPaths PSPs =
11021102
Instance.getPrimarySpecificPathsForSourceFile(*PrimaryFile);
11031103
result |= performCompileStepsPostSILGen(Instance, std::move(SM),
@@ -1114,7 +1114,7 @@ static bool performCompileStepsPostSema(CompilerInstance &Instance,
11141114
for (FileUnit *fileUnit : mod->getFiles()) {
11151115
if (auto SASTF = dyn_cast<SerializedASTFile>(fileUnit))
11161116
if (opts.InputsAndOutputs.isInputPrimary(SASTF->getFilename())) {
1117-
auto SM = performSILGeneration(*SASTF, Instance.getSILTypes(), SILOpts);
1117+
auto SM = performASTLowering(*SASTF, Instance.getSILTypes(), SILOpts);
11181118
const PrimarySpecificPaths &PSPs =
11191119
Instance.getPrimarySpecificPathsForPrimary(SASTF->getFilename());
11201120
result |= performCompileStepsPostSILGen(Instance, std::move(SM), mod,

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ SILParserState::~SILParserState() {
101101

102102
std::unique_ptr<SILModule>
103103
ParseSILModuleRequest::evaluate(Evaluator &evaluator,
104-
SILGenDescriptor desc) const {
104+
ASTLoweringDescriptor desc) const {
105105
auto *SF = desc.getSourceFileToParse();
106106
assert(SF);
107107

lib/SILGen/SILGen.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,8 +1910,8 @@ class SILGenModuleRAII {
19101910
} // end anonymous namespace
19111911

19121912
std::unique_ptr<SILModule>
1913-
SILGenerationRequest::evaluate(Evaluator &evaluator,
1914-
SILGenDescriptor desc) const {
1913+
ASTLoweringRequest::evaluate(Evaluator &evaluator,
1914+
ASTLoweringDescriptor desc) const {
19151915
// If we have a .sil file to parse, defer to the parsing request.
19161916
if (desc.getSourceFileToParse()) {
19171917
return llvm::cantFail(evaluator(ParseSILModuleRequest{desc}));
@@ -1942,17 +1942,16 @@ SILGenerationRequest::evaluate(Evaluator &evaluator,
19421942
}
19431943

19441944
std::unique_ptr<SILModule>
1945-
swift::performSILGeneration(ModuleDecl *mod, Lowering::TypeConverter &tc,
1946-
const SILOptions &options) {
1947-
auto desc = SILGenDescriptor::forWholeModule(mod, tc, options);
1945+
swift::performASTLowering(ModuleDecl *mod, Lowering::TypeConverter &tc,
1946+
const SILOptions &options) {
1947+
auto desc = ASTLoweringDescriptor::forWholeModule(mod, tc, options);
19481948
return llvm::cantFail(
1949-
mod->getASTContext().evaluator(SILGenerationRequest{desc}));
1949+
mod->getASTContext().evaluator(ASTLoweringRequest{desc}));
19501950
}
19511951

19521952
std::unique_ptr<SILModule>
1953-
swift::performSILGeneration(FileUnit &sf, Lowering::TypeConverter &tc,
1954-
const SILOptions &options) {
1955-
auto desc = SILGenDescriptor::forFile(sf, tc, options);
1956-
return llvm::cantFail(
1957-
sf.getASTContext().evaluator(SILGenerationRequest{desc}));
1953+
swift::performASTLowering(FileUnit &sf, Lowering::TypeConverter &tc,
1954+
const SILOptions &options) {
1955+
auto desc = ASTLoweringDescriptor::forFile(sf, tc, options);
1956+
return llvm::cantFail(sf.getASTContext().evaluator(ASTLoweringRequest{desc}));
19581957
}

lib/SILGen/SILGenRequests.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,23 @@ namespace swift {
3030
} // end namespace swift
3131

3232
void swift::simple_display(llvm::raw_ostream &out,
33-
const SILGenDescriptor &desc) {
33+
const ASTLoweringDescriptor &desc) {
3434
auto *MD = desc.context.dyn_cast<ModuleDecl *>();
3535
auto *unit = desc.context.dyn_cast<FileUnit *>();
3636
if (MD) {
37-
out << "SIL Generation for module " << MD->getName();
37+
out << "Lowering AST to SIL for module " << MD->getName();
3838
} else {
3939
assert(unit);
40-
out << "SIL Generation for file ";
40+
out << "Lowering AST to SIL for file ";
4141
simple_display(out, unit);
4242
}
4343
}
4444

45-
SourceLoc swift::extractNearestSourceLoc(const SILGenDescriptor &desc) {
45+
SourceLoc swift::extractNearestSourceLoc(const ASTLoweringDescriptor &desc) {
4646
return SourceLoc();
4747
}
4848

49-
evaluator::DependencySource SILGenerationRequest::readDependencySource(
49+
evaluator::DependencySource ASTLoweringRequest::readDependencySource(
5050
const evaluator::DependencyRecorder &e) const {
5151
auto &desc = std::get<0>(getStorage());
5252

@@ -60,7 +60,7 @@ evaluator::DependencySource SILGenerationRequest::readDependencySource(
6060
return {dyn_cast<SourceFile>(unit), evaluator::DependencyScope::Cascading};
6161
}
6262

63-
ArrayRef<FileUnit *> SILGenDescriptor::getFiles() const {
63+
ArrayRef<FileUnit *> ASTLoweringDescriptor::getFiles() const {
6464
if (auto *mod = context.dyn_cast<ModuleDecl *>())
6565
return mod->getFiles();
6666

@@ -69,7 +69,7 @@ ArrayRef<FileUnit *> SILGenDescriptor::getFiles() const {
6969
return llvm::makeArrayRef(*context.getAddrOfPtr1());
7070
}
7171

72-
SourceFile *SILGenDescriptor::getSourceFileToParse() const {
72+
SourceFile *ASTLoweringDescriptor::getSourceFileToParse() const {
7373
#ifndef NDEBUG
7474
auto sfCount = llvm::count_if(getFiles(), [](FileUnit *file) {
7575
return isa<SourceFile>(file);

tools/SourceKit/lib/SwiftLang/SwiftASTManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ ASTUnitRef ASTProducer::createASTUnit(
10511051
if (auto SF = CompIns.getPrimarySourceFile()) {
10521052
SILOptions SILOpts = Invocation.getSILOptions();
10531053
auto &TC = CompIns.getSILTypes();
1054-
std::unique_ptr<SILModule> SILMod = performSILGeneration(*SF, TC, SILOpts);
1054+
std::unique_ptr<SILModule> SILMod = performASTLowering(*SF, TC, SILOpts);
10551055
runSILDiagnosticPasses(*SILMod);
10561056
}
10571057
}

tools/sil-func-extractor/SILFunctionExtractor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ int main(int argc, char **argv) {
272272
if (CI.getASTContext().hadError())
273273
return 1;
274274

275-
auto SILMod = performSILGeneration(CI.getMainModule(), CI.getSILTypes(),
276-
CI.getSILOptions());
275+
auto SILMod = performASTLowering(CI.getMainModule(), CI.getSILTypes(),
276+
CI.getSILOptions());
277277

278278
// Load the SIL if we have a non-SIB serialized module. SILGen handles SIB for
279279
// us.

0 commit comments

Comments
 (0)