RJIT: Remove Type::CArray and limit use of Type::CString

See previous similar YJIT commit.
This commit is contained in:
Alan Wu 2023-08-28 15:29:46 -04:00
parent 23c83d172c
commit 85aa28e8a6
Notes: git 2023-08-28 21:14:55 +00:00
2 changed files with 15 additions and 22 deletions

View File

@ -794,7 +794,7 @@ module RubyVM::RJIT
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
@ -817,7 +817,7 @@ module RubyVM::RJIT
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
@ -932,7 +932,7 @@ module RubyVM::RJIT
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
@ -954,7 +954,7 @@ module RubyVM::RJIT
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
@ -3082,7 +3082,7 @@ module RubyVM::RJIT
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)
@ -3779,9 +3779,14 @@ module RubyVM::RJIT
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
@ -4723,7 +4728,7 @@ module RubyVM::RJIT
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

View File

@ -35,7 +35,6 @@ module RubyVM::RJIT
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
@ -45,11 +44,10 @@ module RubyVM::RJIT
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
@ -73,7 +71,6 @@ module RubyVM::RJIT
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
@ -115,11 +112,6 @@ module RubyVM::RJIT
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]
@ -169,12 +161,9 @@ module RubyVM::RJIT
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
@ -222,7 +211,6 @@ module RubyVM::RJIT
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