Class: Rigor::Inference::SyntheticMethodIndex
- Inherits:
-
Object
- Object
- Rigor::Inference::SyntheticMethodIndex
- 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[T] 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
-
#class_names ⇒ Object
readonly
Returns the value of attribute class_names.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(entries: [], class_names: []) ⇒ SyntheticMethodIndex
constructor
A new instance of SyntheticMethodIndex.
-
#knows_class?(name) ⇒ Boolean
True when
nameis a substrate-synthesised class (an ADR-36 variant subclass). -
#lookup_instance(class_name, method_name) ⇒ Object
Returns an Array of matching SyntheticMethod records in plugin-registration order.
- #lookup_singleton(class_name, method_name) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(entries: [], class_names: []) ⇒ SyntheticMethodIndex
Returns a new instance of SyntheticMethodIndex.
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rigor/inference/synthetic_method_index.rb', line 31 def initialize(entries: [], class_names: []) 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)) @class_names = Ractor.make_shareable(class_names.to_a.map(&:to_s).uniq.freeze) @class_name_set = Ractor.make_shareable(@class_names.to_set) freeze end |
Instance Attribute Details
#class_names ⇒ Object (readonly)
Returns the value of attribute class_names.
23 24 25 |
# File 'lib/rigor/inference/synthetic_method_index.rb', line 23 def class_names @class_names end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
23 24 25 |
# File 'lib/rigor/inference/synthetic_method_index.rb', line 23 def entries @entries end |
Instance Method Details
#empty? ⇒ Boolean
45 46 47 |
# File 'lib/rigor/inference/synthetic_method_index.rb', line 45 def empty? entries.empty? && class_names.empty? end |
#knows_class?(name) ⇒ Boolean
True when name is a substrate-synthesised class (an ADR-36 variant subclass). Used by
Environment#class_known? so the constant resolves and .new dispatches.
51 52 53 |
# File 'lib/rigor/inference/synthetic_method_index.rb', line 51 def knows_class?(name) @class_name_set.include?(name.to_s) 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.
57 58 59 |
# File 'lib/rigor/inference/synthetic_method_index.rb', line 57 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
61 62 63 |
# File 'lib/rigor/inference/synthetic_method_index.rb', line 61 def lookup_singleton(class_name, method_name) @by_singleton.fetch([class_name, method_name.to_sym], EMPTY_ROW) end |
#to_h ⇒ Object
65 66 67 |
# File 'lib/rigor/inference/synthetic_method_index.rb', line 65 def to_h { "entries" => entries.map(&:to_h), "class_names" => class_names } end |