A value class containing that an int[] does not scalarized when the array is initialized and passed directly in the constructor.
Given:
```
static value class Box_11 {
final int[] v_11;
@ForceInline
Box_11(int[] v_11) {
this.v_11 = v_11;
}
}
@Test
@IR(failOn = {ALLOC_OF_BOX_KLASS, STORE_OF_ANY_KLASS, IRNode.UNSTABLE_IF_TRAP, IRNode.PREDICATE_TRAP})
public static int[] test_11() {
var box = new Box_11(new int[]{16});
return box.v_11;
}
@Check(test = "test_11")
public void checkTest_11(int[] result) {
Verify.checkEQ(new int[]{16}, (int[]) result);
}
```
It fails with:
```
Failed IR Rules (1) of Methods (1)
----------------------------------
1) Method "public static int[] compiler.valhalla.inlinetypes.templating.generated.TestBox.test_11()" - [Failed IR rules: 1]:
* @IR rule 1: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfPlatformAnd={}, applyIfCPUFeatureOr={}, counts={}, applyIfPlatform={}, applyIfPlatformOr={}, failOn={"_#ALLOC_OF_BOX_KLASS#I_", "_#STORE_OF_ANY_KLASS#I_", "_#UNSTABLE_IF_TRAP#_", "_#PREDICATE_TRAP#_"}, applyIfOr={}, applyIfCPUFeatureAnd={}, applyIf={}, applyIfCPUFeature={}, applyIfAnd={}, applyIfNot={})"
> Phase "Before Macro Expansion":
- failOn: Graph contains forbidden nodes:
* Constraint 1: "(\\d+(\\s){2}(Allocate\\b.*)+(\\s){2}===.*allocationKlass:.*\\bcompiler/valhalla/inlinetypes/templating/generated/.*Box\\w*\\s.*)"
- Matched forbidden node:
* 25 Allocate === 5 6 7 8 1 (23 21 22 1 1 _ _ _ 1 ) [[ 26 27 28 35 36 37 ]] rawptr:NotNull ( int:>=0, java/lang/Object:NotNull *, bool, top, bool, bottom, java/lang/Object:NotNull *, long ) allocationKlass:compiler/valhalla/inlinetypes/templating/generated/TestBox$Box_11 TestBox::test_11 @ bci:0 (line 202) !jvms: TestBox::test_11 @ bci:0 (line 202)
```
If you change the shape of the code to be like this, then the allocation gets scalarized.
```
public static int[] test_11() {
var v = new int[]{16};
var box = new Box_11(v);
return box.v_11;
}
```
The constructor was already being inlined without @ForceInline, but following a chat with Tobias I've added it because it's a pre-requisite for the scalarization to occur.
I'm assigning this to myself to try to understand what is going on.
Given:
```
static value class Box_11 {
final int[] v_11;
@ForceInline
Box_11(int[] v_11) {
this.v_11 = v_11;
}
}
@Test
@IR(failOn = {ALLOC_OF_BOX_KLASS, STORE_OF_ANY_KLASS, IRNode.UNSTABLE_IF_TRAP, IRNode.PREDICATE_TRAP})
public static int[] test_11() {
var box = new Box_11(new int[]{16});
return box.v_11;
}
@Check(test = "test_11")
public void checkTest_11(int[] result) {
Verify.checkEQ(new int[]{16}, (int[]) result);
}
```
It fails with:
```
Failed IR Rules (1) of Methods (1)
----------------------------------
1) Method "public static int[] compiler.valhalla.inlinetypes.templating.generated.TestBox.test_11()" - [Failed IR rules: 1]:
* @IR rule 1: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfPlatformAnd={}, applyIfCPUFeatureOr={}, counts={}, applyIfPlatform={}, applyIfPlatformOr={}, failOn={"_#ALLOC_OF_BOX_KLASS#I_", "_#STORE_OF_ANY_KLASS#I_", "_#UNSTABLE_IF_TRAP#_", "_#PREDICATE_TRAP#_"}, applyIfOr={}, applyIfCPUFeatureAnd={}, applyIf={}, applyIfCPUFeature={}, applyIfAnd={}, applyIfNot={})"
> Phase "Before Macro Expansion":
- failOn: Graph contains forbidden nodes:
* Constraint 1: "(\\d+(\\s){2}(Allocate\\b.*)+(\\s){2}===.*allocationKlass:.*\\bcompiler/valhalla/inlinetypes/templating/generated/.*Box\\w*\\s.*)"
- Matched forbidden node:
* 25 Allocate === 5 6 7 8 1 (23 21 22 1 1 _ _ _ 1 ) [[ 26 27 28 35 36 37 ]] rawptr:NotNull ( int:>=0, java/lang/Object:NotNull *, bool, top, bool, bottom, java/lang/Object:NotNull *, long ) allocationKlass:compiler/valhalla/inlinetypes/templating/generated/TestBox$Box_11 TestBox::test_11 @ bci:0 (line 202) !jvms: TestBox::test_11 @ bci:0 (line 202)
```
If you change the shape of the code to be like this, then the allocation gets scalarized.
```
public static int[] test_11() {
var v = new int[]{16};
var box = new Box_11(v);
return box.v_11;
}
```
The constructor was already being inlined without @ForceInline, but following a chat with Tobias I've added it because it's a pre-requisite for the scalarization to occur.
I'm assigning this to myself to try to understand what is going on.