Class: TypeProf::Core::ChangeSet

Inherits:
Object
  • Object
show all
Defined in:
lib/typeprof/core/graph/change_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, target) ⇒ ChangeSet

Returns a new instance of ChangeSet.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/typeprof/core/graph/change_set.rb', line 3

def initialize(node, target)
  @node = node
  @target = target
  @new_vertexes = {}
  @covariant_types = {}
  @contravariant_types = {}
  @edges = []
  @new_edges = []
  @boxes = {}
  @new_boxes = {}
  @diagnostics = []
  @new_diagnostics = []
  @depended_value_entities = []
  @new_depended_value_entities = []
  @depended_method_entities = []
  @new_depended_method_entities = []
  @depended_static_reads = []
  @new_depended_static_reads = []
  @depended_superclasses = []
  @new_depended_superclasses = []
end

Instance Attribute Details

#boxesObject (readonly)

Returns the value of attribute boxes.



25
26
27
# File 'lib/typeprof/core/graph/change_set.rb', line 25

def boxes
  @boxes
end

#contravariant_typesObject (readonly)

Returns the value of attribute contravariant_types.



25
26
27
# File 'lib/typeprof/core/graph/change_set.rb', line 25

def contravariant_types
  @contravariant_types
end

#covariant_typesObject (readonly)

Returns the value of attribute covariant_types.



25
26
27
# File 'lib/typeprof/core/graph/change_set.rb', line 25

def covariant_types
  @covariant_types
end

#diagnosticsObject (readonly)

Returns the value of attribute diagnostics.



25
26
27
# File 'lib/typeprof/core/graph/change_set.rb', line 25

def diagnostics
  @diagnostics
end

#edgesObject (readonly)

Returns the value of attribute edges.



25
26
27
# File 'lib/typeprof/core/graph/change_set.rb', line 25

def edges
  @edges
end

#nodeObject (readonly)

Returns the value of attribute node.



25
26
27
# File 'lib/typeprof/core/graph/change_set.rb', line 25

def node
  @node
end

#targetObject (readonly)

Returns the value of attribute target.



25
26
27
# File 'lib/typeprof/core/graph/change_set.rb', line 25

def target
  @target
end

Instance Method Details

#add_const_read_box(genv, static_ret) ⇒ Object



110
111
112
113
# File 'lib/typeprof/core/graph/change_set.rb', line 110

def add_const_read_box(genv, static_ret)
  key = [:cread, static_ret]
  @new_boxes[key] ||= ConstReadBox.new(@node, genv, static_ret)
end

#add_cvar_read_box(genv, cpath, name) ⇒ Object



125
126
127
128
# File 'lib/typeprof/core/graph/change_set.rb', line 125

def add_cvar_read_box(genv, cpath, name)
  key = [:cvar_read, cpath, name]
  @new_boxes[key] ||= CVarReadBox.new(@node, genv, cpath, name)
end

#add_depended_method_entity(me) ⇒ Object



148
149
150
# File 'lib/typeprof/core/graph/change_set.rb', line 148

def add_depended_method_entity(me)
  @new_depended_method_entities << me
end

#add_depended_static_read(static_read) ⇒ Object



152
153
154
# File 'lib/typeprof/core/graph/change_set.rb', line 152

def add_depended_static_read(static_read)
  @new_depended_static_reads << static_read
end

#add_depended_superclass(mod) ⇒ Object



156
157
158
# File 'lib/typeprof/core/graph/change_set.rb', line 156

def add_depended_superclass(mod)
  @new_depended_superclasses << mod
end

#add_depended_value_entity(ve) ⇒ Object



144
145
146
# File 'lib/typeprof/core/graph/change_set.rb', line 144

def add_depended_value_entity(ve)
  @new_depended_value_entities << ve
end

#add_diagnostic(meth, msg, node = @node) ⇒ Object



140
141
142
# File 'lib/typeprof/core/graph/change_set.rb', line 140

def add_diagnostic(meth, msg, node = @node)
  @new_diagnostics << TypeProf::Diagnostic.new(node, meth, msg)
end

#add_edge(genv, src, dst) ⇒ Object



64
65
66
# File 'lib/typeprof/core/graph/change_set.rb', line 64

def add_edge(genv, src, dst)
  @new_edges << [src, dst]
end

#add_escape_box(genv, a_ret) ⇒ Object



75
76
77
78
# File 'lib/typeprof/core/graph/change_set.rb', line 75

def add_escape_box(genv, a_ret)
  key = [:return, a_ret]
  @new_boxes[key] ||= EscapeBox.new(@node, genv, a_ret)
