Skip to content

Commit

Permalink
Compiler: initialize right-away constants in a separate function (#10334
Browse files Browse the repository at this point in the history
)
  • Loading branch information
asterite authored and bcardiff committed Jan 30, 2021
1 parent b2bd815 commit eff08fe
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/compiler/crystal/codegen/const.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit eff08fe

Please sign in to comment.