Class: Kumi::Core::Analyzer::PassManager

Inherits:
Object
  • Object
show all
Defined in:
lib/kumi/core/analyzer/pass_manager.rb

Defined Under Namespace

Classes: Instrumentation, PassRun

Constant Summary collapse

DEFAULT_PASS_BUDGET_MS =

Default per-pass wall-clock budget in milliseconds. 0 disables the check. Overridable via the KUMI_PASS_BUDGET_MS env var or the :pass_budget_ms option. A generous default so only true runaways trip.

20_000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(passes) ⇒ PassManager

Returns a new instance of PassManager.



38
39
40
41
# File 'lib/kumi/core/analyzer/pass_manager.rb', line 38

def initialize(passes)
  @passes = passes
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



31
32
33
# File 'lib/kumi/core/analyzer/pass_manager.rb', line 31

def errors
  @errors
end

#passesObject (readonly)

Returns the value of attribute passes.



31
32
33
# File 'lib/kumi/core/analyzer/pass_manager.rb', line 31

def passes
  @passes
end

Instance Method Details

#run(syntax_tree, initial_state = nil, errors = [], options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/kumi/core/analyzer/pass_manager.rb', line 43

def run(syntax_tree, initial_state = nil, errors = [], options = {})
  state = initial_state || AnalysisState.new

  passes.each_with_index do |pass_class, phase_index|
    pass_name = pass_class.name.split("::").last
    Checkpoint.entering(pass_name:, idx: phase_index, state:) if options[:checkpoint_enabled]

    instrumentation = Instrumentation.new(pass_name, options)
    instrumentation.before(state)

    run = PassRun.new(pass_class: pass_class, phase_index: phase_index, instrumentation: instrumentation)
    state, budget_failure = run_one_pass(run, syntax_tree, state, errors, options)
    return budget_failure if budget_failure

    instrumentation.after_success(state)
    Checkpoint.leaving(pass_name:, idx: phase_index, state:) if options[:checkpoint_enabled]

    return failure_result(state, errors, pass_class, phase_index) unless errors.empty?
    return ExecutionResult.success(final_state: state, stopped: true) if options[:stop_after] == pass_name
  end

  ExecutionResult.success(final_state: state)
end