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

SI-5330, SI-6014 deal with existential self-type #1074

Closed
wants to merge 1 commit into from

Conversation

adriaanm
Copy link
Contributor

@adriaanm adriaanm commented Aug 7, 2012

This has been broken since b7b81ca2#L0L567.
The existential rash is treated in a similar manner as in fc24db4.

Conceptually, the fix would be def selfTypeSkolemized = widen.skolemizeExistential.narrow,
but simply widening before narrowing achieves the same thing. Since we're in existential voodoo territory,
let's go for the minimal fix: replacing this.narrow by widen.narrow.

review by @odersky

This has been broken since scala@b7b81ca2#L0L567.
The existential rash is treated in a similar manner as in fc24db4.

Conceptually, the fix would be `def selfTypeSkolemized = widen.skolemizeExistential.narrow`,
but simply widening before narrowing achieves the same thing. Since we're in existential voodoo territory,
let's go for the minimal fix: replacing `this.narrow` by `widen.narrow`.
@adriaanm
Copy link
Contributor Author

adriaanm commented Aug 7, 2012

/cc @retronym

@scala-jenkins
Copy link

Started jenkins job pr-rangepos at https://scala-webapps.epfl.ch/jenkins/job/pr-rangepos/101/

@scala-jenkins
Copy link

Started jenkins job pr-scala-testsuite-linux-opt at https://scala-webapps.epfl.ch/jenkins/job/pr-scala-testsuite-linux-opt/804/

@scala-jenkins
Copy link

jenkins job pr-rangepos: Success - https://scala-webapps.epfl.ch/jenkins/job/pr-rangepos/101/

@scala-jenkins
Copy link

jenkins job pr-scala-testsuite-linux-opt: Success - https://scala-webapps.epfl.ch/jenkins/job/pr-scala-testsuite-linux-opt/804/

@odersky
Copy link
Contributor

odersky commented Aug 8, 2012

This looks fishy and will be disastrous from a performance standpoint. Narrow is expensive unless the type is already a singleton type. Widen makes sure it isn't.

@odersky
Copy link
Contributor

odersky commented Aug 8, 2012

In fact, I think it would be OK to outlaw existential self types.

@retronym
Copy link
Member

retronym commented Aug 8, 2012

What could be outlawed in this case?

https://github.com/scala/scala/pull/1074/files#L1R1

@adriaanm adriaanm closed this Aug 8, 2012
@retronym
Copy link
Member

A couple ideas for performance:

  1. Can we shortcut the .widen.narrow dance if the 'this' type doesn't contain existentials?
  2. Can we avoid self.memberType(other) matches symtpe if !(sym.isOverride && other.isOverridableSymbol).

I repeat @paulp's comments from isOverriddingSymbol which might be relevant in determining whether we can take the second shortcut.

/** Equivalent to allOverriddenSymbols.nonEmpty, but more efficient. */
    // !!! When if ever will this answer differ from .isOverride?
    // How/where is the OVERRIDE flag managed, as compared to how checks
    // based on type membership will evaluate?
    def isOverridingSymbol = owner.isClass && (
      owner.ancestors exists (cls => matchingSymbol(cls, owner.thisType) != NoSymbol)
    )

adriaanm pushed a commit to adriaanm/scala that referenced this pull request Nov 14, 2012
This has been broken since scala@b7b81ca2#L0L567.
The existential rash is treated in a similar manner as in fc24db4.

Conceptually, the fix would be `def selfTypeSkolemized =
widen.skolemizeExistential.narrow`, but simply widening before
narrowing achieves the same thing. Since we're in existential voodoo
territory, let's go for the minimal fix: replacing `this.narrow` by
`widen.narrow`.

--
Original patch by @retronym in scala#1074, refined by @paulp to
only perform widen.narrow incantation if there are
existentials present in the widened type, as
narrowing is expensive when the type is not a singleton.

The result is that compiling the entirety of quick, that
code path is hit only 143 times.  All the other calls hit
.narrow directly as before.  It looks like the definition
of negligible in the diff of -Ystatistics when compiling
src/library/scala/collection:

    < #symbols                      : 306315
    ---
    > #symbols                      : 306320
    12c13
    < #unique types                 : 293859
    ---
    > #unique types                 : 293865

I'm assuming based on the 2/1000ths of a percent increase
in symbol and type creation that wall clock is manageable,
but I didn't measure it.
adriaanm added a commit to adriaanm/scala that referenced this pull request Nov 14, 2012
This has been broken since scala@b7b81ca2#L0L567.
The existential rash is treated in a similar manner as in fc24db4.

Conceptually, the fix would be `def selfTypeSkolemized =
widen.skolemizeExistential.narrow`, but simply widening before
narrowing achieves the same thing. Since we're in existential voodoo
territory, let's go for the minimal fix: replacing `this.narrow` by
`widen.narrow`.

--
Original patch by @retronym in scala#1074, refined by @paulp to
only perform widen.narrow incantation if there are
existentials present in the widened type, as
narrowing is expensive when the type is not a singleton.

The result is that compiling the entirety of quick, that
code path is hit only 143 times.  All the other calls hit
.narrow directly as before.  It looks like the definition
of negligible in the diff of -Ystatistics when compiling
src/library/scala/collection:

    < #symbols                      : 306315
    ---
    > #symbols                      : 306320
    12c13
    < #unique types                 : 293859
    ---
    > #unique types                 : 293865

I'm assuming based on the 2/1000ths of a percent increase
in symbol and type creation that wall clock is manageable,
but I didn't measure it.
@adriaanm adriaanm deleted the ticket-5330 branch December 10, 2013 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants