Project

General

Profile

Actions

Bug #20571

closed

Compile error on for loop

Added by kddnewton (Kevin Newton) 5 months ago. Updated 2 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:118270]

Description

for _ in 1.5 or _ in []
end

raises a compile error for the current compiler only with

-- raw disasm--------
   trace: 1
 <L000> [sp: 0, unremovable: 1, refcnt: 1]
   0000 putobject            1.5                                         (   1)
   0002 jump                 <L002>                                      (   1)
 <L006> [sp: 1, unremovable: 1, refcnt: 1]
 <L004> [sp: 1, unremovable: 0, refcnt: 0]
   0004 pop                                                              (   1)
*  0005 pop                                                              (   1)
   0006 putobject            false                                       (   1)
 <L002> [sp: 1, unremovable: 0, refcnt: 1]
   0008 send                 <calldata:each, 0>, nil                     (   1)
 <L001> [sp: -1, unremovable: 0, refcnt: 2]
   0011 leave                                                            (   1)
---------------------
test.rb:1: argument stack underflow (-1)
test.rb: compile error (SyntaxError)

Related issues 1 (0 open1 closed)

Has duplicate Ruby master - Bug #20651: `false && (1 in 1)` produces argument stack underflow (-1)ClosedActions

Updated by jeremyevans0 (Jeremy Evans) 3 months ago

I looked into this and was able to determine the underlying cause (currently on line 7844 of compile.c):

ADD_INSN(cond_seq, line_node, pop); /* discard cached #deconstruct value */ 

Commenting that out fixes the example, though it causes overflow elsewhere. Most likely the pop instruction needs to be conditional, or we are missing a dup instruction somewhere.

Updated by jeremyevans0 (Jeremy Evans) 3 months ago

After some additional work, I think this is an optimizer issue. With --dump=i,-opt, both parse.y and prism generate the exact same instructions. However, with --dump=i, prism does not raise an error, but parse.y does. I'm not sure why the two would use different optimizers.

Actions #3

Updated by mame (Yusuke Endoh) 3 months ago

  • Has duplicate Bug #20651: `false && (1 in 1)` produces argument stack underflow (-1) added
Actions #4

Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Open to Closed
  • Backport changed from 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) 3 months ago

  • Backport changed from 3.1: REQUIRED, 3.2: REQUIRED, 3.3: REQUIRED to 3.1: REQUIRED, 3.2: DONE, 3.3: REQUIRED

Updated by k0kubun (Takashi Kokubun) 2 months ago

  • Backport changed from 3.1: REQUIRED, 3.2: DONE, 3.3: REQUIRED to 3.1: REQUIRED, 3.2: DONE, 3.3: DONE
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0