Skip to content

Instantly share code, notes, and snippets.

@bdw
Created September 26, 2015 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bdw/992dfd5b69b7d42f2239 to your computer and use it in GitHub Desktop.
Save bdw/992dfd5b69b7d42f2239 to your computer and use it in GitHub Desktop.
dynvar bug
# without JIT
# very many of these
F $*IN_RETURN 14 10 4 11
C $*IN_RETURN 1 0 0 1
# then after inlining
I $*IN_RETURN 14 16 2 12
C $*IN_RETURN 1 0 0 1
# with JIT
F $*IN_RETURN 14 10 4 11
C $*IN_RETURN 1 0 0 1
# then a few of:
I $*IN_RETURN 14 16 2 12
C $*IN_RETURN 1 0 0 1
# and finally
F $*IN_RETURN 16 21 2 15
C $*IN_RETURN 1 1 0 1
# notably, that is two frames higher up!
use v6;
class C::C { };
# this causes a mislookup in the compiler,
# which in turn causes a miscompile,
# which in turn causes a crash,
# which is what we notice
EVAL 'sub foo() { return C::C.new(a => 1, b => 2) }; foo()' for ^500
# this code is inlined/notinlined and has a dynvar ref
# but for some reason it doesn't reproduce the bug
# probably because the getdynlex seems to be speshed out
my $bar := 1;
my sub not-inlined() {
$bar * $*FOO;
}
my sub inlined-assign-dynvar() {
my $*FOO := 2;
not-inlined() + not-inlined();
}
my sub toplevel-inliner() {
my $*FOO := 0;
my $sum := inlined-assign-dynvar() + not-inlined();
nqp::die("oh no") if $sum != 4;
}
my $i := 0;
while $i < 500 {
$i := $i + 1;
toplevel-inliner();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment