Module: MilkTea::CBackend::FeatureDetection

Included in:
MilkTea::CBackend
Defined in:
lib/milk_tea/core/c_backend/feature_detection.rb

Constant Summary collapse

FORMAT_HELPER_DEPENDENCIES =
{
  'mt_format_append_str' => %w[mt_format_append_bytes mt_format_check_capacity],
  'mt_format_append_cstr' => %w[mt_format_append_bytes mt_format_check_capacity mt_format_cstr_len],
  'mt_format_append_bool' => %w[mt_format_append_bytes mt_format_check_capacity],
  'mt_format_append_ptr_uint' => %w[mt_format_check_capacity mt_format_ptr_uint_len],
  'mt_format_append_ulong' => %w[mt_format_check_capacity mt_format_ulong_len],
  'mt_format_append_uint' => %w[mt_format_append_ptr_uint mt_format_check_capacity mt_format_ptr_uint_len],
  'mt_format_append_long' => %w[mt_format_append_bytes mt_format_check_capacity mt_format_append_ulong mt_format_ulong_len],
  'mt_format_append_int' => %w[mt_format_append_bytes mt_format_check_capacity mt_format_append_ptr_uint mt_format_ptr_uint_len],
  'mt_format_append_ulong_hex' => %w[mt_format_check_capacity mt_format_ulong_hex_len],
  'mt_format_append_ulong_hex_upper' => %w[mt_format_check_capacity mt_format_ulong_hex_len],
  'mt_format_append_long_hex' => %w[mt_format_append_bytes mt_format_check_capacity mt_format_append_ulong_hex mt_format_ulong_hex_len],
  'mt_format_append_long_hex_upper' => %w[mt_format_append_bytes mt_format_check_capacity mt_format_append_ulong_hex_upper mt_format_ulong_hex_len],
  'mt_format_append_ulong_oct' => %w[mt_format_check_capacity mt_format_ulong_oct_len],
  'mt_format_append_long_oct' => %w[mt_format_append_bytes mt_format_check_capacity mt_format_append_ulong_oct mt_format_ulong_oct_len],
  'mt_format_append_ulong_bin' => %w[mt_format_check_capacity mt_format_ulong_bin_len],
  'mt_format_append_long_bin' => %w[mt_format_append_bytes mt_format_check_capacity mt_format_append_ulong_bin mt_format_ulong_bin_len],
  'mt_format_append_float' => %w[mt_format_check_capacity mt_format_float_len],
  'mt_format_append_double' => %w[mt_format_check_capacity mt_format_double_len],
  'mt_format_append_double_precision' => %w[mt_format_check_capacity mt_format_double_precision_len],
  'mt_format_int_len' => %w[mt_format_ptr_uint_len],
  'mt_format_long_len' => %w[mt_format_ulong_len],
  'mt_format_long_hex_len' => %w[mt_format_ulong_hex_len],
  'mt_format_long_oct_len' => %w[mt_format_ulong_oct_len],
  'mt_format_long_bin_len' => %w[mt_format_ulong_bin_len],
}.freeze

Instance Method Summary collapse

Instance Method Details

#aggregate_contains_string_view?(type, visiting = nil) ⇒ Boolean

Returns:

  • (Boolean)


410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 410

def aggregate_contains_string_view?(type, visiting = nil)
  return false unless type
  return false if visiting&.key?(type)

  visiting = (visiting || {}).merge(type => true)
  case type
  when Types::StringView
    true
  when Types::Struct
    type.fields.any? { |_name, field_type| aggregate_contains_string_view?(field_type, visiting) }
  when Types::Variant
    type.arm_names.any? { |arm_name| (type.arm(arm_name) || {}).any? { |_field_name, field_type| aggregate_contains_string_view?(field_type, visiting) } }
  when Types::Nullable
    aggregate_contains_string_view?(type.base, visiting)
  when Types::GenericInstance
    type.arguments.any? { |argument| aggregate_contains_string_view?(argument, visiting) }
  else
    false
  end
