mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Macro][Dependencies] Properly model macro dependencies in the scanner
Add function to handle all macro dependencies kinds in the scanner,
including taking care of the macro definitions in the module interface
for its client to use. The change involves:
* Encode the macro definition inside the binary module
* Resolve macro modules in the dependencies scanners, including those
declared inside the dependency modules.
* Propagate the macro defined from the direct dependencies to track
all the potentially available modules inside a module compilation.
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
#include "BCReadingExtras.h"
|
||||
#include "DeserializationErrors.h"
|
||||
#include "ModuleFileCoreTableInfo.h"
|
||||
#include "ModuleFormat.h"
|
||||
#include "swift/AST/Module.h"
|
||||
#include "swift/Basic/Assertions.h"
|
||||
#include "swift/Basic/LangOptions.h"
|
||||
#include "swift/Parse/ParseVersion.h"
|
||||
@@ -1130,6 +1132,22 @@ getActualImportControl(unsigned rawValue) {
|
||||
}
|
||||
}
|
||||
|
||||
static std::optional<ExternalMacroPlugin::Access>
|
||||
getActualMacroAccess(unsigned rawValue) {
|
||||
// We switch on the raw value rather than the enum in order to handle future
|
||||
// values.
|
||||
switch (rawValue) {
|
||||
case static_cast<unsigned>(serialization::AccessLevel::Public):
|
||||
return ExternalMacroPlugin::Public;
|
||||
case static_cast<unsigned>(serialization::AccessLevel::Package):
|
||||
return ExternalMacroPlugin::Package;
|
||||
case static_cast<unsigned>(serialization::AccessLevel::Internal):
|
||||
return ExternalMacroPlugin::Internal;
|
||||
default:
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
bool ModuleFileSharedCore::readModuleDocIfPresent(PathObfuscator &pathRecoverer) {
|
||||
if (!this->ModuleDocInputBuffer)
|
||||
return true;
|
||||
@@ -1591,6 +1609,18 @@ ModuleFileSharedCore::ModuleFileSharedCore(
|
||||
ModuleInterfacePath = blobData;
|
||||
break;
|
||||
}
|
||||
case input_block::EXTERNAL_MACRO: {
|
||||
uint8_t rawKind;
|
||||
input_block::ExternalMacroLayout::readRecord(scratch, rawKind);
|
||||
auto accessKind = getActualMacroAccess(rawKind);
|
||||
if (!accessKind) {
|
||||
info.status = error(Status::Malformed);
|
||||
return;
|
||||
}
|
||||
|
||||
MacroModuleNames.push_back({blobData.str(), *accessKind});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// Unknown input kind, possibly for use by a future version of the
|
||||
// module format.
|
||||
|
||||
Reference in New Issue
Block a user