liquid5-c 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -141,140 +141,6 @@ static VALUE native_frontend_candidate(VALUE self, VALUE markup)
141
141
  return Qfalse;
142
142
  }
143
143
 
144
- #ifdef HAVE_RB_CALLABLE_METHOD_ENTRY
145
- typedef struct { VALUE owner, entry, snapshot; ID method; int receiver; bool constant, public_call, builtin; } native_method_guard_t;
146
- static native_method_guard_t *method_guards;
147
- static long method_guard_count;
148
- static VALUE integer_to_i_entry;
149
- static VALUE constant_watchers = Qnil, constant_vm = Qnil, constant_epoch = Qundef;
150
- static ID id_stat, id_constant_invalidations;
151
- static bool guard_roots_registered;
152
-
153
- static VALUE native_watchers_supported(VALUE self, VALUE vm)
154
- {
155
- return liquid_method_basic_definition_p(CLASS_OF(vm), rb_intern("stat")) &&
156
- liquid_method_basic_definition_p(rb_cModule, rb_intern("module_eval")) &&
157
- liquid_method_basic_definition_p(rb_cModule, rb_intern("instance_method")) &&
158
- (RB_TYPE_P(native_unbound_class, T_CLASS) && liquid_method_basic_definition_p(native_unbound_class, rb_intern("bind_call"))) &&
159
- liquid_method_basic_definition_p(rb_cProc, rb_intern("call")) ? Qtrue : Qfalse;
160
- }
161
-
162
- static VALUE native_constant_epoch(void)
163
- {
164
- if (NIL_P(constant_vm) || !liquid_method_basic_definition_p(CLASS_OF(constant_vm), id_stat)) return Qundef;
165
- return rb_funcall(constant_vm, id_stat, 1, ID2SYM(id_constant_invalidations));
166
- }
167
-
168
- static VALUE native_register_guards(VALUE self, VALUE specifications, VALUE watchers, VALUE vm)
169
- {
170
- Check_Type(specifications, T_ARRAY);
171
- long count = RARRAY_LEN(specifications);
172
- if (count < 0 || (size_t)count > SIZE_MAX / sizeof(*method_guards))
173
- rb_raise(rb_eArgError, "too many method guards");
174
- bool first = method_guards == NULL;
175
- if (!first && count != method_guard_count) rb_raise(rb_eArgError, "guard count changed");
176
- for (long i = 0; i < count; i++) {
177
- VALUE spec = RARRAY_AREF(specifications, i);
178
- Check_Type(spec, T_ARRAY);
179
- if (RARRAY_LEN(spec) != 7) rb_raise(rb_eArgError, "invalid method guard");
180
- VALUE owner = RARRAY_AREF(spec, 0);
181
- if (!RB_TYPE_P(owner, T_CLASS) && !RB_TYPE_P(owner, T_MODULE)) rb_raise(rb_eTypeError, "guard owner must be a module");
182
- Check_Type(RARRAY_AREF(spec, 1), T_SYMBOL);
183
- int receiver = NUM2INT(RARRAY_AREF(spec, 2));
184
- if (receiver < 0 || receiver > 3) rb_raise(rb_eArgError, "invalid method guard receiver");
185
- if (!NIL_P(RARRAY_AREF(spec, 4))) Check_Type(RARRAY_AREF(spec, 4), T_ARRAY);
186
- }
187
- if (!NIL_P(watchers)) Check_Type(watchers, T_ARRAY);
188
- if (first) method_guards = ruby_xcalloc((size_t)count, sizeof(*method_guards));
189
- if (!guard_roots_registered) {
190
- rb_gc_register_address(&constant_watchers);
191
- rb_gc_register_address(&constant_vm);
192
- rb_gc_register_address(&constant_epoch);
193
- guard_roots_registered = true;
194
- }
195
- constant_watchers = watchers;
196
- constant_vm = NIL_P(watchers) ? Qnil : vm;
197
- constant_epoch = Qundef;
198
- id_stat = rb_intern("stat");
199
- id_constant_invalidations = rb_intern("constant_cache_invalidations");
200
- if (first) {
201
- for (long i = 0; i < count; i++) {
202
- rb_gc_register_address(&method_guards[i].owner);
203
- rb_gc_register_address(&method_guards[i].entry);
204
- rb_gc_register_address(&method_guards[i].snapshot);
205
- }
206
- }
207
- for (long i = 0; i < count; i++) {
208
- VALUE spec = RARRAY_AREF(specifications, i);
209
- native_method_guard_t *guard = &method_guards[i];
210
- guard->owner = RARRAY_AREF(spec, 0);
211
- guard->method = SYM2ID(RARRAY_AREF(spec, 1));
212
- guard->receiver = NUM2INT(RARRAY_AREF(spec, 2));
213
- guard->constant = RTEST(RARRAY_AREF(spec, 3));
214
- guard->public_call = RTEST(RARRAY_AREF(spec, 6));
215
- guard->builtin = !guard->constant && liquid_method_basic_definition_p(guard->owner, guard->method);
216
- guard->snapshot = RARRAY_AREF(spec, 4);
217
- guard->entry = guard->constant ? RARRAY_AREF(spec, 5) :
218
- liquid_method_entry(guard->owner, guard->method);
219
- if (!guard->constant && guard->owner == rb_cInteger && guard->method == rb_intern("to_i"))
220
- integer_to_i_entry = guard->entry;
221
- }
222
- method_guard_count = count;
223
- return Qtrue;
224
- }
225
-
226
- static bool native_method_guard_current(native_method_guard_t *guard)
227
- {
228
- VALUE current = liquid_method_entry(guard->owner, guard->method);
229
- if (!guard->entry) return false;
230
- if (guard->entry != current) {
231
- // MRI can recreate inherited entries for an unchanged core constructor.
232
- if (!guard->builtin || !liquid_method_basic_definition_p(guard->owner, guard->method)) return false;
233
- guard->entry = current;
234
- if (guard->owner == rb_cInteger && guard->method == rb_intern("to_i")) integer_to_i_entry = current;
235
- }
236
- return true;
237
- }
238
-
239
- static bool native_guards_match(VALUE context, VALUE variable, bool cached_constants)
240
- {
241
- VALUE scanner = rb_ivar_get(context, id_string_scanner);
242
- VALUE receiver_classes[] = { Qnil, CLASS_OF(context), CLASS_OF(scanner), NIL_P(variable) ? Qnil : CLASS_OF(variable) };
243
- for (long i = 0; i < method_guard_count; i++) {
244
- native_method_guard_t *guard = &method_guards[i];
245
- if (guard->constant) {
246
- if (cached_constants) {
247
- // Reader ISeqs are rooted in constant_watchers. MRI invalidates
248
- // their registered IC sites even before they are read again.
249
- // Mutable table slots must still be checked on every operation.
250
- if (!native_snapshot_matches(guard->entry, guard->snapshot)) return false;
251
- } else if (!RTEST(native_constant_matches(Qnil, guard->owner, ID2SYM(guard->method), guard->entry, guard->snapshot))) return false;
252
- continue;
253
- }
254
- if (!native_method_guard_current(guard)) return false;
255
- if (guard->public_call && rb_method_boundp(guard->owner, guard->method, 3) != 1) return false;
256
- if (guard->receiver) {
257
- if (guard->receiver == 3 && NIL_P(variable)) continue;
258
- VALUE target_class = receiver_classes[guard->receiver];
259
- if (guard->receiver == 2 && RB_OBJ_FROZEN(scanner)) return false;
260
- // Standard receivers have the same class already checked above.
261
- // Singleton classes still require their own current method lookup.
262
- if (target_class != guard->owner &&
263
- guard->entry != liquid_method_entry(target_class, guard->method)) return false;
264
- }
265
- }
266
- return true;
267
- }
268
-
269
- static VALUE native_methods_compatible(VALUE self, VALUE context, VALUE variable)
270
- {
271
- VALUE epoch = native_constant_epoch();
272
- if (!native_guards_match(context, variable, epoch != Qundef && epoch == constant_epoch)) return Qfalse;
273
- if (epoch != Qundef && epoch != native_constant_epoch()) return Qfalse;
274
- constant_epoch = epoch;
275
- return Qtrue;
276
- }
277
- #endif
278
144
 
279
145
  static bool native_conversion_is_standard(VALUE value)
280
146
  {
@@ -283,12 +149,7 @@ static bool native_conversion_is_standard(VALUE value)
283
149
  !liquid_method_basic_definition_p(klass, rb_intern("respond_to_missing?")) ||
284
150
  rb_method_boundp(klass, id_evaluate, 0)) return false;
285
151
  if (liquid_method_basic_definition_p(klass, rb_intern("to_i"))) return true;
286
- #ifdef HAVE_RB_CALLABLE_METHOD_ENTRY
287
- return RB_INTEGER_TYPE_P(value) && integer_to_i_entry && integer_to_i_entry ==
288
- liquid_method_entry(CLASS_OF(value), rb_intern("to_i"));
289
- #else
290
152
  return false;
291
- #endif
292
153
  }
293
154
 
294
155
  static bool native_space(unsigned char c)
@@ -1076,13 +937,6 @@ static VALUE native_variable_body(VALUE opaque)
1076
937
  return native_variable_body_probed(opaque, NULL);
1077
938
  }
1078
939
 
1079
- static VALUE native_variable_unpin(VALUE opaque)
1080
- {
1081
- native_parser_t *p = (void *)opaque;
1082
- rb_gc_unregister_address(&p->source);
1083
- return Qnil;
1084
- }
1085
-
1086
940
  static bool native_payload_methods_standard(int operation)