end

#aggregate_equality_needs_string_view?Boolean

Returns:

  • (Boolean)


406
407
408
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 406

def aggregate_equality_needs_string_view?
  aggregate_equality_types.any? { |type| aggregate_contains_string_view?(type) }
end

#aggregate_equality_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


334
335
336
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 334

def aggregate_equality_type?(type)
  struct_equality_type?(type) || type.is_a?(Types::Variant) || type.is_a?(Types::VariantArmPayload)
end

#aggregate_equality_typesObject

Aggregate types (structs and variants) compared with ==/!= anywhere in the program, transitively closed over value-typed fields so nested aggregates used inside a comparison also get an equality helper.



311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 311

def aggregate_equality_types
  @aggregate_equality_types ||= begin
    types = Set.new
    emitted_functions.each do |function|
      function.body.each do |statement|
        statement_matches_expression_predicate?(
          statement,
          expression_pred: ->(expression) { collect_aggregate_equality_from_expression(expression, types) },
        )
      end
    end
    types
  end
end

#collect_aggregate_equality_dependencies(type, types) ⇒ Object



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 372

def collect_aggregate_equality_dependencies(type, types)
  return if types.include?(type)

  case type
  when Types::Variant
    types << type
    type.arm_names.each do |arm_name|
      (type.arm(arm_name) || {}).each_value { |field_type| collect_value_field_equality_dependencies(field_type, types) }
    end
  when Types::VariantArmPayload
    types << type
    arm_fields = type.variant_type.arm(type.arm_name) || {}
    arm_fields.each_value { |field_type| collect_value_field_equality_dependencies(field_type, types) }
  when Types::Struct
    return unless struct_equality_type?(type)

    types << type
    type.fields.each_value { |field_type| collect_value_field_equality_dependencies(field_type, types) }
  end
end

#collect_aggregate_equality_from_expression(expression, types) ⇒ Object



338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 338

def collect_aggregate_equality_from_expression(expression, types)
  case expression
  when IR::Binary
    collect_aggregate_equality_from_expression(expression.left, types)
    collect_aggregate_equality_from_expression(expression.right, types)
    if EQUALITY_OPERATORS.include?(expression.operator) && aggregate_equality_type?(expression.left.type)
      collect_aggregate_equality_dependencies(expression.left.type, types)
    end
  when IR::Call
    collect_aggregate_equality_from_expression(expression.callee, types) unless expression.callee.is_a?(String)
    expression.arguments.each { |argument| collect_aggregate_equality_from_expression(argument, types) }
  when IR::Member
    collect_aggregate_equality_from_expression(expression.receiver, types)
  when IR::Index, IR::CheckedIndex, IR::CheckedSpanIndex, IR::NullableIndex, IR::NullableSpanIndex
    collect_aggregate_equality_from_expression(expression.receiver, types)
    collect_aggregate_equality_from_expression(expression.index, types)
  when IR::Unary
    collect_aggregate_equality_from_expression(expression.operand, types)
  when IR::Conditional
    collect_aggregate_equality_from_expression(expression.condition, types)
    collect_aggregate_equality_from_expression(expression.then_expression, types)
    collect_aggregate_equality_from_expression(expression.else_expression, types)
  when IR::ReinterpretExpr, IR::Cast, IR::AddressOf
    collect_aggregate_equality_from_expression(expression.expression, types)
  when IR::AggregateLiteral
    expression.fields.each { |field| collect_aggregate_equality_from_expression(field.value, types) }
  when IR::ArrayLiteral
    expression.elements.each { |element| collect_aggregate_equality_from_expression(element, types) }
  when IR::VariantLiteral
    expression.fields.each { |field| collect_aggregate_equality_from_expression(field.value, types) }
  end
  false
end

#collect_value_field_equality_dependencies(type, types) ⇒ Object



