Skip to content

Commit 510042f

Browse files
committed
removed the registration logic from Initialization and Depth from Scope.
Swift SVN r4842
1 parent e8686c9 commit 510042f

8 files changed

+12
-78
lines changed

lib/IRGen/Explosion.h

-7
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ class ManagedValue {
4545
return getValue();
4646
}
4747
llvm::Value *getValue() const { return Value; }
48-
49-
bool hasCleanup() const { return false; }
5048

5149
/// Forward this value, deactivating the cleanup and returning the
5250
/// underlying value.
@@ -160,11 +158,7 @@ class Explosion {
160158

161159
/// The next N values are being ignored. They are all unmanaged.
162160
void ignoreUnmanaged(unsigned n) {
163-
#ifndef NDEBUG
164161
assert(NextValue + n <= Values.size());
165-
for (auto i = NextValue, e = NextValue + n; i != e; ++i)
166-
assert(!Values[i].hasCleanup());
167-
#endif
168162
markClaimed(n);
169163
}
170164

@@ -178,7 +172,6 @@ class Explosion {
178172
/// Claim a value which is known to have no management.
179173
llvm::Value *claimUnmanagedNext() {
180174
assert(NextValue < Values.size());
181-
assert(!Values[NextValue].hasCleanup());
182175
return Values[NextValue++].getValue();
183176
}
184177

lib/IRGen/GenFunc.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,6 @@ void CallEmission::emitToExplosion(Explosion &out) {
13521352

13531353
Initialization init;
13541354
InitializedObject obj = init.getObjectForTemporary();
1355-
auto cleanup = init.registerObject(IGF, obj, NotOnHeap, substResultTI);
13561355
Address temp = init.emitLocalAllocation(IGF, obj, NotOnHeap, substResultTI,
13571356
"call.aggresult");
13581357
emitToMemory(temp, substResultTI);
@@ -1363,10 +1362,10 @@ void CallEmission::emitToExplosion(Explosion &out) {
13631362
if (substSchema.isSingleAggregate()) {
13641363
auto substType = substSchema.begin()->getAggregateType()->getPointerTo();
13651364
temp = IGF.Builder.CreateBitCast(temp, substType);
1366-
out.add(ManagedValue(temp.getAddress(), cleanup));
1365+
out.add(ManagedValue(temp.getAddress()));
13671366

1368-
// Otherwise, we need to load. Do a take-load and deactivate the cleanup.
13691367
} else {
1368+
// Otherwise, we need to load.
13701369
substResultTI.loadAsTake(IGF, temp, out);
13711370
}
13721371
return;
@@ -1498,7 +1497,6 @@ void CallEmission::forceCallee() {
14981497
// Allocate the temporary.
14991498
Initialization init;
15001499
auto object = init.getObjectForTemporary();
1501-
init.registerObjectWithoutDestroy(object);
15021500
Address addr = init.emitLocalAllocation(IGF, object, NotOnHeap, substTI,
15031501
"polymorphic-currying-temp")
15041502
.getUnownedAddress();
@@ -1553,7 +1551,6 @@ void CallEmission::externalizeArgument(Explosion &out, Explosion &in,
15531551
if (requiresExternalByvalArgument(IGF.IGM, ty)) {
15541552
Initialization I;
15551553
InitializedObject object = I.getObjectForTemporary();
1556-
I.registerObject(IGF, object, NotOnHeap, ti);
15571554
OwnedAddress addr = ti.allocate(IGF,
15581555
I,
15591556
object,
@@ -1767,7 +1764,6 @@ void IRGenFunction::emitPrologue() {
17671764
// work in the normal way.
17681765
Initialization returnInit;
17691766
auto returnObject = returnInit.getObjectForTemporary();
1770-
returnInit.registerObjectWithoutDestroy(returnObject);
17711767

17721768
// Allocate the slot and leave its allocation cleanup hanging
17731769
// around.

lib/IRGen/GenInit.cpp

-27
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,6 @@ using namespace swift;
3535
using namespace irgen;
3636

3737

38-
/// Register an object with the initialization process.
39-
CleanupsDepth Initialization::registerObject(IRGenFunction &IGF,
40-
InitializedObject object,
41-
OnHeap_t onHeap,
42-
const TypeInfo &objectTI) {
43-
// Create the appropriate destroy cleanup.
44-
registerObject(object, CleanupsDepth::invalid());
45-
46-
return CleanupsDepth::invalid();
47-
}
48-
49-
void Initialization::registerObjectWithoutDestroy(InitializedObject object) {
50-
registerObject(object, CleanupsDepth::invalid());
51-
}
52-
53-
/// Register an object with the initialization process.
54-
void Initialization::registerObject(InitializedObject object,
55-
CleanupsDepth destroy) {
56-
// The invariant is that the cleanup has to be an
57-
// UnboundDestroy if it's valid.
58-
59-
ValueRecord record = {
60-
CleanupsDepth::invalid(), destroy
61-
};
62-
Records.insert(std::make_pair(object.Opaque, record));
63-
}
64-
6538
/// Emit a global variable.
6639
Address IRGenModule::emitGlobalVariable(VarDecl *var,
6740
const TypeInfo &type) {

lib/IRGen/GenInit.h

-22
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#ifndef SWIFT_IRGEN_GENINIT_H
3535
#define SWIFT_IRGEN_GENINIT_H
3636

37-
#include "llvm/ADT/DenseMap.h"
3837
#include "IRGenFunction.h"
3938
#include "swift/SIL/SILValue.h"
4039

@@ -60,19 +59,10 @@ class InitializedObject {
6059
/// To use this, you need to:
6160
/// - create an abstract Object for the object you'd like to initialize,
6261
/// using one of the getObject* methods;
63-
/// - register that Object with the Initialization using one of the
64-
/// registerObject* methods;
6562
///
6663
/// This class also provides several convenience methods for
6764
/// performing one or more stages of this process.
6865
class Initialization {
69-
struct ValueRecord {
70-
CleanupsDepth DeallocCleanup;
71-
CleanupsDepth DestroyCleanup;
72-
};
73-
74-
llvm::DenseMap<void *, ValueRecord> Records;
75-
7666
public:
7767

7868
/// Create an object reference for the given SIL value.
@@ -97,18 +87,6 @@ class Initialization {
9787
OnHeap_t onHeap, const TypeInfo &type,
9888
const Twine &name);
9989

100-
/// Add an object that is going to be initialized; use the
101-
/// appropriate destroy cleanup for the given type.
102-
CleanupsDepth registerObject(IRGenFunction &IGF, InitializedObject object,
103-
OnHeap_t onHeap, const TypeInfo &objectTI);
104-
105-
/// Add an object that is going to be initialized, but which does not
106-
/// need a destroy cleanup.
107-
void registerObjectWithoutDestroy(InitializedObject object);
108-
109-
private:
110-
/// Add an object that is going to be initialized.
111-
void registerObject(InitializedObject object, CleanupsDepth destroy);
11290
};
11391

11492
} // end namespace irgen

lib/IRGen/GenPoly.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ namespace {
404404
void initIntoTemporary(const TypeInfo &substTI) {
405405
Initialization init;
406406
auto object = init.getObjectForTemporary();
407-
auto cleanup = init.registerObject(IGF, object, NotOnHeap, substTI);
408407
auto addr = init.emitLocalAllocation(IGF, object, NotOnHeap, substTI,
409408
"substitution.temp").getAddress();
410409

@@ -415,7 +414,7 @@ namespace {
415414
addr = IGF.Builder.CreateBitCast(addr, IGF.IGM.OpaquePtrTy, "temp.cast");
416415

417416
// Add that to the output explosion.
418-
Out.add(ManagedValue(addr.getAddress(), cleanup));
417+
Out.add(ManagedValue(addr.getAddress()));
419418
}
420419

421420
void visitArrayType(ArrayType *origTy, ArrayType *substTy) {

lib/IRGen/IRGenSIL.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,6 @@ void IRGenSILFunction::visitAllocVarInst(swift::AllocVarInst *i) {
11381138
Initialization init;
11391139
SILValue v(i, 0);
11401140
InitializedObject initVar = init.getObjectForValue(v);
1141-
init.registerObjectWithoutDestroy(initVar);
11421141

11431142
OnHeap_t isOnHeap = NotOnHeap;
11441143
switch (i->getAllocKind()) {
@@ -1186,7 +1185,6 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
11861185
const TypeInfo &type = getFragileTypeInfo(i->getElementType());
11871186
Initialization init;
11881187
InitializedObject initBox = init.getObjectForValue(boxValue);
1189-
init.registerObjectWithoutDestroy(initBox);
11901188
OwnedAddress addr = type.allocate(*this,
11911189
init,
11921190
initBox,

lib/IRGen/IndirectTypeInfo.h

+2-7
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,13 @@ class IndirectTypeInfo : public Base {
5858
// Create a temporary.
5959
Initialization init;
6060
auto temp = init.getObjectForTemporary();
61-
auto cleanup = init.registerObject(IGF, temp, NotOnHeap, *this);
6261
Address dest = asDerived().Derived::allocate(IGF, init, temp, NotOnHeap,
6362
"temporary.forLoad");
6463

6564
// Initialize it with a copy of the source.
6665
asDerived().Derived::initializeWithCopy(IGF, dest, src);
6766

68-
// Enter a cleanup for the temporary.
69-
out.add(ManagedValue(dest.getAddress(), cleanup));
67+
out.add(ManagedValue(dest.getAddress()));
7068
}
7169

7270
void loadUnmanaged(IRGenFunction &IGF, Address src, Explosion &out) const {
@@ -78,8 +76,6 @@ class IndirectTypeInfo : public Base {
7876

7977
// Initialize it with a copy of the source.
8078
asDerived().Derived::initializeWithCopy(IGF, dest, src);
81-
82-
// Enter a cleanup for the temporary.
8379
out.addUnmanaged(dest.getAddress());
8480
}
8581

@@ -88,15 +84,14 @@ class IndirectTypeInfo : public Base {
8884
// to destroy that.
8985
Initialization init;
9086
auto temp = init.getObjectForTemporary();
91-
auto cleanup = init.registerObject(IGF, temp, NotOnHeap, *this);
9287
Address dest = asDerived().Derived::allocate(IGF, init, temp, NotOnHeap,
9388
"temporary.forLoad");
9489

9590
// Initialize it with a take of the source.
9691
asDerived().Derived::initializeWithTake(IGF, dest, src);
9792

9893
// Enter a cleanup for the temporary.
99-
out.add(ManagedValue(dest.getAddress(), cleanup));
94+
out.add(ManagedValue(dest.getAddress()));
10095
}
10196

10297
void assign(IRGenFunction &IGF, Explosion &in, Address dest) const {

lib/IRGen/Scope.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,24 @@ namespace irgen {
2626
/// statement) has been entered.
2727
class Scope {
2828
IRGenFunction &IGF;
29-
CleanupsDepth Depth;
3029
IRGenFunction::LocalTypeDataDepth SavedLocalTypeDataDepth;
31-
30+
bool Popped;
3231
public:
3332
explicit Scope(IRGenFunction &IGF)
34-
: IGF(IGF), SavedLocalTypeDataDepth(IGF.ScopedLocalTypeData.size()) {
33+
: IGF(IGF), SavedLocalTypeDataDepth(IGF.ScopedLocalTypeData.size()) {
34+
Popped = false;
3535
}
3636

3737
void pop() {
38-
assert(Depth.isValid() && "popping a scope twice!");
38+
assert(!Popped);
3939
assert(IGF.ScopedLocalTypeData.size() >= SavedLocalTypeDataDepth);
4040
IGF.endLocalTypeDataScope(SavedLocalTypeDataDepth);
41+
Popped = true;
4142
}
4243

4344
~Scope() {
44-
if (Depth.isValid()) pop();
45+
if (!Popped)
46+
pop();
4547
}
4648
};
4749

0 commit comments

Comments
 (0)