Skip to content

Commit

Permalink
Rename builtin attr :inline to :leaf
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 11, 2023
1 parent 0c0c88d commit 94da5f7
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 26 deletions.
6 changes: 3 additions & 3 deletions compile.c
Expand Up @@ -8214,7 +8214,7 @@ delegate_call_p(const rb_iseq_t *iseq, unsigned int argc, const LINK_ANCHOR *arg
}
}

// Compile Primitive.attr! :inline, ...
// Compile Primitive.attr! :leaf, ...
static int
compile_builtin_attr(rb_iseq_t *iseq, const NODE *node)
{
Expand All @@ -8233,8 +8233,8 @@ compile_builtin_attr(rb_iseq_t *iseq, const NODE *node)
if (!SYMBOL_P(symbol)) goto non_symbol_arg;

string = rb_sym_to_s(symbol);
if (strcmp(RSTRING_PTR(string), "inline") == 0) {
ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_INLINE;
if (strcmp(RSTRING_PTR(string), "leaf") == 0) {
ISEQ_BODY(iseq)->builtin_attrs |= BUILTIN_ATTR_LEAF;
}
else {
goto unknown_arg;
Expand Down
4 changes: 2 additions & 2 deletions kernel.rb
Expand Up @@ -16,7 +16,7 @@ module Kernel
#++
#
def class
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'rb_obj_class(self)'
end

Expand Down Expand Up @@ -65,7 +65,7 @@ def clone(freeze: nil)
#++
#
def frozen?
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'rb_obj_frozen_p(self)'
end

Expand Down
28 changes: 14 additions & 14 deletions numeric.rb
Expand Up @@ -86,7 +86,7 @@ class Integer
#
# Returns +int+, negated.
def -@
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'rb_int_uminus(self)'
end

Expand All @@ -102,7 +102,7 @@ def -@
#
# sprintf("%X", ~0x1122334455) #=> "..FEEDDCCBBAA"
def ~
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'rb_int_comp(self)'
end

Expand All @@ -117,7 +117,7 @@ def ~
# 12345.abs #=> 12345
#
def abs
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'rb_int_abs(self)'
end

Expand Down Expand Up @@ -163,7 +163,7 @@ def abs
# raise "overflow"
# end
def bit_length
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'rb_int_bit_length(self)'
end

Expand All @@ -172,7 +172,7 @@ def bit_length
#
# Returns +true+ if +int+ is an even number.
def even?
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'rb_int_even_p(self)'
end

Expand All @@ -191,7 +191,7 @@ def integer?
#
# Returns +true+ if +int+ is an odd number.
def odd?
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'rb_int_odd_p(self)'
end

Expand Down Expand Up @@ -226,7 +226,7 @@ def ord
# (256**40 - 1).size #=> 40
#
def size
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'rb_int_size(self)'
end

Expand All @@ -251,7 +251,7 @@ def to_int
#
# Returns +true+ if +int+ has a zero value.
def zero?
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'rb_int_zero_p(self)'
end

Expand Down Expand Up @@ -316,12 +316,12 @@ def to_f
# 34.56.abs #=> 34.56
#
def abs
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'rb_float_abs(self)'
end

def magnitude
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'rb_float_abs(self)'
end

Expand All @@ -332,7 +332,7 @@ def magnitude
# Returns +float+, negated.
#
def -@
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'rb_float_uminus(self)'
end

Expand All @@ -343,7 +343,7 @@ def -@
# Returns +true+ if +float+ is 0.0.
#
def zero?
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'RBOOL(FLOAT_ZERO_P(self))'
end

Expand All @@ -354,7 +354,7 @@ def zero?
# Returns +true+ if +float+ is greater than 0.
#
def positive?
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'RBOOL(RFLOAT_VALUE(self) > 0.0)'
end

Expand All @@ -365,7 +365,7 @@ def positive?
# Returns +true+ if +float+ is less than 0.
#
def negative?
Primitive.attr! :inline
Primitive.attr! :leaf
Primitive.cexpr! 'RBOOL(RFLOAT_VALUE(self) < 0.0)'
end

Expand Down
5 changes: 1 addition & 4 deletions tool/mk_builtin_loader.rb
Expand Up @@ -6,7 +6,7 @@

SUBLIBS = {}
REQUIRED = {}
BUILTIN_ATTRS = %w[inline]
BUILTIN_ATTRS = %w[leaf]

def string_literal(lit, str = [])
while lit
Expand Down Expand Up @@ -46,15 +46,12 @@ def inline_text argc, arg1

def inline_attrs(args)
raise "args was empty" if args.empty?
attrs = []
args.each do |arg|
attr = symbol_literal(arg)
unless BUILTIN_ATTRS.include?(attr)
raise "attr (#{attr}) was not in: #{BUILTIN_ATTRS.join(', ')}"
end
attrs << attr
end
attrs
end

def make_cfunc_name inlines, name, lineno
Expand Down
2 changes: 1 addition & 1 deletion vm_core.h
Expand Up @@ -368,7 +368,7 @@ enum rb_iseq_type {
// Attributes specified by Primitive.attr!
enum rb_builtin_attr {
// If true, this ISeq does not call methods.
BUILTIN_ATTR_INLINE = 0x01,
BUILTIN_ATTR_LEAF = 0x01,
};

struct rb_iseq_constant_body {
Expand Down
2 changes: 1 addition & 1 deletion vm_insnhelper.c
Expand Up @@ -6395,7 +6395,7 @@ lookup_builtin_invoker(int argc)
static inline VALUE
invoke_bf(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, const struct rb_builtin_function* bf, const VALUE *argv)
{
const bool canary_p = ISEQ_BODY(reg_cfp->iseq)->builtin_attrs & BUILTIN_ATTR_INLINE; // Verify an assumption of `Primitive.attr! :inline`
const bool canary_p = ISEQ_BODY(reg_cfp->iseq)->builtin_attrs & BUILTIN_ATTR_LEAF; // Verify an assumption of `Primitive.attr! :leaf`
SETUP_CANARY(canary_p);
VALUE ret = (*lookup_builtin_invoker(bf->argc))(ec, reg_cfp->self, argv, (rb_insn_func_t)bf->func_ptr);
CHECK_CANARY(canary_p, BIN(invokebuiltin));
Expand Down
2 changes: 1 addition & 1 deletion yjit.c
Expand Up @@ -735,7 +735,7 @@ rb_leaf_invokebuiltin_iseq_p(const rb_iseq_t *iseq)
return (iseq->body->iseq_size == (invokebuiltin_len + leave_len) &&
rb_vm_insn_addr2opcode((void *)iseq->body->iseq_encoded[0]) == BIN(opt_invokebuiltin_delegate_leave) &&
rb_vm_insn_addr2opcode((void *)iseq->body->iseq_encoded[invokebuiltin_len]) == BIN(leave) &&
(iseq->body->builtin_attrs & BUILTIN_ATTR_INLINE) != 0
(iseq->body->builtin_attrs & BUILTIN_ATTR_LEAF) != 0
);
}

Expand Down

0 comments on commit 94da5f7

Please sign in to comment.