Skip to content

Commit 451fe6a

Browse files
committed
ZJIT: Fix opt_{hash,ary,str}_{freeze,uminus}
The stack layout is incompatible with the way we reify the stack for generating fallback SendWithoutBlock: the receiver is an embedded VALUE in the bytecode, not on the stack. Since we don't expect these to be overridden often, instead of fussing about with the stack layout, just hope for the best and PatchPoint/SideExit. Fix Shopify#760
1 parent 254b9b4 commit 451fe6a

File tree

2 files changed

+219
-75
lines changed

2 files changed

+219
-75
lines changed

test/ruby/test_zjit.rb

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -997,31 +997,87 @@ def test
997997
end
998998

999999
def test_opt_hash_freeze
1000-
assert_compiles '{}', <<~RUBY, insns: [:opt_hash_freeze]
1000+
assert_compiles "[{}, 5]", %q{
1001+
def test = {}.freeze
1002+
result = [test]
1003+
class Hash
1004+
def freeze = 5
1005+
end
1006+
result << test
1007+
}, insns: [:opt_hash_freeze], call_threshold: 1
1008+
end
1009+
1010+
def test_opt_hash_freeze_rewritten
1011+
assert_compiles "5", %q{
1012+
class Hash
1013+
def freeze = 5
1014+
end
10011015
def test = {}.freeze
10021016
test
1003-
RUBY
1017+
}, insns: [:opt_hash_freeze], call_threshold: 1
10041018
end
10051019

10061020
def test_opt_ary_freeze
1007-
assert_compiles '[]', <<~RUBY, insns: [:opt_ary_freeze]
1021+
assert_compiles "[[], 5]", %q{
1022+
def test = [].freeze
1023+
result = [test]
1024+
class Array
1025+
def freeze = 5
1026+
end
1027+
result << test
1028+
}, insns: [:opt_ary_freeze], call_threshold: 1
1029+
end
1030+
1031+
def test_opt_ary_freeze_rewritten
1032+
assert_compiles "5", %q{
1033+
class Array
1034+
def freeze = 5
1035+
end
10081036
def test = [].freeze
10091037
test
1010-
RUBY
1038+
}, insns: [:opt_ary_freeze], call_threshold: 1
10111039
end
10121040

10131041
def test_opt_str_freeze
1014-
assert_compiles '""', <<~RUBY, insns: [:opt_str_freeze]
1015-
def test = "".freeze
1042+
assert_compiles "[\"\", 5]", %q{
1043+
def test = ''.freeze
1044+
result = [test]
1045+
class String
1046+
def freeze = 5
1047+
end
1048+
result << test
1049+
}, insns: [:opt_str_freeze], call_threshold: 1
1050+
end
1051+
1052+
def test_opt_str_freeze_rewritten
1053+
assert_compiles "5", %q{
1054+
class String
1055+
def freeze = 5
1056+
end
1057+
def test = ''.freeze
10161058
test
1017-
RUBY
1059+
}, insns: [:opt_str_freeze], call_threshold: 1
10181060
end
10191061

10201062
def test_opt_str_uminus
1021-
assert_compiles '""', <<~RUBY, insns: [:opt_str_uminus]
1022-
def test = -""
1063+
assert_compiles "[\"\", 5]", %q{
1064+
def test = -''
1065+
result = [test]
1066+
class String
1067+
def -@ = 5
1068+
end
1069+
result << test
1070+
}, insns: [:opt_str_uminus], call_threshold: 1
1071+
end
1072+
1073+
def test_opt_str_uminus_rewritten
1074+
assert_compiles "5", %q{
1075+
class String
1076+
def -@ = 5
1077+
end
1078+
def test = -''
10231079
test
1024-
RUBY
1080+
}, insns: [:opt_str_uminus], call_threshold: 1
10251081
end
10261082

10271083
def test_new_array_empty

0 commit comments

Comments
 (0)