393
394
395
396
397
398
399
400
401
402
403
404
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 393

def collect_value_field_equality_dependencies(type, types)
  case type
  when Types::Nullable
    collect_value_field_equality_dependencies(type.base, types)
  when Types::Struct, Types::Variant
    collect_aggregate_equality_dependencies(type, types)
  when Types::VariantArmPayload
    collect_aggregate_equality_dependencies(type, types)
  when Types::GenericInstance
    collect_value_field_equality_dependencies(array_element_type(type), types) if array_type?(type)
  end
end

#expression_uses_named_call?(expression, callees) ⇒ Boolean

Returns:

  • (Boolean)


481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 481

def expression_uses_named_call?(expression, callees)
  case expression
  when IR::Call
    callees.include?(expression.callee) ||
      (!expression.callee.is_a?(String) && expression_uses_named_call?(expression.callee, callees)) ||
      expression.arguments.any? { |argument| expression_uses_named_call?(argument, callees) }
  when IR::Member
    expression_uses_named_call?(expression.receiver, callees)
  when IR::Index, IR::CheckedIndex, IR::CheckedSpanIndex, IR::NullableIndex, IR::NullableSpanIndex
    expression_uses_named_call?(expression.receiver, callees) || expression_uses_named_call?(expression.index, callees)
  when IR::Unary
    expression_uses_named_call?(expression.operand, callees)
  when IR::Binary
    expression_uses_named_call?(expression.left, callees) || expression_uses_named_call?(expression.right, callees)
  when IR::Conditional
    expression_uses_named_call?(expression.condition, callees) || expression_uses_named_call?(expression.then_expression, callees) || expression_uses_named_call?(expression.else_expression, callees)
  when IR::ReinterpretExpr, IR::Cast, IR::AddressOf
    expression_uses_named_call?(expression.expression, callees)
  when IR::AggregateLiteral
    expression.fields.any? { |field| expression_uses_named_call?(field.value, callees) }
  when IR::ArrayLiteral
    expression.elements.any? { |element| expression_uses_named_call?(element, callees) }
  when IR::VariantLiteral
    expression.fields.any? { |field| expression_uses_named_call?(field.value, callees) }
  else
    false
  end
end

#expression_uses_str_equality?(expression) ⇒ Boolean

Returns:

  • (Boolean)


510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 510

def expression_uses_str_equality?(expression)
  case expression
  when IR::Binary
    string_equality_expression?(expression) || expression_uses_str_equality?(expression.left) || expression_uses_str_equality?(expression.right)
  when IR::Call
    (!expression.callee.is_a?(String) && expression_uses_str_equality?(expression.callee)) || expression.arguments.any? { |argument| expression_uses_str_equality?(argument) }
  when IR::Member
    expression_uses_str_equality?(expression.receiver)
  when IR::Index, IR::CheckedIndex, IR::CheckedSpanIndex, IR::NullableIndex, IR::NullableSpanIndex
    expression_uses_str_equality?(expression.receiver) || expression_uses_str_equality?(expression.index)
  when IR::Unary
    expression_uses_str_equality?(expression.operand)
  when IR::Conditional
    expression_uses_str_equality?(expression.condition) || expression_uses_str_equality?(expression.then_expression) || expression_uses_str_equality?(expression.else_expression)
  when IR::ReinterpretExpr, IR::Cast, IR::AddressOf
    expression_uses_str_equality?(expression.expression)
  when IR::AggregateLiteral
    expression.fields.any? { |field| expression_uses_str_equality?(field.value) }
  when IR::ArrayLiteral
    expression.elements.any? { |element| expression_uses_str_equality?(element) }
  when IR::VariantLiteral
    expression.fields.any? { |field| expression_uses_str_equality?(field.value) }
  else
    false
  end
end

#expression_uses_vector_math?(expr) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 91

