Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler: initialize right-away constants in a separate function #10334

Merged
merged 1 commit into from
Jan 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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