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
+79 -28
View File
@@ -177,6 +177,21 @@ lexer_preserves_newlines_and_skips_comments :: proc(t: ^testing.T) {
testing.expect_value(t, stream.items[1].kind, token.Kind.Identifier)
}
@(test)
inline_is_keyword_and_expand_is_identifier :: proc(t: ^testing.T) {
source_file := source.Source{path="test.bro", text="inline expand"}
diagnostics := source.init_diagnostics(&source_file)
defer source.destroy_diagnostics(&diagnostics)
symbols := symbol.init_table()
defer symbol.destroy_table(&symbols)
stream := lexer.lex(&source_file, &diagnostics, &symbols)
defer delete(stream.items)
testing.expect_value(t, len(diagnostics.items), 0)
testing.expect_value(t, stream.items[0].kind, token.Kind.Keyword_Inline)
testing.expect_value(t, stream.items[1].kind, token.Kind.Identifier)
}
@(test)
lexer_recognizes_bitwise_operators_with_longest_match :: proc(t: ^testing.T) {
source_file := source.Source{path="test.bro", text="~ & &= | |= xor xor= << <<= >> >>= <<| <<|= ^"}
@@ -1253,6 +1268,45 @@ main func() void {
testing.expect(t, !found_old_function_error)
}
@(test)
function_signature_context_infers_enum_literals :: proc(t: ^testing.T) {
text := `TokenKind :: enum {
ident
double_colon
newline
}
ParseError :: enum {
unexpected_token
}
parse func() void ! ParseError {
try expect(.ident)
try expect(.double_colon)
try expect(.newline)
}
expect func(kind TokenKind) void ! ParseError {
if kind == .newline {
return .unexpected_token
}
}
main func() void {
parse() catch |_| {}
}
`
source_file := source.Source{path="test.bro", text=text}
diagnostics := source.init_diagnostics(&source_file)
defer source.destroy_diagnostics(&diagnostics)
symbols := symbol.init_table()
defer symbol.destroy_table(&symbols)
stream := lexer.lex(&source_file, &diagnostics, &symbols)
defer delete(stream.items)
ast_module := parser.parse(&stream, &source_file, &diagnostics)
defer ast.destroy_module(&ast_module)
hir_module := checker.check(&ast_module, &diagnostics, &symbols)
defer hir.destroy_module(&hir_module)
testing.expect_value(t, len(diagnostics.items), 0)
}
@(test)
pipeline_emits_specialized_calling_conventions_and_checked_add :: proc(t: ^testing.T) {
text := `sum_c c_func(a, b int) int {
@@ -3236,10 +3290,10 @@ milestone_37_tuples_reflection_expand_for_and_debug_print_compile_and_run :: pro
@(test)
expanded_matches_and_tag_intrinsics_compile_and_run :: proc(t: ^testing.T) {
output := "/tmp/brolang-test-expand"
output := "/tmp/brolang-test-inline"
defer _ = os.remove(output)
status := compiler_core.compile_package(
"examples/programs/expand", output, nil, target.DEFAULT, cimport.Options{}, ".",
"examples/programs/inline", output, nil, target.DEFAULT, cimport.Options{}, ".",
)
testing.expect_value(t, status, 0)
state, stdout, stderr, _ := os2.process_exec(
@@ -3261,29 +3315,29 @@ main func() void {
inline for {1} |value| { _ = value }
n i32 = 1
match n { expand |value|: _ = value }
match n { inline |value|: _ = value }
e E = .a
match e { expand |value, tag|: _ = value }
match e { inline |value, tag|: _ = value }
match e {
.a, .b: {}
expand |value|: _ = value
inline |value|: _ = value
}
match e {
expand |value|: _ = value
inline |value|: _ = value
.b: {}
}
match e {
else: {}
expand |value|: _ = value
inline |value|: _ = value
}
u Plain = Plain{value = 1}
_ = tag!(u)
_ = tagname!(e)
match e { expand ||: {} }
match e { expand |a, b, c|: {} }
match e { inline ||: {} }
match e { inline |a, b, c|: {} }
}
`
source_file := source.Source{path="expand_diagnostics.bro", text=text}
@@ -3298,7 +3352,6 @@ main func() void {
hir_module := checker.check(&ast_module, &diagnostics, &symbols)
defer hir.destroy_module(&hir_module)
found_old := false
found_subject := false
found_captures := false
found_redundant := false
@@ -3309,17 +3362,15 @@ main func() void {
found_tagname := false
for diagnostic in diagnostics.items {
message := diagnostic.message
found_old = found_old || strings.contains(message, "'inline for' was renamed to 'expand for'")
found_subject = found_subject || strings.contains(message, "'expand' requires an enum or tagged-union")
found_subject = found_subject || strings.contains(message, "'inline' requires an enum or tagged-union")
found_captures = found_captures || strings.contains(message, "requires exactly one capture")
found_redundant = found_redundant || strings.contains(message, "redundant 'expand'")
found_after = found_after || strings.contains(message, "arms after 'expand' are unreachable") || strings.contains(message, "arms after 'else' are unreachable")
found_missing = found_missing || strings.contains(message, "expected an expand value capture")
found_redundant = found_redundant || strings.contains(message, "redundant 'inline'")
found_after = found_after || strings.contains(message, "arms after 'inline' are unreachable") || strings.contains(message, "arms after 'else' are unreachable")
found_missing = found_missing || strings.contains(message, "expected an inline value capture")
found_many = found_many || strings.contains(message, "at most two captures")
found_tag = found_tag || strings.contains(message, "tag! requires a tagged-union value")
found_tagname = found_tagname || strings.contains(message, "tagname! requires a comptime-known enum value")
}
testing.expect(t, found_old)
testing.expect(t, found_subject)
testing.expect(t, found_captures)
testing.expect(t, found_redundant)
@@ -3751,7 +3802,7 @@ main func() i32 { return answer }
milestone_37_expand_loop_control_must_be_statically_resolvable :: proc(t: ^testing.T) {
text := `main func() void {
total i32 = 0
expand for {1, 2} |value| {
inline for {1, 2} |value| {
if total == 0 {
break
}
@@ -3775,7 +3826,7 @@ milestone_37_expand_loop_control_must_be_statically_resolvable :: proc(t: ^testi
for diagnostic in diagnostics.items {
found = found || strings.contains(
diagnostic.message,
"break or continue targeting an expand loop must be compile-time-resolvable",
"break or continue targeting an inline loop must be compile-time-resolvable",
)
}
testing.expect(t, found)
@@ -3803,7 +3854,7 @@ read_initialized_sibling func() i32 {
answer :: $read_initialized_sibling()
main func() i32 {
total usize = 0
expand for make_tokens() |token| {
inline for make_tokens() |token| {
total += token.text.len + token.count
}
if answer != 42 or total != 8 {
@@ -3884,8 +3935,8 @@ milestone_37_expand_expansions_keep_distinct_call_resolutions :: proc(t: ^testin
}
main func() i32 {
total i64 = 0
expand for {{i8(1), i16(2)}, {i32(3), i64(4)}} |row| {
expand for row |value| {
inline for {{i8(1), i16(2)}, {i32(3), i64(4)}} |row| {
inline for row |value| {
total += i64(identity(value))
}
}
@@ -3917,13 +3968,13 @@ main func() i32 {
milestone_37_expand_control_prunes_inference_after_static_exit :: proc(t: ^testing.T) {
text := `take_i8 func(value i8) void { _ = value }
main func() void {
expand for {i8(1), "skip"} |value, index| {
inline for {i8(1), "skip"} |value, index| {
if index == 1 {
continue
}
take_i8(value)
}
expand for {i8(1), "stop"} |value, index| {
inline for {i8(1), "stop"} |value, index| {
if index == 1 {
break
}
@@ -3954,7 +4005,7 @@ StringToken :: struct { kind Kind, value []u8 }
StopToken :: struct { kind Kind, value bool }
take_i8 func(value i8) void { _ = value }
main func() void {
expand for {
inline for {
IntToken {kind = .integer, value = 1},
StringToken {kind = .string, value = "ok"},
StopToken {kind = .stop, value = false},
@@ -3968,7 +4019,7 @@ main func() void {
.stop: break
}
}
expand for {i8(2), "skip", "stop"} |value, index| {
inline for {i8(2), "skip", "stop"} |value, index| {
match index {
0: {}
1..=1, 7: continue
@@ -6742,7 +6793,7 @@ via_nested func() i32 ! AError {
via_expand func() i32 ! AError {
abc(1) catch |err| {
match err {
expand |tag|: match tag {
inline |tag|: match tag {
.a: return err
else: unreachable
}
@@ -15247,7 +15298,7 @@ Map func($E, $V type) type {
init func($E, $V type, values meta.EnumFieldStruct(E, ?V, some!(null))) Map(E, V) {
map Map(E, V) = undefined
match typeinfo!(E) {
.enum |info|: expand for info.fields |field, index| {
.enum |info|: inline for info.fields |field, index| {
map.present[index] = false
if field!(values, field.name) |value| {
map.present[index] = true
@@ -15261,7 +15312,7 @@ init func($E, $V type, values meta.EnumFieldStruct(E, ?V, some!(null))) Map(E, V
get func($E, $V type, map @Map(E, V), key E) ?V {
match typeinfo!(E) {
.enum |info|: expand for info.fields |field, index| {
.enum |info|: inline for info.fields |field, index| {
if key == field!(E, field.name) {
if map.present[index] { return map.values[index] }
return null