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

Revert optimization of constants and class vars #10330

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions spec/compiler/codegen/class_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ describe "Code gen: class" do

it "allows using self in class scope" do
run(%(
require "prelude"

class Foo
def self.foo
1
Expand Down
10 changes: 3 additions & 7 deletions src/compiler/crystal/codegen/class_var.cr
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ class Crystal::CodeGenVisitor

# For unsafe class var we just initialize them without
# using a flag to know if they were initialized
if class_var.uninitialized? || !init_func || !class_var.read?
class_var.no_init_flag = true

if class_var.uninitialized? || !init_func
global = declare_class_var(class_var)
global = ensure_class_var_in_this_module(global, class_var)
if init_func
Expand All @@ -99,7 +97,7 @@ class Crystal::CodeGenVisitor

global, initialized_flag = declare_class_var_and_initialized_flag_in_this_module(class_var)

lazy_initialize_class_var(initializer.node, init_func.not_nil!, global, initialized_flag)
lazy_initialize_class_var(initializer.node, init_func, global, initialized_flag)
end

def lazy_initialize_class_var(node, init_func, global, initialized_flag)
Expand Down Expand Up @@ -177,8 +175,6 @@ class Crystal::CodeGenVisitor
end

def read_class_var_ptr(class_var : MetaTypeVar)
class_var.read = true

owner = class_var.owner
case owner
when VirtualType
Expand All @@ -188,7 +184,7 @@ class Crystal::CodeGenVisitor
end

initializer = class_var.initializer
if !initializer || class_var.uninitialized? || class_var.no_init_flag?
if !initializer || class_var.uninitialized?
# Read directly without init flag, but make sure to declare the global in this module too
return get_class_var_global(class_var)
end
Expand Down
9 changes: 0 additions & 9 deletions src/compiler/crystal/codegen/const.cr
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,6 @@ class Crystal::CodeGenVisitor
end

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

# Maybe the constant was simple and doesn't need a real initialization
global, initialized_flag = declare_const_and_initialized_flag(const)
return global if const.initializer
Expand Down Expand Up @@ -201,8 +194,6 @@ class Crystal::CodeGenVisitor
end

def read_const_pointer(const)
const.read = true

if !const.needs_init_flag?
global_name = const.llvm_name
global = declare_const(const)
Expand Down
5 changes: 0 additions & 5 deletions src/compiler/crystal/codegen/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,6 @@ module Crystal
class Const
property initializer : LLVM::Value?

# Was this constant already read during the codegen phase?
# If not, and we are at the place that declares the constant, we can
# directly initialize the constant now, without checking for an `init` flag.
property? read = false

# If true, there's no need to check whether the constant was initialized or
# not when reading it.
property? no_init_flag = false
Expand Down
9 changes: 0 additions & 9 deletions src/compiler/crystal/semantic/ast.cr
Original file line number Diff line number Diff line change
Expand Up @@ -534,15 +534,6 @@ module Crystal
# Is this variable "unsafe" (no need to check if it was initialized)?
property? uninitialized = false

# Was this class_var already read during the codegen phase?
# If not, and we are at the place that declares the class var, we can
# directly initialize it now, without checking for an `init` flag.
property? read = false

# If true, there's no need to check whether the class var was initialized or
# not when reading it.
property? no_init_flag = false

def kind
case name[0]
when '@'
Expand Down