Skip to content

Commit

Permalink
Avoid dependency on org.graalvm.collections (#11107)
Browse files Browse the repository at this point in the history
I am trying to compile Enso with GraalVM 24.2.0 snapshot to verify that oracle/graal#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.
  • Loading branch information
JaroslavTulach authored Sep 17, 2024
1 parent 667ce03 commit f2a809c
Showing 1 changed file with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
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 {
Expand Down Expand Up @@ -45,7 +44,7 @@ static Object doDate32(
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")
Expand All @@ -56,7 +55,7 @@ static Object doDate64(
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")
Expand All @@ -67,7 +66,7 @@ static Object doInt8(
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")
Expand All @@ -78,7 +77,7 @@ static Object doInt16(
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")
Expand All @@ -89,7 +88,7 @@ static Object doInt32(
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")
Expand All @@ -100,12 +99,11 @@ static Object doInt64(
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);
Expand All @@ -125,12 +123,12 @@ private static Pair<ByteBufferDirect, Integer> pointer(
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);
}
}
Expand All @@ -145,4 +143,6 @@ private static String unknownLayoutMessage(LogicalLayout layout) {
return "unknown layout: " + layout.toString();
}
}

private record BufferInt(ByteBufferDirect buffer, int at) {}
}

0 comments on commit f2a809c

Please sign in to comment.