[AST] NFC: Stop over aligning DeclContexts

DeclContexts as they exist today are "over aligned" when compared to
their natural alignment boundary and therefore they can easily cause
adjacent padding when dropped into the middle of objects via C++
inheritance, or when the clang importer prefaces Swift AST allocations
with a pointer to the corresponding clang AST node.

With this change, we move DeclContexts to the front of the memory layout
of AST nodes. This allows us to restore natural alignment, save memory,
and as a side effect: more easily avoid "over alignment" in the future
because DeclContexts now only need to directly track which AST node
hierarchy they're associated with, not specific AST nodes within each
hierarchy.

Finally, as a word of caution, after this change one can no longer
assume that AST nodes safely convert back and forth with "void*". For
example, WitnessTableEntry needed fixing with this change.
This commit is contained in:
David Zarzycki
2018-01-07 11:30:50 -05:00
parent 3312a22c1a
commit e9b643026b
10 changed files with 191 additions and 75 deletions

View File

@@ -127,7 +127,7 @@ enum class ResilienceStrategy : unsigned {
/// output binary and logical module (such as a single library or executable).
///
/// \sa FileUnit
class ModuleDecl : public TypeDecl, public DeclContext {
class ModuleDecl : public DeclContext, public TypeDecl {
public:
typedef ArrayRef<std::pair<Identifier, SourceLoc>> AccessPathTy;
typedef std::pair<ModuleDecl::AccessPathTy, ModuleDecl*> ImportedModule;