def expression_uses_vector_math?(expr)
  return false unless expr
  return true if expr.respond_to?(:type) && type_contains_vector_math?(expr.type)
  case expr
  when IR::Assignment
    expression_uses_vector_math?(expr.target) || expression_uses_vector_math?(expr.value)
  when IR::AggregateLiteral
    expr.fields.any? { |f| expression_uses_vector_math?(f.value) }
  when IR::Binary
    expression_uses_vector_math?(expr.left) || expression_uses_vector_math?(expr.right)
  when IR::Unary
    expression_uses_vector_math?(expr.operand)
  when IR::Call
    expr.arguments.any? { |a| expression_uses_vector_math?(a) }
  when IR::Member
    expression_uses_vector_math?(expr.receiver)
  when IR::Index
    expression_uses_vector_math?(expr.receiver)
  when IR::Conditional
    expression_uses_vector_math?(expr.then_expression) || expression_uses_vector_math?(expr.else_expression)
  else
    false
  end
end

#format_helper_calleesObject



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 186

def format_helper_callees
  %w[
    mt_format_str_make
    mt_format_str_release
    mt_format_cstr_len
    mt_format_bool_len
    mt_format_ptr_uint_len
    mt_format_ulong_len
    mt_format_uint_len
    mt_format_long_len
    mt_format_int_len
    mt_format_ulong_hex_len
    mt_format_long_hex_len
    mt_format_float_len
    mt_format_double_len
    mt_format_double_precision_len
    mt_format_ulong_oct_len
    mt_format_long_oct_len
    mt_format_ulong_bin_len
    mt_format_long_bin_len
    mt_format_append_str
    mt_format_append_cstr
    mt_format_append_bool
    mt_format_append_ptr_uint
    mt_format_append_ulong
    mt_format_append_uint
    mt_format_append_long
    mt_format_append_int
    mt_format_append_ulong_hex
    mt_format_append_ulong_hex_upper
    mt_format_append_long_hex
    mt_format_append_long_hex_upper
    mt_format_append_float
    mt_format_append_double
    mt_format_append_double_precision
    mt_format_append_ulong_oct
    mt_format_append_long_oct
    mt_format_append_ulong_bin
    mt_format_append_long_bin
  ]
end

#function_uses_named_call?(function, callees) ⇒ Boolean

Returns:

  • (Boolean)


431
432
433
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 431

def function_uses_named_call?(function, callees)
  function.body.any? { |statement| statement_uses_named_call?(statement, callees) }
end

#function_uses_str_equality?(function) ⇒ Boolean

Returns:

  • (Boolean)


435
436
437
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 435

def function_uses_str_equality?(function)
  function.body.any? { |statement| statement_uses_str_equality?(statement) }
end

#required_format_helper_calleesObject



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 228

def required_format_helper_callees
  @required_format_helper_callees ||= begin
    helpers = {}

    emitted_functions.each do |function|
      format_helper_callees.each do |callee|
        helpers[callee] = true if function_uses_named_call?(function, [callee])
      end
    end

    loop do
      changed = false

      helpers.keys.each do |helper|
        (FORMAT_HELPER_DEPENDENCIES[helper] || []).each do |dependency|
          next if helpers[dependency]

          helpers[dependency] = true
          changed = true
        end
      end

      break unless changed
    end

    helpers
  end
end

#statement_matches_expression_predicate?(statement, expression_pred:, **kwargs) ⇒ Boolean

Returns:

  • (Boolean)


439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 439

