Skip to content

More IDE work #2885

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 6 commits into from
Jul 20, 2017
Merged

More IDE work #2885

merged 6 commits into from
Jul 20, 2017

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jul 18, 2017

  • Make NamedTrees survive TypeErrors
    (Same principle as for completions applies).
  • Null out closures in LazyRef and LazyBodyAnnotation once they are evaluated.

@@ -62,6 +62,9 @@ object Interactive {
sourceSymbol(sym.owner)
else sym

private def safely[T](op: => List[T]): List[T] =
Copy link
Member

Choose a reason for hiding this comment

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

Mark it @inline ?

@@ -131,7 +131,7 @@ object Interactive {
* @param includeReferences If true, include references and not just definitions
*/
def namedTrees(trees: List[SourceTree], includeReferences: Boolean, treePredicate: NameTree => Boolean)
(implicit ctx: Context): List[SourceTree] = {
(implicit ctx: Context): List[SourceTree] = safely {
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit of a shame that this means we'll discard all results when the problem might be localized. Alternatively, we could move the try/catch around traverseChildren I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's pretty rare that we would get a TypeError, so not a big deal either way.

@@ -2146,13 +2146,15 @@ object Types {
}

case class LazyRef(refFn: () => Type) extends UncachedProxyType with ValueType {
private var myRefFn: () => Type = refFn
Copy link
Member

Choose a reason for hiding this comment

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

I think this would be slightly nicer as case class LazyRef(private var refFn: () => Type), this way you cannot accidentally capture refFn outside of the constructor.

@@ -2146,13 +2146,15 @@ object Types {
}

case class LazyRef(refFn: () => Type) extends UncachedProxyType with ValueType {
private var myRefFn: () => Type = refFn
Copy link
Member

Choose a reason for hiding this comment

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

Also, another way to avoid the leak would be to write refFn: Context => Type at the cost that equals could not be made to force the reference anymore. I tried it before and it seemed to work, but I haven't benchmarked it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure it would work in general, though. Seems generally dicy to evaluate in a different context. We'd have to check every site where we create a LazyRef whether it is permissible.

odersky added 6 commits July 19, 2017 15:46
Same principle as for completions applies.
This prevented many local functions from being lifted out
to static scope, and thereby caused memory leaks. The memory leak found
in the IDE was caused an anonymous function in NamerContextOps (a base
trait of Context) that was kept as a non-private private method of
NamerContextOps, taking a `this` referring to a context.
The previous attempt did not actually remove the closure, since
LazyRef is a case class.
@@ -61,14 +61,15 @@ object Annotations {
def tree(implicit ctx: Context) = body
}

case class LazyBodyAnnotation(bodyExpr: Context => Tree) extends BodyAnnotation {
case class LazyBodyAnnotation(private var bodyExpr: Context => Tree) extends BodyAnnotation {
Copy link
Member

Choose a reason for hiding this comment

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

It's suspicious that a Context => Tree function would capture a Context.

Copy link
Member

Choose a reason for hiding this comment

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

@odersky odersky changed the title More IDE work [WIP] More IDE work Jul 20, 2017
@odersky odersky merged commit 4f60767 into scala:master Jul 20, 2017
@allanrenucci allanrenucci deleted the harden-ide-2 branch December 14, 2017 19:23
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.

2 participants