Class: Audition::Static::Checks::InstanceMemoization
- Defined in:
- lib/audition/static/checks/instance_memoization.rb
Overview
Lazy memoization on an instance is harmless until the
instance is frozen: Ractor.make_shareable freezes every
object it reaches, and the next @x ||= raises FrozenError.
Two shapes make the freeze provable from the class alone: an
initialize that ends by freezing self (a value object), and a
freeze override (the class expects to be frozen). In the
first the memo can never run; in the second it must be
warmed inside the override, before super, which is the
compute-on-freeze pattern. Class-level memos belong to the
graph audit.
Constant Summary
Constants inherited from Base
Base::EMPTY_CATALOG, Base::WRAPPER
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(file) ⇒ InstanceMemoization
constructor
A new instance of InstanceMemoization.
- #visit_class_node(node) ⇒ Object
-
#visit_def_node(node) ⇒ Object
Only plain instance methods count; a def is not entered, so nothing inside a method body opens a context.
- #visit_module_node(node) ⇒ Object
- #visit_singleton_class_node(node) ⇒ Object
Methods inherited from Base
call, check_name, explain, explanations, handlers, on
Constructor Details
#initialize(file) ⇒ InstanceMemoization
Returns a new instance of InstanceMemoization.
42 43 44 45 46 |
# File 'lib/audition/static/checks/instance_memoization.rb', line 42 def initialize(file) super @contexts = [] @sclass_depth = 0 end |
Instance Method Details
#visit_class_node(node) ⇒ Object
48 |
# File 'lib/audition/static/checks/instance_memoization.rb', line 48 def visit_class_node(node) = scoped { super } |
#visit_def_node(node) ⇒ Object
Only plain instance methods count; a def is not entered, so nothing inside a method body opens a context.
61 62 63 64 65 66 67 |
# File 'lib/audition/static/checks/instance_memoization.rb', line 61 def visit_def_node(node) context = @contexts.last return unless context && node.receiver.nil? && @sclass_depth.zero? record_method(context, node) end |
#visit_module_node(node) ⇒ Object
50 |
# File 'lib/audition/static/checks/instance_memoization.rb', line 50 def visit_module_node(node) = scoped { super } |
#visit_singleton_class_node(node) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/audition/static/checks/instance_memoization.rb', line 52 def visit_singleton_class_node(node) @sclass_depth += 1 super ensure @sclass_depth -= 1 end |