From 78e6d6146e2cee782d97f633764fb055c7ff42b8 Mon Sep 17 00:00:00 2001 From: Niels Bross Date: Thu, 11 Sep 2025 11:23:07 +0200 Subject: [PATCH] Remove compiler ctx allocator --- Ink.jai | 5 ++--- Lexing.jai | 2 -- Parsing.jai | 31 ++++++++++++++----------------- Semantic_Analysis.jai | 7 ++----- module.jai | 2 -- 5 files changed, 18 insertions(+), 29 deletions(-) diff --git a/Ink.jai b/Ink.jai index 9c06276..8c627c7 100644 --- a/Ink.jai +++ b/Ink.jai @@ -237,7 +237,7 @@ run_compile_test :: (path : string, output_type : Output_Type = 0) -> Result, Co } } - result.info_text = builder_to_string(*sb,, ctx.allocator); + result.info_text = builder_to_string(*sb); } if output_type & .StdOut { @@ -369,8 +369,7 @@ make_test_case :: (path : string, stage_flags : Stage_Flags, allocator := contex run_test_new :: (file_path : string, stage_flags : Stage_Flags, results : *[..]Result, output_type : Output_Type = 0) { ctx : Compiler_Context; - ctx.allocator = make_arena(Megabytes(128)); - ctx.file = make_file(*ctx, file_path,, ctx.allocator); + ctx.file = make_file(*ctx, file_path); result : Result; if stage_flags & .Lexer { diff --git a/Lexing.jai b/Lexing.jai index f653c2c..ad4f9e4 100644 --- a/Lexing.jai +++ b/Lexing.jai @@ -367,7 +367,6 @@ make_directive :: (lexer : *Lexer) -> *Token { path_tok := scan_next_token(lexer); path := path_tok.string_value; ctx : Compiler_Context; - ctx.allocator = lexer.ctx.allocator; ctx.environment = lexer.ctx.environment; ctx.file = make_file(*ctx, path); @@ -578,7 +577,6 @@ lex :: (ctx : *Compiler_Context, allocator := temp) { lexer : Lexer; lexer.ctx = ctx; - lexer.ctx.tokens.allocator = ctx.allocator; array_reserve(*lexer.ctx.tokens, 1024 * 1024); init_lexer_from_string(*lexer, ctx.file.source); diff --git a/Parsing.jai b/Parsing.jai index fa9b849..55eeef6 100644 --- a/Parsing.jai +++ b/Parsing.jai @@ -370,19 +370,17 @@ advance_to_sync_point :: (parse_state : *Parse_State) { //////////////////////////// //@nb - Base parsing functions -make_node :: (nodes : *[..]AST_Node, kind : AST_Kind, allocator : Allocator) -> *AST_Node { +make_node :: (nodes : *[..]AST_Node, kind : AST_Kind) -> *AST_Node { node : AST_Node; node.kind = kind; - node.children.allocator = allocator; - node.hint_tokens.allocator = allocator; array_add(nodes, node); return *(nodes.*[nodes.count - 1]); } make_node :: (parse_state : *Parse_State, kind : AST_Kind) -> *AST_Node { - return make_node(*parse_state.ctx.nodes, kind, parse_state.ctx.allocator); + return make_node(*parse_state.ctx.nodes, kind); } // new_builtin_node :: (nodes : *[..]AST_Node, kind : AST_Kind) -> *AST_Node { @@ -426,13 +424,13 @@ make_builtin_token :: (tokens : *[..]Token, builder : *String_Builder, kind : To return *(tokens.*)[tokens.count - 1]; } -new_builtin_struct_node :: (ctx : *Compiler_Context, name : string, members : []Arg, allocator : Allocator) -> *AST_Node { - sc := get_scratch(allocator); +new_builtin_struct_node :: (ctx : *Compiler_Context, name : string, members : []Arg) -> *AST_Node { + sc := get_scratch(context.allocator); defer scratch_end(sc); builder : String_Builder; builder.allocator = sc.allocator; // I want to find a good way to use scratch here... - node := make_node(*ctx.nodes, .Struct, allocator); + node := make_node(*ctx.nodes, .Struct); source_location : Source_Range; @@ -455,11 +453,11 @@ new_builtin_struct_node :: (ctx : *Compiler_Context, name : string, members : [] line += 1; col = 0; - field_list := make_node(*ctx.nodes, .FieldList, allocator); + field_list := make_node(*ctx.nodes, .FieldList); add_child(node, field_list); for member : members { - field := make_node(*ctx.nodes, .Field, allocator); + field := make_node(*ctx.nodes, .Field); field_source_loc : Source_Range; indent(*builder, 1); @@ -488,7 +486,7 @@ new_builtin_struct_node :: (ctx : *Compiler_Context, name : string, members : [] source_location.end = brace_token; - source := builder_to_string(*builder,, allocator); + source := builder_to_string(*builder); source_location.begin.source = *source.data[source_location.begin.column]; source_location.end.source = *source.data[source_location.end.column]; @@ -509,13 +507,13 @@ new_builtin_struct_node :: (ctx : *Compiler_Context, name : string, members : [] return node; } -new_builtin_function_node :: (ctx : *Compiler_Context, name : string, members : []Arg, return_var : Arg, allocator : Allocator) -> *AST_Node { - sc := get_scratch(allocator); +new_builtin_function_node :: (ctx : *Compiler_Context, name : string, members : []Arg, return_var : Arg) -> *AST_Node { + sc := get_scratch(context.allocator); defer scratch_end(sc); builder : String_Builder; builder.allocator = sc.allocator; // I want to find a good way to use scratch here... - node := make_node(*ctx.nodes, .Function, allocator); + node := make_node(*ctx.nodes, .Function); source_location : Source_Range; @@ -531,11 +529,11 @@ new_builtin_function_node :: (ctx : *Compiler_Context, name : string, members : make_builtin_token(*ctx.tokens, *builder, .TOKEN_DOUBLECOLON, "::", *col, *line); append(*builder, " "); make_builtin_token(*ctx.tokens, *builder, .TOKEN_LEFTPAREN, "(", *col, *line); - field_list := make_node(*ctx.nodes, .FieldList, allocator); + field_list := make_node(*ctx.nodes, .FieldList); add_child(node, field_list); for member : members { - field := make_node(*ctx.nodes, .Field, allocator); + field := make_node(*ctx.nodes, .Field); field_source_loc : Source_Range; // field_ident := make_builtin_token(*ctx.tokens, *builder, .TOKEN_IDENTIFIER, tprint("%", member.name), *col, *line); @@ -559,7 +557,7 @@ new_builtin_function_node :: (ctx : *Compiler_Context, name : string, members : source_location.end = semicolon_tok; - source := builder_to_string(*builder,, allocator); + source := builder_to_string(*builder); source_location.begin.source = *source.data[source_location.begin.column]; source_location.end.source = *source.data[source_location.end.column]; @@ -1591,7 +1589,6 @@ parse :: (ctx : *Compiler_Context, allocator := temp) { defer clear_context_allocators(); parse_state : Parse_State; - ctx.nodes.allocator = ctx.allocator; array_reserve(*ctx.nodes, 4096); parse_state.current_token_index = 0; parse_state.ctx = ctx; diff --git a/Semantic_Analysis.jai b/Semantic_Analysis.jai index 16d151f..4b21b94 100644 --- a/Semantic_Analysis.jai +++ b/Semantic_Analysis.jai @@ -723,7 +723,7 @@ Arg :: struct { new_builtin_struct :: (checker : *Semantic_Checker, name : string, members : []Arg) -> *Type_Variable, Type_Variable_Handle { tv, handle := new_builtin_type_variable(checker, .Struct, .Declaration, name, name); - builtin_node := new_builtin_struct_node(checker.ctx, name, members, checker.ctx.allocator); + builtin_node := new_builtin_struct_node(checker.ctx, name, members); symbol : Defined_Symbol; symbol.name = name; @@ -765,7 +765,7 @@ new_builtin_struct :: (checker : *Semantic_Checker, name : string, members : []A new_builtin_function :: (checker : *Semantic_Checker, name : string, args : []Arg, return_arg : Arg) -> *Type_Variable, Type_Variable_Handle { tv, handle := new_builtin_type_variable(checker, .Function, .Declaration, name); - builtin_node := new_builtin_function_node(checker.ctx, name, args, return_arg, checker.ctx.allocator); + builtin_node := new_builtin_function_node(checker.ctx, name, args, return_arg); function : Defined_Symbol; function.name = name; @@ -836,10 +836,8 @@ init_semantic_checker :: (checker : *Semantic_Checker, root : *AST_Node, path : checker.program_root = root; checker.path = path; - checker.ctx.type_variables.allocator = checker.ctx.allocator; array_reserve(*checker.ctx.type_variables, 2048); - checker.ctx.scope_stack.allocator = make_arena(Megabytes(8)); checker.ctx.scope_stack.stack.allocator = checker.ctx.scope_stack.allocator; array_reserve(*checker.ctx.scope_stack.stack, 256); @@ -2094,7 +2092,6 @@ add_builtins :: (checker : *Semantic_Checker) { checker.state = .Adding_Builtins; checker.ctx.file = make_file_from_string(BUILTIN); - checker.ctx.allocator = make_arena(Megabytes(128)); prev_file := checker.ctx.file; prev_root := checker.ctx.root; diff --git a/module.jai b/module.jai index 0149067..881df97 100644 --- a/module.jai +++ b/module.jai @@ -175,8 +175,6 @@ Compiler_Context :: struct { had_error : bool; messages : [..]Compiler_Message; - - allocator : Allocator; } #add_context scratch_allocators : [2]Allocator;