harsher compile error

This commit is contained in:
2026-02-20 12:52:40 -06:00
parent 8d449e6fc6
commit e6d05abd03
2 changed files with 74 additions and 3 deletions

View File

@@ -191,6 +191,7 @@ function extract_module_summaries(compiled) {
if (_summary_resolver == null) return null
var instrs = null
var summaries = []
var unresolved = []
var i = 0
var j = 0
var n = 0
@@ -205,6 +206,7 @@ function extract_module_summaries(compiled) {
var path = null
var result_slot = 0
var summary = null
var inv_n = 0
if (compiled.main == null) return null
instrs = compiled.main.instructions
@@ -254,6 +256,9 @@ function extract_module_summaries(compiled) {
summary = _summary_resolver(path)
if (summary != null) {
summaries[] = {slot: result_slot, summary: summary}
} else {
inv_n = length(instr)
unresolved[] = {path: path, line: instr[inv_n - 2], col: instr[inv_n - 1]}
}
}
}
@@ -261,7 +266,9 @@ function extract_module_summaries(compiled) {
i = i + 1
}
if (length(summaries) > 0) return summaries
if (length(summaries) > 0 || length(unresolved) > 0) {
return {summaries: summaries, unresolved: unresolved}
}
return null
}
@@ -269,6 +276,8 @@ function extract_module_summaries(compiled) {
function run_ast_fn(name, ast, env) {
var compiled = mcode_mod(ast)
var ms = null
var _ui = 0
var _ur = null
var optimized = null
var _di = 0
var _diag = null
@@ -286,8 +295,22 @@ function run_ast_fn(name, ast, env) {
compiled._warn = true
ms = extract_module_summaries(compiled)
if (ms != null) {
compiled._module_summaries = ms
if (length(ms.summaries) > 0) {
compiled._module_summaries = ms.summaries
}
if (length(ms.unresolved) > 0) {
compiled._unresolved_imports = ms.unresolved
}
}
}
if (compiled._unresolved_imports != null) {
_ui = 0
while (_ui < length(compiled._unresolved_imports)) {
_ur = compiled._unresolved_imports[_ui]
print(`${name}:${text(_ur.line)}:${text(_ur.col)}: error: cannot resolve module '${_ur.path}'\n`)
_ui = _ui + 1
}
disrupt
}
optimized = streamline_mod(compiled)
if (optimized._verify) {
@@ -321,7 +344,46 @@ function run_ast_noopt_fn(name, ast, env) {
// Compile AST to blob without loading (for caching)
function compile_to_blob(name, ast) {
var compiled = mcode_mod(ast)
var optimized = streamline_mod(compiled)
var ms = null
var _ui = 0
var _ur = null
var optimized = null
var _di = 0
var _diag = null
var _has_errors = false
if (!_no_warn) {
compiled._warn = true
ms = extract_module_summaries(compiled)
if (ms != null) {
if (length(ms.summaries) > 0) {
compiled._module_summaries = ms.summaries
}
if (length(ms.unresolved) > 0) {
compiled._unresolved_imports = ms.unresolved
}
}
}
if (compiled._unresolved_imports != null) {
_ui = 0
while (_ui < length(compiled._unresolved_imports)) {
_ur = compiled._unresolved_imports[_ui]
print(`${name}:${text(_ur.line)}:${text(_ur.col)}: error: cannot resolve module '${_ur.path}'\n`)
_ui = _ui + 1
}
disrupt
}
optimized = streamline_mod(compiled)
if (optimized._diagnostics != null && length(optimized._diagnostics) > 0) {
_di = 0
_has_errors = false
while (_di < length(optimized._diagnostics)) {
_diag = optimized._diagnostics[_di]
print(`${_diag.file}:${text(_diag.line)}:${text(_diag.col)}: ${_diag.severity}: ${_diag.message}\n`)
if (_diag.severity == "error") _has_errors = true
_di = _di + 1
}
if (_has_errors) disrupt
}
return mach_compile_mcode_bin(name, json.encode(optimized))
}

View File

@@ -1864,6 +1864,7 @@ var streamline = function(ir, log) {
var cs = null
var argc = null
var known_arity = null
var load_field_null = false
// Build module_slots map from ir._module_summaries
if (ir._module_summaries != null) {
@@ -2007,12 +2008,15 @@ var streamline = function(ir, log) {
// --- Warning checks (likely bug) ---
load_field_null = false
if (op == "load_field") {
obj_type = cur_types[instr[2]]
if (obj_type == T_ARRAY) {
emit("warning", line, col, "named property access on array — always returns null")
load_field_null = true
} else if (obj_type == T_TEXT) {
emit("warning", line, col, "named property access on text — always returns null")
load_field_null = true
}
// Cross-module: check if obj is a module with known exports
ms = module_slots[text(instr[2])]
@@ -2044,6 +2048,11 @@ var streamline = function(ir, log) {
// Update types for this instruction
track_types(cur_types, instr)
// Override: load_field on array/text always returns null
if (load_field_null) {
cur_types[instr[1]] = T_NULL
}
i = i + 1
}