[external-witnesstables] Store the entries of a witness table in bump-ptr allocated memory referenced via an ArrayRef instead of a tail allocated array.

This will enable the creation of external witness tables whose entries
can be initialized after the witness table itself has been constructed.
This can occur if the table is deserialized later from a different
module.

Swift SVN r14715
This commit is contained in:
Michael Gottesman
2014-03-06 01:59:15 +00:00
parent 001c1890e5
commit fafe76240e
2 changed files with 19 additions and 20 deletions

View File

@@ -24,25 +24,26 @@
using namespace swift;
SILWitnessTable *SILWitnessTable::create(SILModule &M,
NormalProtocolConformance *Conformance,
ArrayRef<SILWitnessTable::Entry> entries) {
// FIXME: Is it valid to get an empty array ?
size_t AdditionalEntriesSize =
entries.empty() ? 0 : sizeof(Entry) * (entries.size()-1);
void *buf = M.allocate(sizeof(SILWitnessTable) + AdditionalEntriesSize,
SILWitnessTable *
SILWitnessTable::
create(SILModule &M, NormalProtocolConformance *Conformance,
ArrayRef<SILWitnessTable::Entry> entries) {
void *buf = M.allocate(sizeof(SILWitnessTable),
alignof(SILWitnessTable));
SILWitnessTable *wt = ::new (buf) SILWitnessTable(Conformance, entries);
SILWitnessTable *wt = ::new (buf) SILWitnessTable(M, Conformance, entries);
M.witnessTables.push_back(wt);
return wt;
}
SILWitnessTable::SILWitnessTable(NormalProtocolConformance *Conformance,
SILWitnessTable::SILWitnessTable(SILModule &M,
NormalProtocolConformance *Conformance,
ArrayRef<Entry> entries)
: Conformance(Conformance), NumEntries(entries.size())
: Conformance(Conformance), Entries()
{
memcpy(Entries, entries.begin(), sizeof(Entry) * NumEntries);
void *buf = M.allocate(sizeof(Entry)*entries.size(), alignof(Entry));
memcpy(buf, entries.begin(), sizeof(Entry)*entries.size());
Entries = ArrayRef<Entry>(static_cast<Entry*>(buf), entries.size());
// Bump the reference count of witness functions referenced by this table.
for (auto entry : getEntries()) {
switch (entry.getKind()) {