diff options
| author | Stan Lo <stan.lo@shopify.com> | 2025-07-08 18:52:02 +0100 |
|---|---|---|
| committer | Max Bernstein <ruby@bernsteinbear.com> | 2025-07-08 15:51:44 -0400 |
| commit | 342ada1546fc3afffffec00a5a23c157a092e65b (patch) | |
| tree | 19a717dccfa08bd99ed801ef6c6a40e5d4e2733b /zjit | |
| parent | 79915e6f782dc71f32c0d8d45878f0990f755df5 (diff) | |
ZJIT: Use nil? optimization to test guard generation against different types
Diffstat (limited to 'zjit')
| -rw-r--r-- | zjit/src/hir.rs | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs index d11c13638a..00c246aa12 100644 --- a/zjit/src/hir.rs +++ b/zjit/src/hir.rs @@ -6676,4 +6676,106 @@ mod opt_tests { Return v8 "#]]); } + + #[test] + fn test_guard_false_for_nil_opt() { + eval(" + def test(val) = val.nil? + + test(false) + "); + assert_optimized_method_hir("test", expect![[r#" + fn test: + bb0(v0:BasicObject, v1:BasicObject): + PatchPoint MethodRedefined(FalseClass@0x1000, nil?@0x1008) + v7:FalseClassExact = GuardType v1, FalseClassExact + v8:FalseClassExact = CCall nil?@0x1010, v7 + Return v8 + "#]]); + } + + #[test] + fn test_guard_true_for_nil_opt() { + eval(" + def test(val) = val.nil? + + test(true) + "); + assert_optimized_method_hir("test", expect![[r#" + fn test: + bb0(v0:BasicObject, v1:BasicObject): + PatchPoint MethodRedefined(TrueClass@0x1000, nil?@0x1008) + v7:TrueClassExact = GuardType v1, TrueClassExact + v8:FalseClassExact = CCall nil?@0x1010, v7 + Return v8 + "#]]); + } + + #[test] + fn test_guard_symbol_for_nil_opt() { + eval(" + def test(val) = val.nil? + + test(:foo) + "); + assert_optimized_method_hir("test", expect![[r#" + fn test: + bb0(v0:BasicObject, v1:BasicObject): + PatchPoint MethodRedefined(Symbol@0x1000, nil?@0x1008) + v7:StaticSymbol = GuardType v1, StaticSymbol + v8:FalseClassExact = CCall nil?@0x1010, v7 + Return v8 + "#]]); + } + + #[test] + fn test_guard_fixnum_for_nil_opt() { + eval(" + def test(val) = val.nil? + + test(1) + "); + assert_optimized_method_hir("test", expect![[r#" + fn test: + bb0(v0:BasicObject, v1:BasicObject): + PatchPoint MethodRedefined(Integer@0x1000, nil?@0x1008) + v7:Fixnum = GuardType v1, Fixnum + v8:FalseClassExact = CCall nil?@0x1010, v7 + Return v8 + "#]]); + } + + #[test] + fn test_guard_float_for_nil_opt() { + eval(" + def test(val) = val.nil? + + test(1.0) + "); + assert_optimized_method_hir("test", expect![[r#" + fn test: + bb0(v0:BasicObject, v1:BasicObject): + PatchPoint MethodRedefined(Float@0x1000, nil?@0x1008) + v7:Flonum = GuardType v1, Flonum + v8:FalseClassExact = CCall nil?@0x1010, v7 + Return v8 + "#]]); + } + + #[test] + fn test_guard_string_for_nil_opt() { + eval(" + def test(val) = val.nil? + + test('foo') + "); + assert_optimized_method_hir("test", expect![[r#" + fn test: + bb0(v0:BasicObject, v1:BasicObject): + PatchPoint MethodRedefined(String@0x1000, nil?@0x1008) + v7:StringExact = GuardType v1, StringExact + v8:FalseClassExact = CCall nil?@0x1010, v7 + Return v8 + "#]]); + } } |
