Commit 79b7ab49 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Get rid of destructors because they're not even getting called.

Will add them back later
parent d5051f2e
......@@ -801,12 +801,12 @@ test_asm:
objdump -d test | less
@ rm test
test_cpp_asm:
$(CLANG_EXE) ../test/test.cpp -o test -c -O3
$(CLANG_EXE) ../test/test.cpp -o test -c -O3 -std=c++11
# $(GPP) tests/test.cpp -o test -c -O3
objdump -d test | less
rm test
test_cpp_ll:
$(CLANG_EXE) ../test/test.cpp -o test.ll -c -O3 -emit-llvm -S
$(CLANG_EXE) ../test/test.cpp -o test.ll -c -O3 -emit-llvm -S -std=c++11
less test.ll
rm test.ll
......
......@@ -39,7 +39,6 @@ using namespace llvm;
namespace pyston {
#define CLS_DTOR_OFFSET ((const char*)&(((BoxedClass*)0x01)->dtor) - (const char*)0x1)
#define CLS_HASATTRS_OFFSET ((const char*)&(((BoxedClass*)0x01)->hasattrs) - (const char*)0x1)
#define FLAVOR_KINDID_OFFSET ((const char*)&(((ObjectFlavor*)0x01)->kind_id) - (const char*)0x1)
......@@ -153,11 +152,7 @@ private:
errs() << "Found a load: " << *gep_load << '\n';
if (offset == CLS_DTOR_OFFSET) {
errs() << "Dtor; replacing with " << cls->dtor << "\n";
replaceUsesWithConstant(gep_load, (uintptr_t)cls->dtor);
changed = true;
} else if (offset == CLS_HASATTRS_OFFSET) {
if (offset == CLS_HASATTRS_OFFSET) {
errs() << "Hasattrs; replacing with " << cls->hasattrs << "\n";
replaceUsesWithConstant(gep_load, cls->hasattrs);
changed = true;
......
......@@ -359,14 +359,6 @@ public:
class BoxedClass : public HCBox {
public:
// This first typedef is right, but clang miscompiles it (how??), so use the second one:
// typedef void (*Dtor)(Box*);
typedef void* Dtor;
// compiler-level (cf python-level) destructor, that does things like decrementing
// refcounts of any attributes
const Dtor dtor;
// If the user sets __getattribute__ or __getattr__, we will have to invalidate
// all getattr IC entries that relied on the fact that those functions didn't exist.
// Doing this via invalidation means that instance attr lookups don't have
......@@ -382,7 +374,7 @@ public:
// though for now (is_constant && !hasattrs) does imply that the instances are constant.
bool is_constant;
BoxedClass(bool hasattrs, Dtor dtor);
BoxedClass(bool hasattrs);
void freeze() {
assert(!is_constant);
is_constant = true;
......
......@@ -328,7 +328,7 @@ Box* exceptionRepr(Box* b) {
}
static BoxedClass* makeBuiltinException(const char* name) {
BoxedClass* cls = new BoxedClass(true, NULL);
BoxedClass* cls = new BoxedClass(true);
cls->giveAttr("__name__", boxStrConstant(name));
// TODO these should be on the base Exception class:
......@@ -346,7 +346,7 @@ void setupBuiltins() {
builtins_module->setattr("None", None, NULL, NULL);
notimplemented_cls = new BoxedClass(false, NULL);
notimplemented_cls = new BoxedClass(false);
notimplemented_cls->giveAttr("__name__", boxStrConstant("NotImplementedType"));
notimplemented_cls->giveAttr("__repr__",
new BoxedFunction(boxRTFunction((void*)notimplementedRepr, NULL, 1, false)));
......
......@@ -121,7 +121,7 @@ BoxedModule* getTestModule() {
}
void setupCAPI() {
capifunc_cls = new BoxedClass(false, NULL);
capifunc_cls = new BoxedClass(false);
capifunc_cls->giveAttr("__name__", boxStrConstant("capifunc"));
capifunc_cls->giveAttr("__repr__",
......
......@@ -49,10 +49,10 @@ Box* dictItems(BoxedDict* self) {
BoxedList* rtn = new BoxedList();
for (const auto& p : self->d) {
std::vector<Box*> elts;
BoxedTuple::GCVector elts;
elts.push_back(p.first);
elts.push_back(p.second);
BoxedTuple* t = new BoxedTuple(elts);
BoxedTuple* t = new BoxedTuple(std::move(elts));
listAppendInternal(rtn, t);
}
......@@ -101,16 +101,6 @@ Box* dictSetitem(BoxedDict* self, Box* k, Box* v) {
return None;
}
void dict_dtor(BoxedDict* self) {
self->d.clear();
// I thought, in disbelief, that this works:
//(&self->d)->~decltype(self->d)();
// but that's only on clang, so instead do this:
typedef decltype(self->d) T;
(&self->d)->~T();
}
void setupDict() {
dict_cls->giveAttr("__name__", boxStrConstant("dict"));
// dict_cls->giveAttr("__len__", new BoxedFunction(boxRTFunction((void*)dictLen, NULL, 1, false)));
......
......@@ -160,9 +160,6 @@ Box* fileExit(BoxedFile* self, Box* exc_type, Box* exc_val, Box** args) {
return fileClose(self);
}
void file_dtor(BoxedFile* t) {
}
Box* fileNew2(BoxedClass* cls, Box* s) {
assert(cls == file_cls);
return open1(s);
......
......@@ -48,11 +48,6 @@ public:
BoxedXrangeIterator(BoxedXrange* xrange)
: Box(&xrange_iterator_flavor, xrange_iterator_cls), xrange(xrange), cur(xrange->start) {}
static void xrangeIteratorDtor(Box* s) __attribute__((visibility("default"))) {
assert(s->cls == xrange_iterator_cls);
BoxedXrangeIterator* self = static_cast<BoxedXrangeIterator*>(s);
}
static bool xrangeIteratorHasnextUnboxed(Box* s) __attribute__((visibility("default"))) {
assert(s->cls == xrange_iterator_cls);
BoxedXrangeIterator* self = static_cast<BoxedXrangeIterator*>(s);
......@@ -127,9 +122,9 @@ Box* xrangeIter(Box* self) {
}
void setupXrange() {
xrange_cls = new BoxedClass(false, NULL);
xrange_cls = new BoxedClass(false);
xrange_cls->giveAttr("__name__", boxStrConstant("xrange"));
xrange_iterator_cls = new BoxedClass(false, (BoxedClass::Dtor)BoxedXrangeIterator::xrangeIteratorDtor);
xrange_iterator_cls = new BoxedClass(false);
xrange_iterator_cls->giveAttr("__name__", boxStrConstant("rangeiterator"));
CLFunction* xrange_clf = boxRTFunction((void*)xrange1, NULL, 2, false);
......
......@@ -333,9 +333,6 @@ extern "C" void listIteratorGCHandler(GCVisitor* v, void* p) {
extern "C" const ObjectFlavor list_iterator_flavor(&listIteratorGCHandler, NULL);
void listiterDtor(BoxedListIterator* self) {
}
extern "C" Box* listNew1(Box* cls) {
assert(cls == list_cls);
return new BoxedList();
......@@ -351,13 +348,8 @@ extern "C" Box* listNew2(Box* cls, Box* container) {
return rtn;
}
void list_dtor(BoxedList* self) {
if (self->capacity)
rt_free(self->elts);
}
void setupList() {
list_iterator_cls = new BoxedClass(false, (BoxedClass::Dtor)listiterDtor);
list_iterator_cls = new BoxedClass(false);
list_cls->giveAttr("__name__", boxStrConstant("list"));
......
......@@ -282,8 +282,8 @@ extern "C" void checkUnpackingLength(i64 expected, i64 given) {
}
}
BoxedClass::BoxedClass(bool hasattrs, BoxedClass::Dtor dtor)
: HCBox(&type_flavor, type_cls), dtor(dtor), hasattrs(hasattrs), is_constant(false) {
BoxedClass::BoxedClass(bool hasattrs)
: HCBox(&type_flavor, type_cls), hasattrs(hasattrs), is_constant(false) {
}
extern "C" const std::string* getNameOfClass(BoxedClass* cls) {
......
......@@ -172,7 +172,7 @@ using namespace pyston::set;
void setupSet() {
set_cls->giveAttr("__name__", boxStrConstant("set"));
set_iterator_cls = new BoxedClass(false, NULL);
set_iterator_cls = new BoxedClass(false);
set_iterator_cls->giveAttr("__name__", boxStrConstant("setiterator"));
set_iterator_cls->giveAttr("__hasnext__",
new BoxedFunction(boxRTFunction((void*)setiteratorHasnext, BOXED_BOOL, 1, false)));
......
......@@ -45,8 +45,8 @@ extern "C" BoxedString* strAdd(BoxedString* lhs, Box* _rhs) {
}
extern "C" Box* strMod(BoxedString* lhs, Box* rhs) {
const std::vector<Box*>* elts;
std::vector<Box*> _elts;
const BoxedTuple::GCVector* elts;
BoxedTuple::GCVector _elts;
if (rhs->cls == tuple_cls) {
elts = &static_cast<BoxedTuple*>(rhs)->elts;
} else {
......
......@@ -27,13 +27,8 @@
namespace pyston {
extern "C" Box* createTuple(int64_t nelts, Box** elts) {
std::vector<Box*> velts(elts, elts + nelts);
return new BoxedTuple(velts);
}
void tuple_dtor(BoxedTuple* t) {
typedef std::vector<Box*> T;
(&t->elts)->~T();
BoxedTuple::GCVector velts(elts, elts + nelts);
return new BoxedTuple(std::move(velts));
}
Box* tupleGetitem(BoxedTuple* self, Box* slice) {
......
......@@ -159,11 +159,7 @@ extern "C" void tupleGCHandler(GCVisitor* v, void* p) {
boxGCHandler(v, p);
BoxedTuple* t = (BoxedTuple*)p;
int size = t->elts.size();
if (size) {
v->visitRange(const_cast<void**>((void const* const*)&t->elts[0]),
const_cast<void**>((void const* const*)&t->elts[size]));
}
v->visitPotentialRange((void**)&t->elts, (void**)(&t->elts + 1));
}
// This probably belongs in dict.cpp?
......@@ -219,11 +215,8 @@ const AllocationKind hc_kind(&hcGCHandler, NULL);
const AllocationKind conservative_kind(&conservativeGCHandler, NULL);
}
void instancemethod_dtor(BoxedInstanceMethod* b) {
}
extern "C" Box* createClass(std::string* name, BoxedModule* parent_module) {
BoxedClass* rtn = new BoxedClass(true, NULL);
BoxedClass* rtn = new BoxedClass(true);
rtn->giveAttr("__name__", boxString(*name));
Box* modname = parent_module->getattr("__name__", NULL, NULL);
......@@ -363,11 +356,6 @@ Box* moduleRepr(BoxedModule* m) {
return boxString(os.str());
}
void str_dtor(BoxedString* s) {
typedef std::string T;
(&s->s)->~T();
}
CLFunction* unboxRTFunction(Box* b) {
assert(b->cls == function_cls);
return static_cast<BoxedFunction*>(b)->f;
......@@ -377,30 +365,30 @@ bool TRACK_ALLOCATIONS = false;
void setupRuntime() {
HiddenClass::getRoot();
type_cls = new BoxedClass(true, NULL);
type_cls = new BoxedClass(true);
type_cls->cls = type_cls;
none_cls = new BoxedClass(false, NULL);
none_cls = new BoxedClass(false);
None = new Box(&none_flavor, none_cls);
gc::registerStaticRootObj(None);
module_cls = new BoxedClass(true, NULL);
module_cls = new BoxedClass(true);
// TODO it'd be nice to be able to do these in the respective setupType methods,
// but those setup methods probably want access to these objects.
// We could have a multi-stage setup process, but that seems overkill for now.
bool_cls = new BoxedClass(false, NULL);
int_cls = new BoxedClass(false, NULL);
float_cls = new BoxedClass(false, NULL);
str_cls = new BoxedClass(false, (BoxedClass::Dtor)str_dtor);
function_cls = new BoxedClass(true, NULL);
instancemethod_cls = new BoxedClass(false, (BoxedClass::Dtor)instancemethod_dtor);
list_cls = new BoxedClass(false, (BoxedClass::Dtor)list_dtor);
slice_cls = new BoxedClass(true, NULL);
dict_cls = new BoxedClass(false, (BoxedClass::Dtor)dict_dtor);
tuple_cls = new BoxedClass(false, (BoxedClass::Dtor)tuple_dtor);
file_cls = new BoxedClass(false, (BoxedClass::Dtor)file_dtor);
set_cls = new BoxedClass(false, NULL);
bool_cls = new BoxedClass(false);
int_cls = new BoxedClass(false);
float_cls = new BoxedClass(false);
str_cls = new BoxedClass(false);
function_cls = new BoxedClass(true);
instancemethod_cls = new BoxedClass(false);
list_cls = new BoxedClass(false);
slice_cls = new BoxedClass(true);
dict_cls = new BoxedClass(false);
tuple_cls = new BoxedClass(false);
file_cls = new BoxedClass(false);
set_cls = new BoxedClass(false);
STR = typeFromClass(str_cls);
BOXED_INT = typeFromClass(int_cls);
......
......@@ -96,6 +96,74 @@ extern "C" Box* createTuple(int64_t nelts, Box** elts);
extern "C" void printFloat(double d);
class ConservativeWrapper : public GCObject {
public:
void* data[0];
ConservativeWrapper(size_t data_size) : GCObject(&conservative_kind), data() {
assert(data_size % sizeof(void*) == 0);
gc_header.kind_data = data_size;
}
void* operator new(size_t size, size_t data_size) {
assert(size == sizeof(ConservativeWrapper));
return rt_alloc(data_size + size);
}
static ConservativeWrapper* fromPointer(void* p) {
ConservativeWrapper* o = (ConservativeWrapper*)((void**)p - 1);
assert(&o->data == p);
return o;
}
};
template <class T> class StlCompatAllocator {
public:
typedef size_t size_type;
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef std::ptrdiff_t difference_type;
StlCompatAllocator() {}
template <class U> StlCompatAllocator(const StlCompatAllocator<U>& other) {}
template <class U> struct rebind {
typedef StlCompatAllocator<U> other;
};
pointer allocate(size_t n) {
size_t to_allocate = n * sizeof(value_type);
// assert(to_allocate < (1<<16));
ConservativeWrapper* rtn = new (to_allocate) ConservativeWrapper(to_allocate);
return (pointer) & rtn->data[0];
}
void deallocate(pointer p, size_t n) {
ConservativeWrapper* o = ConservativeWrapper::fromPointer(p);
rt_free(o);
}
// I would never be able to come up with this on my own:
// http://en.cppreference.com/w/cpp/memory/allocator/construct
template <class U, class... Args> void construct(U* p, Args&&... args) {
::new ((void*)p) U(std::forward<Args>(args)...);
}
template <class U> void destroy(U* p) { p->~U(); }
bool operator==(const StlCompatAllocator<T> &rhs) const {
return true;
}
bool operator!=(const StlCompatAllocator<T> &rhs) const {
return false;
}
};
class BoxedInt : public Box {
public:
int64_t n;
......@@ -119,6 +187,7 @@ public:
class BoxedString : public Box {
public:
//const std::basic_string<char, std::char_traits<char>, StlCompatAllocator<char> > s;
const std::string s;
BoxedString(const std::string&& s) __attribute__((visibility("default")))
......@@ -157,10 +226,13 @@ public:
class BoxedTuple : public Box {
public:
const std::vector<Box*> elts;
typedef std::vector<Box*, StlCompatAllocator<Box*> > GCVector;
const GCVector elts;
BoxedTuple(std::vector<Box*>& elts) __attribute__((visibility("default")))
BoxedTuple(std::vector<Box*, StlCompatAllocator<Box*> >& elts) __attribute__((visibility("default")))
: Box(&tuple_flavor, tuple_cls), elts(elts) {}
BoxedTuple(std::vector<Box*, StlCompatAllocator<Box*> >&& elts) __attribute__((visibility("default")))
: Box(&tuple_flavor, tuple_cls), elts(std::move(elts)) {}
};
class BoxedFile : public Box {
......@@ -182,66 +254,6 @@ struct PyLt {
bool operator()(Box*, Box*) const;
};
class ConservativeWrapper : public GCObject {
public:
void* data[0];
ConservativeWrapper(size_t data_size) : GCObject(&conservative_kind), data() {
assert(data_size % sizeof(void*) == 0);
gc_header.kind_data = data_size;
}
void* operator new(size_t size, size_t data_size) {
assert(size == sizeof(ConservativeWrapper));
return rt_alloc(data_size + size);
}
static ConservativeWrapper* fromPointer(void* p) {
ConservativeWrapper* o = (ConservativeWrapper*)((void**)p - 1);
assert(&o->data == p);
return o;
}
};
template <class T> class StlCompatAllocator {
public:
typedef size_t size_type;
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef T& reference;
typedef const T& const_reference;
typedef std::ptrdiff_t difference_type;
StlCompatAllocator() {}
template <class U> StlCompatAllocator(const StlCompatAllocator<U>& other) {}
template <class U> struct rebind {
typedef StlCompatAllocator<U> other;
};
pointer allocate(size_t n) {
size_t to_allocate = n * sizeof(value_type);
// assert(to_allocate < (1<<16));
ConservativeWrapper* rtn = new (to_allocate) ConservativeWrapper(to_allocate);
return (pointer) & rtn->data[0];
}
void deallocate(pointer p, size_t n) {
ConservativeWrapper* o = ConservativeWrapper::fromPointer(p);
rt_free(o);
}
// I would never be able to come up with this on my own:
// http://en.cppreference.com/w/cpp/memory/allocator/construct
template <class U, class... Args> void construct(U* p, Args&&... args) {
::new ((void*)p) U(std::forward<Args>(args)...);
}
template <class U> void destroy(U* p) { p->~U(); }
};
class BoxedDict : public Box {
public:
std::unordered_map<Box*, Box*, PyHasher, PyEq, StlCompatAllocator<std::pair<Box*, Box*> > > d;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment