Skip to content

Commit

Permalink
[GR-19220] Split sprintf (#3537)
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4242
  • Loading branch information
andrykonchin committed Apr 17, 2024
2 parents a930d42 + 4a56995 commit 11f1b26
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum Split {
DEFAULT,
ALWAYS,
HEURISTIC,
/** Disallow splitting for this CallTarget, which avoids making a eager uninitialized copy of the AST. Useful
/** Disallow splitting for this CallTarget, which avoids making an eager uninitialized copy of the AST. Useful
* notably for methods not specializing on their arguments and just calling a TruffleBoundary. */
NEVER
}
5 changes: 3 additions & 2 deletions src/main/java/org/truffleruby/cext/CExtNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.truffleruby.annotations.CoreMethod;
import org.truffleruby.annotations.CoreModule;
import org.truffleruby.annotations.Primitive;
import org.truffleruby.annotations.Split;
import org.truffleruby.annotations.Visibility;
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
Expand Down Expand Up @@ -2029,8 +2030,7 @@ protected RubyArray compileArgTypes(AbstractTruffleString format, RubyEncoding e
}
}

@CoreMethod(names = "rb_tr_sprintf", onSingleton = true, required = 3)
@ReportPolymorphism
@CoreMethod(names = "rb_tr_sprintf", onSingleton = true, required = 3, split = Split.ALWAYS)
public abstract static class RBSprintfNode extends CoreMethodArrayArgumentsNode {

@Specialization(guards = "libFormat.isRubyString(format)", limit = "1")
Expand Down Expand Up @@ -2069,6 +2069,7 @@ static RubyString format(Object format, Object stringReader, RubyArray argArray,

@GenerateInline
@GenerateCached(false)
@ReportPolymorphism
public abstract static class RBSprintfInnerNode extends RubyBaseNode {

public abstract BytesResult execute(Node node, AbstractTruffleString format, RubyEncoding encoding,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/truffleruby/core/array/ArrayNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1491,8 +1491,7 @@ public void accept(Node node, CallBlockNode yieldNode, RubyArray array, Object s

}

@CoreMethod(names = "pack", required = 1)
@ReportPolymorphism
@CoreMethod(names = "pack", required = 1, split = Split.ALWAYS)
public abstract static class ArrayPackNode extends CoreMethodArrayArgumentsNode {

@Specialization
Expand All @@ -1506,6 +1505,7 @@ RubyString pack(RubyArray array, Object format,

@GenerateCached(false)
@GenerateInline
@ReportPolymorphism
public abstract static class PackNode extends RubyBaseNode {

public abstract RubyString execute(Node node, RubyArray array, Object format);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/org/truffleruby/core/kernel/KernelNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -1616,8 +1616,8 @@ public static long sleepFor(RubyContext context, RubyThread thread, long duratio

}

@CoreMethod(names = { "format", "sprintf" }, isModuleFunction = true, rest = true, required = 1)
@ReportPolymorphism
@CoreMethod(names = { "format", "sprintf" }, isModuleFunction = true, rest = true, required = 1,
split = Split.ALWAYS)
public abstract static class SprintfNode extends CoreMethodArrayArgumentsNode {

static final String GVAR_DEBUG = "$DEBUG";
Expand Down Expand Up @@ -1665,6 +1665,7 @@ private static RubyString finishFormat(Node node, int formatLength, BytesResult

@GenerateInline
@GenerateCached(false)
@ReportPolymorphism
public abstract static class SprintfInnerNode extends RubyBaseNode {

public abstract BytesResult execute(Node node, AbstractTruffleString format, RubyEncoding encoding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,11 @@ Object dispatch(Frame frame, Object receiver, String methodName, Object[] rubyAr
return callNode.execute(frame, method, receiver, rubyArgs);
}


/** This will be called from the {@link CallInternalMethodNode} child whenever it creates a new
* {@link DirectCallNode}. */
public final void applySplittingInliningStrategy(RootCallTarget callTarget, String methodName,
DirectCallNode callNode) {


final Options options = getContext().getOptions();

// The way that #method_missing is used is usually as an indirection to call some other method, and possibly to
Expand Down
2 changes: 2 additions & 0 deletions src/main/ruby/truffleruby/core/io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,7 @@ def printf(fmt, *args)
fmt = StringValue(fmt)
write sprintf(fmt, *args)
end
Truffle::Graal.always_split(instance_method(:printf))

def read(length = nil, buffer = nil)
ensure_open_and_readable
Expand Down Expand Up @@ -2485,6 +2486,7 @@ def print(*args)
def printf(fmt, *args)
@write.printf(fmt, *args)
end
Truffle::Graal.always_split(instance_method(:printf))

def putc(obj)
@write.putc(obj)
Expand Down
2 changes: 2 additions & 0 deletions src/main/ruby/truffleruby/core/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,8 @@ def printf(*args)
nil
end
module_function :printf
Truffle::Graal.always_split(instance_method(:printf))
Truffle::Graal.always_split(method(:printf))

private def pp(*args)
require 'pp'
Expand Down
2 changes: 2 additions & 0 deletions src/main/ruby/truffleruby/core/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1392,10 +1392,12 @@ def unpack(format, offset: undefined)
end
Primitive.string_unpack(self, format, offset)
end
Truffle::Graal.always_split(instance_method(:unpack))

def unpack1(format, offset: undefined)
unpack(format, offset: offset).first
end
Truffle::Graal.always_split(instance_method(:unpack1))

def unicode_normalize(form = :nfc)
require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize
Expand Down

0 comments on commit 11f1b26

Please sign in to comment.