Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Query collect and group by clauses crashes for BIR optimizer changes #40943

Closed
HindujaB opened this issue Jul 6, 2023 · 1 comment · Fixed by #40579
Closed

[Bug]: Query collect and group by clauses crashes for BIR optimizer changes #40943

HindujaB opened this issue Jul 6, 2023 · 1 comment · Fixed by #40579
Assignees
Labels
needTriage The issue has to be inspected and labeled manually Reason/MultipleComponentInteraction Issue occured due to interactions in multiple components. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug userCategory/Compilation

Comments

@HindujaB
Copy link
Contributor

HindujaB commented Jul 6, 2023

Description

When we change the BIR optimizing order and execute the query expressions, it crashes at code generation.
Ideally, the compilation and code generation should not depend on the BIR optimization phase.

Steps to Reproduce

Move the LargeMethodOptimizer to execute first in the BIR optimizing phase and execute the following code with the newly built pack.

public function main() {
function testMultipleGroupByInSameQuery() {
    var input = [{name: "Saman", price1: 11, price2: 11},
                    {name: "Saman", price1: 15, price2: 12},
                    {name: "Kamal", price1: 10, price2: 13},
                    {name: "Kamal", price1: 9, price2: 12},
                    {name: "Kamal", price1: 13, price2: 9},
                    {name: "Amal", price1: 30, price2: 13}];
    var x1 = from var {name, price1} in input
                collect int:sum(price1);

    var input1 = [{name: "Saman", price1: 11, price2: 11},
                    {name: "Saman", price1: 11, price2: 12},
                    {name: "Kamal", price1: 10, price2: 13},
                    {name: "Kamal", price1: 10, price2: 12},
                    {name: "Kamal", price1: 10, price2: 9},
                    {name: "Amal", price1: 11, price2: 13},
                    {name: "Amal", price1: 11, price2: 15}];
    
    var x2 = from var {name, price1, price2} in input1
                group by name
                group by var p1 = [price1]
                select string:'join("_", name);
}

The above code crashes with following

Inconsistent stackmap frames at branch target 1132
Exception Details:
  Location:
    collect_clause.$split$method$_1(Lio/ballerina/runtime/internal/scheduling/Strand;Lio/ballerina/runtime/internal/values/TypedescValue;)Lio/ballerina/runtime/internal/values/ArrayValue; @1132: aload_0
  Reason:
    Type top (current frame, locals[3]) is not assignable to null (stack map, locals[3])
  Current Frame:
    bci: @67
    flags: { }
    locals: { 'io/ballerina/runtime/internal/scheduling/Strand', long, long_2nd, top, null, null, null, null, null, long, long_2nd, null, long, long_2nd, null, null, null, null, null, null, integer, integer, null, null, integer }
    stack: { integer }
  Stackmap Frame:
    bci: @1132
    flags: { }
    locals: { 'io/ballerina/runtime/internal/scheduling/Strand', long, long_2nd, null, null, null, null, null, long, long_2nd, null, long, long_2nd, null, null, null, null, null, null, integer, integer, null, null, integer }
    stack: { }
  Bytecode:
    0000000: b835 484d 0940 013a 0401 3a05 013a 0601
    0000010: 3a07 013a 0809 3709 013a 0b09 370c 013a
    0000020: 0e01 3a0f 013a 1001 3a11 013a 1201 3a13
    0000030: 0336 1404 3615 013a 1601 3a17 0336 182a
    0000040: b400 119d 0429 2a59 b400 145a 0460 b500
    0000050: 1436 182c 1127 fa04 542a b400 189a 000c
    0000060: 2c11 27fb 0454 a700 0db8 001e 2c11 27fc
    0000070: 0454 bf15 1599 04c0 0336 1515 14ab 0000
    0000080: 0000 0447 0000 0003 0000 0000 0000 0035
    0000090: 0000 0001 0000 0023 0000 0002 0000 002c
    00000a0: 2c11 27fd 0454 a703 aa2c 1127 fe04 54a7
    00000b0: 03af 1100 0036 1414 01dc 402c 1127 ff04
    00000c0: 54bb 3338 59b2 333b 1000 bd00 28b7 333c
    00000d0: 3a04 b206 b23a 06b2 06b5 3a07 b206 b83a
    00000e0: 0814 06b9 3709 b206 bd3a 0b14 06b9 370c
    00000f0: 2c11 2800 0454 1904 2a14 0040 88bd 0043
    0000100: 5914 0044 88bb 0047 5919 0619 07b7 0050
    0000110: 5359 1400 5188 bb00 4759 1908 1609 b800
    0000120: 4db7 0050 5359 1400 2c88 bb00 4759 190b
    0000130: 160c b800 4db7 0050 53b9 0058 0300 3a05
    0000140: 2c11 2801 0454 bb33 3e59 b233 4110 00bd
    0000150: 0028 b733 423a 04b2 06b2 3a06 b206 b53a
    0000160: 07b2 06b8 3a08 1406 c437 09b2 06bd 3a0b
    0000170: 1406 c637 0c2c 1128 0204 5419 042a 1400
    0000180: 4088 bd00 4359 1400 4488 bb00 4759 1906
    0000190: 1907 b700 5053 5914 0051 88bb 0047 5919
    00001a0: 0816 09b8 004d b700 5053 5914 002c 88bb
    00001b0: 0047 5919 0b16 0cb8 004d b700 5053 b900
    00001c0: 5803 003a 0e2c 1128 0304 54bb 3344 59b2
    00001d0: 3347 1000 bd00 28b7 3348 3a04 b206 b23a
    00001e0: 06b2 06d0 3a07 b206 b83a 0814 06d1 3709
    00001f0: b206 bd3a 0b14 06d3 370c 2c11 2804 0454
    0000200: 1904 2a14 0040 88bd 0043 5914 0044 88bb
    0000210: 0047 5919 0619 07b7 0050 5359 1400 5188
    0000220: bb00 4759 1908 1609 b800 4db7 0050 5359
    0000230: 1400 2c88 bb00 4759 190b 160c b800 4db7
    0000240: 0050 53b9 0058 0300 3a0f 2c11 2805 0454
    0000250: bb33 4a59 b233 4d10 00bd 0028 b733 4e3a
    0000260: 04b2 06b2 3a06 b206 d03a 07b2 06b8 3a08
    0000270: 1402 ad37 09b2 06bd 3a0b 1406 c637 0c2c
    0000280: 1128 0604 5419 042a 1400 4088 bd00 4359
    0000290: 1400 4488 bb00 4759 1906 1907 b700 5053
    00002a0: 5914 0051 88bb 0047 5919 0816 09b8 004d
    00002b0: b700 5053 5914 002c 88bb 0047 5919 0b16
    00002c0: 0cb8 004d b700 5053 b900 5803 003a 102c
    00002d0: 1128 0704 54bb 3350 59b2 3353 1000 bd00
    00002e0: 28b7 3354 3a04 b206 b23a 06b2 06d0 3a07
    00002f0: b206 b83a 0814 06d3 3709 b206 bd3a 0b14
    0000300: 02ad 370c 2c11 2808 0454 1904 2a14 0040
    0000310: 88bd 0043 5914 0044 88bb 0047 5919 0619
    0000320: 07b7 0050 5359 1400 5188 bb00 4759 1908
    0000330: 1609 b800 4db7 0050 5359 1400 2c88 bb00
    0000340: 4759 190b 160c b800 4db7 0050 53b9 0058
    0000350: 0300 3a11 2c11 2809 0454 bb33 5659 b233
    0000360: 5910 00bd 0028 b733 5a3a 04b2 06b2 3a06
    0000370: b206 e93a 07b2 06b8 3a08 1406 ea37 09b2
    0000380: 06bd 3a0b 1406 d337 0c2c 1128 0a04 5419
    0000390: 042a 1400 4088 bd00 4359 1400 4488 bb00
    00003a0: 4759 1906 1907 b700 5053 5914 0051 88bb
    00003b0: 0047 5919 0816 09b8 004d b700 5053 5914
    00003c0: 002c 88bb 0047 5919 0b16 0cb8 004d b700
    00003d0: 5053 b900 5803 003a 122c 1128 0b04 5419
    00003e0: 042a 1401 dc88 bd00 6459 1400 4488 bb00
    00003f0: 6659 1905 b700 6953 5914 0051 88bb 0066
    0000400: 5919 0eb7 0069 5359 1400 2c88 bb00 6659
    0000410: 190f b700 6953 5914 0040 88bb 0066 5919
    0000420: 10b7 0069 5359 1400 5f88 bb00 6659 1911
    0000430: b700 6953 5914 0061 88bb 0066 5919 12b7
    0000440: 0069 53b9 0058 0300 3a13 2c11 280c 0454
    0000450: 1100 0136 142c 1128 0d04 54a7 0003 1100
    0000460: 0236 1419 132c 1128 0e04 54b0 2a59 b400
    0000470: 1104 64b5 0011 2ab4 02dd b602 e3c0 335c
    0000480: 59b4 335e 3a13 59b4 335f 3a04 59b4 3360
    0000490: 3a06 59b4 3361 3a07 59b4 3362 3a08 59b4
    00004a0: 3363 3709 59b4 3364 3a0b 59b4 3365 370c
    00004b0: 59b4 3366 3614 b433 6736 182c 1128 0f04
    00004c0: 54a7 fb98 bb33 5c59 b733 6859 1913 b533
    00004d0: 5e59 1904 c000 54b5 335f 5919 06b5 3360
    00004e0: 5919 07b5 3361 5919 08b5 3362 5916 09b5
    00004f0: 3363 5919 0bb5 3364 5916 0cb5 3365 5915
    0000500: 14b5 3366 5915 18b5 3367 5919 16b5 3369
    0000510: 5919 17b5 336a 3a19 2ab4 02dd 1919 b606
    0000520: 8f57 2a59 b400 1104 60b5 0011 2c11 2810
    0000530: 0454 a7fb 4119 132c 1128 1104 54b0     
  Stackmap Table:
    full_frame(@89,{Object[#13],Long,Object[#84],Null,Object[#1695],Object[#1695],Object[#1695],Long,Object[#1695],Long,Null,Null,Null,Null,Null,Object[#107],Integer,Integer,Null,Null,Integer},{})
    same_frame(@105)
    same_frame(@115)
    same_frame(@160)
    same_frame(@169)
    same_frame(@178)
    full_frame(@1104,{Object[#13],Long,Object[#4],Object[#4],Object[#1695],Object[#1695],Object[#1695],Long,Object[#1695],Long,Object[#4],Object[#4],Object[#4],Object[#4],Object[#4],Object[#4],Integer,Integer,Null,Null,Integer},{})
    same_frame(@1118)
    full_frame(@1132,{Object[#13],Long,Null,Null,Null,Null,Null,Long,Null,Long,Null,Null,Null,Null,Null,Null,Integer,Integer,Null,Null,Integer},{})
    full_frame(@1220,{Object[#13],Long,Object[#84],Null,Object[#1695],Object[#1695],Object[#1695],Long,Object[#1695],Long,Null,Null,Null,Null,Null,Object[#107],Integer,Integer,Null,Null,Integer},{})
    same_frame_extended(@1333)

java.lang.VerifyError: Inconsistent stackmap frames at branch target 1132
Exception Details:
  Location:
    collect_clause.$split$method$_1(Lio/ballerina/runtime/internal/scheduling/Strand;Lio/ballerina/runtime/internal/values/TypedescValue;)Lio/ballerina/runtime/internal/values/ArrayValue; @1132: aload_0
  Reason:
    Type top (current frame, locals[3]) is not assignable to null (stack map, locals[3])
  Current Frame:
    bci: @67
    flags: { }
    locals: { 'io/ballerina/runtime/internal/scheduling/Strand', long, long_2nd, top, null, null, null, null, null, long, long_2nd, null, long, long_2nd, null, null, null, null, null, null, integer, integer, null, null, integer }
    stack: { integer }
  Stackmap Frame:
    bci: @1132
    flags: { }
    locals: { 'io/ballerina/runtime/internal/scheduling/Strand', long, long_2nd, null, null, null, null, null, long, long_2nd, null, long, long_2nd, null, null, null, null, null, null, integer, integer, null, null, integer }
    stack: { }
  Bytecode:
    0000000: b835 484d 0940 013a 0401 3a05 013a 0601
    0000010: 3a07 013a 0809 3709 013a 0b09 370c 013a
    0000020: 0e01 3a0f 013a 1001 3a11 013a 1201 3a13
    0000030: 0336 1404 3615 013a 1601 3a17 0336 182a
    0000040: b400 119d 0429 2a59 b400 145a 0460 b500
    0000050: 1436 182c 1127 fa04 542a b400 189a 000c
    0000060: 2c11 27fb 0454 a700 0db8 001e 2c11 27fc
    0000070: 0454 bf15 1599 04c0 0336 1515 14ab 0000
    0000080: 0000 0447 0000 0003 0000 0000 0000 0035
    0000090: 0000 0001 0000 0023 0000 0002 0000 002c
    00000a0: 2c11 27fd 0454 a703 aa2c 1127 fe04 54a7
    00000b0: 03af 1100 0036 1414 01dc 402c 1127 ff04
    00000c0: 54bb 3338 59b2 333b 1000 bd00 28b7 333c
    00000d0: 3a04 b206 b23a 06b2 06b5 3a07 b206 b83a
    00000e0: 0814 06b9 3709 b206 bd3a 0b14 06b9 370c
    00000f0: 2c11 2800 0454 1904 2a14 0040 88bd 0043
    0000100: 5914 0044 88bb 0047 5919 0619 07b7 0050
    0000110: 5359 1400 5188 bb00 4759 1908 1609 b800
    0000120: 4db7 0050 5359 1400 2c88 bb00 4759 190b
    0000130: 160c b800 4db7 0050 53b9 0058 0300 3a05
    0000140: 2c11 2801 0454 bb33 3e59 b233 4110 00bd
    0000150: 0028 b733 423a 04b2 06b2 3a06 b206 b53a
    0000160: 07b2 06b8 3a08 1406 c437 09b2 06bd 3a0b
    0000170: 1406 c637 0c2c 1128 0204 5419 042a 1400
    0000180: 4088 bd00 4359 1400 4488 bb00 4759 1906
    0000190: 1907 b700 5053 5914 0051 88bb 0047 5919
    00001a0: 0816 09b8 004d b700 5053 5914 002c 88bb
    00001b0: 0047 5919 0b16 0cb8 004d b700 5053 b900
    00001c0: 5803 003a 0e2c 1128 0304 54bb 3344 59b2
    00001d0: 3347 1000 bd00 28b7 3348 3a04 b206 b23a
    00001e0: 06b2 06d0 3a07 b206 b83a 0814 06d1 3709
    00001f0: b206 bd3a 0b14 06d3 370c 2c11 2804 0454
    0000200: 1904 2a14 0040 88bd 0043 5914 0044 88bb
    0000210: 0047 5919 0619 07b7 0050 5359 1400 5188
    0000220: bb00 4759 1908 1609 b800 4db7 0050 5359
    0000230: 1400 2c88 bb00 4759 190b 160c b800 4db7
    0000240: 0050 53b9 0058 0300 3a0f 2c11 2805 0454
    0000250: bb33 4a59 b233 4d10 00bd 0028 b733 4e3a
    0000260: 04b2 06b2 3a06 b206 d03a 07b2 06b8 3a08
    0000270: 1402 ad37 09b2 06bd 3a0b 1406 c637 0c2c
    0000280: 1128 0604 5419 042a 1400 4088 bd00 4359
    0000290: 1400 4488 bb00 4759 1906 1907 b700 5053
    00002a0: 5914 0051 88bb 0047 5919 0816 09b8 004d
    00002b0: b700 5053 5914 002c 88bb 0047 5919 0b16
    00002c0: 0cb8 004d b700 5053 b900 5803 003a 102c
    00002d0: 1128 0704 54bb 3350 59b2 3353 1000 bd00
    00002e0: 28b7 3354 3a04 b206 b23a 06b2 06d0 3a07
    00002f0: b206 b83a 0814 06d3 3709 b206 bd3a 0b14
    0000300: 02ad 370c 2c11 2808 0454 1904 2a14 0040
    0000310: 88bd 0043 5914 0044 88bb 0047 5919 0619
    0000320: 07b7 0050 5359 1400 5188 bb00 4759 1908
    0000330: 1609 b800 4db7 0050 5359 1400 2c88 bb00
    0000340: 4759 190b 160c b800 4db7 0050 53b9 0058
    0000350: 0300 3a11 2c11 2809 0454 bb33 5659 b233
    0000360: 5910 00bd 0028 b733 5a3a 04b2 06b2 3a06
    0000370: b206 e93a 07b2 06b8 3a08 1406 ea37 09b2
    0000380: 06bd 3a0b 1406 d337 0c2c 1128 0a04 5419
    0000390: 042a 1400 4088 bd00 4359 1400 4488 bb00
    00003a0: 4759 1906 1907 b700 5053 5914 0051 88bb
    00003b0: 0047 5919 0816 09b8 004d b700 5053 5914
    00003c0: 002c 88bb 0047 5919 0b16 0cb8 004d b700
    00003d0: 5053 b900 5803 003a 122c 1128 0b04 5419
    00003e0: 042a 1401 dc88 bd00 6459 1400 4488 bb00
    00003f0: 6659 1905 b700 6953 5914 0051 88bb 0066
    0000400: 5919 0eb7 0069 5359 1400 2c88 bb00 6659
    0000410: 190f b700 6953 5914 0040 88bb 0066 5919
    0000420: 10b7 0069 5359 1400 5f88 bb00 6659 1911
    0000430: b700 6953 5914 0061 88bb 0066 5919 12b7
    0000440: 0069 53b9 0058 0300 3a13 2c11 280c 0454
    0000450: 1100 0136 142c 1128 0d04 54a7 0003 1100
    0000460: 0236 1419 132c 1128 0e04 54b0 2a59 b400
    0000470: 1104 64b5 0011 2ab4 02dd b602 e3c0 335c
    0000480: 59b4 335e 3a13 59b4 335f 3a04 59b4 3360
    0000490: 3a06 59b4 3361 3a07 59b4 3362 3a08 59b4
    00004a0: 3363 3709 59b4 3364 3a0b 59b4 3365 370c
    00004b0: 59b4 3366 3614 b433 6736 182c 1128 0f04
    00004c0: 54a7 fb98 bb33 5c59 b733 6859 1913 b533
    00004d0: 5e59 1904 c000 54b5 335f 5919 06b5 3360
    00004e0: 5919 07b5 3361 5919 08b5 3362 5916 09b5
    00004f0: 3363 5919 0bb5 3364 5916 0cb5 3365 5915
    0000500: 14b5 3366 5915 18b5 3367 5919 16b5 3369
    0000510: 5919 17b5 336a 3a19 2ab4 02dd 1919 b606
    0000520: 8f57 2a59 b400 1104 60b5 0011 2c11 2810
    0000530: 0454 a7fb 4119 132c 1128 1104 54b0     
  Stackmap Table:
    full_frame(@89,{Object[#13],Long,Object[#84],Null,Object[#1695],Object[#1695],Object[#1695],Long,Object[#1695],Long,Null,Null,Null,Null,Null,Object[#107],Integer,Integer,Null,Null,Integer},{})
    same_frame(@105)
    same_frame(@115)
    same_frame(@160)
    same_frame(@169)
    same_frame(@178)
    full_frame(@1104,{Object[#13],Long,Object[#4],Object[#4],Object[#1695],Object[#1695],Object[#1695],Long,Object[#1695],Long,Object[#4],Object[#4],Object[#4],Object[#4],Object[#4],Object[#4],Integer,Integer,Null,Null,Integer},{})
    same_frame(@1118)
    full_frame(@1132,{Object[#13],Long,Null,Null,Null,Null,Null,Long,Null,Long,Null,Null,Null,Null,Null,Null,Integer,Integer,Null,Null,Integer},{})
    full_frame(@1220,{Object[#13],Long,Object[#84],Null,Object[#1695],Object[#1695],Object[#1695],Long,Object[#1695],Long,Null,Null,Null,Null,Null,Object[#107],Integer,Integer,Null,Null,Integer},{})
    same_frame_extended(@1333)

Affected Version(s)

master

OS, DB, other environment details and versions

No response

Related area

-> Compilation

Related issue(s) (optional)

#40873

Suggested label(s) (optional)

No response

Suggested assignee(s) (optional)

No response

@HindujaB HindujaB added Type/Bug Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime labels Jul 6, 2023
@ballerina-bot ballerina-bot added needTriage The issue has to be inspected and labeled manually userCategory/Compilation labels Jul 6, 2023
@HindujaB
Copy link
Contributor Author

Checked latest #40579
The issue no longer exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needTriage The issue has to be inspected and labeled manually Reason/MultipleComponentInteraction Issue occured due to interactions in multiple components. Team/CompilerFE All issues related to Language implementation and Compiler, this exclude run times. Team/jBallerina All the issues related to BIR, JVM backend code generation and runtime Type/Bug userCategory/Compilation
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants