Skip to content

Commit

Permalink
Stream methods are hidden behind TruffleBoundary
Browse files Browse the repository at this point in the history
  • Loading branch information
Akirathan committed Oct 8, 2024
1 parent dc228b8 commit 71366f1
Showing 1 changed file with 11 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,6 @@ private boolean isFieldGetter(Function function) {
&& function.getCallTarget().getRootNode() instanceof GetFieldBaseNode;
}

protected boolean isMethodProjectPrivate(Type type, String methodName) {
Function method = constructor.getDefinitionScope().getMethodForType(type, methodName);
if (method != null) {
return method.getSchema().isProjectPrivate();
}
method = constructor.getType().getDefinitionScope().getMethodForType(type, methodName);
return method != null && method.getSchema().isProjectPrivate();
}

/** A member is invocable if it is a method on the Atom and it is public. */
@ExportMessage
@CompilerDirectives.TruffleBoundary
Expand All @@ -238,12 +229,8 @@ final boolean isMemberReadable(String member) {
}
}
}
var publicMethodNames =
getInstanceMethods().stream()
.filter(method -> !method.getSchema().isProjectPrivate())
.map(Function::getName)
.collect(Collectors.toUnmodifiableSet());
return publicMethodNames.contains(member);
var method = findMethod(member);
return method != null && !method.getSchema().isProjectPrivate();
}

/**
Expand All @@ -268,16 +255,19 @@ final Object readMember(String member, @CachedLibrary(limit = "3") StructsLibrar
}
}
}
var matchedMethod =
getInstanceMethods().stream().filter(method -> method.getName().equals(member)).findFirst();
if (matchedMethod.isPresent()) {
assert !matchedMethod.get().getSchema().isProjectPrivate()
: "This is checked in isMemberReadable";
return matchedMethod.get();
var method = findMethod(member);
if (method != null && method.getSchema().isProjectPrivate()) {
return method;
}
throw UnknownIdentifierException.create(member);
}

@TruffleBoundary
private Function findMethod(String methodName) {
var matchedMethod = getInstanceMethods().stream().filter(method -> method.getName().equals(methodName)).findFirst();
return matchedMethod.orElse(null);
}

/** Only public (non project-private) methods can be invoked. */
@ExportMessage
static class InvokeMember {
Expand Down

0 comments on commit 71366f1

Please sign in to comment.