Set SILLinkage according to visibility.

Now the SILLinkage for functions and global variables is according to the swift visibility (private, internal or public).

In addition, the fact whether a function or global variable is considered as fragile, is kept in a separate flag at SIL level.
Previously the linkage was used for this (e.g. no inlining of less visible functions to more visible functions). But it had no effect,
because everything was public anyway.

For now this isFragile-flag is set for public transparent functions and for everything if a module is compiled with -sil-serialize-all,
i.e. for the stdlib.

For details see <rdar://problem/18201785> Set SILLinkage correctly and better handling of fragile functions.

The benefits of this change are:
*) Enable to eliminate unused private and internal functions
*) It should be possible now to use private in the stdlib
*) The symbol linkage is as one would expect (previously almost all symbols were public).

More details:

Specializations from fragile functions (e.g. from the stdlib) now get linkonce_odr,default
linkage instead of linkonce_odr,hidden, i.e. they have public visibility.
The reason is: if such a function is called from another fragile function (in the same module),
then it has to be visible from a third module, in case the fragile caller is inlined but not
the specialized function.

I had to update lots of test files, because many CHECK-LABEL lines include the linkage, which has changed.

The -sil-serialize-all option is now handled at SILGen and not at the Serializer.
This means that test files in sil format which are compiled with -sil-serialize-all
must have the [fragile] attribute set for all functions and globals.

The -disable-access-control option doesn't help anymore if the accessed module is not compiled
with -sil-serialize-all, because the linker will complain about unresolved symbols.

A final note: I tried to consider all the implications of this change, but it's not a low-risk change.
If you have any comments, please let me know.



Swift SVN r22215
This commit is contained in:
Erik Eckstein
2014-09-23 12:33:18 +00:00
parent 45c2005c9d
commit c16c510167
228 changed files with 1844 additions and 1690 deletions

View File

@@ -79,10 +79,13 @@ class SILModule::SerializationCallback : public SerializedSILLoader::Callback {
case SILLinkage::Shared:
decl->setLinkage(SILLinkage::SharedExternal);
return;
case SILLinkage::Private: // ?
case SILLinkage::Private:
decl->setLinkage(SILLinkage::PrivateExternal);
return;
case SILLinkage::PublicExternal:
case SILLinkage::HiddenExternal:
case SILLinkage::SharedExternal:
case SILLinkage::PrivateExternal:
return;
}
}
@@ -238,7 +241,8 @@ SILFunction *SILModule::getOrCreateFunction(SILLocation loc,
SILLinkage linkage,
CanSILFunctionType type,
IsBare_t isBareSILFunction,
IsTransparent_t isTransparent) {
IsTransparent_t isTransparent,
IsFragile_t isFragile) {
if (auto fn = lookUpFunction(name)) {
assert(fn->getLoweredFunctionType() == type);
assert(fn->getLinkage() == linkage);
@@ -246,7 +250,7 @@ SILFunction *SILModule::getOrCreateFunction(SILLocation loc,
}
auto fn = SILFunction::create(*this, linkage, name, type, nullptr,
loc, isBareSILFunction, isTransparent);
loc, isBareSILFunction, isTransparent, isFragile);
fn->setDebugScope(new (*this) SILDebugScope(loc, *fn));
return fn;
}
@@ -255,9 +259,10 @@ SILFunction *SILModule::getOrCreateSharedFunction(SILLocation loc,
StringRef name,
CanSILFunctionType type,
IsBare_t isBareSILFunction,
IsTransparent_t isTransparent) {
IsTransparent_t isTransparent,
IsFragile_t isFragile) {
return getOrCreateFunction(loc, name, SILLinkage::Shared,
type, isBareSILFunction, isTransparent);
type, isBareSILFunction, isTransparent, isFragile);
}
ArrayRef<SILType> ValueBase::getTypes() const {