def statement_matches_expression_predicate?(statement, expression_pred:, **kwargs)
  case statement
  when IR::LocalDecl
    statement.value && expression_pred.call(statement.value, **kwargs)
  when IR::Assignment
    expression_pred.call(statement.target, **kwargs) || expression_pred.call(statement.value, **kwargs)
  when IR::BlockStmt
    statement.body.any? { |inner| statement_matches_expression_predicate?(inner, expression_pred:, **kwargs) }
  when IR::WhileStmt
    expression_pred.call(statement.condition, **kwargs) ||
      statement.body.any? { |inner| statement_matches_expression_predicate?(inner, expression_pred:, **kwargs) }
  when IR::ForStmt
    statement_matches_expression_predicate?(statement.init, expression_pred:, **kwargs) ||
      expression_pred.call(statement.condition, **kwargs) ||
      statement.body.any? { |inner| statement_matches_expression_predicate?(inner, expression_pred:, **kwargs) } ||
      statement_matches_expression_predicate?(statement.post, expression_pred:, **kwargs)
  when IR::IfStmt
    expression_pred.call(statement.condition, **kwargs) ||
      statement.then_body.any? { |inner| statement_matches_expression_predicate?(inner, expression_pred:, **kwargs) } ||
      (statement.else_body && statement.else_body.any? { |inner| statement_matches_expression_predicate?(inner, expression_pred:, **kwargs) })
  when IR::SwitchStmt
    expression_pred.call(statement.expression, **kwargs) ||
      statement.cases.any? { |switch_case| switch_case.body.any? { |inner| statement_matches_expression_predicate?(inner, expression_pred:, **kwargs) } }
  when IR::StaticAssert
    expression_pred.call(statement.condition, **kwargs) || expression_pred.call(statement.message, **kwargs)
  when IR::ReturnStmt
    statement.value && expression_pred.call(statement.value, **kwargs)
  when IR::ExpressionStmt
    expression_pred.call(statement.expression, **kwargs)
  else
    false
  end
end

#statement_uses_named_call?(statement, callees) ⇒ Boolean

Returns:

  • (Boolean)


473
474
475
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 473

def statement_uses_named_call?(statement, callees)
  statement_matches_expression_predicate?(statement, expression_pred: ->(e) { expression_uses_named_call?(e, callees) })
end

#statement_uses_str_equality?(statement) ⇒ Boolean

Returns:

  • (Boolean)


477
478
479
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 477

def statement_uses_str_equality?(statement)
  statement_matches_expression_predicate?(statement, expression_pred: ->(e) { expression_uses_str_equality?(e) })
end

#statement_uses_vector_math?(stmt) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 65

def statement_uses_vector_math?(stmt)
  case stmt
  when IR::LocalDecl
    type_contains_vector_math?(stmt.type)
  when IR::Assignment
    type_contains_vector_math?(stmt.target.type) || expression_uses_vector_math?(stmt.value)
  when IR::ExpressionStmt
    expression_uses_vector_math?(stmt.expression)
  when IR::ReturnStmt
    stmt.value && expression_uses_vector_math?(stmt.value)
  when IR::BlockStmt
    stmt.body.any? { |s| statement_uses_vector_math?(s) }
  when IR::WhileStmt
    stmt.body.any? { |s| statement_uses_vector_math?(s) }
  when IR::ForStmt
    stmt.body.any? { |s| statement_uses_vector_math?(s) }
  when IR::IfStmt
    stmt.then_body.any? { |s| statement_uses_vector_math?(s) } ||
      (stmt.else_body && stmt.else_body.any? { |s| statement_uses_vector_math?(s) })
  when IR::SwitchStmt
    stmt.cases.any? { |c| c.body.any? { |s| statement_uses_vector_math?(s) } }
  else
    false
  end
end

#struct_equality_typesObject



326
327
328
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 326

def struct_equality_types
  @struct_equality_types ||= aggregate_equality_types.select { |type| struct_equality_type?(type) || type.is_a?(Types::VariantArmPayload) }
end

#type_contains_string_view?(type) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 33

def type_contains_string_view?(type)
  return false unless type
  return true if type.is_a?(Types::StringView)
  case type
  when Types::Nullable
    type_contains_string_view?(type.base)
  when Types::Span
    type_contains_string_view?(type.element_type)
  when Types::GenericInstance
    type.arguments.any? { |a| type_contains_string_view?(a) }
  else
    false
  end
