Skip to content

Commit

Permalink
Don't use @Builtin.ReturningGuestObject on TruffleObject instances
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Apr 1, 2024
1 parent d3c7538 commit a98f0b7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public boolean exists() {

@Builtin.Method(name = "creation_time_builtin")
@Builtin.WrapException(from = IOException.class)
@Builtin.ReturningGuestObject
@CompilerDirectives.TruffleBoundary
public EnsoDateTime getCreationTime() throws IOException {
return new EnsoDateTime(
Expand All @@ -140,7 +139,6 @@ public EnsoDateTime getCreationTime() throws IOException {

@Builtin.Method(name = "last_modified_time_builtin")
@Builtin.WrapException(from = IOException.class)
@Builtin.ReturningGuestObject
@CompilerDirectives.TruffleBoundary
public EnsoDateTime getLastModifiedTime() throws IOException {
return new EnsoDateTime(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.ExecutableElement;
import javax.tools.Diagnostic.Kind;

/** Generator for builtin method class with no specialization. */
public final class NoSpecializationClassGenerator extends MethodNodeClassGenerator {
Expand Down Expand Up @@ -34,8 +35,18 @@ public NoSpecializationClassGenerator(

@Override
protected MethodGenerator methodsGen() {
var asGuestValue = needsGuestValueConversion(origin);
if (asGuestValue
&& TypeWithKind.isTruffleObject(processingEnvironment, origin.getReturnType())) {
processingEnvironment
.getMessager()
.printMessage(
Kind.ERROR,
"Value is already TruffleObject, don't use @Builtin.ReturningGuestObject",
origin);
}
return new ExecuteMethodImplGenerator(
processingEnvironment, origin, needsGuestValueConversion(origin), varArgExpansion);
processingEnvironment, origin, asGuestValue, varArgExpansion);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ public static boolean isValidGuestType(ProcessingEnvironment processingEnv, Type
return switch (type.getKind()) {
case BOOLEAN, LONG, DOUBLE -> true;
case VOID -> true;
case DECLARED -> {
var truffleObject =
processingEnv
.getElementUtils()
.getTypeElement("com.oracle.truffle.api.interop.TruffleObject");
var isSubclass = processingEnv.getTypeUtils().isSubtype(type, truffleObject.asType());
yield isSubclass;
}
case DECLARED -> isTruffleObject(processingEnv, type);
default -> false;
};
}

static boolean isTruffleObject(ProcessingEnvironment processingEnv, TypeMirror type) {
var truffleObject =
processingEnv
.getElementUtils()
.getTypeElement("com.oracle.truffle.api.interop.TruffleObject");
var isSubclass = processingEnv.getTypeUtils().isSubtype(type, truffleObject.asType());
return isSubclass;
}
}

0 comments on commit a98f0b7

Please sign in to comment.