Skip to content

Commit

Permalink
Use alternative approach: no foreach.
Browse files Browse the repository at this point in the history
It turns out that we may be able to avoid the foreach and the lambda
altogether, and instead use a cloneAttachments function.
  • Loading branch information
diesalbla committed Feb 17, 2020
1 parent 8c0fc27 commit 7ca7131
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 2 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ val mimaFilterSettings = Seq {
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.api.TypeTags.TypeTagImpl"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.api.Universe.TypeTagImpl"),
ProblemFilters.exclude[MissingClassProblem]("scala.reflect.macros.Attachments$"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.macros.Attachments.cloneAttachments"),
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.reflect.macros.NonemptyAttachments.cloneAttachments"),
ProblemFilters.exclude[DirectAbstractMethodProblem]("scala.collection.immutable.ArraySeq.stepper"),
ProblemFilters.exclude[ReversedAbstractMethodProblem]("scala.collection.immutable.ArraySeq.stepper"),
ProblemFilters.exclude[DirectAbstractMethodProblem]("scala.collection.mutable.ArraySeq.stepper"),
Expand Down
9 changes: 2 additions & 7 deletions src/reflect/scala/reflect/internal/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2039,8 +2039,8 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
setInfo (this.info cloneInfo clone)
setAnnotations this.annotations
)
updateAttachmentFun.theClone = clone
this.attachments.all.foreach(updateAttachmentFun)
assert(clone.attachments.isEmpty)
clone.setAttachments(this.attachments.cloneAttachments)
if (clone.thisSym != clone)
clone.typeOfThis = (clone.typeOfThis cloneInfo clone)

Expand All @@ -2050,11 +2050,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
clone
}

private[this] object updateAttachmentFun extends Function1[Any, Unit] {
var theClone: TypeOfClonedSymbol = null
def apply(x: Any): Unit = theClone.updateAttachment(x)
}

/** Internal method to clone a symbol's implementation with the given flags and no info. */
def cloneSymbolImpl(owner: Symbol, newFlags: Long): TypeOfClonedSymbol

Expand Down
2 changes: 2 additions & 0 deletions src/reflect/scala/reflect/macros/Attachments.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ abstract class Attachments { self =>
}

def isEmpty: Boolean = true
def cloneAttachments: Attachments { type Pos = self.Pos } = this
}

private object Attachments {
Expand All @@ -97,4 +98,5 @@ private final class NonemptyAttachments[P >: Null](override val pos: P, override
type Pos = P
def withPos(newPos: Pos) = new NonemptyAttachments(newPos, all)
override def isEmpty: Boolean = false
override def cloneAttachments: Attachments { type Pos = P } = new NonemptyAttachments[P](pos, all)
}

0 comments on commit 7ca7131

Please sign in to comment.