Sema: Plumb through resiliently-accessed global variables

My recent changes added "resiliently-sized" global variables, where a
global in one module is defined to be of a type from another module,
and the type's size is not known at compile time.

This patch adds the other half of the equation: when accessing a
global variable defined by another module, we want to use accessors
since we want to resiliently change global variables from stored to
computed and vice versa.

The main complication here is that the synthesized accessors are not
part of any IterableDeclContext, and require some special-casing in
SILGen and Serialization. There might be simplifications possible here.

For testing and because of how the resilience code works right now,
I added the @_fixed_layout attribute to global variables. In the
future, we probably will not give users a way to promise that a
stored global variable will always remain stored; or perhaps we will
hang this off of a different attribute, once we finalize the precise
set of attributes exposed for resilience.

There's probably some other stuff with lazy and observers I need to
think about here; leaving that for later.
This commit is contained in:
Slava Pestov
2016-01-15 17:12:03 -08:00
parent 6a85b06129
commit 9c3ccc9855
9 changed files with 124 additions and 12 deletions

View File

@@ -3693,6 +3693,18 @@ void Serializer::writeAST(ModuleOrSourceFile DC) {
.push_back({ getStableFixity(OD->getKind()), addDeclRef(D) });
}
// If this is a global variable, force the accessors to be
// serialized.
if (auto VD = dyn_cast<VarDecl>(D)) {
if (VD->getGetter())
addDeclRef(VD->getGetter());
if (VD->getSetter())
addDeclRef(VD->getSetter());
}
// If this nominal type has assocaited top-level decls for a
// derived conformance (for example, ==), force them to be
// serialized.
if (auto IDC = dyn_cast<IterableDeclContext>(D)) {
addOperatorsAndTopLevel(*this, IDC->getMembers(),
operatorMethodDecls, topLevelDecls,