Commit 1782dd56 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #901 from kmod/speculation_fix

Type system fix: need to add unpacking to the type system
parents 9a3a43c3 80f4bc34
......@@ -177,8 +177,10 @@ private:
break;
case AST_TYPE::Tuple: {
AST_Tuple* tt = ast_cast<AST_Tuple>(target);
auto val_types = t->unpackTypes(tt->elts.size());
assert(val_types.size() == tt->elts.size());
for (int i = 0; i < tt->elts.size(); i++) {
_doSet(tt->elts[i], UNKNOWN);
_doSet(tt->elts[i], val_types[i]);
}
break;
}
......
......@@ -57,6 +57,12 @@ CompilerType::Result CompilerType::hasattr(BoxedString* attr) {
return Result::Yes;
}
std::vector<CompilerType*> CompilerType::unpackTypes(int num_into) {
assert((CompilerType*)this != UNKNOWN);
return UNKNOWN->unpackTypes(num_into);
}
void ConcreteCompilerType::serializeToFrame(VAR* var, std::vector<llvm::Value*>& stackmap_args) {
#ifndef NDEBUG
if (llvmType() == g.i1) {
......@@ -490,6 +496,10 @@ public:
}
return rtn;
}
std::vector<CompilerType*> unpackTypes(int num_into) override {
return std::vector<CompilerType*>(num_into, UNKNOWN);
}
};
ConcreteCompilerType* UNKNOWN = new UnknownType();
......@@ -2506,6 +2516,14 @@ public:
return *var->getValue();
}
std::vector<CompilerType*> unpackTypes(int num_into) override {
if (num_into != elt_types.size()) {
return ValuedCompilerType::unpackTypes(num_into);
}
return elt_types;
}
};
CompilerType* makeTupleType(const std::vector<CompilerType*>& elt_types) {
......
......@@ -57,6 +57,7 @@ public:
virtual BoxedClass* guaranteedClass() = 0;
virtual Box* deserializeFromFrame(const FrameVals& vals) = 0;
virtual int numFrameArgs() = 0;
virtual std::vector<CompilerType*> unpackTypes(int num_into);
};
typedef std::unordered_map<CompilerVariable*, CompilerVariable*> DupCache;
......
......@@ -2823,7 +2823,7 @@ Box* callattrInternal(Box* obj, BoxedString* attr, LookupScope scope, CallRewrit
r_val = grewrite_args.out_rtn;
}
} else {
val = getattrInternalEx<CXX>(obj, attr, NULL, scope == CLASS_ONLY, true, &bind_obj, &r_bind_obj);
val = getattrInternalEx<S>(obj, attr, NULL, scope == CLASS_ONLY, true, &bind_obj, &r_bind_obj);
}
if (val == NULL) {
......
# Make sure that callattrs handle exceptions (including
# different exception styles) correctly.
class C(object):
def __getattr__(self, attr):
raise ValueError()
def f():
c = C()
for i in xrange(10000):
try:
c.foo()
except ValueError:
pass
f()
# Regression test: make sure that irgen and type analysis
# both handle tuple -packing and -unpcaking.
def get_str():
return "Hello world"
def f():
_, a = 1, get_str()
a.lower()
for i in xrange(100000):
f()
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