Class: IgniterLang::CompilerOrchestrator

Inherits:
Object
  • Object
show all
Defined in:
lib/igniter_lang/compiler_orchestrator.rb

Constant Summary collapse

FORMAT_VERSION =
SemanticIREmitter::FORMAT_VERSION
STRICT_REQUIREMENT_KIND =
"compiler_profile_contract_strict_requirement"
STRICT_REQUIREMENT_MODE =
"strict_contract_digest"
CONTRACT_DIGEST_MISMATCH_CODE =
"compiler_profile_contract.contract_digest_mismatch"
CONTRACT_DIGEST_REFUSAL_CODE =
"compiler_profile_contract_refusal.contract_digest_mismatch"
STRICT_REQUIREMENT_MALFORMED_CODE =
"compiler_profile_contract_refusal.strict_requirement_malformed"
STRICT_REQUIREMENT_SOURCES =
["proof_local_gate", "internal_test_seam"].freeze

Instance Method Summary collapse

Constructor Details

#initialize(classifier: Classifier.new, typechecker: TypeChecker.new, emitter: SemanticIREmitter.new, assembler: Assembler.new, compiler_profile_contract_provider: nil, compiler_profile_contract_strict_requirement: nil) ⇒ CompilerOrchestrator

Returns a new instance of CompilerOrchestrator.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/igniter_lang/compiler_orchestrator.rb', line 29

def initialize(
  classifier: Classifier.new,
  typechecker: TypeChecker.new,
  emitter: SemanticIREmitter.new,
  assembler: Assembler.new,
  compiler_profile_contract_provider: nil,
  compiler_profile_contract_strict_requirement: nil
)
  @classifier = classifier
  @typechecker = typechecker
  @emitter = emitter
  @assembler = assembler
  @compiler_profile_contract_provider = compiler_profile_contract_provider
  @compiler_profile_contract_strict_requirement = compiler_profile_contract_strict_requirement
end

Instance Method Details

#compile(source_path:, out_path:, sample_input: nil, sample_input_resolver: nil, runtime_smoke: nil, compiler_profile_source: nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/igniter_lang/compiler_orchestrator.rb', line 45

def compile(
  source_path:,
  out_path:,
  sample_input: nil,
  sample_input_resolver: nil,
  runtime_smoke: nil,
  compiler_profile_source: nil
)
  source_path = Pathname.new(source_path)
  out_path = Pathname.new(out_path)
  parsed = ParsedProgram.parse(File.read(source_path), source_path: source_path.to_s).to_h
  return parse_failure(parsed, source_path, out_path) unless parsed.fetch("parse_errors").empty?

  resolved_sample_input = sample_input || resolve_sample_input(parsed, sample_input_resolver)
  classified = @classifier.classify(parsed, sample_input: resolved_sample_input)
  typed = @typechecker.typecheck(classified)
  compilation = @emitter.emit_typed(typed)
  report = CompilationReport.enrich(
    report: compilation.fetch("compilation_report"),
    parsed: parsed
  )
  semantic_ir = compilation.fetch("semantic_ir")
  report_for_assembly = report

  if report.fetch("pass_result") == "ok"
    validation = compiler_profile_contract_validation(
      source_path: source_path,
      out_path: out_path,
      parsed_program: parsed,
      compiler_profile_source: compiler_profile_source
    )
    report = CompilationReport.with_compiler_profile_contract_validation(
      report: report,
      validation: validation
    )
  end

  return refusal(report, source_path, out_path) unless report.fetch("pass_result") == "ok"

  strict_terminal = compiler_profile_contract_strict_terminal(
    report: report,
    source_path: source_path
  )
  return strict_terminal if strict_terminal

  # PROP-036: compiler_profile_source is passed unchanged to the assembler.
  # The orchestrator is a transport boundary only — it does not derive, load,
  # discover, default, finalize, or validate profiles. Assembler validation
  # remains authoritative. Nil preserves legacy_optional behavior.
  assembled = @assembler.assemble_artifacts(
    case_name: case_name_for(source_path, parsed),
    report: report_for_assembly,
    semantic_ir: semantic_ir,
    target_dir: out_path,
    compiler_profile_source: compiler_profile_source
  )
  smoke = runtime_smoke&.call(out_path: out_path, sample_input: resolved_sample_input)

  if smoke && !smoke.fetch("trusted")
    smoke_report = CompilationReport.runtime_smoke_failure(
      report: report,
      smoke: smoke,
      source_path: source_path
    )
    return refusal(smoke_report, source_path, out_path, status: "runtime_smoke_failed")
  end

  {
    "status" => "ok",
    "result" => CompilerResult.ok(
      format_version: FORMAT_VERSION,
      semantic_ir: semantic_ir,
      source_path: source_path,
      report: report,
      igapp_path: out_path,
      contracts: assembled.fetch("contracts"),
      runtime_smoke: smoke
    ),
    "parsed_program" => parsed,
    "classified_program" => classified,
    "typed_program" => typed,
    "semantic_ir" => semantic_ir,
    "compilation_report" => report,
    "assembled" => assembled,
    "sample_input" => resolved_sample_input
  }
rescue AssemblyRefused => e
  report = CompilationReport.internal_error(
    format_version: FORMAT_VERSION,
    source_path: source_path,
    rule: "assembler_refused",
    error: e
  )
  refusal(report, source_path, out_path, status: "assembler_refused")
rescue => e
  report = CompilationReport.internal_error(
    format_version: FORMAT_VERSION,
    source_path: source_path,
    rule: "compiler_error",
    error: e
  )
  refusal(report, source_path, out_path, status: "error")
end