Skip to content

Commit

Permalink
Switch fully to argument-by-argument call matching for PyTDFunction.
Browse files Browse the repository at this point in the history
* Groups matches by view so that multiple overloads work.
* Gets rid of the "variable view" hack we were using to simultaneously support
  the old and new matching implementations.
* Does a few performance optimizations to mitigate slowdowns caused by changes
  to CFG queries. This change was causing a few random slowdowns/timeouts by
  causing us to hit queries that are inexplicably slow. I simplified variables
  and avoided/delayed filtering in a few places to fix this.
* Removes buggy enforcement of --strict-parameter-checks in
  matcher.compute_one_match. I'll re-implement this feature flag in a more
  correct manner at a later time.
* Updates the subprocess overlay to work with the new matching implementation.

PiperOrigin-RevId: 482701895
  • Loading branch information
rchen152 committed Oct 26, 2022
1 parent d5c0a6d commit 8155f0f
Show file tree
Hide file tree
Showing 18 changed files with 354 additions and 289 deletions.
1 change: 1 addition & 0 deletions pytype/abstract/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ py_library(
.mixin
pytype.utils
pytype.pytd.pytd
pytype.typegraph.cfg
)

py_library(
Expand Down
24 changes: 0 additions & 24 deletions pytype/abstract/_function_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,6 @@ def match_args(self, node, args, alias_map=None, match_all_views=False):
return self._match_args_sequentially(node, args, alias_map, match_all_views)

def _is_complex_generic_call(self, args):
if _isinstance(self, "SignedFunction"):
return False
for sig in function.get_signatures(self):
parameter_typevar_count = 0
for name, t in sig.annotations.items():
stack = [t]
seen = set()
while stack:
cur = stack.pop()
if cur in seen:
continue
seen.add(cur)
if cur.template:
return True
parameter_typevar_count += (name != "return" and cur.formal)
if _isinstance(cur, "Union"):
stack.extend(cur.options)
if parameter_typevar_count > 1:
return True
if self.is_attribute_of_class and args.posargs:
for self_val in args.posargs[0].data:
for cls in self_val.cls.mro:
if cls.template:
return True
return False

def _match_views(self, node, args, alias_map, match_all_views):
Expand Down
2 changes: 1 addition & 1 deletion pytype/abstract/_interpreter_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def _match_args_sequentially(self, node, args, alias_map, match_all_views):
matcher = self.ctx.matcher(node)
try:
matches = matcher.compute_matches(
args_to_match, match_all_views, alias_map)
args_to_match, match_all_views, alias_map=alias_map)
except matcher.MatchError as e:
raise function.WrongArgTypes(self.signature, args, self.ctx, e.bad_type)
return [m.subst for m in matches]
Expand Down
Loading

0 comments on commit 8155f0f

Please sign in to comment.