Skip to content

Backport/names names names #39

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

Closed
wants to merge 17 commits into from
Closed
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
20 changes: 18 additions & 2 deletions project/VersionUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import Keys._
import java.util.{Date, Locale, Properties, TimeZone}
import java.io.{File, FileInputStream}
import java.text.SimpleDateFormat
import java.time.Instant
import java.time.format.DateTimeFormatter
import java.time.temporal.{TemporalAccessor, TemporalQueries, TemporalQuery}

import scala.collection.JavaConverters._
import BuildSettings.autoImport._
Expand Down Expand Up @@ -71,8 +74,21 @@ object VersionUtil {
val db = new FileRepositoryBuilder().findGitDir.build
val head = db.resolve("HEAD")
if (head eq null) {
log.info("No git HEAD commit found -- Using current date and 'unknown' SHA")
(new Date, "unknown")
import scala.sys.process._
try {
// Workaround lack of git worktree support in JGit https://bugs.eclipse.org/bugs/show_bug.cgi?id=477475
val sha = List("git", "rev-parse", "HEAD").!!.trim
val commitDateIso = List("git", "log", "-1", "--format=%cI", "HEAD").!!.trim
val date = java.util.Date.from(DateTimeFormatter.ISO_DATE_TIME.parse(commitDateIso, new TemporalQuery[Instant] {
override def queryFrom(temporal: TemporalAccessor): Instant = Instant.from(temporal)
}))
(date, sha.substring(0, 7))
} catch {
case ex: Exception =>
ex.printStackTrace()
log.info("No git HEAD commit found -- Using current date and 'unknown' SHA")
(new Date, "unknown")
}
} else {
val commit = new RevWalk(db).parseCommit(head)
(new Date(commit.getCommitTime.toLong * 1000L), commit.getName.substring(0, 7))
Expand Down
13 changes: 8 additions & 5 deletions src/compiler/scala/tools/nsc/CompilerCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

package scala.tools.nsc

import java.nio.file.Files

import io.File

/** A class representing command line info for scalac */
Expand Down Expand Up @@ -119,11 +121,12 @@ class CompilerCommand(arguments: List[String], val settings: Settings) {
*/
def expandArg(arg: String): List[String] = {
def stripComment(s: String) = s takeWhile (_ != '#')
val file = File(arg stripPrefix "@")
if (!file.exists)
throw new java.io.FileNotFoundException("argument file %s could not be found" format file.name)

settings splitParams (file.lines() map stripComment mkString " ")
import java.nio.file._
import collection.JavaConverters._
val file = Paths.get(arg stripPrefix "@")
if (!Files.exists(file))
throw new java.io.FileNotFoundException("argument file %s could not be found" format file)
settings splitParams (Files.readAllLines(file).asScala map stripComment mkString " ")
}

// override this if you don't want arguments processed here
Expand Down
3 changes: 3 additions & 0 deletions src/compiler/scala/tools/nsc/Global.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,9 @@ class Global(var currentSettings: Settings, reporter0: Reporter)

reporting.summarizeErrors()

// val allNamesArray: Array[String] = allNames().map(_.toString).toArray.sorted
// allNamesArray.foreach(println(_))

if (traceSymbolActivity)
units map (_.body) foreach (traceSymbols recordSymbolsInTree _)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ abstract class BCodeHelpers extends BCodeIdiomatic {
*/
def getAnnotPickle(jclassName: String, sym: Symbol): Option[AnnotationInfo] = {
currentRun.symData get sym match {
case Some(pickle) if !sym.isModuleClass =>
case Some(pickle) if !sym.isModuleClass => // pickles for module classes are in the companion / mirror class
val scalaAnnot = {
val sigBytes = ScalaSigBytes(pickle.bytes.take(pickle.writeIndex))
AnnotationInfo(sigBytes.sigAnnot, Nil, (nme.bytes, sigBytes) :: Nil)
Expand Down
10 changes: 4 additions & 6 deletions src/compiler/scala/tools/nsc/symtab/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
package scala.tools.nsc
package symtab

import classfile.ClassfileParser
import classfile.{ClassfileParser, ReusableDataReader}
import java.io.IOException
import scala.reflect.internal.MissingRequirementError
import scala.reflect.io.{AbstractFile, NoAbstractFile}
import scala.tools.nsc.util.{ClassPath, ClassRepresentation}
import scala.reflect.internal.TypesStats
import scala.reflect.internal.util.StatisticsStatics
import scala.reflect.internal.util.{ReusableInstance, StatisticsStatics}

/** This class ...
*
Expand Down Expand Up @@ -301,13 +301,11 @@ abstract class SymbolLoaders {
}
}
}

private val classFileDataReader: ReusableInstance[ReusableDataReader] = new ReusableInstance[ReusableDataReader](() => new ReusableDataReader())
class ClassfileLoader(val classfile: AbstractFile, clazz: ClassSymbol, module: ModuleSymbol) extends SymbolLoader with FlagAssigningCompleter {
private object classfileParser extends {
val symbolTable: SymbolLoaders.this.symbolTable.type = SymbolLoaders.this.symbolTable
} with ClassfileParser {
override protected type ThisConstantPool = ConstantPool
override protected def newConstantPool: ThisConstantPool = new ConstantPool
} with ClassfileParser(classFileDataReader) {
override protected def lookupMemberAtTyperPhaseIfPossible(sym: Symbol, name: Name): Symbol =
SymbolLoaders.this.lookupMemberAtTyperPhaseIfPossible(sym, name)
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ package scala.tools.nsc
package symtab
package classfile

import java.lang.Float.intBitsToFloat
import java.io.{ByteArrayInputStream, DataInputStream}
import java.lang.Double.longBitsToDouble
import java.lang.Float.intBitsToFloat
import java.util

import scala.tools.nsc.io.AbstractFile

Expand All @@ -25,8 +27,11 @@ import scala.tools.nsc.io.AbstractFile
* @author Philippe Altherr
* @version 1.0, 23/03/2004
*/
class AbstractFileReader(val file: AbstractFile, val buf: Array[Byte]) {
def this(file: AbstractFile) = this(file, file.toByteArray)
final class AbstractFileReader(val buf: Array[Byte]) extends DataReader {
@deprecated("Use other constructor", "2.13.0")
def this(file: AbstractFile) {
this(file.toByteArray)
}

/** the current input pointer
*/
Expand Down Expand Up @@ -59,17 +64,25 @@ class AbstractFileReader(val file: AbstractFile, val buf: Array[Byte]) {
((nextByte & 0xff) << 24) + ((nextByte & 0xff) << 16) +
((nextByte & 0xff) << 8) + (nextByte & 0xff)

/** extract a byte at position bp from buf
*/
def getByte(mybp: Int): Byte =
buf(mybp)

def getBytes(mybp: Int, bytes: Array[Byte]): Unit = {
System.arraycopy(buf, mybp, bytes, 0, bytes.length)
}

/** extract a character at position bp from buf
*/
def getChar(mybp: Int): Char =
(((buf(mybp) & 0xff) << 8) + (buf(mybp+1) & 0xff)).toChar
(((getByte(mybp) & 0xff) << 8) + (getByte(mybp+1) & 0xff)).toChar

/** extract an integer at position bp from buf
*/
def getInt(mybp: Int): Int =
((buf(mybp ) & 0xff) << 24) + ((buf(mybp+1) & 0xff) << 16) +
((buf(mybp+2) & 0xff) << 8) + (buf(mybp+3) & 0xff)
((getByte(mybp) & 0xff) << 24) + ((getByte(mybp + 1) & 0xff) << 16) +
((getByte(mybp + 2) & 0xff) << 8) + (getByte(mybp + 3) & 0xff)

/** extract a long integer at position bp from buf
*/
Expand All @@ -84,8 +97,11 @@ class AbstractFileReader(val file: AbstractFile, val buf: Array[Byte]) {
*/
def getDouble(mybp: Int): Double = longBitsToDouble(getLong(mybp))

def getUTF(mybp: Int, len: Int): String = {
new DataInputStream(new ByteArrayInputStream(buf, mybp, len)).readUTF
}

/** skip next 'n' bytes
*/
def skip(n: Int) { bp += n }

def skip(n: Int): Unit = { bp += n }
}
Loading