Class: Rigor::Inference::SyntheticMethodIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/rigor/inference/synthetic_method_index.rb

Overview

Frozen, Ractor-shareable lookup table for the synthetic methods emitted by ADR-16 Tier C declarations during a single ‘Analysis::Runner#run`. Constructed by the pre-pass scanner (see SyntheticMethodScanner) and consulted by MethodDispatcher below `RbsDispatch.try_dispatch` (per WD13: user-authored RBS overrides substrate synthesis).

The index is keyed by ‘(class_name, method_name, kind)`. A single key may resolve to multiple SyntheticMethod records if two plugins emit the same name (e.g. `rigor-dry-struct` and a hypothetical `rigor-dry-struct-extras` both registering the same attribute). Per ADR-16 WD11 / the WD-discussion in `## Open questions` the dispatcher uses first-wins by registration order; this index preserves that order in `lookup`’s return.

## Slice 2b — return-type precision posture

The recorded ‘SyntheticMethod#return_type` is a String (e.g. `“ActiveStorage::Attached::One”`), preserved verbatim from the manifest’s emit table. Slice 2b’s engine wiring treats every match as returning ‘Dynamic` per WD13’s floor — the recorded string is the input to a later slice’s precision promotion via ADR-13’s ‘Plugin::TypeNodeResolver`.

Constant Summary collapse

EMPTY_ROW =
[].freeze
EMPTY =
new(entries: []).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries: []) ⇒ SyntheticMethodIndex

Returns a new instance of SyntheticMethodIndex.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rigor/inference/synthetic_method_index.rb', line 34

def initialize(entries: [])
  unless entries.is_a?(Array) && entries.all?(SyntheticMethod)
    raise ArgumentError,
          "SyntheticMethodIndex#entries must be an Array of SyntheticMethod, got #{entries.inspect}"
  end

  @entries = Ractor.make_shareable(entries.dup)
  @by_instance = Ractor.make_shareable(bucket(entries, SyntheticMethod::INSTANCE))
  @by_singleton = Ractor.make_shareable(bucket(entries, SyntheticMethod::SINGLETON))
  freeze
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



32
33
34
# File 'lib/rigor/inference/synthetic_method_index.rb', line 32

def entries
  @entries
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/rigor/inference/synthetic_method_index.rb', line 46

def empty?
  entries.empty?
end

#lookup_instance(class_name, method_name) ⇒ Object

Returns an Array of matching Rigor::Inference::SyntheticMethod records in plugin-registration order. Empty Array when no plugin has declared a Tier C entry that interpolates to this name.



53
54
55
# File 'lib/rigor/inference/synthetic_method_index.rb', line 53

def lookup_instance(class_name, method_name)
  @by_instance.fetch([class_name, method_name.to_sym], EMPTY_ROW)
end

#lookup_singleton(class_name, method_name) ⇒ Object



57
58
59
# File 'lib/rigor/inference/synthetic_method_index.rb', line 57

def lookup_singleton(class_name, method_name)
  @by_singleton.fetch([class_name, method_name.to_sym], EMPTY_ROW)
end

#to_hObject



61
62
63
# File 'lib/rigor/inference/synthetic_method_index.rb', line 61

def to_h
  { "entries" => entries.map(&:to_h) }
end