Module: IgniterLang::CompilationReport

Defined in:
lib/igniter_lang/compilation_report.rb

Class Method Summary collapse

Class Method Details

.diagnostic_category_for(report) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/igniter_lang/compilation_report.rb', line 76

def diagnostic_category_for(report)
  stages = report.fetch("stages", {})
  return "typechecker_oof" if stages.fetch("typecheck", nil) == "oof"
  return "emitter_error" if stages.fetch("emit", nil) == "error"

  "classifier_oof"
end

.enrich(report:, parsed:) ⇒ Object



57
58
59
60
61
62
63
64
65
66
# File 'lib/igniter_lang/compilation_report.rb', line 57

def enrich(report:, parsed:)
  contract_name = parsed.fetch("contracts", []).fetch(0, {}).fetch("name", nil)
  report.merge(
    "diagnostics" => Diagnostics.enrich(
      report.fetch("diagnostics", []),
      category: diagnostic_category_for(report),
      contract: contract_name
    )
  )
end

.internal_error(format_version:, source_path:, rule:, error:) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/igniter_lang/compilation_report.rb', line 37

def internal_error(format_version:, source_path:, rule:, error:)
  {
    "kind" => "compilation_report",
    "format_version" => format_version,
    "program_id" => "compilation_report/#{rule}",
    "grammar_version" => "unknown",
    "source_hash" => nil,
    "source_path" => source_path.to_s,
    "pass_result" => "error",
    "stages" => {
      "parse" => "unknown",
      "classify" => "unknown",
      "typecheck" => "unknown",
      "emit" => "unknown"
    },
    "diagnostics" => internal_error_diagnostics(rule, error),
    "semantic_ir_ref" => nil
  }
end

.internal_error_diagnostics(rule, error) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/igniter_lang/compilation_report.rb', line 84

def internal_error_diagnostics(rule, error)
  return Diagnostics.from_assembler_refusal(error) if rule == "assembler_refused"

  Diagnostics.enrich(
    [
      {
        "rule" => rule,
        "severity" => "error",
        "message" => "#{error.class}: #{error.message}"
      }
    ],
    category: "emitter_error"
  )
end

.parse_failure(format_version:, parsed:, source_path:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/igniter_lang/compilation_report.rb', line 9

def parse_failure(format_version:, parsed:, source_path:)
  {
    "kind" => "compilation_report",
    "format_version" => format_version,
    "program_id" => "compilation_report/parse_error",
    "grammar_version" => parsed.fetch("grammar_version"),
    "source_hash" => parsed.fetch("source_hash"),
    "source_path" => source_path.to_s,
    "pass_result" => "error",
    "stages" => {
      "parse" => "error",
      "classify" => "skipped",
      "typecheck" => "skipped",
      "emit" => "skipped"
    },
    "diagnostics" => Diagnostics.from_parse_errors(parsed.fetch("parse_errors")),
    "semantic_ir_ref" => nil
  }
end

.runtime_smoke_failure(report:, smoke:, source_path:) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/igniter_lang/compilation_report.rb', line 29

def runtime_smoke_failure(report:, smoke:, source_path:)
  report.merge(
    "pass_result" => "error",
    "source_path" => source_path.to_s,
    "diagnostics" => report.fetch("diagnostics", []) + Diagnostics.from_runtime_smoke(smoke)
  )
end

.with_compiler_profile_contract_validation(report:, validation:) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/igniter_lang/compilation_report.rb', line 68

def with_compiler_profile_contract_validation(report:, validation:)
  return report unless validation

  report.merge(
    "compiler_profile_contract_validation" => validation.merge("report_only" => true)
  )
end