rename expand to inline

This commit is contained in:
2026-08-02 20:31:05 +02:00
parent c92723bc14
commit 9e79d6692b
13 changed files with 123 additions and 82 deletions
+14 -14
View File
@@ -10574,7 +10574,7 @@ expand_field_bindings :: proc(
value := state.values[value_id]
if ct_value_contains_undefined(&state, value_id) {
if diagnose {
_ = ct_fail(&state, .Not_Comptime, checker.ast_module.exprs[expr].span, "expand for cannot expand an undefined comptime value")
_ = ct_fail(&state, .Not_Comptime, checker.ast_module.exprs[expr].span, "inline for cannot iterate an undefined comptime value")
}
return nil, .Diagnosed if state.diagnostic != source.INVALID_DIAGNOSTIC else .Invalid
}
@@ -10712,7 +10712,7 @@ contains_expand_control :: proc(
}
case .For, .While:
// Unlabelled control belongs to the nested loop. A labelled jump can still
// name the surrounding expand loop and is therefore relevant here.
// name the surrounding inline loop and is therefore relevant here.
if contains_expand_control(checker, statement.body, target_label, false) {
return true
}
@@ -10817,7 +10817,7 @@ flatten_expand_iteration :: proc(
if diagnostic != nil {
diagnostic^ = source.add(
checker.diagnostics, statement.span,
"break or continue targeting an expand loop must be compile-time-resolvable",
"break or continue targeting an inline loop must be compile-time-resolvable",
)
}
return .Invalid
@@ -10856,7 +10856,7 @@ flatten_expand_iteration :: proc(
if diagnostic != nil {
diagnostic^ = source.add(
checker.diagnostics, statement.span,
"break or continue targeting an expand loop must be compile-time-resolvable",
"break or continue targeting an inline loop must be compile-time-resolvable",
)
}
return .Invalid
@@ -10882,7 +10882,7 @@ flatten_expand_iteration :: proc(
if diagnostic != nil {
diagnostic^ = source.add(
checker.diagnostics, statement.span,
"break or continue targeting an expand loop must be compile-time-resolvable",
"break or continue targeting an inline loop must be compile-time-resolvable",
)
}
return .Invalid
@@ -11814,7 +11814,7 @@ build_block :: proc(
case .For:
if statement.expand {
if statement.pointer_capture {
id := source.add(checker.diagnostics, statement.span, "expand for does not support pointer captures")
id := source.add(checker.diagnostics, statement.span, "inline for does not support pointer captures")
append(&body, hir.stmt_id(len(checker.module.statements)))
append(&checker.module.statements, hir.Stmt{kind=.Trap, span=statement.span, diagnostic=id})
ctx.problematic^ = true
@@ -11822,9 +11822,9 @@ build_block :: proc(
}
bindings, expand_error := expand_field_bindings(checker, statement.expr, statement.name, ctx.pkg, ctx.file, true)
if expand_error != .None && expand_error != .Diagnosed {
message := "expand for requires a comptime tuple, fixed array, range, slice, or reflection value"
message := "inline for requires a comptime tuple, fixed array, range, slice, or reflection value"
if expand_error == .Quota {
message = "expand for expansion exceeds the compile-time evaluation quota"
message = "inline for expansion exceeds the compile-time evaluation quota"
}
id := source.add(
checker.diagnostics, statement.span,
@@ -12869,28 +12869,28 @@ emit_match :: proc(
continue
}
if has_else || has_expand {
message := "arms after 'else' are unreachable" if has_else else "arms after 'expand' are unreachable"
message := "arms after 'else' are unreachable" if has_else else "arms after 'inline' are unreachable"
source.add(checker.diagnostics, arm.span, message)
ok = false
}
if arm.expand {
if !is_tagged && !is_enum_subject {
source.add(checker.diagnostics, arm.span, "'expand' requires an enum or tagged-union match subject")
source.add(checker.diagnostics, arm.span, "'inline' requires an enum or tagged-union match subject")
ok = false
continue
}
expected_captures := 1 if is_enum_subject else 2
if len(arm.captures) == 0 || len(arm.captures) > expected_captures {
description := "exactly one capture" if is_enum_subject else "one or two captures"
source.addf(checker.diagnostics, arm.span, "expanded match on '%s' requires %s", type_label(checker, subject_type), description)
source.addf(checker.diagnostics, arm.span, "inlined match on '%s' requires %s", type_label(checker, subject_type), description)
ok = false
}
if is_enum_subject && arm.pointer_capture {
source.add(checker.diagnostics, arm.span, "enum expansion does not support pointer captures")
source.add(checker.diagnostics, arm.span, "enum inlining does not support pointer captures")
ok = false
}
if len(arm.captures) > 1 && arm.captures[0] != checker.sink_symbol && arm.captures[0] == arm.captures[1] {
source.add(checker.diagnostics, arm.span, "expand captures must have distinct names")
source.add(checker.diagnostics, arm.span, "inline captures must have distinct names")
ok = false
}
remaining := 0
@@ -12963,7 +12963,7 @@ emit_match :: proc(
}
}
if remaining == 0 {
source.add(checker.diagnostics, arm.span, "redundant 'expand': the 'match' already covers every variant")
source.add(checker.diagnostics, arm.span, "redundant 'inline': the 'match' already covers every variant")
ok = false
}
has_expand = true