SIL: Only give closures shared linkage if they're going to be serialized

Otherwise, we don't want them to be linkonce_odr at the LLVM level
to avoid unnecessary link-time overhead.
This commit is contained in:
Slava Pestov
2017-03-29 00:56:19 -07:00
parent 289428ca55
commit 94ce4c2ac3
39 changed files with 195 additions and 215 deletions

View File

@@ -415,19 +415,23 @@ bool SILDeclRef::isImplicit() const {
}
SILLinkage SILDeclRef::getLinkage(ForDefinition_t forDefinition) const {
// Anonymous functions have shared linkage.
// FIXME: This should really be the linkage of the parent function.
if (getAbstractClosureExpr())
return SILLinkage::Shared;
if (auto *ace = getAbstractClosureExpr()) {
if (isSerialized())
return SILLinkage::Shared;
return SILLinkage::Private;
}
// Native function-local declarations have shared linkage.
// FIXME: @objc declarations should be too, but we currently have no way
// of marking them "used" other than making them external.
ValueDecl *d = getDecl();
DeclContext *moduleContext = d->getDeclContext();
while (!moduleContext->isModuleScopeContext()) {
if (!isForeign && moduleContext->isLocalContext())
return SILLinkage::Shared;
if (!isForeign && moduleContext->isLocalContext()) {
if (isSerialized())
return SILLinkage::Shared;
return SILLinkage::Private;
}
moduleContext = moduleContext->getParent();
}