diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2016-10-06 15:02:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-06 15:02:17 +0200 |
commit | 87a775724173bd803a0c4956408e61fd0d5812af (patch) | |
tree | c564a236f9247b085ed26c1fb007dad74ed049dd /src/dotty/tools/dotc/util | |
parent | a3064622e7ce4d73ddd91de0fc6bebfe0ec23ae9 (diff) | |
parent | e0a14e7939eda6a7f4914831975b2ac8877696f2 (diff) | |
download | dotty-87a775724173bd803a0c4956408e61fd0d5812af.tar.gz dotty-87a775724173bd803a0c4956408e61fd0d5812af.tar.bz2 dotty-87a775724173bd803a0c4956408e61fd0d5812af.zip |
Merge pull request #1492 from dotty-staging/add-inline
Implement inline
Diffstat (limited to 'src/dotty/tools/dotc/util')
-rw-r--r-- | src/dotty/tools/dotc/util/Attachment.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/util/Property.scala | 10 | ||||
-rw-r--r-- | src/dotty/tools/dotc/util/SourceFile.scala | 1 | ||||
-rw-r--r-- | src/dotty/tools/dotc/util/SourcePosition.scala | 6 | ||||
-rw-r--r-- | src/dotty/tools/dotc/util/Stats.scala | 17 |
5 files changed, 29 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/util/Attachment.scala b/src/dotty/tools/dotc/util/Attachment.scala index 8088b4cd0..20facfd97 100644 --- a/src/dotty/tools/dotc/util/Attachment.scala +++ b/src/dotty/tools/dotc/util/Attachment.scala @@ -4,9 +4,7 @@ package dotty.tools.dotc.util * adding, removing and lookup of attachments. Attachments are typed key/value pairs. */ object Attachment { - - /** The class of keys for attachments yielding values of type V */ - class Key[+V] + import Property.Key /** An implementation trait for attachments. * Clients should inherit from Container instead. diff --git a/src/dotty/tools/dotc/util/Property.scala b/src/dotty/tools/dotc/util/Property.scala new file mode 100644 index 000000000..608fc88e6 --- /dev/null +++ b/src/dotty/tools/dotc/util/Property.scala @@ -0,0 +1,10 @@ +package dotty.tools.dotc.util + +/** Defines a key type with which to tag properties, such as attachments + * or context properties + */ +object Property { + + /** The class of keys for properties of type V */ + class Key[+V] +}
\ No newline at end of file diff --git a/src/dotty/tools/dotc/util/SourceFile.scala b/src/dotty/tools/dotc/util/SourceFile.scala index 344bc253a..8bd0ecfd6 100644 --- a/src/dotty/tools/dotc/util/SourceFile.scala +++ b/src/dotty/tools/dotc/util/SourceFile.scala @@ -140,5 +140,6 @@ case class SourceFile(file: AbstractFile, content: Array[Char]) extends interfac @sharable object NoSource extends SourceFile("<no source>", Nil) { override def exists = false + override def atPos(pos: Position): SourcePosition = NoSourcePosition } diff --git a/src/dotty/tools/dotc/util/SourcePosition.scala b/src/dotty/tools/dotc/util/SourcePosition.scala index 0b2b2aa0b..68a9b6403 100644 --- a/src/dotty/tools/dotc/util/SourcePosition.scala +++ b/src/dotty/tools/dotc/util/SourcePosition.scala @@ -5,7 +5,8 @@ package util import Positions.{Position, NoPosition} /** A source position is comprised of a position in a source file */ -case class SourcePosition(source: SourceFile, pos: Position) extends interfaces.SourcePosition { +case class SourcePosition(source: SourceFile, pos: Position, outer: SourcePosition = NoSourcePosition) +extends interfaces.SourcePosition { def exists = pos.exists def lineContent: String = source.lineContent(point) @@ -24,6 +25,8 @@ case class SourcePosition(source: SourceFile, pos: Position) extends interfaces. def endLine: Int = source.offsetToLine(end) def endColumn: Int = source.column(end) + def withOuter(outer: SourcePosition) = new SourcePosition(source, pos, outer) + override def toString = if (source.exists) s"${source.file}:${line + 1}" else s"(no source file, offset = ${pos.point})" @@ -32,5 +35,6 @@ case class SourcePosition(source: SourceFile, pos: Position) extends interfaces. /** A sentinel for a non-existing source position */ @sharable object NoSourcePosition extends SourcePosition(NoSource, NoPosition) { override def toString = "?" + override def withOuter(outer: SourcePosition) = outer } diff --git a/src/dotty/tools/dotc/util/Stats.scala b/src/dotty/tools/dotc/util/Stats.scala index fdd3602c9..b7e0996f5 100644 --- a/src/dotty/tools/dotc/util/Stats.scala +++ b/src/dotty/tools/dotc/util/Stats.scala @@ -7,27 +7,34 @@ import collection.mutable @sharable object Stats { - final val enabled = true + final val enabled = false /** The period in ms in which stack snapshots are displayed */ final val HeartBeatPeriod = 250 + var monitored = false + @volatile private var stack: List[String] = Nil val hits = new mutable.HashMap[String, Int] { override def default(key: String): Int = 0 } - def record(fn: String, n: Int = 1) = { + @inline + def record(fn: String, n: Int = 1) = + if (enabled) doRecord(fn, n) + + private def doRecord(fn: String, n: Int) = if (monitored) { val name = if (fn.startsWith("member-")) "member" else fn hits(name) += n } - } - - var monitored = false + @inline def track[T](fn: String)(op: => T) = + if (enabled) doTrack(fn)(op) else op + + def doTrack[T](fn: String)(op: => T) = if (monitored) { stack = fn :: stack record(fn) |