Skip to content

Commit

Permalink
RJIT: Remove Type::CArray and limit use of Type::CString
Browse files Browse the repository at this point in the history
See previous similar YJIT commit.
  • Loading branch information
XrXr committed Aug 28, 2023
1 parent bb8a90e commit 30f0e91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
21 changes: 13 additions & 8 deletions lib/ruby_vm/rjit/insn_compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ def putstring(jit, ctx, asm)
asm.mov(C_ARGS[1], to_value(put_val))
asm.call(C.rb_ec_str_resurrect)

stack_top = ctx.stack_push(Type::CString)
stack_top = ctx.stack_push(Type::TString)
asm.mov(stack_top, C_RET)

KeepCompiling
Expand All @@ -817,7 +817,7 @@ def concatstrings(jit, ctx, asm)
asm.call(C.rb_str_concat_literals)

ctx.stack_pop(n)
stack_ret = ctx.stack_push(Type::CString)
stack_ret = ctx.stack_push(Type::TString)
asm.mov(stack_ret, C_RET)

KeepCompiling
Expand Down Expand Up @@ -932,7 +932,7 @@ def newarray(jit, ctx, asm)
asm.call(C.rb_ec_ary_new_from_values)

ctx.stack_pop(n)
stack_ret = ctx.stack_push(Type::CArray)
stack_ret = ctx.stack_push(Type::TArray)
asm.mov(stack_ret, C_RET)

KeepCompiling
Expand All @@ -954,7 +954,7 @@ def duparray(jit, ctx, asm)
asm.mov(C_ARGS[0], ary)
asm.call(C.rb_ary_resurrect)

stack_ret = ctx.stack_push(Type::CArray)
stack_ret = ctx.stack_push(Type::TArray)
asm.mov(stack_ret, C_RET)

KeepCompiling
Expand Down Expand Up @@ -3082,7 +3082,7 @@ def jit_rb_str_concat(jit, ctx, asm, argc, known_recv_class)
asm.test(recv_reg, C::RUBY_ENCODING_MASK)

# Push once, use the resulting operand in both branches below.
stack_ret = ctx.stack_push(Type::CString)
stack_ret = ctx.stack_push(Type::TString)

enc_mismatch = asm.new_label('enc_mismatch')
asm.jnz(enc_mismatch)
Expand Down Expand Up @@ -3779,9 +3779,14 @@ def jit_guard_known_klass(jit, ctx, asm, known_klass, obj_opnd, insn_opnd, compt
jit_chain_guard(:jne, jit, ctx, asm, side_exit, limit:)

if known_klass == C.rb_cString
ctx.upgrade_opnd_type(insn_opnd, Type::CString)
# Upgrading to Type::CString here is incorrect.
# The guard we put only checks RBASIC_CLASS(obj),
# which adding a singleton class can change. We
# additionally need to know the string is frozen
# to claim Type::CString.
ctx.upgrade_opnd_type(insn_opnd, Type::TString)
elsif known_klass == C.rb_cArray
ctx.upgrade_opnd_type(insn_opnd, Type::CArray)
ctx.upgrade_opnd_type(insn_opnd, Type::TArray)
end
end
end
Expand Down Expand Up @@ -4723,7 +4728,7 @@ def jit_call_iseq(jit, ctx, asm, cme, calling, iseq, frame_type: nil, prev_ep: n
asm.call(C.rb_ec_ary_new_from_values)

ctx.stack_pop(n)
stack_ret = ctx.stack_push(Type::CArray)
stack_ret = ctx.stack_push(Type::TArray)
asm.mov(stack_ret, C_RET)
end
end
Expand Down
16 changes: 2 additions & 14 deletions lib/ruby_vm/rjit/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def heap?
case self
in Type::UnknownHeap then true
in Type::TArray then true
in Type::CArray then true
in Type::Hash then true
in Type::HeapSymbol then true
in Type::TString then true
Expand All @@ -45,11 +44,10 @@ def heap?
end
end

# Check if it's a T_ARRAY object (both TArray and CArray are T_ARRAY)
# Check if it's a T_ARRAY object
def array?
case self
in Type::TArray then true
in Type::CArray then true
else false
end
end
Expand All @@ -73,7 +71,6 @@ def known_class
in Type::Flonum then C.rb_cFloat
in Type::ImmSymbol | Type::HeapSymbol then C.rb_cSymbol
in Type::CString then C.rb_cString
in Type::CArray then C.rb_cArray
else nil
end
end
Expand Down Expand Up @@ -115,11 +112,6 @@ def diff(dst)
return TypeDiff::Compatible[1]
end

# A CArray is also a TArray.
if self == Type::CArray && dst == Type::TArray
return TypeDiff::Compatible[1]
end

# Specific heap type into unknown heap type is imperfect but valid
if self.heap? && dst == Type::UnknownHeap
return TypeDiff::Compatible[1]
Expand Down Expand Up @@ -169,12 +161,9 @@ def from(val)
end
else
val_class = C.to_value(C.rb_class_of(val))
if val_class == C.rb_cString
if val_class == C.rb_cString && C.rb_obj_frozen_p(val)
return Type::CString
end
if val_class == C.rb_cArray
return Type::CArray
end
if C.to_value(val) == C.rb_block_param_proxy
return Type::BlockParamProxy
end
Expand Down Expand Up @@ -222,7 +211,6 @@ def static_symbol?(obj)
Type::TString = Type[:TString] # An object with the T_STRING flag set, possibly an rb_cString
Type::CString = Type[:CString] # An un-subclassed string of type rb_cString (can have instance vars in some cases)
Type::TArray = Type[:TArray] # An object with the T_ARRAY flag set, possibly an rb_cArray
Type::CArray = Type[:CArray] # An un-subclassed string of type rb_cArray (can have instance vars in some cases)

Type::BlockParamProxy = Type[:BlockParamProxy] # A special sentinel value indicating the block parameter should be read from

Expand Down

0 comments on commit 30f0e91

Please sign in to comment.