Skip to content

Commit

Permalink
Codegen: track whether constant is accessed with pointerof(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Oct 7, 2020
1 parent f8a94ea commit 5957b12
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/compiler/crystal/codegen/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,14 @@ module Crystal
# Returns `true` if this constant's value is a simple literal, like
# `nil`, a number, char, string or symbol literal.
def simple?
return false if pointer_read?

value.simple_literal?
end

def needs_init_flag?
return true if pointer_read?

!(initializer || no_init_flag? || simple?)
end

Expand Down
1 change: 1 addition & 0 deletions src/compiler/crystal/semantic/main_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,7 @@ module Crystal
when Path
exp.accept self
if const = exp.target_const
const.pointer_read = true
const.value
end
when ReadInstanceVar
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3133,6 +3133,10 @@ module Crystal
property vars : MetaVars?
property? used = false
property? visited = false

# Is this constant accessed with pointerof(...)?
property? pointer_read = false

property visitor : MainVisitor?

def initialize(program, namespace, name, @value)
Expand Down

0 comments on commit 5957b12

Please sign in to comment.