Skip to content

Avoid infinite loop in type variable instantiation #9030

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

Merged
merged 1 commit into from
May 24, 2020

Conversation

smarter
Copy link
Member

@smarter smarter commented May 23, 2020

Rename checkNonCyclic to occursAtToplevel and refactor it to return
a boolean, use it in ConstraintHandling#instanceType to make sure we
do not introduce a cycle when instantiating a type variable.

Some alternatives I considered:

  • Run widenInferred inside frozen constraints: this prevents
    Set[A] | Set[Int] to be widened to Set[Int] after instantiating
    A := Int
  • Run widenInferred with the upper bound of param instead of param
    itself as a bound: I think this is still not safe because the upper
    bound of param might recursively refer to param, it also breaks
    type inference of one expression in ZIO.

@smarter
Copy link
Member Author

smarter commented May 23, 2020

test performance please

@dottybot
Copy link
Member

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/9030/ to see the changes.

Benchmarks is based on merging with master (59587ba)

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for suggestion LGTM

@odersky odersky assigned smarter and unassigned odersky May 24, 2020
Rename `checkNonCyclic` to `occursAtToplevel` and refactor it to return
a boolean, use it in `ConstraintHandling#instanceType` to make sure we
do not introduce a cycle when instantiating a type variable.

Some alternatives I considered:
- Run `widenInferred` inside frozen constraints: this prevents
  `Set[A] | Set[Int]` to be widened to `Set[Int]` after instantiating
  `A := Int`
- Run `widenInferred` with the upper bound of `param` instead of `param`
  itself as a bound: I think this is still not safe because the upper
  bound of `param` might recursively refer to `param`, it also breaks
  type inference of one expression in ZIO.
@smarter smarter merged commit 420822b into scala:master May 24, 2020
@smarter smarter deleted the widenInferred branch May 24, 2020 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants