Centralize the definition of isMemberwiseInitialized()

This utility was defined in Sema, used in Sema and Index, declared in
two headers, and semi- copy-pasted into SILGen. Pull it into
VarDecl::isMemberwiseInitialized() and use it consistently.
This commit is contained in:
Doug Gregor
2019-04-29 10:30:38 -07:00
parent 209e7fcd83
commit 1a169b91bd
8 changed files with 43 additions and 39 deletions

View File

@@ -2050,26 +2050,6 @@ static void maybeAddMemberwiseDefaultArg(ParamDecl *arg, VarDecl *var,
arg->setDefaultArgumentKind(DefaultArgumentKind::StoredProperty);
}
bool swift::isMemberwiseInitialized(VarDecl *var) {
// Implicit, computed, and static properties are not initialized.
// The exception is lazy properties, which due to batch mode we may or
// may not have yet finalized, so they may currently be "stored" or
// "computed" in the current AST state.
if (var->isImplicit() || var->isStatic())
return false;
if (!var->hasStorage() && !var->getAttrs().hasAttribute<LazyAttr>() &&
!var->getAttachedPropertyDelegate())
return false;
// Initialized 'let' properties have storage, but don't get an argument
// to the memberwise initializer since they already have an initial
// value that cannot be overridden.
if (var->isLet() && var->isParentInitialized())
return false;
return true;
}
/// Create an implicit struct or class constructor.
///
/// \param decl The struct or class for which a constructor will be created.
@@ -2097,7 +2077,7 @@ ConstructorDecl *swift::createImplicitConstructor(TypeChecker &tc,
if (!var)
continue;
if (!isMemberwiseInitialized(var))
if (!var->isMemberwiseInitialized())
continue;
accessLevel = std::min(accessLevel, var->getFormalAccess());