From c31c423386ad7f11a3901f8dd8de0e170f181adb Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sun, 3 Aug 2025 22:58:51 +0200 Subject: [PATCH] Reduce allocated Vmem for the compiler on 32 bit machines. --- releasenotes.md | 1 + src/compiler/compiler.c | 11 +++++++---- src/utils/malloc.c | 9 ++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/releasenotes.md b/releasenotes.md index ea0cc7811..1e41d2092 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -11,6 +11,7 @@ - With avx512, passing a 512 bit vector in a union would be lowered incorrectly, causing an assert. #2362 - Codegen error in `if (try x = (true ? io::EOF? : 1))`, i.e. using if-try with a known Empty. - Codegen error in `if (try x = (false ? io::EOF? : 1))`, i.e. using if-try with a CT known value. +- Reduce allocated Vmem for the compiler on 32 bit machines. ### Stdlib changes - Add `==` to `Pair`, `Triple` and TzDateTime. Add print to `Pair` and `Triple`. diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c index 8d7d9625b..25f680c6d 100644 --- a/src/compiler/compiler.c +++ b/src/compiler/compiler.c @@ -40,6 +40,8 @@ static const char *out_name(void) return NULL; } +#define START_VMEM_SIZE (sizeof(size_t) == 4 ? 1024 : 4096) + void compiler_init(BuildOptions *build_options) { // Process --path @@ -76,13 +78,14 @@ void compiler_init(BuildOptions *build_options) compiler.context.module_list = NULL; compiler.context.generic_module_list = NULL; compiler.context.method_extensions = NULL; - vmem_init(&ast_arena, 4096); + + vmem_init(&ast_arena, START_VMEM_SIZE); ast_calloc(); - vmem_init(&expr_arena, 4096); + vmem_init(&expr_arena, START_VMEM_SIZE); expr_calloc(); - vmem_init(&decl_arena, 4096); + vmem_init(&decl_arena, START_VMEM_SIZE); decl_calloc(); - vmem_init(&type_info_arena, 4096); + vmem_init(&type_info_arena, START_VMEM_SIZE); type_info_calloc(); // Create zero index value. if (build_options->std_lib_dir) diff --git a/src/utils/malloc.c b/src/utils/malloc.c index 9bafdf598..ae147c4ec 100644 --- a/src/utils/malloc.c +++ b/src/utils/malloc.c @@ -14,11 +14,14 @@ static Vmem arena; uintptr_t arena_zero; static Vmem char_arena; +#define START_VMEM_SIZE (sizeof(size_t) == 4 ? 1024 : 4096) + void memory_init(size_t max_mem) { if (max_mem) vmem_set_max_limit(max_mem); - vmem_init(&arena, 4096); - vmem_init(&char_arena, 2048); + + vmem_init(&arena, START_VMEM_SIZE); + vmem_init(&char_arena, START_VMEM_SIZE / 2); allocations_done = 0; arena_zero = (uintptr_t)arena.ptr; vmem_alloc(&arena, 16); @@ -73,7 +76,7 @@ void run_arena_allocator_tests(void) ASSERT(calloc_arena(10) != calloc_arena(10) && "Expected different values..."); printf("-- Tested basic allocation - OK.\n"); ASSERT(arena.allocated == 48 && "Expected allocations rounded to next 16 bytes"); - calloc_arena(1); + (void)calloc_arena(1); ASSERT(arena.allocated == 64 && "Expected allocations rounded to next 16 bytes"); printf("-- Tested allocation alignment - OK.\n"); ASSERT(calloc_arena(1024 * 1024) != NULL && "Expected allocation to work");