@@ -1817,6 +1817,8 @@ class SILGenModuleRAII {
1817
1817
1818
1818
public:
1819
1819
void emitSourceFile (SourceFile *sf) {
1820
+ assert (sf->ASTStage == SourceFile::TypeChecked);
1821
+
1820
1822
SourceFileScope scope (SGM, sf);
1821
1823
for (Decl *D : sf->getTopLevelDecls ()) {
1822
1824
FrontendStatsTracer StatsTracer (SGM.getASTContext ().Stats ,
@@ -1835,7 +1837,7 @@ class SILGenModuleRAII {
1835
1837
}
1836
1838
}
1837
1839
1838
- SILGenModuleRAII (SILModule &M, ModuleDecl *SM ) : SGM{M, SM } {}
1840
+ explicit SILGenModuleRAII (SILModule &M) : SGM{M, M. getSwiftModule () } {}
1839
1841
1840
1842
~SILGenModuleRAII () {
1841
1843
// Emit any delayed definitions that were forced.
@@ -1858,72 +1860,49 @@ class SILGenModuleRAII {
1858
1860
} // end anonymous namespace
1859
1861
1860
1862
std::unique_ptr<SILModule>
1861
- SILGenSourceFileRequest::evaluate (Evaluator &evaluator,
1862
- SILGenDescriptor desc) const {
1863
- // If we have a .sil file to parse, defer to the parsing request.
1864
- if (desc.getSourceFileToParse ()) {
1865
- return llvm::cantFail (evaluator (ParseSILModuleRequest{desc}));
1866
- }
1867
-
1868
- auto *unit = desc.context .get <FileUnit *>();
1869
- auto *mod = unit->getParentModule ();
1870
- auto M = SILModule::createEmptyModule (desc.context , desc.conv , desc.opts );
1871
- SILGenModuleRAII scope (*M, mod);
1872
-
1873
- if (auto *file = dyn_cast<SourceFile>(unit)) {
1874
- scope.emitSourceFile (file);
1875
- } else if (auto *file = dyn_cast<SerializedASTFile>(unit)) {
1876
- if (file->isSIB ())
1877
- M->getSILLoader ()->getAllForModule (mod->getName (), file);
1878
- }
1879
-
1880
- return M;
1881
- }
1882
-
1883
- std::unique_ptr<SILModule>
1884
- SILGenWholeModuleRequest::evaluate (Evaluator &evaluator,
1885
- SILGenDescriptor desc) const {
1863
+ SILGenerationRequest::evaluate (Evaluator &evaluator,
1864
+ SILGenDescriptor desc) const {
1886
1865
// If we have a .sil file to parse, defer to the parsing request.
1887
1866
if (desc.getSourceFileToParse ()) {
1888
1867
return llvm::cantFail (evaluator (ParseSILModuleRequest{desc}));
1889
1868
}
1890
1869
1891
- auto *mod = desc.context .get <ModuleDecl *>();
1892
- auto M = SILModule::createEmptyModule (desc.context , desc.conv , desc.opts );
1893
- SILGenModuleRAII scope (*M, mod);
1870
+ // Otherwise perform SIL generation of the passed SourceFiles.
1871
+ auto silMod = SILModule::createEmptyModule (desc.context , desc.conv ,
1872
+ desc.opts );
1873
+ SILGenModuleRAII scope (*silMod);
1894
1874
1895
- for (auto file : mod->getFiles ()) {
1896
- auto nextSF = dyn_cast<SourceFile>(file);
1897
- if (!nextSF || nextSF->ASTStage != SourceFile::TypeChecked)
1898
- continue ;
1899
- scope.emitSourceFile (nextSF);
1875
+ for (auto file : desc.getFiles ()) {
1876
+ if (auto *nextSF = dyn_cast<SourceFile>(file))
1877
+ scope.emitSourceFile (nextSF);
1900
1878
}
1901
1879
1902
- // Also make sure to process any intermediate files that may contain SIL
1903
- bool hasSIB = std::any_of (mod->getFiles ().begin (),
1904
- mod->getFiles ().end (),
1905
- [](const FileUnit *File) -> bool {
1880
+ // Also make sure to process any intermediate files that may contain SIL.
1881
+ bool hasSIB = llvm::any_of (desc.getFiles (), [](const FileUnit *File) -> bool {
1906
1882
auto *SASTF = dyn_cast<SerializedASTFile>(File);
1907
1883
return SASTF && SASTF->isSIB ();
1908
1884
});
1909
- if (hasSIB)
1910
- M->getSILLoader ()->getAllForModule (mod->getName (), nullptr );
1885
+ if (hasSIB) {
1886
+ auto primary = desc.context .dyn_cast <FileUnit *>();
1887
+ silMod->getSILLoader ()->getAllForModule (silMod->getSwiftModule ()->getName (),
1888
+ primary);
1889
+ }
1911
1890
1912
- return M ;
1891
+ return silMod ;
1913
1892
}
1914
1893
1915
1894
std::unique_ptr<SILModule>
1916
1895
swift::performSILGeneration (ModuleDecl *mod, Lowering::TypeConverter &tc,
1917
1896
const SILOptions &options) {
1918
1897
auto desc = SILGenDescriptor::forWholeModule (mod, tc, options);
1919
1898
return llvm::cantFail (
1920
- mod->getASTContext ().evaluator (SILGenWholeModuleRequest {desc}));
1899
+ mod->getASTContext ().evaluator (SILGenerationRequest {desc}));
1921
1900
}
1922
1901
1923
1902
std::unique_ptr<SILModule>
1924
1903
swift::performSILGeneration (FileUnit &sf, Lowering::TypeConverter &tc,
1925
1904
const SILOptions &options) {
1926
1905
auto desc = SILGenDescriptor::forFile (sf, tc, options);
1927
1906
return llvm::cantFail (
1928
- sf.getASTContext ().evaluator (SILGenSourceFileRequest {desc}));
1907
+ sf.getASTContext ().evaluator (SILGenerationRequest {desc}));
1929
1908
}
0 commit comments