Skip to content

Decomposition of HintRef is slow #3268

@rchen152

Description

@rchen152

Describe the Bug

I recently fixed #793 (contextual typing with union hints) by changing the logic for hint decomposition to iterate over union members, trying every one. This is fairly expensive, and I had to add a couple hard-coded limits for the maximum union size we'll iterate over. There are a few optimizations we can try to make this more performant (ideas courtesy of @samwgoldman):

  • pre-process expressions to separate “contextually sensitive” from non, avoiding even attempting contextual typing for expressions which don’t need it. These expressions can just be inferred once.
  • a normalization process for hints which can simplify hint type. For example, a hint with the form Any | t can match any expression, so we can simplify the hint away.
  • a matching/filtering process during the contextual push down which can filter contexts which are not useful.
  • making the process of decomposing hints lazy, to avoid the computation when the hint would go unused

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

contextual-typingissues related to contextual typing

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions