aparapi icon indicating copy to clipboard operation
aparapi copied to clipboard

Allow directly returning new arrays

Open hunterbastian opened this issue 6 months ago • 0 comments

Summary

Fixes #66.

This allows Aparapi codegen to handle methods that directly return a newly instantiated primitive array, such as:

return new double[1024];

Previously, BlockWriter threw a CodeGenException when newarray appeared directly under a return. The generated OpenCL now mirrors the existing accepted workaround where the array is first assigned to a local variable and then returned.

Changes

  • Emit a temporary local array for direct return new <primitive>[...] expressions.
  • Return the generated temporary array name from the direct-return path.
  • Update primitive array codegen expectations for boolean, byte, short, int, long, float, and double arrays.
  • Re-enable the existing ReturnInstantiatedArrayDirectlyTest reproducer now that the bug is fixed.

Verification

Ran on JDK 17 with JAVA_TOOL_OPTIONS=-XX:+IgnoreUnrecognizedVMOptions because the existing Surefire config includes the legacy -XX:MaxPermSize=512m flag.

git diff --check
env JAVA_TOOL_OPTIONS=-XX:+IgnoreUnrecognizedVMOptions JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home /private/tmp/apache-maven-3.9.11/bin/mvn -q -Dmaven.repo.local=/private/tmp/aparapi-m2 -Djacoco.skip=true -Dtest=ReturnInstantiatedArrayDirectlyTest,ReturnDoubleArrayNewTest,ReturnByteArrayNewTest,ReturnShortArrayNewTest,ReturnIntArrayNewTest,ReturnLongArrayNewTest,ReturnFloatArrayNewTest,ReturnBooleanNewArrayTest test
env JAVA_TOOL_OPTIONS=-XX:+IgnoreUnrecognizedVMOptions JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home /private/tmp/apache-maven-3.9.11/bin/mvn -q -Dmaven.repo.local=/private/tmp/aparapi-m2 -DskipTests package

If accepted/merged, I'm happy to coordinate bounty payment details privately.

hunterbastian avatar May 11 '26 07:05 hunterbastian