end

#type_contains_vector_math?(type) ⇒ Boolean

Returns:

  • (Boolean)


116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 116

def type_contains_vector_math?(type)
  return false unless type
  return true if type.is_a?(Types::Vector) || type.is_a?(Types::Matrix) || type.is_a?(Types::Quaternion)
  case type
  when Types::Nullable
    type_contains_vector_math?(type.base)
  when Types::Span
    type_contains_vector_math?(type.element_type)
  when Types::GenericInstance
    type.arguments.any? { |a| type_contains_vector_math?(a) }
  else
    false
  end
end

#uses_async_memory_helpers?Boolean

Returns:

  • (Boolean)


159
160
161
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 159

def uses_async_memory_helpers?
  emitted_functions.any? { |function| function_uses_named_call?(function, %w[mt_async_alloc mt_async_free]) }
end

#uses_cyclic_variant_heap_copy?Boolean

Returns:

  • (Boolean)


163
164
165
166
167
168
169
170
171
172
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 163

def uses_cyclic_variant_heap_copy?
  all_variants = emitted_aggregate_variants + collect_generic_variant_decls
  all_variants.any? do |v|
    v.arms.any? do |arm|
      arm.fields.any? do |f|
        aggregate_field_creates_cycle?(f.type, v.linkage_name)
      end
    end
  end
end

#uses_detach_helper?Boolean

Returns:

  • (Boolean)


182
183
184
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 182

def uses_detach_helper?
  emitted_functions.any? { |function| function_uses_named_call?(function, %w[mt_detach_run mt_detach_join]) }
end

#uses_entrypoint_argv_helpers?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 151

def uses_entrypoint_argv_helpers?
  emitted_functions.any? { |function| function_uses_named_call?(function, %w[mt_entry_argv_to_span_str mt_free_entry_argv_strs]) }
end

#uses_fatal_helper?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 131

def uses_fatal_helper?
  uses_mt_fatal_helper? || uses_mt_fatal_str_helper?
end

#uses_fmt_builder?Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 6

def uses_fmt_builder?
  return @uses_fmt_builder if defined?(@uses_fmt_builder)

  @uses_fmt_builder = emitted_functions.any? do |function|
    function_uses_named_call?(function, %w[mt_fmt_begin])
  end
end

#uses_foreign_temp_cstr_helpers?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 147

def uses_foreign_temp_cstr_helpers?
  emitted_functions.any? { |function| function_uses_named_call?(function, %w[mt_foreign_str_to_cstr_temp mt_free_foreign_cstr_temp mt_foreign_strs_to_cstrs_temp mt_free_foreign_cstrs_temp]) }
end

#uses_format_helpers?Boolean

Returns:

  • (Boolean)


284
285
286
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 284

def uses_format_helpers?
  !required_format_helper_callees.empty?
end

#uses_mt_fatal_helper?Boolean

Returns:

  • (Boolean)


135
136
137
138
139
140
141
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 135

def uses_mt_fatal_helper?
  return true if @debug_guards

  collect_checked_array_index_types.any? || collect_checked_span_index_types.any? ||
    uses_format_helpers? ||
    emitted_functions.any? { |function| function_uses_named_call?(function, %w[mt_fatal mt_str_buffer_len mt_str_buffer_as_cstr mt_str_buffer_assign mt_str_buffer_append mt_foreign_str_to_cstr_temp mt_foreign_strs_to_cstrs_temp]) }
end

#uses_mt_fatal_str_helper?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 143

def uses_mt_fatal_str_helper?
  emitted_functions.any? { |function| function_uses_named_call?(function, %w[mt_fatal_str]) }
end

#uses_parallel_for_helper?Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 174

def uses_parallel_for_helper?
  emitted_functions.any? { |function| function_uses_named_call?(function, %w[mt_parallel_for]) }
end

#uses_spawn_all_helper?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 178

