Commit affb88b1 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Reenable unboxed ints

- Change INT to a type that remembers whether it was boxed or not.
- We still need a way of specifying a plain unboxed int, so add a
"phony" UNBOXED_INT.  UNBOXED_INT is not usable as a variable type,
but can be used to specify argument and return types.  It's up to
the receiver (irgen or type analysis) to convert UNBOXED_INT to
a usable INT.  Right now that's only guarded with a number of
asserts (and not through, say, the C++ type system).
parent 0ce6a6be
...@@ -57,12 +57,12 @@ ConcreteCompilerType* NullTypeAnalysis::getTypeAtBlockEnd(InternedString name, C ...@@ -57,12 +57,12 @@ ConcreteCompilerType* NullTypeAnalysis::getTypeAtBlockEnd(InternedString name, C
// Note: the behavior of this function must match irgenerator.cpp::unboxVar() // Note: the behavior of this function must match irgenerator.cpp::unboxVar()
static ConcreteCompilerType* unboxedType(ConcreteCompilerType* t) { static CompilerType* unboxedType(ConcreteCompilerType* t) {
if (t == BOXED_BOOL) if (t == BOXED_BOOL)
return BOOL; return BOOL;
#if ENABLE_UNBOXED_VALUES
if (t == BOXED_INT) if (t == BOXED_INT)
return INT; return INT;
#if ENABLE_UNBOXED_VALUES
if (t == BOXED_FLOAT) if (t == BOXED_FLOAT)
return FLOAT; return FLOAT;
#endif #endif
...@@ -117,17 +117,17 @@ private: ...@@ -117,17 +117,17 @@ private:
assert(speculation != TypeAnalysis::NONE); assert(speculation != TypeAnalysis::NONE);
if (speculated_cls != NULL && speculated_cls->is_constant) { if (speculated_cls != NULL && speculated_cls->is_constant) {
ConcreteCompilerType* speculated_type = unboxedType(typeFromClass(speculated_cls)); CompilerType* speculated_type = unboxedType(typeFromClass(speculated_cls));
if (VERBOSITY() >= 2) {
printf("in propagator, speculating that %s would actually be %s, at ", old_type->debugName().c_str(),
speculated_type->debugName().c_str());
fflush(stdout);
print_ast(node);
llvm::outs().flush();
printf("\n");
}
if (!old_type->canConvertTo(speculated_type)) { if (!old_type->canConvertTo(speculated_type)) {
if (VERBOSITY() >= 2) {
printf("in propagator, speculating that %s would actually be %s, at ",
old_type->debugName().c_str(), speculated_type->debugName().c_str());
fflush(stdout);
print_ast(node);
llvm::outs().flush();
printf("\n");
}
type_speculations[node] = speculated_cls; type_speculations[node] = speculated_cls;
return speculated_type; return speculated_type;
} }
...@@ -147,6 +147,7 @@ private: ...@@ -147,6 +147,7 @@ private:
} }
expr_types[node] = rtn; expr_types[node] = rtn;
assert(rtn->isUsable());
return rtn; return rtn;
} }
...@@ -163,10 +164,12 @@ private: ...@@ -163,10 +164,12 @@ private:
} }
expr_types[node] = rtn; expr_types[node] = rtn;
assert(rtn->isUsable());
return rtn; return rtn;
} }
void _doSet(InternedString target, CompilerType* t) { void _doSet(InternedString target, CompilerType* t) {
assert(t->isUsable());
if (t) if (t)
sym_table[target] = t; sym_table[target] = t;
} }
......
This diff is collapsed.
...@@ -47,7 +47,7 @@ public: ...@@ -47,7 +47,7 @@ public:
virtual std::string debugName() = 0; virtual std::string debugName() = 0;
virtual ConcreteCompilerType* getConcreteType() = 0; virtual ConcreteCompilerType* getConcreteType() = 0;
virtual ConcreteCompilerType* getBoxType() = 0; virtual ConcreteCompilerType* getBoxType() = 0;
virtual bool canConvertTo(ConcreteCompilerType* other_type) = 0; virtual bool canConvertTo(CompilerType* other_type) = 0;
virtual CompilerType* getattrType(BoxedString* attr, bool cls_only) = 0; virtual CompilerType* getattrType(BoxedString* attr, bool cls_only) = 0;
virtual CompilerType* getPystonIterType(); virtual CompilerType* getPystonIterType();
virtual Result hasattr(BoxedString* attr); virtual Result hasattr(BoxedString* attr);
...@@ -58,6 +58,13 @@ public: ...@@ -58,6 +58,13 @@ public:
virtual Box* deserializeFromFrame(const FrameVals& vals) = 0; virtual Box* deserializeFromFrame(const FrameVals& vals) = 0;
virtual int numFrameArgs() = 0; virtual int numFrameArgs() = 0;
virtual std::vector<CompilerType*> unpackTypes(int num_into); virtual std::vector<CompilerType*> unpackTypes(int num_into);
// Some types are not "usable" even if they are "concrete". Concrete means that it's possible to
// represent the value as an llvm::Value*; usable means that we are allowed to use it as a variable's
// type. Some concrete types are not usable; for example unboxed ints are concrete (can be represented
// as an i64) but are not usable, since we need to use the form that remembers what it gets boxed to.
virtual CompilerType* getUsableType() { return this; }
bool isUsable() { return this == getUsableType(); }
}; };
typedef std::unordered_map<CompilerVariable*, CompilerVariable*> DupCache; typedef std::unordered_map<CompilerVariable*, CompilerVariable*> DupCache;
...@@ -94,7 +101,7 @@ public: ...@@ -94,7 +101,7 @@ public:
printf("grab not defined for %s\n", debugName().c_str()); printf("grab not defined for %s\n", debugName().c_str());
abort(); abort();
} }
bool canConvertTo(ConcreteCompilerType* other_type) override { bool canConvertTo(CompilerType* other_type) override {
printf("canConvertTo not defined for %s\n", debugName().c_str()); printf("canConvertTo not defined for %s\n", debugName().c_str());
abort(); abort();
} }
...@@ -102,13 +109,12 @@ public: ...@@ -102,13 +109,12 @@ public:
printf("makeConverted not defined for %s\n", debugName().c_str()); printf("makeConverted not defined for %s\n", debugName().c_str());
abort(); abort();
} }
virtual ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info, VAR* var) { virtual CompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info, VAR* var) {
printf("nonzero not defined for %s\n", debugName().c_str()); printf("nonzero not defined for %s\n", debugName().c_str());
abort(); abort();
} }
virtual ConcreteCompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, VAR* var, virtual CompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, VAR* var, AST_TYPE::AST_TYPE op_type);
AST_TYPE::AST_TYPE op_type); virtual CompilerVariable* hasnext(IREmitter& emitter, const OpInfo& info, VAR* var) {
virtual ConcreteCompilerVariable* hasnext(IREmitter& emitter, const OpInfo& info, VAR* var) {
printf("hasnext not defined for %s\n", debugName().c_str()); printf("hasnext not defined for %s\n", debugName().c_str());
abort(); abort();
} }
...@@ -139,7 +145,7 @@ public: ...@@ -139,7 +145,7 @@ public:
printf("call not defined for %s\n", debugName().c_str()); printf("call not defined for %s\n", debugName().c_str());
abort(); abort();
} }
virtual ConcreteCompilerVariable* len(IREmitter& emitter, const OpInfo& info, VAR* var) { virtual CompilerVariable* len(IREmitter& emitter, const OpInfo& info, VAR* var) {
printf("len not defined for %s\n", debugName().c_str()); printf("len not defined for %s\n", debugName().c_str());
abort(); abort();
} }
...@@ -202,7 +208,7 @@ public: ...@@ -202,7 +208,7 @@ public:
CompilerVariable* dup(ConcreteCompilerVariable* v, DupCache& cache) override; CompilerVariable* dup(ConcreteCompilerVariable* v, DupCache& cache) override;
ConcreteCompilerType* getConcreteType() override { return this; } ConcreteCompilerType* getConcreteType() override { return this; }
bool canConvertTo(ConcreteCompilerType* other_type) override { return other_type == this || other_type == UNKNOWN; } bool canConvertTo(CompilerType* other_type) override { return other_type == this || other_type == UNKNOWN; }
ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerVariable* var, ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerVariable* var,
ConcreteCompilerType* other_type) override; ConcreteCompilerType* other_type) override;
void serializeToFrame(VAR* var, std::vector<llvm::Value*>& stackmap_args) override; void serializeToFrame(VAR* var, std::vector<llvm::Value*>& stackmap_args) override;
...@@ -261,14 +267,14 @@ public: ...@@ -261,14 +267,14 @@ public:
virtual CompilerType* getType() = 0; virtual CompilerType* getType() = 0;
virtual ConcreteCompilerType* getConcreteType() = 0; virtual ConcreteCompilerType* getConcreteType() = 0;
virtual ConcreteCompilerType* getBoxType() = 0; virtual ConcreteCompilerType* getBoxType() = 0;
virtual bool canConvertTo(ConcreteCompilerType* other_type) = 0; virtual bool canConvertTo(CompilerType* other_type) = 0;
virtual ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerType* other_type) = 0; virtual ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerType* other_type) = 0;
virtual llvm::Value* makeClassCheck(IREmitter& emitter, BoxedClass* cls) = 0; virtual llvm::Value* makeClassCheck(IREmitter& emitter, BoxedClass* cls) = 0;
virtual BoxedClass* guaranteedClass() = 0; virtual BoxedClass* guaranteedClass() = 0;
virtual ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info) = 0; virtual CompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info) = 0;
virtual ConcreteCompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, AST_TYPE::AST_TYPE op_type) = 0; virtual CompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, AST_TYPE::AST_TYPE op_type) = 0;
virtual ConcreteCompilerVariable* hasnext(IREmitter& emitter, const OpInfo& info) = 0; virtual CompilerVariable* hasnext(IREmitter& emitter, const OpInfo& info) = 0;
virtual CompilerVariable* getattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, bool cls_only) = 0; virtual CompilerVariable* getattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, bool cls_only) = 0;
virtual void setattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, CompilerVariable* v) = 0; virtual void setattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, CompilerVariable* v) = 0;
virtual void delattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr) = 0; virtual void delattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr) = 0;
...@@ -278,7 +284,7 @@ public: ...@@ -278,7 +284,7 @@ public:
virtual CompilerVariable* call(IREmitter& emitter, const OpInfo& info, struct ArgPassSpec argspec, virtual CompilerVariable* call(IREmitter& emitter, const OpInfo& info, struct ArgPassSpec argspec,
const std::vector<CompilerVariable*>& args, const std::vector<CompilerVariable*>& args,
const std::vector<BoxedString*>* keyword_names) = 0; const std::vector<BoxedString*>* keyword_names) = 0;
virtual ConcreteCompilerVariable* len(IREmitter& emitter, const OpInfo& info) = 0; virtual CompilerVariable* len(IREmitter& emitter, const OpInfo& info) = 0;
virtual CompilerVariable* getitem(IREmitter& emitter, const OpInfo& info, CompilerVariable*) = 0; virtual CompilerVariable* getitem(IREmitter& emitter, const OpInfo& info, CompilerVariable*) = 0;
virtual CompilerVariable* getPystonIter(IREmitter& emitter, const OpInfo& info) = 0; virtual CompilerVariable* getPystonIter(IREmitter& emitter, const OpInfo& info) = 0;
virtual CompilerVariable* binexp(IREmitter& emitter, const OpInfo& info, CompilerVariable* rhs, virtual CompilerVariable* binexp(IREmitter& emitter, const OpInfo& info, CompilerVariable* rhs,
...@@ -330,19 +336,19 @@ public: ...@@ -330,19 +336,19 @@ public:
return rtn; return rtn;
} }
bool canConvertTo(ConcreteCompilerType* other_type) override { return type->canConvertTo(other_type); } bool canConvertTo(CompilerType* other_type) override { return type->canConvertTo(other_type); }
ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerType* other_type) override { ConcreteCompilerVariable* makeConverted(IREmitter& emitter, ConcreteCompilerType* other_type) override {
ConcreteCompilerVariable* rtn = type->makeConverted(emitter, this, other_type); ConcreteCompilerVariable* rtn = type->makeConverted(emitter, this, other_type);
ASSERT(rtn->getType() == other_type, "%s", type->debugName().c_str()); ASSERT(rtn->getType() == other_type, "%s", type->debugName().c_str());
return rtn; return rtn;
} }
ConcreteCompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info) override { CompilerVariable* nonzero(IREmitter& emitter, const OpInfo& info) override {
return type->nonzero(emitter, info, this); return type->nonzero(emitter, info, this);
} }
ConcreteCompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, AST_TYPE::AST_TYPE op_type) override { CompilerVariable* unaryop(IREmitter& emitter, const OpInfo& info, AST_TYPE::AST_TYPE op_type) override {
return type->unaryop(emitter, info, this, op_type); return type->unaryop(emitter, info, this, op_type);
} }
ConcreteCompilerVariable* hasnext(IREmitter& emitter, const OpInfo& info) override { CompilerVariable* hasnext(IREmitter& emitter, const OpInfo& info) override {
return type->hasnext(emitter, info, this); return type->hasnext(emitter, info, this);
} }
CompilerVariable* getattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, bool cls_only) override { CompilerVariable* getattr(IREmitter& emitter, const OpInfo& info, BoxedString* attr, bool cls_only) override {
...@@ -366,9 +372,7 @@ public: ...@@ -366,9 +372,7 @@ public:
const std::vector<BoxedString*>* keyword_names) override { const std::vector<BoxedString*>* keyword_names) override {
return type->call(emitter, info, this, argspec, args, keyword_names); return type->call(emitter, info, this, argspec, args, keyword_names);
} }
ConcreteCompilerVariable* len(IREmitter& emitter, const OpInfo& info) override { CompilerVariable* len(IREmitter& emitter, const OpInfo& info) override { return type->len(emitter, info, this); }
return type->len(emitter, info, this);
}
CompilerVariable* getitem(IREmitter& emitter, const OpInfo& info, CompilerVariable* slice) override { CompilerVariable* getitem(IREmitter& emitter, const OpInfo& info, CompilerVariable* slice) override {
return type->getitem(emitter, info, this, slice); return type->getitem(emitter, info, this, slice);
} }
...@@ -407,8 +411,14 @@ public: ...@@ -407,8 +411,14 @@ public:
// Emit the test for whether one variable 'is' another one. // Emit the test for whether one variable 'is' another one.
ConcreteCompilerVariable* doIs(IREmitter& emitter, CompilerVariable* lhs, CompilerVariable* rhs, bool negate); ConcreteCompilerVariable* doIs(IREmitter& emitter, CompilerVariable* lhs, CompilerVariable* rhs, bool negate);
// These functions all return an INT variable, from either an unboxed representation (makeInt) or
// a boxed representation (makeUnboxedInt)
CompilerVariable* makeInt(int64_t);
CompilerVariable* makeInt(llvm::Value*);
CompilerVariable* makeUnboxedInt(IREmitter&, ConcreteCompilerVariable*);
CompilerVariable* makeUnboxedInt(IREmitter&, llvm::Value*);
ConcreteCompilerVariable* makeBool(bool); ConcreteCompilerVariable* makeBool(bool);
ConcreteCompilerVariable* makeInt(int64_t);
ConcreteCompilerVariable* makeFloat(double); ConcreteCompilerVariable* makeFloat(double);
ConcreteCompilerVariable* makeLong(Box*); ConcreteCompilerVariable* makeLong(Box*);
ConcreteCompilerVariable* makePureImaginary(Box*); ConcreteCompilerVariable* makePureImaginary(Box*);
...@@ -447,8 +457,8 @@ CompilerVariable* _ValuedCompilerType<V>::contains(IREmitter& emitter, const OpI ...@@ -447,8 +457,8 @@ CompilerVariable* _ValuedCompilerType<V>::contains(IREmitter& emitter, const OpI
} }
template <typename V> template <typename V>
ConcreteCompilerVariable* _ValuedCompilerType<V>::unaryop(IREmitter& emitter, const OpInfo& info, VAR* var, CompilerVariable* _ValuedCompilerType<V>::unaryop(IREmitter& emitter, const OpInfo& info, VAR* var,
AST_TYPE::AST_TYPE op_type) { AST_TYPE::AST_TYPE op_type) {
ConcreteCompilerVariable* converted = makeConverted(emitter, var, getBoxType()); ConcreteCompilerVariable* converted = makeConverted(emitter, var, getBoxType());
auto r = UNKNOWN->unaryop(emitter, info, converted, op_type); auto r = UNKNOWN->unaryop(emitter, info, converted, op_type);
converted->decvref(emitter); converted->decvref(emitter);
......
...@@ -799,7 +799,7 @@ private: ...@@ -799,7 +799,7 @@ private:
assert(node->args.size() == 1); assert(node->args.size() == 1);
CompilerVariable* obj = evalExpr(node->args[0], unw_info); CompilerVariable* obj = evalExpr(node->args[0], unw_info);
ConcreteCompilerVariable* rtn = obj->nonzero(emitter, getOpInfoForNode(node, unw_info)); CompilerVariable* rtn = obj->nonzero(emitter, getOpInfoForNode(node, unw_info));
obj->decvref(emitter); obj->decvref(emitter);
return rtn; return rtn;
} }
...@@ -807,7 +807,7 @@ private: ...@@ -807,7 +807,7 @@ private:
assert(node->args.size() == 1); assert(node->args.size() == 1);
CompilerVariable* obj = evalExpr(node->args[0], unw_info); CompilerVariable* obj = evalExpr(node->args[0], unw_info);
ConcreteCompilerVariable* rtn = obj->hasnext(emitter, getOpInfoForNode(node, unw_info)); CompilerVariable* rtn = obj->hasnext(emitter, getOpInfoForNode(node, unw_info));
obj->decvref(emitter); obj->decvref(emitter);
return rtn; return rtn;
} }
...@@ -1348,18 +1348,18 @@ private: ...@@ -1348,18 +1348,18 @@ private:
CompilerVariable* operand = evalExpr(node->operand, unw_info); CompilerVariable* operand = evalExpr(node->operand, unw_info);
if (node->op_type == AST_TYPE::Not) { if (node->op_type == AST_TYPE::Not) {
ConcreteCompilerVariable* rtn = operand->nonzero(emitter, getOpInfoForNode(node, unw_info)); CompilerVariable* rtn = operand->nonzero(emitter, getOpInfoForNode(node, unw_info));
operand->decvref(emitter); operand->decvref(emitter);
assert(rtn->getType() == BOOL); assert(rtn->getType() == BOOL);
llvm::Value* v = i1FromBool(emitter, rtn); llvm::Value* v = i1FromBool(emitter, static_cast<ConcreteCompilerVariable*>(rtn));
assert(v->getType() == g.i1); assert(v->getType() == g.i1);
llvm::Value* negated = emitter.getBuilder()->CreateNot(v); llvm::Value* negated = emitter.getBuilder()->CreateNot(v);
rtn->decvref(emitter); rtn->decvref(emitter);
return boolFromI1(emitter, negated); return boolFromI1(emitter, negated);
} else { } else {
ConcreteCompilerVariable* rtn = operand->unaryop(emitter, getOpInfoForNode(node, unw_info), node->op_type); CompilerVariable* rtn = operand->unaryop(emitter, getOpInfoForNode(node, unw_info), node->op_type);
operand->decvref(emitter); operand->decvref(emitter);
return rtn; return rtn;
} }
...@@ -1517,13 +1517,11 @@ private: ...@@ -1517,13 +1517,11 @@ private:
} }
// Note: the behavior of this function must match type_analysis.cpp:unboxedType() // Note: the behavior of this function must match type_analysis.cpp:unboxedType()
ConcreteCompilerVariable* unboxVar(ConcreteCompilerType* t, llvm::Value* v, bool grabbed) { CompilerVariable* unboxVar(ConcreteCompilerType* t, llvm::Value* v, bool grabbed) {
#if ENABLE_UNBOXED_VALUES
if (t == BOXED_INT) { if (t == BOXED_INT) {
llvm::Value* unboxed = emitter.getBuilder()->CreateCall(g.funcs.unboxInt, v); return makeUnboxedInt(emitter, v);
ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(INT, unboxed, true);
return rtn;
} }
#if ENABLE_UNBOXED_VALUES
if (t == BOXED_FLOAT) { if (t == BOXED_FLOAT) {
llvm::Value* unboxed = emitter.getBuilder()->CreateCall(g.funcs.unboxFloat, v); llvm::Value* unboxed = emitter.getBuilder()->CreateCall(g.funcs.unboxFloat, v);
ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(FLOAT, unboxed, true); ConcreteCompilerVariable* rtn = new ConcreteCompilerVariable(FLOAT, unboxed, true);
...@@ -1548,7 +1546,7 @@ private: ...@@ -1548,7 +1546,7 @@ private:
ConcreteCompilerType* speculated_type = typeFromClass(speculated_class); ConcreteCompilerType* speculated_type = typeFromClass(speculated_class);
if (VERBOSITY("irgen") >= 2) { if (VERBOSITY("irgen") >= 2) {
printf("Speculating that %s is actually %s, at ", rtn->getConcreteType()->debugName().c_str(), printf("Speculating that %s is actually %s, at ", rtn->getType()->debugName().c_str(),
speculated_type->debugName().c_str()); speculated_type->debugName().c_str());
fflush(stdout); fflush(stdout);
print_ast(node); print_ast(node);
...@@ -1580,6 +1578,7 @@ private: ...@@ -1580,6 +1578,7 @@ private:
} }
assert(rtn); assert(rtn);
assert(rtn->getType()->isUsable());
return rtn; return rtn;
} }
...@@ -1728,6 +1727,7 @@ private: ...@@ -1728,6 +1727,7 @@ private:
void _doSet(InternedString name, CompilerVariable* val, const UnwindInfo& unw_info) { void _doSet(InternedString name, CompilerVariable* val, const UnwindInfo& unw_info) {
assert(name.s() != "None"); assert(name.s() != "None");
assert(name.s() != FRAME_INFO_PTR_NAME); assert(name.s() != FRAME_INFO_PTR_NAME);
assert(val->getType()->isUsable());
auto scope_info = irstate->getScopeInfo(); auto scope_info = irstate->getScopeInfo();
ScopeInfo::VarScopeType vst = scope_info->getScopeTypeOfName(name); ScopeInfo::VarScopeType vst = scope_info->getScopeTypeOfName(name);
...@@ -2210,8 +2210,8 @@ private: ...@@ -2210,8 +2210,8 @@ private:
ConcreteCompilerVariable* var = p.second->makeConverted(emitter, p.second->getConcreteType()); ConcreteCompilerVariable* var = p.second->makeConverted(emitter, p.second->getConcreteType());
converted_args.push_back(var); converted_args.push_back(var);
assert(var->getType() != BOXED_INT);
#if ENABLE_UNBOXED_VALUES #if ENABLE_UNBOXED_VALUES
assert(var->getType() != BOXED_INT && "should probably unbox it, but why is it boxed in the first place?");
assert(var->getType() != BOXED_FLOAT assert(var->getType() != BOXED_FLOAT
&& "should probably unbox it, but why is it boxed in the first place?"); && "should probably unbox it, but why is it boxed in the first place?");
#endif #endif
...@@ -2438,13 +2438,13 @@ private: ...@@ -2438,13 +2438,13 @@ private:
void loadArgument(InternedString name, ConcreteCompilerType* t, llvm::Value* v, const UnwindInfo& unw_info) { void loadArgument(InternedString name, ConcreteCompilerType* t, llvm::Value* v, const UnwindInfo& unw_info) {
assert(name.s() != FRAME_INFO_PTR_NAME); assert(name.s() != FRAME_INFO_PTR_NAME);
ConcreteCompilerVariable* var = unboxVar(t, v, false); CompilerVariable* var = unboxVar(t, v, false);
_doSet(name, var, unw_info); _doSet(name, var, unw_info);
var->decvref(emitter); var->decvref(emitter);
} }
void loadArgument(AST_expr* name, ConcreteCompilerType* t, llvm::Value* v, const UnwindInfo& unw_info) { void loadArgument(AST_expr* name, ConcreteCompilerType* t, llvm::Value* v, const UnwindInfo& unw_info) {
ConcreteCompilerVariable* var = unboxVar(t, v, false); CompilerVariable* var = unboxVar(t, v, false);
_doSet(name, var, unw_info); _doSet(name, var, unw_info);
var->decvref(emitter); var->decvref(emitter);
} }
...@@ -2467,6 +2467,7 @@ private: ...@@ -2467,6 +2467,7 @@ private:
std::map<InternedString, CompilerVariable*> sorted_symbol_table(symbol_table.begin(), symbol_table.end()); std::map<InternedString, CompilerVariable*> sorted_symbol_table(symbol_table.begin(), symbol_table.end());
for (const auto& p : sorted_symbol_table) { for (const auto& p : sorted_symbol_table) {
assert(p.first.s() != FRAME_INFO_PTR_NAME); assert(p.first.s() != FRAME_INFO_PTR_NAME);
assert(p.second->getType()->isUsable());
if (allowableFakeEndingSymbol(p.first)) if (allowableFakeEndingSymbol(p.first))
continue; continue;
...@@ -2483,6 +2484,7 @@ private: ...@@ -2483,6 +2484,7 @@ private:
} else if (irstate->getPhis()->isRequiredAfter(p.first, myblock)) { } else if (irstate->getPhis()->isRequiredAfter(p.first, myblock)) {
assert(scope_info->getScopeTypeOfName(p.first) != ScopeInfo::VarScopeType::GLOBAL); assert(scope_info->getScopeTypeOfName(p.first) != ScopeInfo::VarScopeType::GLOBAL);
ConcreteCompilerType* phi_type = types->getTypeAtBlockEnd(p.first, myblock); ConcreteCompilerType* phi_type = types->getTypeAtBlockEnd(p.first, myblock);
assert(phi_type->isUsable());
// printf("Converting %s from %s to %s\n", p.first.c_str(), // printf("Converting %s from %s to %s\n", p.first.c_str(),
// p.second->getType()->debugName().c_str(), phi_type->debugName().c_str()); // p.second->getType()->debugName().c_str(), phi_type->debugName().c_str());
// printf("have to convert %s from %s to %s\n", p.first.c_str(), // printf("have to convert %s from %s to %s\n", p.first.c_str(),
...@@ -2533,6 +2535,7 @@ private: ...@@ -2533,6 +2535,7 @@ private:
} else { } else {
// printf("no st entry, setting undefined\n"); // printf("no st entry, setting undefined\n");
ConcreteCompilerType* phi_type = types->getTypeAtBlockEnd(*it, myblock); ConcreteCompilerType* phi_type = types->getTypeAtBlockEnd(*it, myblock);
assert(phi_type->isUsable());
cur = new ConcreteCompilerVariable(phi_type, llvm::UndefValue::get(phi_type->llvmType()), true); cur = new ConcreteCompilerVariable(phi_type, llvm::UndefValue::get(phi_type->llvmType()), true);
_setFake(defined_name, makeBool(0)); _setFake(defined_name, makeBool(0));
} }
...@@ -2553,7 +2556,7 @@ public: ...@@ -2553,7 +2556,7 @@ public:
pp->addFrameVar(PASSED_GLOBALS_NAME, UNKNOWN); pp->addFrameVar(PASSED_GLOBALS_NAME, UNKNOWN);
} }
assert(INT->llvmType() == g.i64); assert(UNBOXED_INT->llvmType() == g.i64);
if (ENABLE_JIT_OBJECT_CACHE) { if (ENABLE_JIT_OBJECT_CACHE) {
llvm::Value* v; llvm::Value* v;
if (current_stmt) if (current_stmt)
...@@ -2565,7 +2568,7 @@ public: ...@@ -2565,7 +2568,7 @@ public:
stackmap_args.push_back(getConstantInt((uint64_t)current_stmt, g.i64)); stackmap_args.push_back(getConstantInt((uint64_t)current_stmt, g.i64));
} }
pp->addFrameVar("!current_stmt", INT); pp->addFrameVar("!current_stmt", UNBOXED_INT);
if (ENABLE_FRAME_INTROSPECTION) { if (ENABLE_FRAME_INTROSPECTION) {
// TODO: don't need to use a sorted symbol table if we're explicitly recording the names! // TODO: don't need to use a sorted symbol table if we're explicitly recording the names!
...@@ -2600,6 +2603,10 @@ public: ...@@ -2600,6 +2603,10 @@ public:
// This should have been consumed: // This should have been consumed:
assert(incoming_exc_state.empty()); assert(incoming_exc_state.empty());
for (auto&& p : symbol_table) {
ASSERT(p.second->getType()->isUsable(), "%s", p.first.c_str());
}
if (myblock->successors.size() == 0) { if (myblock->successors.size() == 0) {
for (auto& p : *st) { for (auto& p : *st) {
p.second->decvref(emitter); p.second->decvref(emitter);
...@@ -2645,6 +2652,7 @@ public: ...@@ -2645,6 +2652,7 @@ public:
} else { } else {
ending_type = types->getTypeAtBlockEnd(it->first, myblock); ending_type = types->getTypeAtBlockEnd(it->first, myblock);
} }
assert(ending_type->isUsable());
//(*phi_st)[it->first] = it->second->makeConverted(emitter, it->second->getConcreteType()); //(*phi_st)[it->first] = it->second->makeConverted(emitter, it->second->getConcreteType());
// printf("%s %p %d\n", it->first.c_str(), it->second, it->second->getVrefs()); // printf("%s %p %d\n", it->first.c_str(), it->second, it->second->getVrefs());
(*phi_st)[it->first] = it->second->split(emitter)->makeConverted(emitter, ending_type); (*phi_st)[it->first] = it->second->split(emitter)->makeConverted(emitter, ending_type);
...@@ -2661,8 +2669,10 @@ public: ...@@ -2661,8 +2669,10 @@ public:
assert(name.s() != FRAME_INFO_PTR_NAME); assert(name.s() != FRAME_INFO_PTR_NAME);
ASSERT(irstate->getScopeInfo()->getScopeTypeOfName(name) != ScopeInfo::VarScopeType::GLOBAL, "%s", ASSERT(irstate->getScopeInfo()->getScopeTypeOfName(name) != ScopeInfo::VarScopeType::GLOBAL, "%s",
name.c_str()); name.c_str());
ASSERT(var->getType()->isUsable(), "%s", name.c_str());
#if ENABLE_UNBOXED_VALUES #if ENABLE_UNBOXED_VALUES
assert(var->getType() != BOXED_INT);
assert(var->getType() != BOXED_FLOAT); assert(var->getType() != BOXED_FLOAT);
#endif #endif
CompilerVariable*& cur = symbol_table[name]; CompilerVariable*& cur = symbol_table[name];
...@@ -2675,7 +2685,9 @@ public: ...@@ -2675,7 +2685,9 @@ public:
DupCache cache; DupCache cache;
for (SymbolTable::iterator it = st->begin(); it != st->end(); ++it) { for (SymbolTable::iterator it = st->begin(); it != st->end(); ++it) {
// printf("Copying in %s: %p, %d\n", it->first.c_str(), it->second, it->second->getVrefs()); // printf("Copying in %s: %p, %d\n", it->first.c_str(), it->second, it->second->getVrefs());
// printf("Copying in %s, a %s\n", it->first.c_str(), it->second->getType()->debugName().c_str());
symbol_table[it->first] = it->second->dup(cache); symbol_table[it->first] = it->second->dup(cache);
assert(symbol_table[it->first]->getType()->isUsable());
// printf("got: %p, %d\n", symbol_table[it->first], symbol_table[it->first]->getVrefs()); // printf("got: %p, %d\n", symbol_table[it->first], symbol_table[it->first]->getVrefs());
} }
} }
......
...@@ -93,10 +93,10 @@ template <class V> class ValuedCompilerType; ...@@ -93,10 +93,10 @@ template <class V> class ValuedCompilerType;
typedef ValuedCompilerType<llvm::Value*> ConcreteCompilerType; typedef ValuedCompilerType<llvm::Value*> ConcreteCompilerType;
ConcreteCompilerType* typeFromClass(BoxedClass*); ConcreteCompilerType* typeFromClass(BoxedClass*);
extern ConcreteCompilerType* INT, *BOXED_INT, *LONG, *FLOAT, *BOXED_FLOAT, *UNKNOWN, *BOOL, *STR, *NONE, *LIST, *SLICE,*ELLIPSIS, extern ConcreteCompilerType* UNBOXED_INT, *BOXED_INT, *LONG, *FLOAT, *BOXED_FLOAT, *UNKNOWN, *BOOL, *STR, *NONE, *LIST,
*MODULE, *DICT, *BOOL, *BOXED_BOOL, *BOXED_TUPLE, *SET, *FROZENSET, *CLOSURE, *GENERATOR, *BOXED_COMPLEX, *SLICE, *ELLIPSIS, *MODULE, *DICT, *BOOL, *BOXED_BOOL, *BOXED_TUPLE, *SET, *FROZENSET, *CLOSURE, *GENERATOR,
*FRAME_INFO; *BOXED_COMPLEX, *FRAME_INFO;
extern CompilerType* UNDEF; extern CompilerType* UNDEF, *INT;
class CompilerVariable; class CompilerVariable;
template <class V> class ValuedCompilerVariable; template <class V> class ValuedCompilerVariable;
......
...@@ -270,7 +270,7 @@ void setupXrange() { ...@@ -270,7 +270,7 @@ void setupXrange() {
"__iter__", new BoxedFunction(boxRTFunction((void*)xrangeIterIter, typeFromClass(xrange_iterator_cls), 1))); "__iter__", new BoxedFunction(boxRTFunction((void*)xrangeIterIter, typeFromClass(xrange_iterator_cls), 1)));
xrange_iterator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext)); xrange_iterator_cls->giveAttr("__hasnext__", new BoxedFunction(hasnext));
CLFunction* next = boxRTFunction((void*)BoxedXrangeIterator::xrangeIteratorNextUnboxed, INT, 1); CLFunction* next = boxRTFunction((void*)BoxedXrangeIterator::xrangeIteratorNextUnboxed, UNBOXED_INT, 1);
addRTFunction(next, (void*)BoxedXrangeIterator::xrangeIteratorNext, BOXED_INT); addRTFunction(next, (void*)BoxedXrangeIterator::xrangeIteratorNext, BOXED_INT);
xrange_iterator_cls->giveAttr("next", new BoxedFunction(next)); xrange_iterator_cls->giveAttr("next", new BoxedFunction(next));
......
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