end

#add_gvar_read_box(genv, var) ⇒ Object



115
116
117
118
# File 'lib/typeprof/core/graph/change_set.rb', line 115

def add_gvar_read_box(genv, var)
  key = [:gvar_read, var]
  @new_boxes[key] ||= GVarReadBox.new(@node, genv, var)
end

#add_hash_splat_box(genv, arg, unified_key, unified_val) ⇒ Object



85
86
87
88
# File 'lib/typeprof/core/graph/change_set.rb', line 85

def add_hash_splat_box(genv, arg, unified_key, unified_val)
  key = [:hash_splat, arg, unified_key, unified_val]
  @new_boxes[key] ||= HashSplatBox.new(@node, genv, arg, unified_key, unified_val)
end

#add_instance_type_box(genv, singleton_ty_vtx) ⇒ Object



135
136
137
138
# File 'lib/typeprof/core/graph/change_set.rb', line 135

def add_instance_type_box(genv, singleton_ty_vtx)
  key = [:instance_type, singleton_ty_vtx]
  @new_boxes[key] ||= InstanceTypeBox.new(@node, genv, singleton_ty_vtx)
end

#add_ivar_read_box(genv, cpath, singleton, name) ⇒ Object



120
121
122
123
# File 'lib/typeprof/core/graph/change_set.rb', line 120

def add_ivar_read_box(genv, cpath, singleton, name)
  key = [:ivar_read, cpath, singleton, name]
  @new_boxes[key] ||= IVarReadBox.new(@node, genv, cpath, singleton, name)
end

#add_masgn_box(genv, value, lefts, rest_elem, rights) ⇒ Object



90
91
92
93
# File 'lib/typeprof/core/graph/change_set.rb', line 90

def add_masgn_box(genv, value, lefts, rest_elem, rights)
  key = [:masgn, value, lefts, rest_elem, rights]
  @new_boxes[key] ||= MAsgnBox.new(@node, genv, value, lefts, rest_elem, rights)
end

#add_method_alias_box(genv, cpath, singleton, new_mid, old_mid) ⇒ Object



105
106
107
108
# File 'lib/typeprof/core/graph/change_set.rb', line 105

def add_method_alias_box(genv, cpath, singleton, new_mid, old_mid)
  key = [:mdecl, cpath, singleton, new_mid, old_mid]
  @new_boxes[key] ||= MethodAliasBox.new(@node, genv, cpath, singleton, new_mid, old_mid)
end

#add_method_call_box(genv, recv, mid, a_args, subclasses) ⇒ Object

TODO: if an edge is removed during one analysis, we may need to remove sub-boxes?



70
71
72
73
# File 'lib/typeprof/core/graph/change_set.rb', line 70

def add_method_call_box(genv, recv, mid, a_args, subclasses)
  key = [:mcall, recv, mid, a_args, subclasses]
  @new_boxes[key] ||= MethodCallBox.new(@node, genv, recv, mid, a_args, subclasses)
end

#add_method_decl_box(genv, cpath, singleton, mid, method_types, overloading) ⇒ Object



100
101
102
103
# File 'lib/typeprof/core/graph/change_set.rb', line 100

def add_method_decl_box(genv, cpath, singleton, mid, method_types, overloading)
  key = [:mdecl, cpath, singleton, mid, method_types, overloading]
  @new_boxes[key] ||= MethodDeclBox.new(@node, genv, cpath, singleton, mid, method_types, overloading)
end

#add_method_def_box(genv, cpath, singleton, mid, f_args, ret_boxes) ⇒ Object



95
96
97
98
# File 'lib/typeprof/core/graph/change_set.rb', line 95

def add_method_def_box(genv, cpath, singleton, mid, f_args, ret_boxes)
  key = [:mdef, cpath, singleton, mid, f_args, ret_boxes]
  @new_boxes[key] ||= MethodDefBox.new(@node, genv, cpath, singleton, mid, f_args, ret_boxes)
end

#add_splat_box(genv, arg, idx = nil) ⇒ Object



80
81
82
83
# File 'lib/typeprof/core/graph/change_set.rb', line 80

def add_splat_box(genv, arg, idx = nil)
  key = [:splat, arg, idx]
  @new_boxes[key] ||= SplatBox.new(@node, genv, arg, idx)
end

#add_type_read_box(genv, type) ⇒ Object



130
131
132
133
# File 'lib/typeprof/core/graph/change_set.rb', line 130

