Skip to content

Commit 509a6e3

Browse files
committed
Remove check_match methods
1 parent 3251cbc commit 509a6e3

3 files changed

Lines changed: 3 additions & 227 deletions

File tree

lib/typeprof/core/graph/box.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def match_arguments?(genv, changes, param_map, a_args, method_type)
182182
return true
183183
end
184184

185-
def check_match_overload(changes, genv, method_type, node, param_map, a_args, ret, force)
185+
def resolve_overload(changes, genv, method_type, node, param_map, a_args, ret, force)
186186
param_map0 = param_map.dup
187187
if method_type.type_params
188188
method_type.type_params.zip(yield(method_type)) do |var, vtx|
@@ -247,13 +247,13 @@ def check_match_overload(changes, genv, method_type, node, param_map, a_args, re
247247
def resolve_overloads(changes, genv, node, param_map, a_args, ret, &blk)
248248
if @method_types.size == 1
249249
method_type = @method_types.first
250-
check_match_overload(changes, genv, method_type, node, param_map, a_args, ret, true, &blk)
250+
resolve_overload(changes, genv, method_type, node, param_map, a_args, ret, true, &blk)
251251
return
252252
end
253253

254254
match_any_overload = false
255255
@method_types.each do |method_type|
256-
if check_match_overload(changes, genv, method_type, node, param_map, a_args, ret, false, &blk)
256+
if resolve_overload(changes, genv, method_type, node, param_map, a_args, ret, false, &blk)
257257
match_any_overload = true
258258
end
259259
end

lib/typeprof/core/graph/vertex.rb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,6 @@ def each_type(&blk)
2020
end
2121
end
2222

23-
def check_match(genv, changes, vtx)
24-
vtx.each_type do |ty|
25-
if ty.is_a?(Type::Var)
26-
changes.add_edge(genv, self, ty.vtx) if self != ty.vtx
27-
return true
28-
end
29-
end
30-
31-
return true if vtx.types.empty?
32-
33-
each_type do |ty|
34-
return true if vtx.types.include?(ty) # fast path
35-
if ty.check_match(genv, changes, vtx)
36-
return true
37-
end
38-
end
39-
40-
return false
41-
end
42-
4323
def show
4424
Fiber[:show_rec] ||= Set[]
4525
if Fiber[:show_rec].include?(self)

lib/typeprof/core/type.rb

Lines changed: 0 additions & 204 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,6 @@ def base_type(_)
5454
self
5555
end
5656

57-
def check_match(genv, changes, vtx)
58-
vtx.each_type do |other_ty|
59-
case other_ty
60-
when Singleton
61-
other_mod = other_ty.mod
62-
if other_mod.module?
63-
# TODO: implement
64-
else
65-
mod = @mod
66-
while mod
67-
return true if mod == other_mod
68-
changes.add_depended_superclass(mod)
69-
mod = mod.superclass
70-
end
71-
end
72-
when Instance
73-
base_ty = @mod.module? ? genv.mod_type : genv.cls_type
74-
return true if base_ty.check_match(genv, changes, Source.new(other_ty))
75-
end
76-
end
77-
return false
78-
end
79-
8057
def show
8158
"singleton(#{ @mod.show_cpath })"
8259
end
@@ -102,87 +79,6 @@ def base_type(_)
10279
self
10380
end
10481

105-
def check_match(genv, changes, vtx)
106-
vtx.each_type do |other_ty|
107-
case other_ty
108-
when Instance
109-
ty = self
110-
while ty
111-
if ty.mod == other_ty.mod
112-
args_all_match = true
113-
ty.args.zip(other_ty.args) do |arg, other_arg|
114-
unless arg.check_match(genv, changes, other_arg || Source.new)
115-
args_all_match = false
116-
break
117-
end
118-
end
119-
return true if args_all_match
120-
end
121-
changes.add_depended_superclass(ty.mod)
122-
123-
if other_ty.mod.module?
124-
return true if check_match_prepended_modules(genv, changes, ty, other_ty)
125-
return true if check_match_included_modules(genv, changes, ty, other_ty)
126-
end
127-
128-
ty = genv.get_superclass_type(ty, changes, {})
129-
end
130-
end
131-
end
132-
return false
133-
end
134-
135-
def check_match_prepended_modules(genv, changes, ty, other_ty)
136-
ty.mod.prepended_modules.each do |prep_decl, prep_mod|
137-
if prep_decl.is_a?(AST::SigPrependNode) && prep_mod.type_params
138-
prep_ty = genv.get_instance_type(prep_mod, prep_decl.args, changes, {}, ty)
139-
else
140-
type_params = prep_mod.type_params.map {|ty_param| Source.new() } # TODO: better support
141-
prep_ty = Type::Instance.new(genv, prep_mod, type_params)
142-
end
143-
if prep_ty.mod == other_ty.mod
144-
args_all_match = true
145-
prep_ty.args.zip(other_ty.args) do |arg, other_arg|
146-
if other_arg && !arg.check_match(genv, changes, other_arg)
147-
args_all_match = false
148-
break
149-
end
150-
end
151-
return true if args_all_match
152-
end
153-
changes.add_depended_superclass(prep_ty.mod)
154-
155-
return true if check_match_prepended_modules(genv, changes, prep_ty, other_ty)
156-
return true if check_match_included_modules(genv, changes, prep_ty, other_ty)
157-
end
158-
return false
159-
end
160-
161-
def check_match_included_modules(genv, changes, ty, other_ty)
162-
ty.mod.included_modules.each do |inc_decl, inc_mod|
163-
if inc_decl.is_a?(AST::SigIncludeNode) && inc_mod.type_params
164-
inc_ty = genv.get_instance_type(inc_mod, inc_decl.args, changes, {}, ty)
165-
else
166-
type_params = inc_mod.type_params.map {|ty_param| Source.new() } # TODO: better support
167-
inc_ty = Type::Instance.new(genv, inc_mod, type_params)
168-
end
169-
if inc_ty.mod == other_ty.mod
170-
args_all_match = true
171-
inc_ty.args.zip(other_ty.args) do |arg, other_arg|
172-
if other_arg && !arg.check_match(genv, changes, other_arg)
173-
args_all_match = false
174-
break
175-
end
176-
end
177-
return true if args_all_match
178-
end
179-
changes.add_depended_superclass(inc_ty.mod)
180-
181-
return true if check_match_included_modules(genv, changes, inc_ty, other_ty)
182-
end
183-
return false
184-
end
185-
18682
def show
18783
case @mod.cpath
18884
when [:NilClass] then "nil"
@@ -245,24 +141,6 @@ def base_type(genv)
245141
@base_type
246142
end
247143

248-
def check_match(genv, changes, vtx)
249-
vtx.each_type do |other_ty|
250-
if other_ty.is_a?(Array)
251-
if @elems.size == other_ty.elems.size
252-
match = true
253-
@elems.zip(other_ty.elems) do |elem, other_elem|
254-
unless elem.check_match(genv, changes, other_elem)
255-
match = false
256-
break
257-
end
258-
end
259-
return true if match
260-
end
261-
end
262-
end
263-
@base_type.check_match(genv, changes, vtx)
264-
end
265-
266144
def show
267145
if @elems
268146
"[#{ @elems.map {|e| Type.strip_parens(e.show) }.join(", ") }]"
@@ -292,32 +170,6 @@ def base_type(genv)
292170
@base_type
293171
end
294172

295-
def check_match(genv, changes, vtx)
296-
vtx.each_type do |other_ty|
297-
case other_ty
298-
when Record
299-
# Hash can match with Record if Hash has Symbol keys
300-
# and Hash value type can accept all Record field values
301-
key_ty = get_key
302-
val_ty = get_value
303-
304-
# Check if this Hash has Symbol keys
305-
return false unless key_ty && Source.new(genv.symbol_type).check_match(genv, changes, key_ty)
306-
307-
# Check if Hash value type contains all required types for Record fields
308-
other_ty.fields.each do |_key, field_val_vtx|
309-
# For each Record field, check if field type can match with Hash value type
310-
return false unless val_ty && field_val_vtx.check_match(genv, changes, val_ty)
311-
end
312-
313-
return true
314-
end
315-
end
316-
317-
# Fall back to base_type check for other cases
318-
@base_type.check_match(genv, changes, vtx)
319-
end
320-
321173
def show
322174
@base_type.show
323175
end
@@ -334,10 +186,6 @@ def base_type(genv)
334186
genv.proc_type
335187
end
336188

337-
def check_match(genv, changes, vtx)
338-
genv.proc_type.check_match(genv, changes, vtx)
339-
end
340-
341189
def show
342190
"<Proc>"
343191
end
@@ -355,18 +203,6 @@ def base_type(genv)
355203
genv.symbol_type
356204
end
357205

358-
def check_match(genv, changes, vtx)
359-
vtx.each_type do |other_ty|
360-
case other_ty
361-
when Symbol
362-
return true if @sym == other_ty.sym
363-
when Instance
364-
return true if genv.symbol_type.check_match(genv, changes, Source.new(other_ty))
365-
end
366-
end
367-
return false
368-
end
369-
370206
def show
371207
@sym.inspect
372208
end
@@ -380,10 +216,6 @@ def base_type(genv)
380216
genv.obj_type
381217
end
382218

383-
def check_match(genv, changes, vtx)
384-
return true
385-
end
386-
387219
def show
388220
"bot"
389221
end
@@ -402,10 +234,6 @@ def base_type(genv)
402234
genv.obj_type # Is this ok?
403235
end
404236

405-
def check_match(genv, changes, vtx)
406-
true # should implement a better support...
407-
end
408-
409237
def show
410238
"var[#{ @name }]"
411239
end
@@ -438,38 +266,6 @@ def base_type(genv)
438266
@base_type
439267
end
440268

441-
def check_match(genv, changes, vtx)
442-
vtx.each_type do |other_ty|
443-
case other_ty
444-
when Record
445-
# Check if all fields match
446-
return false unless @fields.size == other_ty.fields.size
447-
@fields.each do |key, val_vtx|
448-
other_val_vtx = other_ty.fields[key]
449-
return false unless other_val_vtx
450-
return false unless val_vtx.check_match(genv, changes, other_val_vtx)
451-
end
452-
return true
453-
when Hash
454-
# Record can match with Hash only if the Hash has Symbol keys
455-
# and all record values can match with the Hash value type
456-
key_vtx = other_ty.get_key
457-
val_vtx = other_ty.get_value
458-
459-
# Check if Hash key type is Symbol
460-
return false unless key_vtx && Source.new(genv.symbol_type).check_match(genv, changes, key_vtx)
461-
462-
# Check if all record field values can match with Hash value type
463-
@fields.each do |_key, field_val_vtx|
464-
return false unless field_val_vtx.check_match(genv, changes, val_vtx)
465-
end
466-
467-
return true
468-
end
469-
end
470-
return false
471-
end
472-
473269
def show
474270
field_strs = @fields.map do |key, val_vtx|
475271
"#{ key }: #{ Type.strip_parens(val_vtx.show) }"

0 commit comments

Comments
 (0)