Class: Rigor::Inference::FallbackTracer
- Inherits:
-
Object
- Object
- Rigor::Inference::FallbackTracer
- Includes:
- Enumerable
- Defined in:
- lib/rigor/inference/fallback_tracer.rb
Overview
Mutable observer that accumulates Rigor::Inference::Fallback events emitted by the type-inference engine. Pass an instance to Rigor::Scope#type_of(node, tracer: …) to record every fail-soft fallback. The tracer MUST NOT change the return value of type_of; see docs/internal-spec/inference-engine.md (Fail-Soft Policy).
Future slices may add additional record_* methods (e.g. record_dispatch_miss for Slice 3, record_budget_cutoff for Slice 5); the namespaced method names exist so a single tracer can collect multiple event families without confusing them.
Instance Method Summary collapse
- #clear ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #events ⇒ Object
- #families ⇒ Object
-
#initialize ⇒ FallbackTracer
constructor
A new instance of FallbackTracer.
- #kinds ⇒ Object
- #record_fallback(event) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ FallbackTracer
Returns a new instance of FallbackTracer.
18 19 20 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 18 def initialize @events = [] end |
Instance Method Details
#clear ⇒ Object
58 59 60 61 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 58 def clear @events.clear self end |
#each(&block) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 41 def each(&block) return @events.each unless block @events.each(&block) self end |
#empty? ⇒ Boolean
33 34 35 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 33 def empty? @events.empty? end |
#events ⇒ Object
22 23 24 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 22 def events @events.dup.freeze end |
#families ⇒ Object
54 55 56 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 54 def families @events.map(&:family).uniq end |
#kinds ⇒ Object
50 51 52 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 50 def kinds @events.map(&:node_class).uniq end |
#record_fallback(event) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 26 def record_fallback(event) raise ArgumentError, "expected Rigor::Inference::Fallback, got #{event.class}" unless event.is_a?(Fallback) @events << event self end |
#size ⇒ Object
37 38 39 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 37 def size @events.size end |