Avoid dependency on org.graalvm.collections (#11107)

I am trying to compile Enso with GraalVM 24.2.0 snapshot to verify that https://github.com/oracle/graal/pull/8266 changes would work for Enso. Among the problems I am facing is a dependency on `org.graalvm.collections` because of using `Pair`. I don't think we need such dependency. Let's avoid it by using our own `record` with two components.
This commit is contained in:
Jaroslav Tulach 2024-09-17 13:25:18 +02:00 committed by GitHub
parent 667ce038e7
commit f2a809c4e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,7 +14,6 @@ import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.library.ExportLibrary;
import com.oracle.truffle.api.library.ExportMessage;
import org.enso.interpreter.arrow.LogicalLayout;
import org.graalvm.collections.Pair;
@ExportLibrary(InteropLibrary.class)
public class ArrowCastToFixedSizeArrayFactory implements TruffleObject {
@ -45,7 +44,7 @@ public class ArrowCastToFixedSizeArrayFactory implements TruffleObject {
throws UnsupportedMessageException, ArityException, UnsupportedTypeException {
var unit = LogicalLayout.Date32;
var pair = pointer(args, iop, unit);
return new ArrowFixedArrayDate(pair.getLeft(), pair.getRight(), unit);
return new ArrowFixedArrayDate(pair.buffer(), pair.at(), unit);
}
@Specialization(guards = "receiver.getLayout() == Date64")
@ -56,7 +55,7 @@ public class ArrowCastToFixedSizeArrayFactory implements TruffleObject {
throws UnsupportedMessageException, ArityException, UnsupportedTypeException {
var unit = LogicalLayout.Date64;
var pair = pointer(args, iop, unit);
return new ArrowFixedArrayDate(pair.getLeft(), pair.getRight(), unit);
return new ArrowFixedArrayDate(pair.buffer(), pair.at(), unit);
}
@Specialization(guards = "receiver.getLayout() == Int8")
@ -67,7 +66,7 @@ public class ArrowCastToFixedSizeArrayFactory implements TruffleObject {
throws UnsupportedMessageException, ArityException, UnsupportedTypeException {
var unit = LogicalLayout.Int8;
var pair = pointer(args, iop, unit);
return new ArrowFixedArrayInt(pair.getLeft(), pair.getRight(), unit);
return new ArrowFixedArrayInt(pair.buffer(), pair.at(), unit);
}
@Specialization(guards = "receiver.getLayout() == Int16")
@ -78,7 +77,7 @@ public class ArrowCastToFixedSizeArrayFactory implements TruffleObject {
throws UnsupportedMessageException, ArityException, UnsupportedTypeException {
var unit = LogicalLayout.Int16;
var pair = pointer(args, iop, unit);
return new ArrowFixedArrayInt(pair.getLeft(), pair.getRight(), unit);
return new ArrowFixedArrayInt(pair.buffer(), pair.at(), unit);
}
@Specialization(guards = "receiver.getLayout() == Int32")
@ -89,7 +88,7 @@ public class ArrowCastToFixedSizeArrayFactory implements TruffleObject {
throws UnsupportedMessageException, ArityException, UnsupportedTypeException {
var unit = LogicalLayout.Int32;
var pair = pointer(args, iop, unit);
return new ArrowFixedArrayInt(pair.getLeft(), pair.getRight(), unit);
return new ArrowFixedArrayInt(pair.buffer(), pair.at(), unit);
}
@Specialization(guards = "receiver.getLayout() == Int64")
@ -100,12 +99,11 @@ public class ArrowCastToFixedSizeArrayFactory implements TruffleObject {
throws UnsupportedMessageException, ArityException, UnsupportedTypeException {
var unit = LogicalLayout.Int64;
var pair = pointer(args, iop, unit);
return new ArrowFixedArrayInt(pair.getLeft(), pair.getRight(), unit);
return new ArrowFixedArrayInt(pair.buffer(), pair.at(), unit);
}
@CompilerDirectives.TruffleBoundary
private static Pair<ByteBufferDirect, Integer> pointer(
Object[] args, InteropLibrary interop, SizeInBytes unit)
private static BufferInt pointer(Object[] args, InteropLibrary interop, SizeInBytes unit)
throws ArityException, UnsupportedTypeException, UnsupportedMessageException {
if (args.length < 2) {
throw ArityException.create(2, 3, args.length);
@ -125,12 +123,12 @@ public class ArrowCastToFixedSizeArrayFactory implements TruffleObject {
throw UnsupportedTypeException.create(
new Object[] {args[2]}, "Address of non-null bitmap is invalid");
}
return Pair.create(
return new BufferInt(
ByteBufferDirect.fromAddress(
interop.asLong(args[0]), interop.asLong(args[2]), capacity, unit),
capacity);
} else {
return Pair.create(
return new BufferInt(
ByteBufferDirect.fromAddress(interop.asLong(args[0]), capacity, unit), capacity);
}
}
@ -145,4 +143,6 @@ public class ArrowCastToFixedSizeArrayFactory implements TruffleObject {
return "unknown layout: " + layout.toString();
}
}
private record BufferInt(ByteBufferDirect buffer, int at) {}
}