mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Serialization] Mark deserialized decls as early-attr-validated.
This should not have any observable effect, but it means the compiler won't waste time validating the attributes of deserialized declarations. Swift SVN r21499
This commit is contained in:
@@ -282,6 +282,10 @@ private:
|
||||
assert(status == getStatus() && "not enough bits for status");
|
||||
}
|
||||
|
||||
/// Creates a new AST node to represent a deserialized decl.
|
||||
template <typename T, typename ...Args>
|
||||
T *createDecl(Args &&... args);
|
||||
|
||||
/// Constructs an new module and validates it.
|
||||
ModuleFile(std::unique_ptr<llvm::MemoryBuffer> moduleInputBuffer,
|
||||
std::unique_ptr<llvm::MemoryBuffer> moduleDocInputBuffer,
|
||||
|
||||
@@ -1441,6 +1441,15 @@ getActualOptionalTypeKind(uint8_t raw) {
|
||||
return Nothing;
|
||||
}
|
||||
|
||||
template <typename T, typename ...Args>
|
||||
T *ModuleFile::createDecl(Args &&... args) {
|
||||
// Note that this method is not used for all decl kinds.
|
||||
static_assert(std::is_base_of<Decl, T>::value, "not a Decl");
|
||||
T *result = new (getContext()) T(std::forward<Args>(args)...);
|
||||
result->setEarlyAttrValidation(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
if (DID == 0)
|
||||
return nullptr;
|
||||
@@ -1637,7 +1646,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
if (declOrOffset.isComplete())
|
||||
return declOrOffset;
|
||||
|
||||
auto alias = new (ctx) TypeAliasDecl(SourceLoc(), getIdentifier(nameID),
|
||||
auto alias = createDecl<TypeAliasDecl>(SourceLoc(), getIdentifier(nameID),
|
||||
SourceLoc(), underlyingType, DC);
|
||||
declOrOffset = alias;
|
||||
|
||||
@@ -1682,7 +1691,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
if (declOrOffset.isComplete())
|
||||
return declOrOffset;
|
||||
|
||||
auto genericParam = new (ctx) GenericTypeParamDecl(DC,
|
||||
auto genericParam = createDecl<GenericTypeParamDecl>(DC,
|
||||
getIdentifier(nameID),
|
||||
SourceLoc(),
|
||||
depth,
|
||||
@@ -1726,7 +1735,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
if (declOrOffset.isComplete())
|
||||
return declOrOffset;
|
||||
|
||||
auto assocType = new (ctx) AssociatedTypeDecl(DC, SourceLoc(),
|
||||
auto assocType = createDecl<AssociatedTypeDecl>(DC, SourceLoc(),
|
||||
getIdentifier(nameID),
|
||||
SourceLoc(), this,
|
||||
defaultDefinitionID);
|
||||
@@ -1767,8 +1776,9 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
if (declOrOffset.isComplete())
|
||||
return declOrOffset;
|
||||
|
||||
auto theStruct = new (ctx) StructDecl(SourceLoc(), getIdentifier(nameID),
|
||||
SourceLoc(), { }, genericParams, DC);
|
||||
auto theStruct = createDecl<StructDecl>(SourceLoc(), getIdentifier(nameID),
|
||||
SourceLoc(), None, genericParams,
|
||||
DC);
|
||||
declOrOffset = theStruct;
|
||||
|
||||
if (auto accessLevel = getActualAccessibility(rawAccessLevel)) {
|
||||
@@ -1846,7 +1856,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
failability = *actualFailability;
|
||||
|
||||
DeclName name(ctx, ctx.Id_init, argNames);
|
||||
auto ctor = new (ctx) ConstructorDecl(name, SourceLoc(), failability,
|
||||
auto ctor = createDecl<ConstructorDecl>(name, SourceLoc(), failability,
|
||||
SourceLoc(), /*bodyParams=*/nullptr,
|
||||
nullptr, genericParams, parent);
|
||||
declOrOffset = ctor;
|
||||
@@ -1934,7 +1944,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
if (declOrOffset.isComplete())
|
||||
return declOrOffset;
|
||||
|
||||
auto var = new (ctx) VarDecl(isStatic, isLet, SourceLoc(),
|
||||
auto var = createDecl<VarDecl>(isStatic, isLet, SourceLoc(),
|
||||
getIdentifier(nameID), type, DC);
|
||||
|
||||
declOrOffset = var;
|
||||
@@ -2013,7 +2023,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
if (declOrOffset.isComplete())
|
||||
return declOrOffset;
|
||||
|
||||
auto param = new (ctx) ParamDecl(isLet, SourceLoc(),
|
||||
auto param = createDecl<ParamDecl>(isLet, SourceLoc(),
|
||||
getIdentifier(argNameID), SourceLoc(),
|
||||
getIdentifier(paramNameID), type, DC);
|
||||
|
||||
@@ -2083,6 +2093,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
auto fn = FuncDecl::createDeserialized(
|
||||
ctx, SourceLoc(), staticSpelling.getValue(), SourceLoc(), name,
|
||||
SourceLoc(), genericParams, /*type=*/nullptr, numParamPatterns, DC);
|
||||
fn->setEarlyAttrValidation();
|
||||
declOrOffset = fn;
|
||||
|
||||
if (auto accessLevel = getActualAccessibility(rawAccessLevel)) {
|
||||
@@ -2162,7 +2173,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto binding = new (ctx) PatternBindingDecl(
|
||||
auto binding = createDecl<PatternBindingDecl>(
|
||||
SourceLoc(), StaticSpelling.getValue(), SourceLoc(), pattern,
|
||||
/*init=*/nullptr,
|
||||
/*conditional=*/false, getDeclContext(contextID));
|
||||
@@ -2191,8 +2202,8 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
if (declOrOffset.isComplete())
|
||||
return declOrOffset;
|
||||
|
||||
auto proto = new (ctx) ProtocolDecl(DC, SourceLoc(), SourceLoc(),
|
||||
getIdentifier(nameID), { });
|
||||
auto proto = createDecl<ProtocolDecl>(DC, SourceLoc(), SourceLoc(),
|
||||
getIdentifier(nameID), None);
|
||||
declOrOffset = proto;
|
||||
|
||||
if (isClassBounded)
|
||||
@@ -2243,7 +2254,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
DeclID contextID;
|
||||
|
||||
decls_block::PrefixOperatorLayout::readRecord(scratch, nameID, contextID);
|
||||
declOrOffset = new (ctx) PrefixOperatorDecl(getDeclContext(contextID),
|
||||
declOrOffset = createDecl<PrefixOperatorDecl>(getDeclContext(contextID),
|
||||
SourceLoc(),
|
||||
getIdentifier(nameID),
|
||||
SourceLoc(), SourceLoc(),
|
||||
@@ -2256,7 +2267,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
DeclID contextID;
|
||||
|
||||
decls_block::PostfixOperatorLayout::readRecord(scratch, nameID, contextID);
|
||||
declOrOffset = new (ctx) PostfixOperatorDecl(getDeclContext(contextID),
|
||||
declOrOffset = createDecl<PostfixOperatorDecl>(getDeclContext(contextID),
|
||||
SourceLoc(),
|
||||
getIdentifier(nameID),
|
||||
SourceLoc(), SourceLoc(),
|
||||
@@ -2290,7 +2301,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
InfixData infixData(precedence, associativity.getValue(),
|
||||
isAssignment);
|
||||
|
||||
declOrOffset = new (ctx) InfixOperatorDecl(getDeclContext(contextID),
|
||||
declOrOffset = createDecl<InfixOperatorDecl>(getDeclContext(contextID),
|
||||
SourceLoc(),
|
||||
getIdentifier(nameID),
|
||||
SourceLoc(), SourceLoc(),
|
||||
@@ -2325,8 +2336,8 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
if (declOrOffset.isComplete())
|
||||
return declOrOffset;
|
||||
|
||||
auto theClass = new (ctx) ClassDecl(SourceLoc(), getIdentifier(nameID),
|
||||
SourceLoc(), { }, genericParams, DC);
|
||||
auto theClass = createDecl<ClassDecl>(SourceLoc(), getIdentifier(nameID),
|
||||
SourceLoc(), None, genericParams, DC);
|
||||
declOrOffset = theClass;
|
||||
|
||||
if (auto accessLevel = getActualAccessibility(rawAccessLevel)) {
|
||||
@@ -2398,8 +2409,8 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
if (declOrOffset.isComplete())
|
||||
return declOrOffset;
|
||||
|
||||
auto theEnum = new (ctx) EnumDecl(SourceLoc(), getIdentifier(nameID),
|
||||
SourceLoc(), { }, genericParams, DC);
|
||||
auto theEnum = createDecl<EnumDecl>(SourceLoc(), getIdentifier(nameID),
|
||||
SourceLoc(), None, genericParams, DC);
|
||||
|
||||
declOrOffset = theEnum;
|
||||
|
||||
@@ -2464,7 +2475,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
return declOrOffset;
|
||||
|
||||
// FIXME: Deserialize the literal raw value, if any.
|
||||
auto elem = new (ctx) EnumElementDecl(SourceLoc(),
|
||||
auto elem = createDecl<EnumElementDecl>(SourceLoc(),
|
||||
getIdentifier(nameID),
|
||||
TypeLoc::withoutLoc(argTy),
|
||||
SourceLoc(),
|
||||
@@ -2516,7 +2527,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
argNames.push_back(getIdentifier(argNameID));
|
||||
|
||||
DeclName name(ctx, ctx.Id_subscript, argNames);
|
||||
auto subscript = new (ctx) SubscriptDecl(name, SourceLoc(), indices,
|
||||
auto subscript = createDecl<SubscriptDecl>(name, SourceLoc(), indices,
|
||||
SourceLoc(), elemTy, DC);
|
||||
declOrOffset = subscript;
|
||||
|
||||
@@ -2565,7 +2576,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
nominal->getGenericParams()};
|
||||
auto extension = ExtensionDecl::create(ctx, SourceLoc(), component, { },
|
||||
DC);
|
||||
|
||||
extension->setEarlyAttrValidation();
|
||||
declOrOffset = extension;
|
||||
|
||||
if (isImplicit)
|
||||
@@ -2605,7 +2616,7 @@ Decl *ModuleFile::getDecl(DeclID DID, Optional<DeclContext *> ForcedContext) {
|
||||
if (declOrOffset.isComplete())
|
||||
return declOrOffset;
|
||||
|
||||
auto dtor = new (ctx) DestructorDecl(ctx.Id_deinit, SourceLoc(),
|
||||
auto dtor = createDecl<DestructorDecl>(ctx.Id_deinit, SourceLoc(),
|
||||
/*selfpat*/nullptr, DC);
|
||||
declOrOffset = dtor;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user