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

Avoid dependency on org.graalvm.collections #11107

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {}
}
Loading