def add_type_read_box(genv, type)
  key = [:type_read, type]
  @new_boxes[key] ||= TypeReadBox.new(@node, genv, type)
end

#copy_from(other) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/typeprof/core/graph/change_set.rb', line 34

def copy_from(other)
  @covariant_types = other.covariant_types.dup
  @contravariant_types = other.contravariant_types.dup
  @edges = other.edges.dup
  @boxes = other.boxes.dup
  @diagnostics = other.diagnostics.dup

  other.covariant_types.clear
  other.contravariant_types.clear
  other.edges.clear
  other.boxes.clear
  other.diagnostics.clear
end

#new_contravariant_vertex(genv, sig_type_node) ⇒ Object



59
60
61
62
# File 'lib/typeprof/core/graph/change_set.rb', line 59

def new_contravariant_vertex(genv, sig_type_node)
  # This is used to avoid duplicated vertex generation for the same sig node
  @contravariant_types[sig_type_node] ||= Vertex.new(sig_type_node)
end

#new_covariant_vertex(genv, sig_type_node) ⇒ Object



54
55
56
57
# File 'lib/typeprof/core/graph/change_set.rb', line 54

def new_covariant_vertex(genv, sig_type_node)
  # This is used to avoid duplicated vertex generation for the same sig node
  @covariant_types[sig_type_node] ||= Vertex.new(sig_type_node)
end

#new_vertex(genv, origin, base_vtx) ⇒ Object



48
49
50
51
52
# File 'lib/typeprof/core/graph/change_set.rb', line 48

def new_vertex(genv, origin, base_vtx)
  new_vtx = @new_vertexes[base_vtx] ||= Vertex.new(origin)
  add_edge(genv, base_vtx, new_vtx)
  new_vtx
end

#reinstall(genv) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/typeprof/core/graph/change_set.rb', line 160

def reinstall(genv)
  @new_edges.uniq!
  @new_edges.each do |src, dst|
    src.add_edge(genv, dst) unless @edges.include?([src, dst])
  end
  @edges.each do |src, dst|
    src.remove_edge(genv, dst) unless @new_edges.include?([src, dst])
  end
  @edges, @new_edges = @new_edges, @edges
  @new_edges.clear

  @boxes.each do |key, box|
    box.destroy(genv)
  end
  @boxes, @new_boxes = @new_boxes, @boxes
  @new_boxes.clear

  @diagnostics.each do |diag|
    genv.add_diagnostic_path(diag.node.lenv.path)
    diag.node.remove_diagnostic(diag)
  end
  @new_diagnostics.each do |diag|
    genv.add_diagnostic_path(diag.node.lenv.path)
    diag.node.add_diagnostic(diag)
  end
  @diagnostics, @new_diagnostics = @new_diagnostics, @diagnostics
  @new_diagnostics.clear

  @depended_value_entities.each do |ve|
    ve.read_boxes.delete(@target) || raise
  end
  @new_depended_value_entities.uniq!
  @new_depended_value_entities.each do |ve|
    ve.read_boxes << @target
  end
  @depended_value_entities, @new_depended_value_entities = @new_depended_value_entities, @depended_value_entities
  @new_depended_value_entities.clear

  @depended_method_entities.each do |me|
    me.method_call_boxes.delete(@target) || raise
  end
  @new_depended_method_entities.uniq!
  @new_depended_method_entities.each do |me|
    me.method_call_boxes << @target
  end
  @depended_method_entities, @new_depended_method_entities = @new_depended_method_entities, @depended_method_entities
  @new_depended_method_entities.clear

  @depended_static_reads.each do |static_read|
    static_read.followers.delete(@target)
  end
  @new_depended_static_reads.uniq!
  @new_depended_static_reads.each do |static_read|
    static_read.followers << @target
  end

  @depended_static_reads, @new_depended_static_reads = @new_depended_static_reads, @depended_static_reads
  @new_depended_static_reads.clear

  @depended_superclasses.each do |mod|
    mod.subclass_checks.delete(@target)
  end
  @new_depended_superclasses.uniq!
  @new_depended_superclasses.each do |mod|
    mod.subclass_checks << @target
  end

  @depended_superclasses, @new_depended_superclasses = @new_depended_superclasses, @depended_superclasses
  @new_depended_superclasses.clear
end

#reuse(new_node) ⇒ Object



27
28
29
30
31
32
# File 'lib/typeprof/core/graph/change_set.rb', line 27

def reuse(new_node)
  @node = new_node
  @boxes.each_value do |box|
    box.reuse(new_node)
  end
end