Code generator should drop `default` from executeFoo variants drawn from an interface with defaults
I have several types of nodes, a few of them express a common interface but are not actually related. Setting up a dozen different executeFoo variants is repetitive. So I'd like to factor this out into an interface with defaults.
public interface ExpressionInterface extends NodeInterface, Cloneable {
Object execute(VirtualFrame frame);
default long executeLong(VirtualFrame frame) throws UnexpectedResultException {
return TypesGen.expectLong(execute(frame));
}
//..
}
This would let me share some code between my expression nodes and my root nodes, and other nodes that aren't expressions and shouldn't occur in expression position, but just happen to want to share this boilerplate.
public abstract class Expression extends Node implements ExpressionInterface {}
public class FunctionBody extends RootNode implements ExpressionInterface {
// ...
}
public class MyRootNode extends RootNode implements ExpressionInterface {
// ...
}
But, when I go to use the truffle dsl it gets confused, and tries to copy the default keyword from the interface into the generated class code. For something like
public abstract class Var extends Expression {
protected final FrameSlot slot;
protected Var(FrameSlot slot) { this.slot = slot; }
@Specialization(rewriteOn = FrameSlotTypeException.class)
protected long readLong(VirtualFrame frame) throws FrameSlotTypeException {
return frame.getLong(slot);
}
@Specialization(replaces = {"readLong"})
protected Object read(VirtualFrame frame) {
return frame.getValue(slot);
}
}
it gets confused and tries to produce the generated code that looks like:
@GeneratedBy(Var.class)
public final class VarNodeGen extends Var {
// ...
@Override
public default boolean executeLong(VirtualFrame frameValue) throws UnexpectedResultException {
// ...
}
}
But default isn't legal in that position, as we're now defining a member of a class.
I'd expect it to just filter default out of the type signatures here.
With that removed, the generated code would work fine.
Tracking internally as Issue GR-20930.