report global cycle endpoints
This commit is contained in:
@@ -7088,6 +7088,28 @@ Cycle_Frame :: struct {
|
||||
next_dependency: int,
|
||||
}
|
||||
|
||||
cycle_global_location :: proc(checker: ^Checker, global_id: hir.Global_Id) -> (name, path: string, line: int) {
|
||||
name = "<unknown>"
|
||||
path = "<unknown>"
|
||||
line = 1
|
||||
index := int(global_id)
|
||||
if global_id == hir.INVALID_GLOBAL || index >= len(checker.module.globals) {
|
||||
return
|
||||
}
|
||||
name = symbol_text(checker, checker.module.globals[global_id].name)
|
||||
if index >= len(checker.ast_module.globals) {
|
||||
return
|
||||
}
|
||||
span := checker.ast_module.globals[global_id].span
|
||||
source_file := source.source_for_span(checker.diagnostics, span)
|
||||
if source_file == nil {
|
||||
return
|
||||
}
|
||||
path = source_file.path
|
||||
line, _ = source.line_and_column(source_file, span.start)
|
||||
return
|
||||
}
|
||||
|
||||
detect_global_cycles_visit :: proc(checker: ^Checker, global_id: hir.Global_Id, states: []u8) {
|
||||
if states[global_id] == 2 {
|
||||
return
|
||||
@@ -7120,11 +7142,18 @@ detect_global_cycles_visit :: proc(checker: ^Checker, global_id: hir.Global_Id,
|
||||
continue
|
||||
}
|
||||
if states[dependency] == 1 {
|
||||
start_name, start_path, start_line := cycle_global_location(checker, dependency)
|
||||
end_name, end_path, end_line := cycle_global_location(checker, frame.global)
|
||||
id := source.addf(
|
||||
checker.diagnostics,
|
||||
checker.ast_module.globals[dependency].span,
|
||||
"global initialization cycle involving '%s'",
|
||||
symbol_text(checker, checker.module.globals[dependency].name),
|
||||
"global initialization cycle from '%s' at %s:%d to '%s' at %s:%d",
|
||||
start_name,
|
||||
start_path,
|
||||
start_line,
|
||||
end_name,
|
||||
end_path,
|
||||
end_line,
|
||||
)
|
||||
checker.module.globals[dependency].diagnostic = id
|
||||
checker.module.globals[dependency].problematic = true
|
||||
|
||||
Reference in New Issue
Block a user