Skip to content

Clean up solveOne#6492

Merged
adriaanm merged 2 commits intoscala:2.13.xfrom
adriaanm:cleanup_solveOne
Apr 30, 2018
Merged

Clean up solveOne#6492
adriaanm merged 2 commits intoscala:2.13.xfrom
adriaanm:cleanup_solveOne

Conversation

@adriaanm
Copy link
Contributor

@adriaanm adriaanm commented Apr 5, 2018

Be conservative in our changes, but at least use =:= when
comparing types, so that an eta-expanded type constructor
and its 0-arg type ref compare equal.

Since there will be a complete overhaul of type inference in dotty,
let's not cause small fluctuations here in the mean time.

Type inference hasn't changed much in 13 years, so it seems
unwise to start tweaking quirks users have come to rely on.

Also, don't do tparam.subst(tparams, tvars) -- iterate
over tparams and tvars simultaneously, and just say tvar.

Add a configForeach combinator that iterates over arrays,
in hopes of getting a bit more locality. It would be nice if
its HOF was inlined, but it doesn't seem to happen currently.

Fixes scala/bug#8602 and fixes scala/bug#10722

@adriaanm adriaanm requested a review from lrytz April 5, 2018 10:03
@adriaanm adriaanm added this to the 2.13.0-M4 milestone Apr 5, 2018
Be conservative in our changes, but at least use `=:=` when
comparing types, so that an eta-expanded type constructor
and its 0-arg type ref compare equal.

Since there will be a complete overhaul of type inference in dotty,
let's not cause small fluctuations here in the mean time.

Type inference hasn't changed much in 13 years, so it seems
unwise to start tweaking quirks users have come to rely on.

Also, don't do `tparam.subst(tparams, tvars)` -- iterate
over `tparams` and `tvars` simultaneously, and just say `tvar`.

Add a `configForeach` combinator that iterates over arrays,
in hopes of getting a bit more locality. It would be nice if
its HOF was inlined, but it doesn't seem to happen currently.

Co-authored-by: Georgi Krastev <joro.kr.21@gmail.com>
Co-authored-by: Miles Sabin <miles@milessabin.com>
@joroKr21
Copy link
Member

joroKr21 commented Apr 5, 2018

You might want to add a test from #6333

When solving a list of type variables, bounds between them should
not be added as constraints when they are of different kinds.

The bug was fixed in the cleanup in the parent commit,
which was inspired by the work by joroKr21
val _tparams = tparams.toArray
val _variances = variances.toArray
val _len = _tvars.length
// TODO: can we make this reliably inline its HOF argument when it's a function?
Copy link
Member

Choose a reason for hiding this comment

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

What made you conclude it's not inlined? I did

../build/quick/bin/scalac -opt-warnings -opt:l:inline '-opt-inline-from:**' ../src/reflect/scala/reflect/internal/tpe/TypeConstraints.scala -Yopt-log-inline _

and see

Inline into scala/reflect/internal/tpe/TypeConstraints.solve: inlined scala/reflect/internal/tpe/TypeConstraints.configForeach$1. Before: 65 ins, inlined: 37 ins.
Inline into scala/reflect/internal/tpe/TypeConstraints.solveOne$1: inlined scala/reflect/internal/tpe/TypeConstraints.configForeach$1. Before: 323 ins, inlined: 37 ins.
Inline into scala/reflect/internal/tpe/TypeConstraints.solveOne$1: inlined scala/reflect/internal/tpe/TypeConstraints.configForeach$1. Before: 365 ins, inlined: 37 ins.
Inline into scala/reflect/internal/tpe/TypeConstraints.solveOne$1: inlined scala/reflect/internal/tpe/TypeConstraints.configForeach$1. Before: 408 ins, inlined: 37 ins.

Running cfr, I see all the inlined while loops and no more closure allocations.

@adriaanm
Copy link
Contributor Author

adriaanm commented Apr 16, 2018 via email

@adriaanm
Copy link
Contributor Author

adriaanm commented Apr 16, 2018 via email

@adriaanm adriaanm merged commit 50a616a into scala:2.13.x Apr 30, 2018
adriaanm added a commit to adriaanm/scala that referenced this pull request Jun 5, 2019
I don't have a great explanation, but the =:= on detecting
occurrences of type params in bounds was too eager.

When the info of a type param is a WildcardType, it
matches anything and type variables get overconstrained.

Discovered while looking into why this doesn't type check:

I noticed that there was cross talk between the type
params of java.util.Function in .
adriaanm added a commit to adriaanm/scala that referenced this pull request Jun 7, 2019
Use == instead of =:= because we're looking for occurs, not equality.

When we were using =:= to detect occurrences of type params in bounds,
we'd accidentally unify too much (e.g. on wildcards / other type vars).

Discovered while looking into why this doesn't type check:
`java.util.stream.Stream.of(1,2,3).map(_.toString)`

(scala/bug 11558)

I noticed that there was cross talk between the type
params of java.util.Function during type inference.
adriaanm added a commit to adriaanm/scala that referenced this pull request Jun 14, 2019
Use == instead of =:= because we're looking for occurs, not equality.

When we were using =:= to detect occurrences of type params in bounds,
we'd accidentally unify too much (e.g. on wildcards / other type vars).

Discovered while looking into why this doesn't type check:
`java.util.stream.Stream.of(1,2,3).map(_.toString)`

(scala/bug 11558)

I noticed that there was cross talk between the type
params of java.util.Function during type inference.
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.

Compiler crashes with "trying to do lub/glb of typevar" value class regression trying to do lub/glb of typevar

3 participants