1087
941
  {
1088
942
  if (!native_primitives_standard(true)) return false;
@@ -1126,8 +980,10 @@ static VALUE native_parse_payload(VALUE markup, VALUE cache, int operation, bool
1126
980
  if (rb_enc_get_index(parser.source) != utf8_encoding_index ||
1127
981
  rb_enc_str_coderange(parser.source) == ENC_CODERANGE_BROKEN) return Qnil;
1128
982
  parser.length = (size_t)RSTRING_LEN(parser.source);
1129
- rb_gc_register_address(&parser.source);
1130
- VALUE result = rb_ensure(native_variable_body, (VALUE)&parser, native_variable_unpin, (VALUE)&parser);
983
+ // The parser lives on the machine stack, so the conservative scan keeps its
984
+ // VALUEs alive and pinned without a global root that could outlive an
985
+ // abandoned fiber.
986
+ VALUE result = native_variable_body((VALUE)&parser);
1131
987
  if (!NIL_P(result) && !NIL_P(cache) && !native_normal_hash(cache)) result = Qnil;
1132
988
  if ((!checked_cache || liquid_gc_count() != before_gc) && !native_payload_methods_standard(operation)) result = Qnil;
1133
989
  RB_GC_GUARD(parser.source);
@@ -1178,149 +1034,11 @@ static VALUE native_record_stats(VALUE self, VALUE context, VALUE reason)
1178
1034
 
1179
1035
  static VALUE native_parser_tracing(VALUE self)
1180
1036
  {
1181
- #ifdef HAVE_RUBY_VM_EVENT_FLAGS
1182
- return liquid_vm_tracing() ? Qtrue : Qfalse;
1183
- #else
1184
1037
  // Portable frontend checks methods before and after construction; the
1185
1038
  // single-operation optimization above requires the optional tracing flag.
1186
1039
  return Qfalse;
1187
- #endif
1188
- }
1189
-
1190
- #ifdef LIQUID_HAVE_GUARDED_COMPILER
1191
-
1192
- static bool native_opted_out(const char *option)
1193
- {
1194
- const char *value = getenv(option);
1195
- return value && !strcmp(value, "false");
1196
- }
1197
-
1198
- static bool native_parse_interrupted(size_t gc_before)
1199
- {
1200
- return gc_before != liquid_gc_count() || liquid_vm_tracing();
1201
- }
1202
-
1203
- static bool native_bare_identifier(VALUE markup)
1204
- {
1205
- if (!RB_TYPE_P(markup, T_STRING)) return false;
1206
- const unsigned char *bytes = (const unsigned char *)RSTRING_PTR(markup);
1207
- size_t i = 0, size = (size_t)RSTRING_LEN(markup);
1208
- while (i < size && native_space(bytes[i])) i++;
1209
- if (i == size || !native_alpha(bytes[i++])) return false;
1210
- while (i < size && (native_alpha(bytes[i]) || native_digit(bytes[i]) || bytes[i] == '-')) i++;
1211
- if (i < size && bytes[i] == '?') i++;
1212
- while (i < size && native_space(bytes[i])) i++;
1213
- return i == size;
1214
1040
  }
1215
1041
 
1216
- static bool native_plain_lookup(VALUE markup)
1217
- {
1218
- if (!RB_TYPE_P(markup, T_STRING) || RSTRING_LEN(markup) >= 128) return false;
1219
- const unsigned char *bytes = (const unsigned char *)RSTRING_PTR(markup);
1220
- size_t i = 0, size = (size_t)RSTRING_LEN(markup);
1221
- for (;;) {
1222
- while (i < size && native_space(bytes[i])) i++;
1223
- if (i == size || !native_alpha(bytes[i++])) return false;
1224
- while (i < size && (native_alpha(bytes[i]) || native_digit(bytes[i]) || bytes[i] == '-')) i++;
1225
- if (i < size && bytes[i] == '?') i++;
1226
- while (i < size && native_space(bytes[i])) i++;
1227
- if (i == size) return true;
1228
- if (bytes[i++] != '.') return false;
1229
- }
1230
- }
1231
-
1232
- static VALUE native_try_variable_impl(VALUE self, VALUE markup, VALUE context, VALUE variable, bool retry);
1233
-
1234
- static VALUE native_variable_guard_failure(VALUE self, VALUE markup, VALUE context, VALUE variable, bool retry)
1235
- {
1236
- if (retry) {
1237
- VALUE helper = rb_const_get(mLiquidC, rb_intern("NativeParser"));
1238
- if (RTEST(rb_funcall(helper, rb_intern("compatible?"), 2, context, variable)))
1239
- return native_try_variable_impl(self, markup, context, variable, false);
1240
- }
1241
- native_record_stats(self, context, ID2SYM(rb_intern("hooks")));
1242
- return Qnil;
1243
- }
1244
-
1245
- static VALUE native_try_variable_impl(VALUE self, VALUE markup, VALUE context, VALUE variable, bool retry)
1246
- {
1247
- if (!method_guard_count) return Qnil;
1248
- if (liquid_vm_tracing()) return Qnil;
1249
- if (rb_obj_class(context) != native_context_class || rb_obj_class(variable) != cLiquidVariable) return Qnil;
1250
- VALUE early_cache = rb_ivar_get(context, id_cache_native);
1251
- // Reject costly short unique forms before environment/method checks.
1252
- if (RB_TYPE_P(early_cache, T_HASH) && RHASH_SIZE(early_cache) > 32 &&
1253
- RB_TYPE_P(markup, T_STRING) && RSTRING_LEN(markup) < 128) {
1254
- native_record_stats(self, context, ID2SYM(rb_intern("guard_cost")));
1255
- return Qnil;
1256
- }
1257
- if (native_bare_identifier(markup) && (!RB_TYPE_P(early_cache, T_HASH) || RHASH_SIZE(early_cache) != 1)) {
1258
- native_record_stats(self, context, ID2SYM(rb_intern("guard_cost")));
1259
- return Qnil;
1260
- }
1261
- if (RB_TYPE_P(early_cache, T_HASH) && native_plain_lookup(markup)) {
1262
- VALUE document = rb_ivar_get(context, rb_intern("document_body"));
1263
- if (!NIL_P(document) && !document_body_cache_stable(document, RHASH_SIZE(early_cache))) {
1264
- native_record_stats(self, context, ID2SYM(rb_intern("guard_cost")));
1265
- return Qnil;
1266
- }
1267
- }
1268
- // Tokenizer setup initializes this flag. Standalone Variable.new retains
1269
- // the original Ruby path rather than calling extra context callbacks.
1270
- if (!rb_ivar_defined(context, id_disabled_native)) {
1271
- native_record_stats(self, context, ID2SYM(rb_intern("context")));
1272
- return Qnil;
1273
- }
1274
- if (!RTEST(rb_ivar_get(mLiquidC, id_enabled_native)) || native_opted_out("LIQUID_C_NATIVE_PARSER")) {
1275
- native_record_stats(self, context, ID2SYM(rb_intern("disabled")));
1276
- return Qnil;
1277
- }
1278
- size_t guard_gc = liquid_gc_count();
1279
- if (!RTEST(native_methods_compatible(self, context, variable)))
1280
- return native_variable_guard_failure(self, markup, context, variable, retry);
1281
- if (liquid_gc_count() != guard_gc) {
1282
- guard_gc = liquid_gc_count();
1283
- if (!RTEST(native_methods_compatible(self, context, variable)) || liquid_gc_count() != guard_gc)
1284
- return native_variable_guard_failure(self, markup, context, variable, retry);
1285
- }
1286
- if (liquid_vm_tracing()) return Qnil;
1287
- if (RTEST(rb_ivar_get(context, id_disabled_native))) {
1288
- native_record_stats(self, context, ID2SYM(rb_intern("disabled")));
1289
- return Qnil;
1290
- }
1291
- VALUE mode = rb_ivar_get(context, id_mode_native);
1292
- if (mode != ID2SYM(rb_intern("lax")) && mode != ID2SYM(rb_intern("warn")) && mode != ID2SYM(rb_intern("strict"))) {
1293
- native_record_stats(self, context, ID2SYM(rb_intern("mode")));
1294
- return Qnil;
1295
- }
1296
- VALUE cache = rb_ivar_get(context, id_cache_native);
1297
- if (RTEST(cache)) {
1298
- if (CLASS_OF(cache) != rb_cHash) return Qnil;
1299
- if (!native_string_cache(cache)) {
1300
- native_record_stats(self, context, ID2SYM(rb_intern("cache")));
1301
- return Qnil;
1302
- }
1303
- } else cache = Qnil;
1304
- if (rb_get_alloc_func(cLiquidVariableLookup) != rb_get_alloc_func(rb_cObject) ||
1305
- rb_get_alloc_func(cLiquidRangeLookup) != rb_get_alloc_func(rb_cObject)) return Qnil;
1306
- size_t gc_count = liquid_gc_count();
1307
- VALUE result = native_parse_payload(markup, cache, 0, true, false, NULL);
1308
- if (NIL_P(result)) {
1309
- native_record_stats(self, context, ID2SYM(rb_intern("syntax")));
1310
- return Qnil;
1311
- }
1312
- if (liquid_vm_tracing()) return Qnil;
1313
- if (liquid_gc_count() != gc_count && !RTEST(native_methods_compatible(self, context, variable))) return Qnil;
1314
- native_publish_cache(self, cache, RARRAY_AREF(result, 2));
1315
- native_record_stats(self, context, ID2SYM(rb_intern("accepted")));
1316
- return result;
1317
- }
1318
- static VALUE native_try_variable(VALUE self, VALUE markup, VALUE context, VALUE variable)
1319
- {
1320
- return native_try_variable_impl(self, markup, context, variable, true);
1321
- }
1322
-
1323
- #endif
1324
1042
 
1325
1043
  static VALUE native_variable_candidate(VALUE self, VALUE markup, VALUE context)
1326
1044
  {
@@ -1368,101 +1086,14 @@ static VALUE native_case_expression(int argc, VALUE *argv, VALUE self)
1368
1086
  return rb_call_super_kw(argc, argv, RB_PASS_CALLED_KEYWORDS);
1369
1087
  }
1370
1088
 
1371
- #ifdef HAVE_RB_CALLABLE_METHOD_ENTRY
1372
- static VALUE native_if_parse_entry, native_for_parse_entry;
1373
- static VALUE native_context_entries[3];
1374
- static VALUE native_switching_module;
1375
- static ID id_strict_context_native, id_strict_parse_native;
1376
-
1377
- static VALUE native_fast_header(VALUE self, VALUE markup);
1378
-
1379
- typedef struct { VALUE self, markup; bool second; } native_strict_args_t;
1380
-
1381
- static VALUE native_strict_body(VALUE opaque)
1382
- {
1383
- native_strict_args_t *args = (void *)opaque;
1384
- VALUE fast = native_fast_header(args->self, args->markup);
1385
- if (fast != Qundef) return fast;
1386
- if (args->second) return rb_funcall(args->self, rb_intern("strict2_parse"), 1, args->markup);
1387
- VALUE klass = rb_obj_class(args->self);
1388
- int index = klass == native_if_class ? 0 : (klass == native_unless_class ? 1 : (klass == native_for_class ? 2 : -1));
1389
- if (index >= 0 && !(index == 2 && RB_OBJ_FROZEN(args->self)) &&
1390
- native_context_entries[index] == liquid_method_entry(CLASS_OF(args->self), id_strict_context_native) &&
1391
- (index == 2 ? native_for_parse_entry : native_if_parse_entry) ==
1392
- liquid_method_entry(CLASS_OF(args->self), id_strict_parse_native) &&
1393
- RTEST(native_case_candidate(Qnil, args->markup, Qnil))) {
1394
- VALUE helper = rb_const_get(mLiquidC, rb_intern("NativeTags"));
1395
- VALUE kind = ID2SYM(rb_intern(index == 2 ? "for" : "condition"));
1396
- VALUE result = rb_funcall(helper, rb_intern("try_tag_header"), 3, args->self, args->markup, kind);
1397
- if (!NIL_P(result)) {
1398
- VALUE payload = RARRAY_AREF(result, 0);
1399
- if (index != 2) return payload;
1400
- Check_Type(payload, T_ARRAY);
1401
- if (RARRAY_LEN(payload) != 6) rb_raise(rb_eRuntimeError, "invalid native for header");
1402
- for (size_t i = 0; i < 6; i++) rb_ivar_set(args->self, id_for_fields[i], RARRAY_AREF(payload, i));
1403
- return Qnil;
1404
- }
1405
- }
1406
- return rb_funcall(args->self, id_strict_parse_native, 1, args->markup);
1407
- }
1408
-
1409
- static VALUE native_strict_rescue(VALUE opaque, VALUE exception)
1410
- {
1411
- VALUE syntax_error = rb_const_get(mLiquid, rb_intern("SyntaxError"));
1412
- if (!rb_obj_is_kind_of(exception, syntax_error)) rb_exc_raise(exception);
1413
- native_strict_args_t *args = (void *)opaque;
1414
- VALUE line = rb_funcall(args->self, rb_intern("line_number"), 0);
1415
- rb_funcallv_public(exception, rb_intern("line_number="), 1, &line);
1416
- VALUE markup = rb_funcall(args->self, rb_intern("markup_context"), 1, args->markup);
1417
- rb_funcallv_public(exception, rb_intern("markup_context="), 1, &markup);
1418
- rb_exc_raise(exception);
1419
- }
1420
-
1421
- static VALUE native_strict_context(VALUE self, VALUE markup)
1422
- {
1423
- native_strict_args_t args = { self, markup };
1424
- return rb_rescue2(native_strict_body, (VALUE)&args, native_strict_rescue, (VALUE)&args, rb_eException, (VALUE)0);
1425
- }
1426
- static VALUE native_strict2_context(VALUE self, VALUE markup)
1427
- {
1428
- native_strict_args_t args = { self, markup, true };
1429
- return rb_rescue2(native_strict_body, (VALUE)&args, native_strict_rescue, (VALUE)&args, rb_eException, (VALUE)0);
1430
- }
1431
-
1432
- static VALUE native_install_compiler_context(VALUE self)
1433
- {
1434
- VALUE owner = rb_const_get(mLiquid, rb_intern("ParserSwitching"));
1435
- rb_define_private_method(owner, "strict2_parse_with_error_context", native_strict2_context, 1);
1436
- return Qnil;
1437
- }
1438
-
1439
- #endif
1440
1089
 
1441
1090
  static VALUE native_install_header_parser(VALUE self, VALUE original, VALUE for_tag)
1442
1091
  {
1443
- #ifdef HAVE_RB_CALLABLE_METHOD_ENTRY
1444
- if (RTEST(for_tag)) {
1445
- native_original_for = original;
1446
- native_for_parse_entry = liquid_method_entry(native_for_class, rb_intern("strict_parse"));
1447
- } else {
1448
- native_original_if = original;
1449
- native_if_parse_entry = liquid_method_entry(native_if_class, rb_intern("strict_parse"));
1450
- }
1451
- #endif
1452
1092
  return Qnil;
1453
1093
  }
1454
1094
 
1455
1095
  static VALUE native_install_strict_context(VALUE self)
1456
1096
  {
1457
- #ifdef HAVE_RB_CALLABLE_METHOD_ENTRY
1458
- id_strict_context_native = rb_intern("strict_parse_with_error_context");
1459
- id_strict_parse_native = rb_intern("strict_parse");
1460
- native_switching_module = rb_const_get(mLiquid, rb_intern("ParserSwitching"));
1461
- rb_define_private_method(native_switching_module, "strict_parse_with_error_context", native_strict_context, 1);
1462
- VALUE classes[] = { native_if_class, native_unless_class, native_for_class };
1463
- for (size_t i = 0; i < 3; i++)
1464
- native_context_entries[i] = liquid_method_entry(classes[i], id_strict_context_native);
1465
- #endif
1466
1097
  return Qnil;
1467
1098
  }
1468
1099
 
@@ -1475,13 +1106,9 @@ static VALUE native_install_case_parser(VALUE self)
1475
1106
  static VALUE native_variable_frontend(VALUE self, VALUE markup, VALUE context, VALUE variable)
1476
1107
  {
1477
1108
  if (!native_variable_ready) return Qnil;
1478
- #ifdef LIQUID_HAVE_GUARDED_COMPILER
1479
- return native_try_variable(self, markup, context, variable);
1480
- #else
1481
1109
  if (!RTEST(native_variable_candidate(self, markup, context))) return Qnil;
1482
1110
  VALUE helper = rb_const_get(mLiquidC, rb_intern("NativeParser"));
1483
1111
  return rb_funcall(helper, rb_intern("parse"), 3, markup, context, variable);
1484
- #endif
1485
1112
  }
1486
1113
 
1487
1114
  static VALUE native_variable_frontend_method(VALUE self, VALUE markup)
@@ -1496,695 +1123,6 @@ static VALUE native_enable_variable_frontend(VALUE self)
1496
1123
  return Qnil;
1497
1124
  }
1498
1125
 
1499
- #ifdef LIQUID_HAVE_GUARDED_COMPILER
1500
- static struct { VALUE owner, entry; ID method; bool public_call, control, builtin; } compiler_methods[256];
1501
- static size_t compiler_method_count;
1502
- static VALUE renderer_guard_entries = Qnil;
1503
- static VALUE compiler_body_class = Qnil;
1504
- static rb_alloc_func_t compiler_body_allocator;
1505
- static VALUE compiler_constants = Qnil;
1506
- static VALUE compiler_constant_watchers = Qnil;
1507
- static VALUE compiler_ancestor_prefixes = Qnil;
1508
- static VALUE control_helpers[2], control_else_class, control_environment_class, native_assign_class, native_capture_class, native_include_class;
1509
- static VALUE control_tag_new_entry;
1510
- static bool native_control_binding(VALUE lexical_owner, ID name, VALUE expected);
1511
-
1512
- static VALUE native_register_control(VALUE self, VALUE helpers, VALUE constants, VALUE prefixes, VALUE watchers)
1513
- {
1514
- Check_Type(helpers, T_ARRAY);
1515
- Check_Type(constants, T_ARRAY);
1516
- Check_Type(prefixes, T_ARRAY);
1517
- if (!NIL_P(watchers)) Check_Type(watchers, T_ARRAY);
1518
- if (!NIL_P(compiler_constants)) rb_raise(rb_eRuntimeError, "control guards already registered");
1519
- VALUE unbound = rb_const_get(rb_cObject, rb_intern("UnboundMethod"));
1520
- for (long i = 0; i < RARRAY_LEN(helpers); i++)
1521
- if (!rb_obj_is_kind_of(RARRAY_AREF(helpers, i), unbound)) rb_raise(rb_eTypeError, "expected UnboundMethod");
1522
- for (long i = 0; i < RARRAY_LEN(prefixes); i++) {
1523
- VALUE pair = RARRAY_AREF(prefixes, i);
1524
- Check_Type(pair, T_ARRAY);
1525
- if (RARRAY_LEN(pair) != 2 || !RB_TYPE_P(RARRAY_AREF(pair, 0), T_CLASS))
1526
- rb_raise(rb_eTypeError, "expected class and ancestor prefix");
1527
- Check_Type(RARRAY_AREF(pair, 1), T_ARRAY);
1528
- }
1529
- if (RARRAY_LEN(helpers) != 2) rb_raise(rb_eArgError, "invalid control helpers");
1530
- for (long i = 0; i < RARRAY_LEN(constants); i++) {
1531
- VALUE spec = RARRAY_AREF(constants, i);
1532
- Check_Type(spec, T_ARRAY);
1533
- if (RARRAY_LEN(spec) != 3) rb_raise(rb_eArgError, "invalid control constant");
1534
- VALUE owner = RARRAY_AREF(spec, 0);
1535
- if (!RB_TYPE_P(owner, T_CLASS) && !RB_TYPE_P(owner, T_MODULE)) rb_raise(rb_eTypeError, "expected module");
1536
- Check_Type(RARRAY_AREF(spec, 1), T_SYMBOL);
1537
- }
1538
- compiler_constants = constants;
1539
- compiler_constant_watchers = watchers;
1540
- compiler_ancestor_prefixes = prefixes;
1541
- control_else_class = rb_const_get(mLiquid, rb_intern("ElseCondition"));
1542
- control_environment_class = rb_const_get(mLiquid, rb_intern("Environment"));
1543
- native_assign_class = rb_const_get(mLiquid, rb_intern("Assign"));
1544
- native_capture_class = rb_const_get(mLiquid, rb_intern("Capture"));
1545
- native_include_class = rb_const_get(mLiquid, rb_intern("Include"));
1546
- control_tag_new_entry = liquid_method_entry(CLASS_OF(native_if_class), rb_intern("new"));
1547
- for (size_t i = 0; i < 2; i++) {
1548
- VALUE helper = RARRAY_AREF(helpers, i);
1549
- if (!rb_obj_is_kind_of(helper, rb_const_get(rb_cObject, rb_intern("UnboundMethod"))))
1550
- rb_raise(rb_eTypeError, "expected UnboundMethod");
1551
- control_helpers[i] = liquid_method_handle(rb_obj_method(helper, ID2SYM(rb_intern("bind_call"))));
1552
- }
1553
- return Qnil;
1554
- }
1555
- static VALUE compiler_stat = Qnil, compiler_epoch = Qundef;
1556
- static bool compiler_ready;
1557
- static bool compiler_registered;
1558
- static ID renderer_ids[3];
1559
-
1560
- static VALUE native_register_compiler(VALUE self, VALUE specifications, VALUE enabled)
1561
- {
1562
- Check_Type(specifications, T_ARRAY);
1563
- if (compiler_registered) rb_raise(rb_eRuntimeError, "compiler guards already registered");
1564
- if (RARRAY_LEN(specifications) > 256) rb_raise(rb_eArgError, "too many compiler guards");
1565
- for (long i = 0; i < RARRAY_LEN(specifications); i++) {
1566
- VALUE spec = RARRAY_AREF(specifications, i);
1567
- Check_Type(spec, T_ARRAY);
1568
- if (RARRAY_LEN(spec) != 3) rb_raise(rb_eArgError, "invalid compiler guard");
1569
- VALUE owner = RARRAY_AREF(spec, 0);
1570
- if (!RB_TYPE_P(owner, T_CLASS) && !RB_TYPE_P(owner, T_MODULE)) rb_raise(rb_eTypeError, "guard owner must be a module");
1571
- Check_Type(RARRAY_AREF(spec, 1), T_SYMBOL);
1572
- }
1573
- compiler_registered = true;
1574
- compiler_body_class = rb_const_get(mLiquidC, rb_intern("BlockBody"));
1575
- compiler_body_allocator = rb_get_alloc_func(compiler_body_class);
1576
- compiler_method_count = (size_t)RARRAY_LEN(specifications);
1577
- for (long i = 0; i < RARRAY_LEN(specifications); i++) {
1578
- VALUE spec = RARRAY_AREF(specifications, i);
1579
- VALUE owner = RARRAY_AREF(spec, 0);
1580
- ID method = SYM2ID(RARRAY_AREF(spec, 1));
1581
- VALUE entry = liquid_method_entry(owner, method);
1582
- compiler_methods[i].control = RTEST(RARRAY_AREF(spec, 2));
1583
- compiler_methods[i].builtin = liquid_method_basic_definition_p(owner, method);
1584
- compiler_methods[i].owner = owner;
1585
- compiler_methods[i].entry = entry;
1586
- compiler_methods[i].method = method;
1587
- compiler_methods[i].public_call =
1588
- (owner == compiler_body_class && method != rb_intern("initialize")) || owner == native_context_class ||
1589
- owner == CLASS_OF(compiler_body_class) || owner == CLASS_OF(control_else_class) ||
1590
- owner == CLASS_OF(native_condition_class) || owner == control_environment_class ||
1591
- owner == cLiquidVariableLookup || owner == cLiquidRangeLookup ||
1592
- ((owner == native_condition_class || owner == control_else_class) && method != rb_intern("initialize"));
1593
- rb_gc_register_address(&compiler_methods[i].owner);
1594
- rb_gc_register_address(&compiler_methods[i].entry);
1595
- }
1596
- bool renderers_standard = liquid_vm_render_methods_standard();
1597
- renderer_guard_entries = rb_ary_new_capa(3);
1598
- const char *names[] = { "render", "render_to_output_buffer", "render_obj_to_output" };
1599
- for (size_t i = 0; i < 3; i++) {
1600
- renderer_ids[i] = rb_intern(names[i]);
1601
- VALUE entry = renderers_standard ? liquid_method_entry(cLiquidVariable, renderer_ids[i]) : 0;
1602
- rb_ary_push(renderer_guard_entries, entry);
1603
- }
1604
- compiler_ready = RTEST(enabled);
1605
- if (!liquid_method_basic_definition_p(native_unbound_class, rb_intern("==")) ||
1606
- !liquid_method_basic_definition_p(native_unbound_class, rb_intern("super_method")) ||
1607
- !liquid_method_basic_definition_p(native_unbound_class, rb_intern("bind_call"))) compiler_ready = false;
1608
- if (!native_primitives_standard(false)) compiler_ready = false;
1609
- if (!NIL_P(constant_vm) && liquid_method_basic_definition_p(CLASS_OF(constant_vm), id_stat))
1610
- compiler_stat = liquid_method_handle(rb_obj_method(constant_vm, ID2SYM(id_stat)));
1611
- return compiler_ready ? Qtrue : Qfalse;
1612
- }
1613
-
1614
- bool variable_render_methods_standard(void)
1615
- {
1616
- if (!compiler_registered) return false;
1617
- for (size_t i = 0; i < 3; i++) {
1618
- VALUE current = liquid_method_entry(cLiquidVariable, renderer_ids[i]);
1619
- if (RARRAY_AREF(renderer_guard_entries, i) == current) continue;
1620
- // Re-aliasing a builtin creates a new method entry with the same body.
1621
- size_t gc = liquid_gc_count();
1622
- bool standard = liquid_vm_render_methods_standard();
1623
- if (gc != liquid_gc_count()) return false;
1624
- if (!standard) return false;
1625
- for (size_t j = 0; j < 3; j++)
1626
- rb_ary_store(renderer_guard_entries, (long)j, liquid_method_entry(cLiquidVariable, renderer_ids[j]));
1627
- break;
1628
- }
1629
- return true;
1630
- }
1631
-
1632
- bool variable_render_traced(void)
1633
- {
1634
- return liquid_vm_tracing();
1635
- }
1636
-
1637
- bool variable_output_method_standard(void)
1638
- {
1639
- return compiler_ready && !liquid_vm_tracing() && RARRAY_AREF(renderer_guard_entries, 2) ==
1640
- liquid_method_entry(cLiquidVariable, renderer_ids[2]);
1641
- }
1642
-
1643
- static bool native_compiler_method_entries_match(bool control)
1644
- {
1645
- for (size_t i = 0; i < compiler_method_count; i++) {
1646
- if (compiler_methods[i].control != control) continue;
1647
- VALUE owner = compiler_methods[i].owner;
1648
- ID method = compiler_methods[i].method;
1649
- VALUE current_entry = liquid_method_entry(owner, method);
1650
- if (compiler_methods[i].entry != current_entry) {
1651
- if (!compiler_methods[i].builtin || !liquid_method_basic_definition_p(owner, method)) return false;
1652
- compiler_methods[i].entry = current_entry;
1653
- }
1654
- if (compiler_methods[i].public_call && rb_method_boundp(owner, method, 3) != 1) return false;
1655
- }
1656
- return true;
1657
- }
1658
-
1659
- static bool native_compiler_methods_standard(variable_parse_args_t *args)
1660
- {
1661
- VALUE context = args->parse_context;
1662
- if (rb_get_alloc_func(compiler_body_class) != compiler_body_allocator) return false;
1663
- if (CLASS_OF(context) != native_context_class || (!NIL_P(args->code_obj) && CLASS_OF(args->code_obj) != compiler_body_class)) return false;
1664
- size_t validation_gc = liquid_gc_count();
1665
- VALUE epoch = Qundef;
1666
- if (!NIL_P(compiler_stat)) {
1667
- VALUE key = ID2SYM(id_constant_invalidations);
1668
- epoch = liquid_method_call(1, &key, compiler_stat);
1669
- }
1670
- bool unchanged_constants = epoch != Qundef && epoch == compiler_epoch;
1671
- if (!native_guards_match(context, Qnil, unchanged_constants)) return false;
1672
- if (!native_compiler_method_entries_match(false)) return false;
1673
- if (NIL_P(compiler_constants)) return false;
1674
- if (!unchanged_constants || NIL_P(compiler_constant_watchers)) {
1675
- for (long i = 0; i < RARRAY_LEN(compiler_constants); i++) {
1676
- VALUE spec = RARRAY_AREF(compiler_constants, i);
1677
- VALUE expected = RARRAY_AREF(spec, 2);
1678
- if (expected != compiler_body_class && expected != control_environment_class) continue;
1679
- if (!RTEST(native_constant_matches(Qnil, RARRAY_AREF(spec, 0), RARRAY_AREF(spec, 1), expected, Qnil))) return false;
1680
- }
1681
- }
1682
- VALUE klass = CLASS_OF(cLiquidVariable);
1683
- if (!liquid_method_basic_definition_p(klass, id_new_native) ||
1684
- !liquid_method_basic_definition_p(klass, id_allocate_native) ||
1685
- rb_get_alloc_func(cLiquidVariable) != rb_get_alloc_func(rb_cObject)) return false;
1686
- if (!native_primitives_standard(true)) return false;
1687
- if (rb_get_alloc_func(cLiquidVariableLookup) != rb_get_alloc_func(rb_cObject) ||
1688
- rb_get_alloc_func(cLiquidRangeLookup) != rb_get_alloc_func(rb_cObject) ||
1689
- rb_get_alloc_func(native_parser_class) != rb_get_alloc_func(rb_cObject)) return false;
1690
- if (validation_gc != liquid_gc_count()) return false;
1691
- compiler_epoch = epoch;
1692
- VALUE options = rb_ivar_get(context, id_options_native);
1693
- if (CLASS_OF(options) != rb_cHash ||
1694
- RTEST(rb_hash_lookup2(options, ID2SYM(id_stats_native), Qnil)) ||
1695
- RTEST(rb_hash_lookup2(options, ID2SYM(rb_intern("stats_callbacks")), Qnil))) return false;
1696
- if (!RTEST(rb_ivar_get(mLiquidC, id_enabled_native)) || RTEST(rb_ivar_get(context, id_disabled_native))) return false;
1697
- VALUE mode = rb_ivar_get(context, id_mode_native);
1698
- if (mode != ID2SYM(rb_intern("lax")) && mode != ID2SYM(rb_intern("warn")) && mode != ID2SYM(rb_intern("strict"))) return false;
1699
- VALUE cache = rb_ivar_get(context, id_cache_native);
1700
- if (RTEST(cache) && (CLASS_OF(cache) != rb_cHash || RB_OBJ_FROZEN(cache) || !native_string_cache(cache))) return false;
1701
- return true;
1702
- }
1703
-
1704
- // Structural hooks are needed only when entering the native control parser.
1705
- // A variable-only interval need not validate unrelated tag implementations.
1706
- static bool native_control_methods_standard(void)
1707
- {
1708
- if (!native_compiler_method_entries_match(true)) return false;
1709
- if (NIL_P(compiler_constants)) return false;
1710
- for (long i = 0; i < RARRAY_LEN(compiler_constants); i++) {
1711
- VALUE spec = RARRAY_AREF(compiler_constants, i);
1712
- if (!RTEST(native_constant_matches(Qnil, RARRAY_AREF(spec, 0), RARRAY_AREF(spec, 1), RARRAY_AREF(spec, 2), Qnil))) return false;
1713
- }
1714
- for (long i = 0; i < RARRAY_LEN(compiler_ancestor_prefixes); i++) {
1715
- VALUE pair = RARRAY_AREF(compiler_ancestor_prefixes, i);
1716
- VALUE prefix = RARRAY_AREF(pair, 1);
1717
- VALUE ancestors = rb_mod_ancestors(RARRAY_AREF(pair, 0));
1718
- if (RARRAY_LEN(ancestors) < RARRAY_LEN(prefix)) return false;
1719
- for (long j = 0; j < RARRAY_LEN(prefix); j++)
1720
- if (RARRAY_AREF(ancestors, j) != RARRAY_AREF(prefix, j)) return false;
1721
- }
1722
- return native_control_binding(native_if_class, rb_intern("Condition"), native_condition_class) &&
1723
- native_control_binding(native_if_class, rb_intern("ElseCondition"), control_else_class);
1724
- }
1725
-
1726
- static VALUE native_fast_header(VALUE self, VALUE markup)
1727
- {
1728
- if (!compiler_ready || liquid_vm_tracing()) return Qundef;
1729
- VALUE klass = CLASS_OF(self);
1730
- bool condition = klass == native_if_class || klass == native_unless_class;
1731
- if (!condition && klass != native_for_class) return Qundef;
1732
- if (native_opted_out("LIQUID_C_NATIVE_TAGS") || native_opted_out("LIQUID_C_NATIVE_PARSER")) return Qundef;
1733
- VALUE context = rb_ivar_get(self, id_parse_context_native);
1734
- VALUE mode = rb_ivar_get(context, id_mode_native);
1735
- if (mode != ID2SYM(rb_intern("warn")) && mode != ID2SYM(rb_intern("strict"))) return Qundef;
1736
- variable_parse_args_t args = { .parse_context = context, .code_obj = Qnil };
1737
- size_t gc = liquid_gc_count();
1738
- if (!native_compiler_methods_standard(&args) || !native_control_methods_standard() || gc != liquid_gc_count()) return Qundef;
1739
- if (condition && (rb_get_alloc_func(native_condition_class) != rb_get_alloc_func(rb_cObject) ||
1740
- !liquid_method_basic_definition_p(CLASS_OF(native_condition_class), id_new_native) ||
1741
- !liquid_method_basic_definition_p(CLASS_OF(native_condition_class), id_allocate_native))) return Qundef;
1742
- VALUE cache = rb_ivar_get(context, id_cache_native);
1743
- VALUE result = native_parse_payload(markup, RTEST(cache) ? cache : Qnil, condition ? 1 : 2, true, true, NULL);
1744
- if (NIL_P(result) || native_parse_interrupted(gc)) return Qundef;
1745
- VALUE payload = RARRAY_AREF(result, 0);
1746
- native_publish_cache(Qnil, cache, RARRAY_AREF(result, 1));
1747
- if (!condition) {
1748
- for (size_t i = 0; i < 6; i++) rb_ivar_set(self, id_for_fields[i], RARRAY_AREF(payload, i));
1749
- payload = Qnil;
1750
- }
1751
- RB_GC_GUARD(result);
1752
- return payload;
1753
- }
1754
-
1755
- static void native_restore_assembler(vm_assembler_t *code, const vm_assembler_t *saved,
1756
- size_t instruction_size, size_t constant_size)
1757
- {
1758
- for (size_t i = constant_size / sizeof(VALUE); i < c_buffer_size(&code->constants) / sizeof(VALUE); i++) {
1759
- st_data_t key = ((VALUE *)code->constants.data)[i];
1760
- st_delete(code->constants_table, &key, NULL);
1761
- }
1762
- code->instructions.data_end = code->instructions.data + instruction_size;
1763
- code->constants.data_end = code->constants.data + constant_size;
1764
- code->stack_size = saved->stack_size;
1765
- code->max_stack_size = saved->max_stack_size;
1766
- code->protected_stack_size = saved->protected_stack_size;
1767
- }
1768
-
1769
- bool native_compiler_guard(variable_parse_args_t *args)
1770
- {
1771
- variable_compile_guard_t *guard = args->guard;
1772
- if (!compiler_ready || !guard || liquid_vm_tracing() || !method_guard_count) return false;
1773
- #ifdef LIQUID_C_TEST_ALLOC_FAILURES
1774
- if (!NIL_P(native_parser_test_callback)) return false;
1775
- #endif
1776
- size_t gc = liquid_gc_count();
1777
- if (!guard->valid || gc != guard->gc_count) {
1778
- guard->valid = false;
1779
- guard->control_validated = false;
1780
- VALUE mode = rb_ivar_get(args->parse_context, id_mode_native);
1781
- if (mode != ID2SYM(rb_intern("lax")) && mode != ID2SYM(rb_intern("warn")) &&
1782
- mode != ID2SYM(rb_intern("strict"))) return false;
1783
-
1784
- if (native_opted_out("LIQUID_C_NATIVE_COMPILER") || native_opted_out("LIQUID_C_NATIVE_PARSER")) return false;
1785
-
1786
- if (!native_compiler_methods_standard(args) || native_parse_interrupted(gc)) return false;
1787
- guard->valid = true;
1788
- guard->gc_count = gc;
1789
- guard->cache = rb_ivar_get(args->parse_context, id_cache_native);
1790
- guard->environment = Qnil;
1791
- guard->tags = Qnil;
1792
- guard->literals_checked = false;
1793
- guard->control_checked = false;
1794
- }
1795
- return true;
1796
- }
1797
-
1798
- bool native_control_guard(variable_parse_args_t *args)
1799
- {
1800
- if (!native_compiler_guard(args)) return false;
1801
- if (!args->guard->control_validated) {
1802
- size_t gc = liquid_gc_count();
1803
- bool standard = native_control_methods_standard();
1804
- if (native_parse_interrupted(gc)) {
1805
- args->guard->valid = false;
1806
- return false;
1807
- }
1808
- if (!standard) return false;
1809
- args->guard->tags_enabled = !native_opted_out("LIQUID_C_NATIVE_TAGS");
1810
- args->guard->control_validated = true;
1811
- }
1812
- return true;
1813
- }
1814
-
1815
- bool native_assignment_class_p(VALUE klass)
1816
- {
1817
- return klass == native_assign_class;
1818
- }
1819
-
1820
- static bool native_control_binding(VALUE lexical_owner, ID name, VALUE expected)
1821
- {
1822
- VALUE lexical[] = { lexical_owner, mLiquid };
1823
- for (size_t i = 0; i < sizeof(lexical) / sizeof(lexical[0]); i++) {
1824
- VALUE owner = lexical[i];
1825
- if (rb_const_defined_at(owner, name))
1826
- return !RTEST(native_autoload_p(owner, name)) && rb_const_get_at(owner, name) == expected;
1827
- }
1828
- // The full ancestor prefix is verified by the control guard. Looking only
1829
- // at defined constants cannot trigger autoload or const_missing callbacks.
1830
- VALUE prefix = Qnil;
1831
- for (long i = 0; i < RARRAY_LEN(compiler_ancestor_prefixes); i++) {
1832
- VALUE pair = RARRAY_AREF(compiler_ancestor_prefixes, i);
1833
- if (RARRAY_AREF(pair, 0) == lexical_owner) {
1834
- prefix = RARRAY_AREF(pair, 1);
1835
- break;
1836
- }
1837
- }
1838
- if (NIL_P(prefix)) return false;
1839
- for (long i = 1; i < RARRAY_LEN(prefix); i++) {
1840
- VALUE owner = RARRAY_AREF(prefix, i);
1841
- if (rb_const_defined_at(owner, name))
1842
- return !RTEST(native_autoload_p(owner, name)) && rb_const_get_at(owner, name) == expected;
1843
- }
1844
- return false;
1845
- }
1846
-
1847
- // A result is publishable only while the checks made by native_compiler_guard
1848
- // still hold. Use its GC count across all allocations for the tag or variable.
1849
- static bool native_compiler_accepts_result(variable_compile_guard_t *guard, VALUE result)
1850
- {
1851
- if (NIL_P(result) || native_parse_interrupted(guard->gc_count)) guard->valid = false;
1852
- return guard->valid;
1853
- }
1854
-
1855
- static bool native_tag_constructor_standard(VALUE klass)
1856
- {
1857
- return rb_get_alloc_func(klass) == rb_get_alloc_func(rb_cObject) &&
1858
- liquid_method_entry(CLASS_OF(klass), id_new_native) == control_tag_new_entry &&
1859
- liquid_method_basic_definition_p(CLASS_OF(klass), id_allocate_native);
1860
- }
1861
-
1862
- static VALUE native_tag_alloc(VALUE klass, VALUE name, VALUE markup, VALUE context, VALUE line)
1863
- {
1864
- VALUE tag = rb_obj_alloc(klass);
1865
- rb_ivar_set(tag, rb_intern("@tag_name"), name);
1866
- rb_ivar_set(tag, rb_intern("@markup"), markup);
1867
- rb_ivar_set(tag, id_parse_context_native, context);
1868
- rb_ivar_set(tag, id_ivar_line_number, line);
1869
- return tag;
1870
- }
1871
-
1872
- // Assign retains its ordinary Variable and Ruby renderer. Only supported,
1873
- // non-diagnostic construction stays inside the current native parse interval.
1874
- VALUE native_parse_assignment(variable_parse_args_t *args, VALUE klass, VALUE name, VALUE markup)
1875
- {
1876
- if (!native_assignment_class_p(klass) || !native_control_guard(args)) return Qundef;
1877
- ID last_match = rb_intern("last_match");
1878
- if (!native_control_binding(native_assign_class, rb_intern("Variable"), cLiquidVariable) ||
1879
- !native_control_binding(native_assign_class, rb_intern("Regexp"), rb_cRegexp) ||
1880
- !liquid_method_basic_definition_p(CLASS_OF(rb_cRegexp), last_match) ||
1881
- rb_method_boundp(CLASS_OF(rb_cRegexp), last_match, 3) != 1) return Qundef;
1882
- if (!args->guard->tags_enabled || !native_tag_constructor_standard(klass)) return Qundef;
1883
- native_parser_t lhs = { .source = markup, .length = (size_t)RSTRING_LEN(markup) };
1884
- native_next(&lhs);
1885
- if (lhs.token != N_ID || native_word(&lhs, "contains") ||
1886
- RSTRING_PTR(markup)[lhs.end - 1] == '?') return Qundef;
1887
- size_t position = lhs.end;
1888
- while (position < lhs.length && native_space((unsigned char)RSTRING_PTR(markup)[position])) position++;
1889
- if (position == lhs.length || RSTRING_PTR(markup)[position++] != '=') return Qundef;
1890
- while (position < lhs.length && native_space((unsigned char)RSTRING_PTR(markup)[position])) position++;
1891
- VALUE target = native_slice(&lhs, lhs.start, lhs.end);
1892
- VALUE rhs = native_slice(&lhs, position, lhs.length);
1893
- if (!native_compiler_accepts_result(args->guard, rhs)) return Qundef;
1894
- VALUE cache = args->guard->cache;
1895
- VALUE parsed = native_parse_payload(rhs, RTEST(cache) ? cache : Qnil, 0, true, true, NULL);
1896
- if (!native_compiler_accepts_result(args->guard, parsed)) return Qundef;
1897
- VALUE line = rb_ivar_get(args->parse_context, id_ivar_line_number);
1898
- VALUE variable = variable_from_parse(rhs, args->parse_context, line, RARRAY_AREF(parsed, 0), RARRAY_AREF(parsed, 1));
1899
- if (!native_compiler_accepts_result(args->guard, variable)) return Qundef;
1900
- VALUE tag = native_tag_alloc(klass, name, markup, args->parse_context, line);
1901
- rb_ivar_set(tag, rb_intern("@to"), target);
1902
- rb_ivar_set(tag, rb_intern("@from"), variable);
1903
- if (!native_compiler_accepts_result(args->guard, tag)) return Qundef;
1904
- native_publish_cache(Qnil, cache, RARRAY_AREF(parsed, 2));
1905
- if (args->guard->gc_count != liquid_gc_count()) args->guard->valid = false;
1906
- RB_GC_GUARD(parsed);
1907
- RB_GC_GUARD(variable);
1908
- RB_GC_GUARD(rhs);
1909
- RB_GC_GUARD(target);
1910
- RB_GC_GUARD(markup);
1911
- RB_GC_GUARD(tag);
1912
- return tag;
1913
- }
1914
-
1915
- bool native_include_class_p(VALUE klass)
1916
- {
1917
- return klass == native_include_class;
1918
- }
1919
-
1920
- VALUE native_parse_include(variable_parse_args_t *args, VALUE klass, VALUE name, VALUE markup)
1921
- {
1922
- if (!native_include_class_p(klass) ||
1923
- rb_ivar_get(args->parse_context, id_mode_native) != ID2SYM(rb_intern("warn")) ||
1924
- !native_control_guard(args)) return Qundef;
1925
- if (!args->guard->tags_enabled || !native_tag_constructor_standard(klass)) return Qundef;
1926
- VALUE cache = args->guard->cache;
1927
- VALUE parsed = native_parse_payload(markup, RTEST(cache) ? cache : Qnil, 4, true, true, args->guard);
1928
- if (!native_compiler_accepts_result(args->guard, parsed)) return Qundef;
1929
- VALUE fields = RARRAY_AREF(parsed, 0);
1930
- if (!RTEST(RARRAY_AREF(fields, 5)) &&
1931
- (!liquid_method_basic_definition_p(rb_cFalseClass, rb_intern("==")) ||
1932
- rb_method_boundp(rb_cFalseClass, rb_intern("=="), 3) != 1)) return Qundef;
1933
- VALUE tag = native_tag_alloc(klass, name, markup, args->parse_context, rb_ivar_get(args->parse_context, id_ivar_line_number));
1934
- const char *names[] = { "@template_name_expr", "@variable_name_expr", "@alias_name", "@is_for_loop", "@attributes" };
1935
- for (size_t i = 0; i < 5; i++) {
1936
- if ((i == 1 && !RTEST(RARRAY_AREF(fields, 5))) || (i == 2 && NIL_P(RARRAY_AREF(fields, i)))) continue;
1937
- rb_ivar_set(tag, rb_intern(names[i]), RARRAY_AREF(fields, i));
1938
- }
1939
- if (!native_compiler_accepts_result(args->guard, tag)) return Qundef;
1940
- native_publish_cache(Qnil, cache, RARRAY_AREF(parsed, 1));
1941
- if (args->guard->gc_count != liquid_gc_count()) args->guard->valid = false;
1942
- RB_GC_GUARD(parsed);
1943
- return tag;
1944
- }
1945
-
1946
- VALUE native_parse_capture(variable_parse_args_t *args, VALUE klass, VALUE name, VALUE markup)
1947
- {
1948
- if (klass != native_capture_class ||
1949
- rb_ivar_get(args->parse_context, id_mode_native) != ID2SYM(rb_intern("warn")) ||
1950
- !native_control_guard(args)) return Qundef;
1951
- if (!args->guard->tags_enabled || !native_tag_constructor_standard(klass) ||
1952
- rb_get_alloc_func(compiler_body_class) != compiler_body_allocator ||
1953
- !liquid_method_basic_definition_p(CLASS_OF(compiler_body_class), id_new_native) ||
1954
- !liquid_method_basic_definition_p(CLASS_OF(compiler_body_class), id_allocate_native)) return Qundef;
1955
- native_parser_t parser = { .source = markup, .length = (size_t)RSTRING_LEN(markup) };
1956
- native_next(&parser);
1957
- if (parser.token != N_ID || native_word(&parser, "contains")) return Qundef;
1958
- size_t start = parser.start, end = parser.end;
1959
- native_next(&parser);
1960
- if (parser.token != N_END) return Qundef;
1961
- VALUE target = native_slice(&parser, start, end);
1962
- VALUE tag = native_tag_alloc(klass, name, markup, args->parse_context, rb_ivar_get(args->parse_context, id_ivar_line_number));
1963
- rb_ivar_set(tag, rb_intern("@blank"), Qtrue);
1964
- rb_ivar_set(tag, rb_intern("@to"), target);
1965
- if (!native_compiler_accepts_result(args->guard, tag)) return Qundef;
1966
- RB_GC_GUARD(target);
1967
- return tag;
1968
- }
1969
-
1970
- int native_control_kind(VALUE klass)
1971
- {
1972
- return klass == native_if_class || klass == native_unless_class ? 1 :
1973
- (klass == native_for_class ? 2 : (klass == native_capture_class ? 3 : 0));
1974
- }
1975
-
1976
- VALUE native_registered_tag(variable_parse_args_t *args, VALUE environment, VALUE name)
1977
- {
1978
- if (!args->guard->valid || args->guard->gc_count != liquid_gc_count()) return Qundef;
1979
- if (!native_compiler_guard(args) || CLASS_OF(environment) != control_environment_class) return Qundef;
1980
- variable_compile_guard_t *guard = args->guard;
1981
- VALUE tags = guard->tags;
1982
- if (guard->environment != environment) {
1983
- tags = rb_ivar_get(environment, rb_intern("@tags"));
1984
- size_t gc = liquid_gc_count();
1985
- if (CLASS_OF(tags) != rb_cHash || !native_string_cache(tags) ||
1986
- !liquid_method_basic_definition_p(rb_cHash, rb_intern("default")) ||
1987
- !NIL_P(native_hash_property(tags, HASH_DEFAULT_PROC_READER)) ||
1988
- !NIL_P(native_hash_property(tags, HASH_DEFAULT_READER)) || gc != liquid_gc_count()) return Qundef;
1989
- guard->environment = environment;
1990
- guard->tags = tags;
1991
- }
1992
- return rb_hash_lookup2(tags, name, Qnil);
1993
- }
1994
-
1995
- VALUE native_control_header(variable_parse_args_t *args, VALUE markup, int kind, bool commit)
1996
- {
1997
- if (!native_control_guard(args)) return Qnil;
1998
- if (!args->guard->control_checked) {
1999
- args->guard->control_checked = true;
2000
- args->guard->control_enabled = false;
2001
- VALUE mode = rb_ivar_get(args->parse_context, id_mode_native);
2002
- if (mode != ID2SYM(rb_intern("warn")) && mode != ID2SYM(rb_intern("strict"))) return Qnil;
2003
-
2004
- if (!args->guard->tags_enabled) return Qnil;
2005
- VALUE classes[] = { native_condition_class, control_else_class, native_if_class, native_unless_class, native_for_class };
2006
- for (size_t i = 0; i < sizeof(classes) / sizeof(classes[0]); i++) {
2007
- VALUE klass = classes[i];
2008
- bool original_new = i < 2 ? liquid_method_basic_definition_p(CLASS_OF(klass), id_new_native) :
2009
- liquid_method_entry(CLASS_OF(klass), id_new_native) == control_tag_new_entry;
2010
- if (rb_get_alloc_func(klass) != rb_get_alloc_func(rb_cObject) || !original_new ||
2011
- !liquid_method_basic_definition_p(CLASS_OF(klass), id_allocate_native)) return Qnil;
2012
- }
2013
- if (rb_get_alloc_func(compiler_body_class) != compiler_body_allocator ||
2014
- !liquid_method_basic_definition_p(CLASS_OF(compiler_body_class), id_new_native) ||
2015
- !liquid_method_basic_definition_p(CLASS_OF(compiler_body_class), id_allocate_native)) return Qnil;
2016
- args->guard->control_enabled = true;
2017
- }
2018
- if (!args->guard->control_enabled) return Qnil;
2019
- size_t gc = liquid_gc_count();
2020
- VALUE cache = args->guard->cache;
2021
- VALUE result = native_parse_payload(markup, RTEST(cache) ? cache : Qnil, kind == 1 ? 1 : 2, true, true, args->guard);
2022
- if (NIL_P(result) || native_parse_interrupted(gc)) return Qnil;
2023
- if (commit) native_publish_cache(Qnil, cache, RARRAY_AREF(result, 1));
2024
- RB_GC_GUARD(result);
2025
- return result;
2026
- }
2027
-
2028
- void native_control_for_fields(VALUE tag, VALUE payload)
2029
- {
2030
- for (size_t i = 0; i < 6; i++) rb_ivar_set(tag, id_for_fields[i], RARRAY_AREF(payload, i));
2031
- }
2032
-
2033
- void native_control_commit(variable_parse_args_t *args, VALUE header)
2034
- {
2035
- native_publish_cache(Qnil, args->guard->cache, RARRAY_AREF(header, 1));
2036
- }
2037
-
2038
- void native_control_attach(variable_parse_args_t *args, VALUE condition, VALUE body)
2039
- {
2040
- if (native_control_guard(args) && native_control_condition(condition))
2041
- rb_ivar_set(condition, rb_intern("@attachment"), body);
2042
- else {
2043
- args->guard->valid = false;
2044
- rb_funcallv_public(condition, rb_intern("attach"), 1, &body);
2045
- }
2046
- }
2047
-
2048
- VALUE native_control_else(variable_parse_args_t *args)
2049
- {
2050
- if (!native_control_guard(args) || rb_get_alloc_func(control_else_class) != rb_get_alloc_func(rb_cObject)) {
2051
- args->guard->valid = false;
2052
- return rb_funcall(control_else_class, id_new_native, 0);
2053
- }
2054
- size_t gc = liquid_gc_count();
2055
- VALUE node = rb_obj_alloc(control_else_class);
2056
- if (gc != liquid_gc_count()) {
2057
- args->guard->valid = false;
2058
- rb_funcall(node, rb_intern("initialize"), 0);
2059
- } else {
2060
- rb_ivar_set(node, rb_intern("@left"), Qnil);
2061
- rb_ivar_set(node, rb_intern("@operator"), Qnil);
2062
- rb_ivar_set(node, rb_intern("@right"), Qnil);
2063
- rb_ivar_set(node, rb_intern("@child_relation"), Qnil);
2064
- rb_ivar_set(node, rb_intern("@child_condition"), Qnil);
2065
- }
2066
- RB_GC_GUARD(node);
2067
- return node;
2068
- }
2069
-
2070
- bool native_control_condition(VALUE node)
2071
- {
2072
- return CLASS_OF(node) == native_condition_class || CLASS_OF(node) == control_else_class;
2073
- }
2074
-
2075
- typedef struct { variable_parse_args_t *args; VALUE tag; } native_finish_t;
2076
-
2077
- static void native_finish_body(variable_parse_args_t *args, VALUE body, const char *method)
2078
- {
2079
- if (!native_control_guard(args) || CLASS_OF(body) != compiler_body_class) args->guard->valid = false;
2080
- rb_funcallv_public(body, rb_intern(method), 0, NULL);
2081
- }
2082
-
2083
- static VALUE native_finish_attachment(native_finish_t *finish, VALUE condition)
2084
- {
2085
- if (native_control_guard(finish->args) && native_control_condition(condition))
2086
- return rb_ivar_get(condition, rb_intern("@attachment"));
2087
- finish->args->guard->valid = false;
2088
- return rb_funcallv_public(condition, rb_intern("attachment"), 0, NULL);
2089
- }
2090
-
2091
- static VALUE native_finish_condition(RB_BLOCK_CALL_FUNC_ARGLIST(condition, opaque))
2092
- {
2093
- native_finish_t *finish = (void *)opaque;
2094
- VALUE blank;
2095
- if (native_control_guard(finish->args) && native_control_kind(CLASS_OF(finish->tag)))
2096
- blank = rb_ivar_get(finish->tag, rb_intern("@blank"));
2097
- else {
2098
- finish->args->guard->valid = false;
2099
- blank = rb_funcall(finish->tag, rb_intern("blank?"), 0);
2100
- }
2101
- if (RTEST(blank)) native_finish_body(finish->args, native_finish_attachment(finish, condition), "remove_blank_strings");
2102
- native_finish_body(finish->args, native_finish_attachment(finish, condition), "freeze");
2103
- return Qnil;
2104
- }
2105
-
2106
- void native_control_finish(variable_parse_args_t *args, VALUE tag, int kind)
2107
- {
2108
- if (kind == 3) {
2109
- native_finish_body(args, rb_ivar_get(tag, rb_intern("@body")), "freeze");
2110
- return;
2111
- }
2112
- if (!args->guard->valid || !args->guard->control_validated || !native_control_guard(args)) {
2113
- args->guard->valid = false;
2114
- liquid_method_call(1, &tag, control_helpers[kind - 1]);
2115
- return;
2116
- }
2117
- if (kind == 1) {
2118
- native_finish_t finish = { args, tag };
2119
- rb_block_call(rb_ivar_get(tag, rb_intern("@blocks")), rb_intern("reverse_each"), 0, NULL,
2120
- native_finish_condition, (VALUE)&finish);
2121
- } else {
2122
- if (RTEST(rb_ivar_get(tag, rb_intern("@blank")))) {
2123
- VALUE otherwise = rb_ivar_get(tag, rb_intern("@else_block"));
2124
- if (!NIL_P(otherwise)) native_finish_body(args, otherwise, "remove_blank_strings");
2125
- native_finish_body(args, rb_ivar_get(tag, rb_intern("@for_block")), "remove_blank_strings");
2126
- }
2127
- VALUE otherwise = rb_ivar_get(tag, rb_intern("@else_block"));
2128
- if (!NIL_P(otherwise)) native_finish_body(args, otherwise, "freeze");
2129
- native_finish_body(args, rb_ivar_get(tag, rb_intern("@for_block")), "freeze");
2130
- }
2131
- }
2132
-
2133
- bool native_compile_variable(variable_parse_args_t *args, VALUE line_number)
2134
- {
2135
- if (!compiler_ready || !args->guard || liquid_vm_tracing()) return false;
2136
- // The tokenizer owns and pins the frozen source during parsing.
2137
- VALUE source = args->source;
2138
- size_t offset = (size_t)(args->markup - RSTRING_PTR(source));
2139
- size_t length = (size_t)(args->markup_end - args->markup);
2140
- int coderange = ENC_CODERANGE_UNKNOWN;
2141
- rb_str_coderange_scan_restartable(args->markup, args->markup_end, utf8_encoding, &coderange);
2142
- if (coderange == ENC_CODERANGE_BROKEN || coderange == ENC_CODERANGE_UNKNOWN) return false;
2143
- native_parser_t parser = { .source = source, .cache = Qnil,
2144
- .pending = Qnil, .position = offset, .length = offset + length, .code = args->code, .guarded = true, .compact_pending = true };
2145
- native_parser_t probe = parser, validated_name;
2146
- if (!native_validate_variable(&probe, &validated_name)) return false;
2147
- if (!native_compiler_guard(args)) return false;
2148
- variable_compile_guard_t *guard = args->guard;
2149
- parser.cache = RTEST(guard->cache) ? guard->cache : Qnil;
2150
- parser.initial_gc_count = guard->gc_count;
2151
- // The descriptor owns its markup bytes independently of the tokenizer.
2152
- // Temporary parsing uses offsets into the tokenizer's pinned source.
2153
- VALUE node = variable_placeholder_new(source, offset, length, args->parse_context, line_number);
2154
- if (!native_compiler_accepts_result(guard, node)) return false;
2155
- vm_assembler_t saved = *args->code;
2156
- size_t instruction_size = c_buffer_size(&saved.instructions);
2157
- size_t constant_size = c_buffer_size(&saved.constants);
2158
- vm_assembler_add_unique_variable(args->code, line_number, node);
2159
- args->code->protected_stack_size = args->code->stack_size;
2160
- // Reuse the lexical preflight without copying its earlier cache/GC state.
2161
- native_parser_t name_probe = parser;
2162
- name_probe.position = validated_name.position;
2163
- name_probe.start = validated_name.start;
2164
- name_probe.end = validated_name.end;
2165
- name_probe.token = validated_name.token;
2166
- VALUE result = native_variable_body_probed((VALUE)&parser, &name_probe);
2167
- if (!native_compiler_accepts_result(guard, result)) {
2168
- native_restore_assembler(args->code, &saved, instruction_size, constant_size);
2169
- return false;
2170
- }
2171
- variable_placeholder_set(node, parser.variable_name, parser.variable_filters);
2172
- vm_assembler_add_pop_write(args->code);
2173
- // Only builtin Hash operations on verified plain String keys execute here.
2174
- if (RB_TYPE_P(parser.pending, T_STRING)) native_publish_entry(parser.pending, parser.pending_value, parser.cache);
2175
- else native_publish_cache(Qnil, parser.cache, parser.pending);
2176
- if (guard->gc_count != liquid_gc_count()) guard->valid = false;
2177
- RB_GC_GUARD(result);
2178
- RB_GC_GUARD(node);
2179
- RB_GC_GUARD(source);
2180
- RB_GC_GUARD(parser.pending);
2181
- RB_GC_GUARD(parser.pending_value);
2182
- return true;
2183
- }
2184
- #else
2185
- #ifdef HAVE_RB_CALLABLE_METHOD_ENTRY
2186
- static VALUE native_fast_header(VALUE self, VALUE markup) { return Qundef; }
2187
- #endif
2188
1126
  bool native_compiler_guard(variable_parse_args_t *args) { return false; }
2189
1127
  bool native_include_class_p(VALUE klass) { return false; }
2190
1128
  VALUE native_parse_include(variable_parse_args_t *args, VALUE klass, VALUE name, VALUE markup) { return Qundef; }
@@ -2205,29 +1143,9 @@ bool native_compile_variable(variable_parse_args_t *args, VALUE line_number) { r
2205
1143
  bool variable_render_methods_standard(void) { return liquid_vm_render_methods_standard(); }
2206
1144
  bool variable_render_traced(void) { return true; }
2207
1145
  bool variable_output_method_standard(void) { return false; }
2208
- #endif
2209
1146
 
2210
1147
  void liquid_define_native_parser(void)
2211
1148
  {
2212
- #ifdef LIQUID_HAVE_GUARDED_COMPILER
2213
- rb_global_variable(&renderer_guard_entries);
2214
- rb_global_variable(&compiler_body_class);
2215
- rb_global_variable(&compiler_constants);
2216
- rb_global_variable(&native_assign_class);
2217
- rb_global_variable(&native_capture_class);
2218
- rb_global_variable(&native_include_class);
2219
- rb_global_variable(&compiler_constant_watchers);
2220
- rb_global_variable(&compiler_ancestor_prefixes);
2221
- rb_global_variable(&control_else_class);
2222
- rb_global_variable(&control_environment_class);
2223
- rb_global_variable(&control_tag_new_entry);
2224
- for (size_t i = 0; i < 2; i++) rb_global_variable(&control_helpers[i]);
2225
- rb_define_singleton_method(mLiquidC, "native_register_control", native_register_control, 4);
2226
- rb_global_variable(&compiler_stat);
2227
- rb_global_variable(&compiler_epoch);
2228
- rb_define_singleton_method(mLiquidC, "native_register_compiler", native_register_compiler, 2);
2229
- rb_define_singleton_method(mLiquidC, "native_install_compiler_context", native_install_compiler_context, 0);
2230
- #endif
2231
1149
  #ifdef LIQUID_C_TEST_ALLOC_FAILURES
2232
1150
  rb_global_variable(&native_parser_test_callback);
2233
1151
  rb_define_singleton_method(mLiquidC, "native_parser_test_callback=", native_set_parser_test_callback, 1);
@@ -2313,12 +1231,6 @@ void liquid_define_native_parser(void)
2313
1231
  rb_global_variable(&native_for_class);
2314
1232
  rb_global_variable(&native_original_if);
2315
1233
  rb_global_variable(&native_original_for);
2316
- #ifdef HAVE_RB_CALLABLE_METHOD_ENTRY
2317
- rb_global_variable(&native_if_parse_entry);
2318
- rb_global_variable(&native_for_parse_entry);
2319
- rb_global_variable(&native_switching_module);
2320
- for (size_t i = 0; i < 3; i++) rb_global_variable(&native_context_entries[i]);
2321
- #endif
2322
1234
  rb_global_variable(&native_context_class);
2323
1235
  rb_global_variable(&native_case_class);
2324
1236
  native_context_class = rb_const_get(mLiquid, rb_intern("ParseContext"));
@@ -2326,9 +1238,6 @@ void liquid_define_native_parser(void)
2326
1238
  native_if_class = rb_const_get(mLiquid, rb_intern("If"));
2327
1239
  native_unless_class = rb_const_get(mLiquid, rb_intern("Unless"));
2328
1240
  native_for_class = rb_const_get(mLiquid, rb_intern("For"));
2329
- #ifdef LIQUID_HAVE_GUARDED_COMPILER
2330
- rb_define_singleton_method(mLiquidC, "native_try_parse_variable", native_try_variable, 3);
2331
- #endif
2332
1241
  rb_define_singleton_method(mLiquidC, "native_install_case_parser", native_install_case_parser, 0);
2333
1242
  rb_define_singleton_method(mLiquidC, "native_install_header_parser", native_install_header_parser, 2);
2334
1243
  rb_define_singleton_method(mLiquidC, "native_install_strict_context", native_install_strict_context, 0);
@@ -2336,11 +1245,6 @@ void liquid_define_native_parser(void)
2336
1245
  rb_define_singleton_method(mLiquidC, "native_variable_frontend", native_variable_frontend, 3);
2337
1246
  rb_define_private_method(rb_const_get(mLiquid, rb_intern("Variable")), "liquid_c_native_parse", native_variable_frontend_method, 1);
2338
1247
  rb_define_singleton_method(mLiquidC, "native_enable_variable_frontend", native_enable_variable_frontend, 0);
2339
- #ifdef HAVE_RB_CALLABLE_METHOD_ENTRY
2340
- rb_define_singleton_method(mLiquidC, "native_constant_watchers_supported?", native_watchers_supported, 1);
2341
- rb_define_singleton_method(mLiquidC, "native_parser_register_guards", native_register_guards, 3);
2342
- rb_define_singleton_method(mLiquidC, "native_parser_methods_compatible?", native_methods_compatible, 2);
2343
- #endif
2344
1248
  rb_define_singleton_method(mLiquidC, "native_constant_matches?", native_constant_matches, 4);
2345
1249
  rb_define_singleton_method(mLiquidC, "native_public_method?", native_public_method, 2);
2346
1250
  rb_define_singleton_method(mLiquidC, "native_frontend_candidate?", native_frontend_candidate, 1);