Commit 5aafab07 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix usage of undef variables

I think I had gotten confused and mixed up "undefined variables" (Python
variables which hadn't gotten set) and "undefined values" (results of
expressions that the JIT knows will throw, or otherwise can't evaluate).

For undefined *variables*, we represent them using None, since they can
still have refcount operations done on them.

For undefined *values* (or results), we can use llvm's undefValues, since
they should never be touched.
parent 1da14a3c
......@@ -2782,10 +2782,6 @@ public:
return rtn;
}
ConcreteCompilerVariable* makeConverted(IREmitter& emitter, VAR* var, ConcreteCompilerType* other_type) override {
if (other_type == other_type->getBoxType()) {
assert(other_type == UNKNOWN);
return emitter.getNone()->makeConverted(emitter, other_type);
}
llvm::Value* v = llvm::UndefValue::get(other_type->llvmType());
return new ConcreteCompilerVariable(other_type, v);
}
......
......@@ -922,7 +922,7 @@ private:
// trigger an exception, but the irgenerator will know that definitely-defined
// local symbols will not throw.
emitter.getBuilder()->CreateUnreachable();
exc_type = exc_value = exc_tb = emitter.getNone();
exc_type = exc_value = exc_tb = undefVariable();
// endBlock(DEAD);
}
......
......@@ -76,6 +76,9 @@ bool RefcountTracker::isNullable(llvm::Value* v) {
}
void RefcountTracker::refConsumed(llvm::Value* v, llvm::Instruction* inst) {
if (llvm::isa<UndefValue>(v))
return;
assert(this->vars[v].reftype != RefType::UNKNOWN);
this->refs_consumed[inst].push_back(v);
......@@ -632,6 +635,9 @@ void RefcountTracker::addRefcounts(IRGenState* irstate) {
if (rt->vars.count(v))
return;
if (llvm::isa<UndefValue>(v))
return;
auto t = v->getType();
auto p = llvm::dyn_cast<llvm::PointerType>(t);
if (!p) {
......
# Regression test: promoting an UNDEF to a known type
def f():
match = None # This could be a function that usually returns None but sometimes returns a string
if 0:
s = match.foo() or ""
print s
for i in xrange(10000):
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