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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.

private var evaluated = false
private var myBody: Tree = _
def tree(implicit ctx: Context) = {
if (evaluated) assert(myBody != null)
else {
evaluated = true
myBody = bodyExpr(ctx)
bodyExpr = null
}
myBody
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,7 @@ object Types {
}
}

case class LazyRef(refFn: () => Type) extends UncachedProxyType with ValueType {
case class LazyRef(private var refFn: () => Type) extends UncachedProxyType with ValueType {
private var myRef: Type = null
private var computed = false
def ref = {
Expand Down
14 changes: 7 additions & 7 deletions compiler/src/dotty/tools/dotc/interactive/Interactive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?

try op catch { case ex: TypeError => Nil }

/** Possible completions at position `pos` */
def completions(trees: List[SourceTree], pos: SourcePosition)(implicit ctx: Context): List[Symbol] = {
val path = pathTo(trees, pos)
Expand All @@ -85,16 +88,13 @@ object Interactive {
}

/** Possible completions of members of `prefix` which are accessible when called inside `boundary` */
def completions(prefix: Type, boundary: Symbol)(implicit ctx: Context): List[Symbol] = {
val boundaryCtx = ctx.withOwner(boundary)
try
def completions(prefix: Type, boundary: Symbol)(implicit ctx: Context): List[Symbol] =
safely {
val boundaryCtx = ctx.withOwner(boundary)
prefix.memberDenots(completionsFilter, (name, buf) =>
buf ++= prefix.member(name).altsWith(d => !d.isAbsent && d.symbol.isAccessibleFrom(prefix)(boundaryCtx))
).map(_.symbol).toList
catch {
case ex: TypeError => Nil
}
}

/** Filter for names that should appear when looking for completions. */
private[this] object completionsFilter extends NameFilter {
Expand Down Expand Up @@ -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.

val buf = new mutable.ListBuffer[SourceTree]

trees foreach { case SourceTree(topTree, source) =>
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/LambdaLift.scala
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
if (enclosure.is(PackageClass)) enclosure
else if (enclosure.isConstructor) markFree(sym, enclosure.owner.enclosure)
else markFree(sym, enclosure.enclosure)
narrowLiftedOwner(enclosure, intermediate orElse sym.enclosingClass)
if (intermediate.exists) narrowLiftedOwner(enclosure, intermediate)
if (!intermediate.isRealClass || enclosure.isConstructor) {
// Constructors and methods nested inside traits get the free variables
// of the enclosing trait or class.
Expand Down Expand Up @@ -384,7 +384,7 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
local.copySymDenotation(
owner = newOwner,
name = newName(local),
initFlags = local.flags &~ Module | Private | maybeStatic,
initFlags = local.flags &~ Module &~ Final | Private | maybeStatic,
// drop Module because class is no longer a singleton in the lifted context.
info = liftedInfo(local)).installAfter(thisTransform)
}
Expand Down