Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve type variable name generation and recursive type detection when printing type errors #10488

Merged
merged 2 commits into from
Oct 15, 2021

Commits on Oct 12, 2021

  1. Separate type variable naming and loop marking when printing errors

    Improve type variable name generation and recursive type detection
    when printing type errors by
    
    1. Iterating over the whole trace and reserving type variable names
       once, to ensure that type variable names aren't reused in confusing
       ways between types.
    
    2. Detecting recursive types (i.e., marking loops) for each type
       individually during printing, ensuring that spurious `as 'a`
       clauses aren't generated and that `as`-bound names can't be
       referred to across different types.
    
    This involved updating the `Printtyp` module: first refactoring
    `mark_loops_rec` into a general case analysis
    `iter_type_expr_for_printing`, and then implementing both
    `reserve_names` and `mark_loops` in terms of it (via
    `Names.add_named_vars` and a new `mark_loops_rec` that only handles
    marking loops and not generating names).
    
    As a result, the API for printing types also changed:
    
    * `type_expr` still does what it always did.
    
    * To handle multiple types simultaneously, use `prepare_for_printing`
      and `prepared_type_expr` (replacing `marked_type_expr` and the
      associated marking facilities).
    
    * Within `Printtyp`, we use `named_type_expr`, which is in-between the
      other formatters and assumes names have been generated but does its
      own loop marking.
    antalsz committed Oct 12, 2021
    Configuration menu
    Copy the full SHA
    9c35329 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    326894d View commit details
    Browse the repository at this point in the history