Prespecialize standard library only if it is loaded

We currently load it for prespecialization when it wasn't loaded initially.

This causes an inadvertant issue for invertible protocols.

When we don’t have the stdlib loaded initially, we “synthesize” the
invertible protocol from the Builtin module by creating a new `ProtocolDecl*`
and stashing it on the `ASTContext`.
If the stdlib gets loaded later, deserialized stdlib types conform to the deserialized `Escapable` protocol
which has a different `ProtocolDecl *` pointer for `Escapable`.
So queries like `conformsToInvertible` fail because they are using the wrong `ProtocolDecl*`
for `Copyable`/`Escapable` while looking up the ConformanceTable.
This commit is contained in:
Meghana Gupta
2024-09-30 10:21:11 -07:00
parent 827caa9fce
commit cf4832e4d4

View File

@@ -920,7 +920,7 @@ void SILModule::performOnceForPrespecializedImportedExtensions(
SmallVector<ModuleDecl *, 8> importedModules;
// Add the Swift module.
if (!isStdlibModule()) {
auto *SwiftStdlib = getASTContext().getStdlibModule(true);
auto *SwiftStdlib = getASTContext().getStdlibModule();
if (SwiftStdlib)
importedModules.push_back(SwiftStdlib);
}