Class: Rigor::Inference::FallbackTracer
- Inherits:
-
Object
- Object
- Rigor::Inference::FallbackTracer
- Includes:
- Enumerable
- Defined in:
- lib/rigor/inference/fallback_tracer.rb,
sig/rigor/inference.rbs
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).
Instance Method Summary collapse
- #clear ⇒ void
- #each {|arg0| ... } ⇒ Object
- #empty? ⇒ Boolean
- #events ⇒ Array[Fallback]
- #families ⇒ Array[Symbol]
-
#initialize ⇒ FallbackTracer
constructor
A new instance of FallbackTracer.
- #kinds ⇒ Array[Class]
- #record_fallback(event) ⇒ void
- #size ⇒ Integer
Constructor Details
#initialize ⇒ FallbackTracer
Returns a new instance of FallbackTracer.
12 13 14 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 12 def initialize @events = [] end |
Instance Method Details
#clear ⇒ void
This method returns an undefined value.
52 53 54 55 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 52 def clear @events.clear self end |
#each ⇒ self #each ⇒ Enumerator[Fallback, self]
35 36 37 38 39 40 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 35 def each(&block) return @events.each unless block @events.each(&block) self end |
#empty? ⇒ Boolean
27 28 29 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 27 def empty? @events.empty? end |
#events ⇒ Array[Fallback]
16 17 18 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 16 def events @events.dup.freeze end |
#families ⇒ Array[Symbol]
48 49 50 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 48 def families @events.map(&:family).uniq end |
#kinds ⇒ Array[Class]
44 45 46 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 44 def kinds @events.map(&:node_class).uniq end |
#record_fallback(event) ⇒ void
This method returns an undefined value.
20 21 22 23 24 25 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 20 def record_fallback(event) raise ArgumentError, "expected Rigor::Inference::Fallback, got #{event.class}" unless event.is_a?(Fallback) @events << event self end |
#size ⇒ Integer
31 32 33 |
# File 'lib/rigor/inference/fallback_tracer.rb', line 31 def size @events.size end |