Commit 649a9808 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Small fix to let random.Random work

Use call_done_guarding to defer the call to setDoneGuarding
until later.  As messy as it is, I guess this was the point of
the more_guards_after passing tha we had.

We'll have some issues with typeCall if the __init__ func wants
to set some guards too, since those will happen after __new__
was already called (too late for guards); we'd have to figure
out how to get __init__ to do all of its guards before calling
__new__.  (This applies even if we try to do it in multiple passes,
since we wouldn't have a "all guards before any mutations" flow.)
parent 2dc8229e
......@@ -2225,9 +2225,9 @@ Box* callFunc(BoxedFunction* func, CallRewriteArgs* rewrite_args, ArgPassSpec ar
} else {
rewrite_args->obj.setDoneUsing();
}
assert(rewrite_args->call_done_guarding);
if (!rewrite_args->rewriter->isDoneGuarding())
if (rewrite_args->call_done_guarding)
rewrite_args->rewriter->setDoneGuarding();
assert(rewrite_args->rewriter->isDoneGuarding());
// if (guard_clfunc) {
// Have to save the defaults array since the object itself will probably get overwritten:
// rewrite_args->obj = rewrite_args->obj.move(-2);
......@@ -3443,7 +3443,6 @@ Box* typeCallInternal(BoxedFunction* f, CallRewriteArgs* rewrite_args, ArgPassSp
r_init = std::move(grewrite_args.out_rtn);
r_init.addGuard((intptr_t)init_attr);
}
rewrite_args->rewriter->setDoneGuarding();
}
} else {
init_attr = typeLookup(cls, _init_str, NULL);
......@@ -3483,6 +3482,7 @@ Box* typeCallInternal(BoxedFunction* f, CallRewriteArgs* rewrite_args, ArgPassSp
if (!srewrite_args.out_success) {
rewrite_args = NULL;
} else {
assert(rewrite_args->rewriter->isDoneGuarding());
r_made = std::move(srewrite_args.out_rtn);
}
} else {
......@@ -3502,8 +3502,7 @@ Box* typeCallInternal(BoxedFunction* f, CallRewriteArgs* rewrite_args, ArgPassSp
if (init_attr && init_attr != typeLookup(object_cls, _init_str, NULL)) {
Box* initrtn;
if (rewrite_args) {
CallRewriteArgs srewrite_args(rewrite_args->rewriter, std::move(r_init), rewrite_args->destination,
rewrite_args->call_done_guarding);
CallRewriteArgs srewrite_args(rewrite_args->rewriter, std::move(r_init), rewrite_args->destination, false);
if (npassed_args >= 1)
srewrite_args.arg1 = r_made.addUse();
if (npassed_args >= 2)
......
......@@ -7,3 +7,11 @@ r.jumpahead(100)
print r.getrandbits(100)
r.setstate(s)
print r.getrandbits(100)
class Random(_random.Random):
def __init__(self, a=None):
super(Random, self).seed(a)
for i in xrange(100):
r = Random(i)
print r.getrandbits(100)
# skip-if: IMAGE != 'pyston_dbg'
# fail-if: '-n' in EXTRA_JIT_ARGS or '-O' in EXTRA_JIT_ARGS
# - failing to rewrite
import _random
class Random(_random.Random):
def __init__(self, a=None):
super(Random, self).seed(a)
for i in xrange(100):
r = Random(i)
print r.getrandbits(100)
# allow-warning: converting unicode literal to str
# skip-if: IMAGE != 'pyston_dbg'
# fail-if: '-n' in EXTRA_JIT_ARGS or '-O' in EXTRA_JIT_ARGS
# - failing to rewrite
import random
......
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