Skip to content

Fix #6199: Use a skolemized prefix in asSeenFrom when needed #6454

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 7, 2019

Conversation

smarter
Copy link
Member

@smarter smarter commented May 4, 2019

Prior to
91ee02f,
unstable prefixes appearing in selection types were handled in a
two-pass approach which can be summarized as:

  1. Type the selection with the unstable prefix, if this prefix appears
    in a position where it cannot be widened away, mark it with a special
    annotation.
  2. If the result of the selection contains this annotation, retype it
    after having wrapped its prefix in a skolem.

This got replaced by the use of an ApproximatingTypeMap which can
always construct a valid (but potentially approximated) type for the
selection.

Most of the time this is all we need but there are some cases where
skolemizing the prefix is still useful as witnessed by the tests added
in this commit. They are now handled by unconditionally skolemizing
unstable prefixes.

To avoid any potential performance impact from this, we teach
asSeenFrom to always widen these prefixes first and only make use of
the skolem to avoid returning an approximation. Since this almost never
occurs (it happens only once when compiling Dotty) this means we incur
almost no extra cost (the skolem itself still needs to be allocated
unconditionally in advance, this cannot be delegated to asSeenFrom
because it's supposed to be an idempotent operation and each skolem is
unique).

@smarter smarter force-pushed the fix/type-member-inf-7 branch from 5b454e3 to c768382 Compare May 4, 2019 23:05
@smarter smarter requested a review from odersky May 4, 2019 23:06
@smarter smarter force-pushed the fix/type-member-inf-7 branch 2 times, most recently from f556249 to 3c75623 Compare May 4, 2019 23:29
@smarter
Copy link
Member Author

smarter commented May 4, 2019

test performance please

@dottybot
Copy link
Member

dottybot commented May 4, 2019

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

def accessibleDenot(pre: Type, name: Name, sig: Signature) = {
val d = pre.member(name).atSignature(sig)
def accessibleDenot(qualType: Type, name: Name, sig: Signature) = {
val pre = ctx.typeAssigner.maybeSkolemizePrefix(qualType, name)
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not super happy with having to recompute whether the prefix needs to be skolemized in the unpickler, but I don't really see a way around it. Maybe asSeenFrom should behave differently when unpickling a tree, but how do you even know if the type on which asSeenFrom is called comes from a tree being unpickled ? And even if we manage to allow unstable prefixes when unpickling, is that really sound when combined with inlining ?

@dottybot
Copy link
Member

dottybot commented May 5, 2019

Performance test finished successfully:

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

Benchmarks is based on merging with master (61ea245)

@liufengyun
Copy link
Contributor

test performance please

@dottybot
Copy link
Member

dottybot commented May 5, 2019

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

@dottybot
Copy link
Member

dottybot commented May 5, 2019

Performance test finished successfully:

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

Benchmarks is based on merging with master (61ea245)

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.

Otherwise LGTM

@odersky odersky assigned smarter and unassigned odersky May 6, 2019
Prior to
scala@91ee02f,
unstable prefixes appearing in selection types were handled in a
two-pass approach which can be summarized as:

1. Type the selection with the unstable prefix, if this prefix appears
   in a position where it cannot be widened away, mark it with a special
   annotation.
2. If the result of the selection contains this annotation, retype it
   after having wrapped its prefix in a skolem.

This got replaced by the use of an `ApproximatingTypeMap` which can
always construct a valid (but potentially approximated) type for the
selection.

Most of the time this is all we need but there are some cases where
skolemizing the prefix is still useful as witnessed by the tests added
in this commit. They are now handled by unconditionally skolemizing
unstable prefixes.

To avoid any potential performance impact from this, we teach
`asSeenFrom` to always widen these prefixes first and only make use of
the skolem to avoid returning an approximation. Since this almost never
occurs (it happens only once when compiling Dotty) this means we incur
almost no extra cost (the skolem itself still needs to be allocated
unconditionally in advance, this cannot be delegated to `asSeenFrom`
because it's supposed to be an idempotent operation and each skolem is
unique).
@smarter smarter force-pushed the fix/type-member-inf-7 branch from 3c75623 to 502c7c9 Compare May 7, 2019 16:42
@smarter smarter merged commit c99e771 into scala:master May 7, 2019
@allanrenucci allanrenucci deleted the fix/type-member-inf-7 branch May 7, 2019 20:40
@anatoliykmetyuk anatoliykmetyuk added this to the 0.15 Tech Preview milestone May 21, 2019
smarter added a commit to smarter/zio that referenced this pull request Jun 26, 2019
These are no longer needed thanks to
scala/scala3#6454
ghostdogpr pushed a commit to zio/zio that referenced this pull request Jun 27, 2019
…make the CI compile the tests with Dotty too (#1088)

* Fix the Dotty build

stacktracerJVM and coreJVM were using different versions of dotty, so
`++0.16.0-RC3; coreJVM/compile` failed (it worked if you did
"++0.16.0-RC3!`, which is what the CI does).

* Make compileJVM compile the tests too

That way, compileJVM is used by the CI to test Dotty, so this ensures
that the tests compile with Dotty.

* Avoid passing the same option twice to Dotty

This is already set in `extraOptions`.

* Remove some Dotty workarounds

These are no longer needed thanks to
scala/scala3#6454
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.

5 participants