Skip to content

Commit 92013ab

Browse files
committed
Merge pull request #354 from dotty-staging/fix/capturedvars
Fix/capturedvars
2 parents 9641b2a + 0fd1ced commit 92013ab

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

src/dotty/tools/dotc/transform/CapturedVars.scala

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,12 @@ class CapturedVars extends MiniPhase with IdentityDenotTransformer { thisTransfo
5959
refMap.getOrElse(cls, refMap(defn.ObjectClass))
6060
}
6161

62-
def capturedType(vble: Symbol)(implicit ctx: Context): Type = {
63-
val oldInfo = vble.denot(ctx.withPhase(thisTransform)).info
64-
refCls(oldInfo.classSymbol, vble.isVolatile).typeRef
65-
}
66-
6762
override def prepareForValDef(vdef: ValDef)(implicit ctx: Context) = {
6863
val sym = vdef.symbol
6964
if (captured contains sym) {
7065
val newd = sym.denot(ctx.withPhase(thisTransform)).copySymDenotation(
71-
info = refCls(sym.info.classSymbol, sym.hasAnnotation(defn.VolatileAnnot)).typeRef)
66+
info = refCls(sym.info.classSymbol, sym.hasAnnotation(defn.VolatileAnnot)).typeRef,
67+
initFlags = sym.flags &~ Mutable)
7268
newd.removeAnnotation(defn.VolatileAnnot)
7369
newd.installAfter(thisTransform)
7470
}

src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,7 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) {
9999
* Lines are numbered from 0
100100
*/
101101
def offsetToLine(offset: Int): Int = {
102-
val lines = lineIndices
103-
def findLine(lo: Int, hi: Int, mid: Int): Int =
104-
if (offset < lines(mid)) findLine(lo, mid - 1, (lo + mid - 1) / 2)
105-
else if (offset >= lines(mid + 1)) findLine(mid + 1, hi, (mid + 1 + hi) / 2)
106-
else mid
107-
lastLine = findLine(0, lines.length, lastLine)
102+
lastLine = Util.bestFit(lineIndices, offset, lastLine)
108103
lastLine
109104
}
110105

src/dotty/tools/dotc/util/Util.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package dotty.tools.dotc.util
2+
import reflect.ClassTag
3+
4+
object Util {
5+
6+
/** The index `i` in `candidates.indices` such that `candidates(i) <= x` and
7+
* `candidates(i)` is closest to `x`, determined by binary search, or -1
8+
* if `x < candidates(0)`.
9+
* @param hint If between 0 and `candidates.length` use this
10+
* as the first search point, otherwise use
11+
* `candidates.length/2`.
12+
* @pre candidates is sorted
13+
*/
14+
def bestFit(candidates: Array[Int], x: Int, hint: Int = -1): Int = {
15+
def recur(lo: Int, hi: Int, mid: Int): Int =
16+
if (x < candidates(mid))
17+
recur(lo, mid - 1, (lo + mid - 1) / 2)
18+
else if (mid + 1 < candidates.length && x >= candidates(mid + 1))
19+
recur(mid + 1, hi, (mid + 1 + hi) / 2)
20+
else mid
21+
val initMid =
22+
if (0 <= hint && hint < candidates.length) hint
23+
else candidates.length / 2
24+
if (candidates.isEmpty || x < candidates(0)) -1
25+
else recur(0, candidates.length, initMid)
26+
}
27+
28+
/** An array twice the size of given array, with existing elements copied over */
29+
def dble[T: ClassTag](arr: Array[T]) = {
30+
val arr1 = new Array[T](arr.length * 2)
31+
Array.copy(arr, 0, arr1, 0, arr.length)
32+
arr1
33+
}
34+
}

0 commit comments

Comments
 (0)