Merge pull request #32657 from aschwaighofer/wip_prespecialize_exported

Preliminary support for `_specialize(exported: true, ...)`
This commit is contained in:
Arnold Schwaighofer
2020-10-13 07:57:51 -07:00
committed by GitHub
98 changed files with 2479 additions and 387 deletions

View File

@@ -3295,13 +3295,14 @@ ValueDecl::getFormalAccessScope(const DeclContext *useDC,
/// See ValueDecl::isAccessibleFrom for a description of \p forConformance.
static bool checkAccessUsingAccessScopes(const DeclContext *useDC,
const ValueDecl *VD,
AccessLevel access) {
AccessLevel access,
bool includeInlineable) {
if (VD->getASTContext().isAccessControlDisabled())
return true;
AccessScope accessScope =
getAccessScopeForFormalAccess(VD, access, useDC,
/*treatUsableFromInlineAsPublic*/false);
AccessScope accessScope = getAccessScopeForFormalAccess(
VD, access, useDC,
/*treatUsableFromInlineAsPublic*/ includeInlineable);
if (accessScope.getDeclContext() == useDC) return true;
if (!AccessScope(useDC).isChildOf(accessScope)) return false;
@@ -3324,6 +3325,7 @@ static bool checkAccessUsingAccessScopes(const DeclContext *useDC,
/// See ValueDecl::isAccessibleFrom for a description of \p forConformance.
static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
bool forConformance,
bool includeInlineable,
llvm::function_ref<AccessLevel()> getAccessLevel) {
if (VD->getASTContext().isAccessControlDisabled())
return true;
@@ -3336,7 +3338,7 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
// check declarations inside inaccessible members via slower
// access scope based check, which is helpful for diagnostics.
if (!(sourceDC->getSelfProtocolDecl() || VD->isOperator()))
return checkAccessUsingAccessScopes(useDC, VD, access);
return checkAccessUsingAccessScopes(useDC, VD, access, includeInlineable);
if (!forConformance) {
if (auto *proto = sourceDC->getSelfProtocolDecl()) {
@@ -3351,7 +3353,7 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
}
// Skip the fast path below and just compare access scopes.
return checkAccessUsingAccessScopes(useDC, VD, access);
return checkAccessUsingAccessScopes(useDC, VD, access, includeInlineable);
}
}
@@ -3391,8 +3393,9 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
}
bool ValueDecl::isAccessibleFrom(const DeclContext *useDC,
bool forConformance) const {
return checkAccess(useDC, this, forConformance,
bool forConformance,
bool includeInlineable) const {
return checkAccess(useDC, this, forConformance, includeInlineable,
[&]() { return getFormalAccess(); });
}
@@ -3409,7 +3412,7 @@ bool AbstractStorageDecl::isSetterAccessibleFrom(const DeclContext *DC,
if (isa<ParamDecl>(this))
return true;
return checkAccess(DC, this, forConformance,
return checkAccess(DC, this, forConformance, /*includeInlineable*/ false,
[&]() { return getSetterFormalAccess(); });
}