From 68e7152a644d42e10ce9f4529bce7039f8292c46 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Sat, 30 Jan 2021 10:36:42 -0300 Subject: [PATCH] Compiler: initialize right-away constants in a separate function (#10334) --- src/compiler/crystal/codegen/const.cr | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/compiler/crystal/codegen/const.cr b/src/compiler/crystal/codegen/const.cr index bab26049f9d1..ed6532c88738 100644 --- a/src/compiler/crystal/codegen/const.cr +++ b/src/compiler/crystal/codegen/const.cr @@ -121,10 +121,7 @@ class Crystal::CodeGenVisitor def initialize_const(const) # If the constant wasn't read yet, we can initialize it right now and # avoid checking an "initialized" flag every time we read it. - unless const.read? - const.no_init_flag = true - return initialize_no_init_flag_const(const) - end + const.no_init_flag = true unless const.read? # Maybe the constant was simple and doesn't need a real initialization global, initialized_flag = declare_const_and_initialized_flag(const) @@ -135,7 +132,12 @@ class Crystal::CodeGenVisitor func = check_main_fun init_function_name, func set_current_debug_location const.locations.try &.first? if @debug.line_numbers? - run_once(initialized_flag, func) + + if const.no_init_flag? + call func + else + run_once(initialized_flag, func) + end global end