Skip to content

Commit b519088

Browse files
committed
Don't constant-fold something producing a Seq.
Otherwise, if the value is used twice, we'll end up exhuasting it the first time and it will explode every time afterwards. (We maybe want to look at whether some things are bogusly marked PURE, but this will fix all such problems and I can't think of a situation where you'd ever want this misbehavior.)
1 parent dfc53aa commit b519088

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Perl6/Optimizer.nqp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ my class Symbols {
3333
has $!Routine;
3434
has $!Nil;
3535
has $!Failure;
36+
has $!Seq;
3637

3738
# Top routine, for faking it when optimizing post-inline.
3839
has $!fake_top_routine;
@@ -59,6 +60,7 @@ my class Symbols {
5960
$!Routine := self.find_lexical('Routine');
6061
$!Nil := self.find_lexical('Nil');
6162
$!Failure := self.find_lexical('Failure');
63+
$!Seq := self.find_lexical('Seq');
6264
nqp::pop(@!block_stack);
6365
}
6466

@@ -100,6 +102,7 @@ my class Symbols {
100102
method PseudoStash() { $!PseudoStash }
101103
method Nil() { $!Nil }
102104
method Failure() { $!Failure }
105+
method Seq() { $!Seq }
103106

104107
# The following function is a nearly 1:1 copy of World.find_symbol.
105108
# Finds a symbol that has a known value at compile time from the
@@ -1420,7 +1423,7 @@ class Perl6::Optimizer {
14201423
$survived := 0;
14211424
}
14221425
}
1423-
if $survived && !nqp::istype($ret_value, $!symbols.Failure) {
1426+
if $survived && self.constant_foldable_type($ret_value) {
14241427
return $NULL if $!void_context && !$!in_declaration;
14251428
$*W.add_object($ret_value);
14261429
my $wval := QAST::WVal.new(:value($ret_value));
@@ -1552,6 +1555,13 @@ class Perl6::Optimizer {
15521555
return NQPMu;
15531556
}
15541557

1558+
method constant_foldable_type($value) {
1559+
!(
1560+
nqp::istype($value, $!symbols.Seq) ||
1561+
nqp::istype($value, $!symbols.Failure)
1562+
)
1563+
}
1564+
15551565
my @native_assign_ops := ['', 'assign_i', 'assign_n', 'assign_s'];
15561566
method optimize_nameless_call($op) {
15571567
if +@($op) > 0 {

0 commit comments

Comments
 (0)