Clean up the linkage model and the computation of linkage.

In general, this forces SILGen and IRGen code that's grabbing
a declaration to state whether it's doing so to define it.

Change SIL serialization to serialize the linkage of functions
and global variables, which means also serializing declarations.

Change the deserializer to use this stored linkage, even when
only deserializing a declaration, and to call a callback to
inform the client that it has deserialized a new entity.

Take advantage of that callback in the linking pass to alter
the deserialized linkage as appropriate for the fact that we
imported the declaration.  This computation should really take
advantage of the relationship between modules, but currently
it does not.

Swift SVN r12090
This commit is contained in:
John McCall
2014-01-09 08:58:07 +00:00
parent 622c2f6ce8
commit 5da6defa1f
48 changed files with 1289 additions and 617 deletions

View File

@@ -135,6 +135,52 @@ public:
}
};
/// A class for holding a value that can be partially deserialized.
///
/// This class assumes that "T()" is not a valid deserialized value.
template <typename T>
class PartiallySerialized {
private:
using RawBitOffset = decltype(DeclTypeCursor.GetCurrentBitNo());
/// The deserialized value.
T Value;
/// The offset. Set to 0 when fully deserialized.
serialization::BitOffset Offset;
public:
/*implicit*/ PartiallySerialized(serialization::BitOffset offset)
: Value(), Offset(offset) {}
/*implicit*/ PartiallySerialized(RawBitOffset offset)
: Value(), Offset(offset) {}
bool isDeserialized() const {
return Value != T();
}
bool isFullyDeserialized() const {
return isDeserialized() && Offset == 0;
}
serialization::BitOffset getOffset() const {
assert(!isFullyDeserialized());
return Offset;
}
T get() const {
assert(isDeserialized());
return Value;
}
void set(T value, bool isFullyDeserialized) {
assert(!isDeserialized() || Value == value);
Value = value;
if (isFullyDeserialized) Offset = 0;
}
};
private:
/// Decls referenced by this module.
std::vector<Serialized<Decl*>> Decls;
@@ -190,11 +236,18 @@ private:
Status = issue;
}
public:
ASTContext &getContext() const {
assert(FileContext && "no associated context yet");
return FileContext->getParentModule()->Ctx;
}
Module *getAssociatedModule() const {
assert(FileContext && "no associated context yet");
return FileContext->getParentModule();
}
private:
/// Read an on-disk decl hash table stored in index_block::DeclListLayout
/// format.
std::unique_ptr<SerializedDeclTable>