def uses_spawn_all_helper?
  emitted_functions.any? { |function| function_uses_named_call?(function, %w[mt_spawn_all]) }
end

#uses_str_buffer_helpers?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 155

def uses_str_buffer_helpers?
  emitted_functions.any? { |function| function_uses_named_call?(function, %w[mt_str_buffer_len mt_str_buffer_as_cstr mt_str_buffer_clear mt_str_buffer_assign mt_str_buffer_append mt_str_buffer_prepare_write]) }
end

#uses_str_concat_helper?Boolean

Returns:

  • (Boolean)


292
293
294
295
296
297
298
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 292

def uses_str_concat_helper?
  return @uses_str_concat if defined?(@uses_str_concat)

  @uses_str_concat = emitted_functions.any? do |function|
    function_uses_named_call?(function, %w[mt_str_concat])
  end
end

#uses_str_equality_helper?Boolean

Returns:

  • (Boolean)


288
289
290
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 288

def uses_str_equality_helper?
  emitted_functions.any? { |function| function_uses_str_equality?(function) }
end

#uses_string_view?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 14

def uses_string_view?
  return @uses_string_view if defined?(@uses_string_view)
  @uses_string_view = begin
    uses_fatal_helper? || uses_format_helpers? || uses_str_buffer_helpers? ||
      uses_entrypoint_argv_helpers? || uses_str_equality_helper? ||
      uses_foreign_temp_cstr_helpers? ||
      emitted_functions.any? do |function|
        type_contains_string_view?(function.return_type) ||
          function.params.any? { |param| type_contains_string_view?(param.type) }
      end ||
      emitted_aggregate_structs.any? { |s| s.fields.any? { |f| type_contains_string_view?(f.type) } } ||
      emitted_aggregate_unions.any? { |u| u.fields.any? { |f| type_contains_string_view?(f.type) } } ||
      emitted_aggregate_variants.any? { |v| v.arms.any? { |a| a.fields.any? { |f| type_contains_string_view?(f.type) } } } ||
      emitted_constants.any? { |c| type_contains_string_view?(c.type) } ||
      emitted_globals.any? { |g| type_contains_string_view?(g.type) } ||
      !collect_str_literals.empty?
  end
end

#uses_struct_equality_helper?Boolean

Returns:

  • (Boolean)


304
305
306
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 304

def uses_struct_equality_helper?
  !struct_equality_types.empty?
end

#uses_variant_equality_helper?Boolean

Returns:

  • (Boolean)


300
301
302
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 300

def uses_variant_equality_helper?
  !variant_equality_types.empty?
end

#uses_vector_math_types?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 48

def uses_vector_math_types?
  return @uses_vector_math_types if defined?(@uses_vector_math_types)
  @uses_vector_math_types = begin
    emitted_functions.any? do |function|
      type_contains_vector_math?(function.return_type) ||
        function.params.any? { |param| type_contains_vector_math?(param.type) } ||
        function.body.any? { |stmt| statement_uses_vector_math?(stmt) }
    end ||
      emitted_aggregate_structs.any? { |s| s.fields.any? { |f| type_contains_vector_math?(f.type) } } ||
      emitted_aggregate_unions.any? { |u| u.fields.any? { |f| type_contains_vector_math?(f.type) } } ||
      emitted_aggregate_variants.any? { |v| v.arms.any? { |a| a.fields.any? { |f| type_contains_vector_math?(f.type) } } } ||
      emitted_constants.any? { |c| type_contains_vector_math?(c.type) } ||
      emitted_globals.any? { |g| type_contains_vector_math?(g.type) }
  end
  @uses_vector_math_types
end

#variant_equality_typesObject



330
331
332
# File 'lib/milk_tea/core/c_backend/feature_detection.rb', line 330

def variant_equality_types
  @variant_equality_types ||= aggregate_equality_types.select { |type| type.is_a?(Types::Variant) }
end