mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[serialization] Handle references to generic parameters.
Generic parameters are implemented using specially-tagged TypeAliasDecls. Unlike normal ValueDecls, their names are not resilient, and so cross- module references shouldn't refer to them by name. Instead, use an index into the generic parameter list of their context. Since generic parameters can appear within extensions, this new kind isn't mutually exclusive with the just-introduced ExtensionValue. Change that to be a separate flag that applies to both Values and GenericParameters. Swift SVN r6304
This commit is contained in:
@@ -1215,10 +1215,11 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext,
|
||||
case decls_block::XREF: {
|
||||
uint8_t kind;
|
||||
TypeID expectedTypeID;
|
||||
bool isWithinExtension;
|
||||
ArrayRef<uint64_t> rawAccessPath;
|
||||
|
||||
decls_block::XRefLayout::readRecord(scratch, kind, expectedTypeID,
|
||||
rawAccessPath);
|
||||
isWithinExtension, rawAccessPath);
|
||||
|
||||
// First, find the module this reference is referring to.
|
||||
Identifier moduleName = getIdentifier(rawAccessPath.front());
|
||||
@@ -1229,10 +1230,10 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext,
|
||||
|
||||
switch (kind) {
|
||||
case XRefKind::SwiftValue:
|
||||
case XRefKind::SwiftExtensionValue: {
|
||||
case XRefKind::SwiftGenericParameter: {
|
||||
// Start by looking up the top-level decl in the module.
|
||||
Module *baseModule = M;
|
||||
if (kind == XRefKind::SwiftExtensionValue) {
|
||||
if (isWithinExtension) {
|
||||
baseModule = getModule(ctx, getIdentifier(rawAccessPath.front()));
|
||||
rawAccessPath = rawAccessPath.slice(1);
|
||||
}
|
||||
@@ -1262,8 +1263,9 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext,
|
||||
// If we have a type to validate against, filter out any ValueDecls that
|
||||
// don't match that type.
|
||||
CanType expectedTy;
|
||||
if (Type maybeExpectedTy = getType(expectedTypeID))
|
||||
expectedTy = maybeExpectedTy->getCanonicalType();
|
||||
if (kind == XRefKind::SwiftValue)
|
||||
if (Type maybeExpectedTy = getType(expectedTypeID))
|
||||
expectedTy = maybeExpectedTy->getCanonicalType();
|
||||
|
||||
ValueDecl *result = nullptr;
|
||||
for (auto value : values) {
|
||||
@@ -1291,6 +1293,30 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (kind == XRefKind::SwiftGenericParameter) {
|
||||
GenericParamList *paramList = nullptr;
|
||||
|
||||
if (auto nominal = dyn_cast<NominalTypeDecl>(result))
|
||||
paramList = nominal->getGenericParams();
|
||||
else if (auto fn = dyn_cast<FuncDecl>(result))
|
||||
paramList = fn->getGenericParams();
|
||||
else if (auto ctor = dyn_cast<ConstructorDecl>(result))
|
||||
paramList = ctor->getGenericParams();
|
||||
|
||||
if (!paramList) {
|
||||
error();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (expectedTypeID >= paramList->size()) {
|
||||
error();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
result = paramList->getParams()[expectedTypeID].getDecl();
|
||||
assert(result);
|
||||
}
|
||||
|
||||
declOrOffset = result;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user