Skip to content

Kill reflect io #2313

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 12 commits into from
May 9, 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
9 changes: 5 additions & 4 deletions bin/common
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ else
echo "Failed to parse .packages file"
build_all
fi

if [ ! -f "$INTERFACES_JAR" -o ! -f "$MAIN_JAR" -o ! -f "$DOTTY_LIB_JAR" -o ! -f "$TEST_JAR" ]; then
echo ".packages file corrupted, rebuilding"
build_all
fi
fi

################# After this point, jar variables will be set #################
Expand Down Expand Up @@ -142,10 +147,6 @@ if [ "$SCALA_LIBRARY_JAR" == "" ]; then
SCALA_LIBRARY_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-library/jars" "scala-library-$SCALA_VERSION.jar")
fi

if [ "$SCALA_REFLECT_JAR" == "" ]; then
SCALA_REFLECT_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang/scala-reflect/jars" "scala-reflect-$SCALA_VERSION.jar")
fi

if [ "$SCALA_ASM_JAR" == "" ]; then
SCALA_ASM_JAR=$(find_jar "$HOME/.ivy2/cache/org.scala-lang.modules/scala-asm/bundles" "scala-asm-$SCALA_ASM_VERSION.jar")
fi
Expand Down
7 changes: 3 additions & 4 deletions bin/dotc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ CompilerMain=dotty.tools.dotc.Main
FromTasty=dotty.tools.dotc.FromTasty
ReplMain=dotty.tools.dotc.repl.Main

if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_REFLECT_JAR" -o ! -f "$SCALA_ASM_JAR" -o ! -f "$SBT_INTERFACE_JAR" ]
if [ ! -f "$SCALA_LIBRARY_JAR" -o ! -f "$SCALA_ASM_JAR" -o ! -f "$SBT_INTERFACE_JAR" ]
then
echo To use this script please set
echo SCALA_LIBRARY_JAR to point to scala-library-$SCALA_VERSION.jar "(currently $SCALA_LIBRARY_JAR)"
echo SCALA_REFLECT_JAR to point to scala-reflect-$SCALA_VERSION.jar "(currently $SCALA_REFLECT_JAR)"
echo SCALA_ASM_JAR to point to scala-asm-$SCALA_ASM_VERSION.jar "(currently $SCALA_ASM_JAR)"
echo SBT_INTERFACE_JAR to point to interface-$SBT_VERSION.jar "(currently $SBT_INTERFACE_JAR)"
fi
Expand Down Expand Up @@ -116,9 +115,9 @@ trap onExit INT
classpathArgs () {
if [[ "true" == "$bootstrapped" ]]; then
check_jar "dotty-bootstrapped" "$DOTTY_JAR" "target" 'build_jar "test:runMain dotc.build" target' &> /dev/null
toolchain="$DOTTY_JAR:$DOTTY_LIB_JAR:$SCALA_LIBRARY_JAR:$SCALA_REFLECT_JAR:$SCALA_ASM_JAR:$SBT_INTERFACE_JAR"
toolchain="$DOTTY_JAR:$DOTTY_LIB_JAR:$SCALA_LIBRARY_JAR:$SCALA_ASM_JAR:$SBT_INTERFACE_JAR"
else
toolchain="$SCALA_LIBRARY_JAR:$DOTTY_LIB_JAR:$SCALA_REFLECT_JAR:$SCALA_ASM_JAR:$SBT_INTERFACE_JAR"
toolchain="$SCALA_LIBRARY_JAR:$DOTTY_LIB_JAR:$SCALA_ASM_JAR:$SBT_INTERFACE_JAR"
fi
bcpJars="$INTERFACES_JAR:$MAIN_JAR:$DOTTY_LIB_JAR"
cpJars="$INTERFACES_JAR:$MAIN_JAR:$DOTTY_LIB_JAR:$TEST_JAR"
Expand Down
20 changes: 15 additions & 5 deletions bin/test/TestScripts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ class TestScripts {

private def executeScript(script: String): (Int, String) = {
val sb = new StringBuilder
val ret = Process(script) ! ProcessLogger { line => println(line); sb.append(line) }
val ret = Process(script) ! ProcessLogger { line => println(line); sb.append(line + "\n") }
val output = sb.toString
println(output) // For CI, otherwise "terminal inactive for 5m0s, build cancelled"
(ret, output)
}

Expand Down Expand Up @@ -59,7 +58,7 @@ class TestScripts {

val (retDotr, dotrOutput) = executeScript("./bin/dotr HelloWorld")
assert(
retDotr == 0 && dotrOutput == "hello world",
retDotr == 0 && dotrOutput == "hello world\n",
s"Running hello world exited with status: $retDotr and output: $dotrOutput"
)
}
Expand Down Expand Up @@ -93,8 +92,19 @@ class TestScripts {

/** dotc script should work after corrupting .packages */
@Test def reCreatesPackagesIfNecessary = doUnlessWindows {
executeScript("sed -i.old 's/2.1/2.X/' ./.packages") // That's going to replace 2.11 with 2.X1
val (retFirstBuild, _) = executeScript("./bin/dotc ./tests/pos/HelloWorld.scala")
import java.nio.file.{Paths, Files}
import java.nio.charset.StandardCharsets
val contents =
"""|/Users/fixel/Projects/dotty/interfaces/target/dotty-interfaces-0.1.1-bin-SNAPSHOT-X.jar
|/Users/fixel/Projects/dotty/compiler/target/scala-2.11/dotty-compiler_2.1X-0.1.1-bin-SNAPSHOT.jar
|/Users/fixel/Projects/dotty/library/target/scala-2.11/dotty-library_2.1X-0.1.1-bin-SNAPSHOT.jar
|/Users/fixel/Projects/dotty/doc-tool/target/scala-2.11/dotty-doc_2.1X-0.1.1-bin-SNAPSHOT-tests.jar"""
.stripMargin

Files.write(Paths.get("./.packages"), contents.getBytes(StandardCharsets.UTF_8))

val (retFirstBuild, output) = executeScript("./bin/dotc ./tests/pos/HelloWorld.scala")
assert(output.contains(".packages file corrupted"))
assert(retFirstBuild == 0, "building dotc failed")
}
}
2 changes: 1 addition & 1 deletion compiler/sjs/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class JSCodeGen()(implicit ctx: Context) {

private def getFileFor(cunit: CompilationUnit, sym: Symbol,
suffix: String) = {
import scala.reflect.io._
import dotty.tools.io._

val outputDirectory: AbstractFile = // TODO Support virtual files
new PlainDirectory(new Directory(new java.io.File(ctx.settings.d.value)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import java.io.{File => JFile}
import scala.collection.generic.Clearable
import scala.collection.mutable
import scala.reflect.ClassTag
import scala.reflect.io.{Directory, PlainDirectory, AbstractFile}
import dotty.tools.io.{Directory, PlainDirectory, AbstractFile}
import scala.tools.asm.{ClassVisitor, FieldVisitor, MethodVisitor}
import scala.tools.nsc.backend.jvm.{BCodeHelpers, BackendInterface}
import dotty.tools.dotc.core._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.collection.generic.Clearable
import scala.collection.mutable
import scala.reflect.ClassTag
import scala.reflect.internal.util.WeakHashSet
import scala.reflect.io.{AbstractFile, Directory, PlainDirectory}
import dotty.tools.io.{AbstractFile, Directory, PlainDirectory}
import scala.tools.asm.{AnnotationVisitor, ClassVisitor, FieldVisitor, MethodVisitor}
import scala.tools.nsc.backend.jvm.{BCodeHelpers, BackendInterface}
import dotty.tools.dotc.core._
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import dotty.tools.dotc.util.{DotClass, Positions}
import tpd._
import StdNames._

import scala.reflect.io.{AbstractFile, Directory, PlainDirectory}
import dotty.tools.io.{AbstractFile, Directory, PlainDirectory}

class GenBCode extends Phase {
def phaseName: String = "genBCode"
Expand Down Expand Up @@ -62,10 +62,10 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter

val sourceFile = ctx.compilationUnit.source

/** Convert a `scala.reflect.io.AbstractFile` into a
/** Convert a `dotty.tools.io.AbstractFile` into a
* `dotty.tools.dotc.interfaces.AbstractFile`.
*/
private[this] def convertAbstractFile(absfile: scala.reflect.io.AbstractFile): interfaces.AbstractFile =
private[this] def convertAbstractFile(absfile: dotty.tools.io.AbstractFile): interfaces.AbstractFile =
new interfaces.AbstractFile {
override def name = absfile.name
override def path = absfile.path
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/LabelDefs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import scala.collection.generic.Clearable
import scala.collection.mutable
import scala.collection.mutable.{ListBuffer, ArrayBuffer}
import scala.reflect.ClassTag
import scala.reflect.io.{Directory, PlainDirectory, AbstractFile}
import dotty.tools.io.{Directory, PlainDirectory, AbstractFile}
import scala.tools.asm.{ClassVisitor, FieldVisitor, MethodVisitor}
import scala.tools.nsc.backend.jvm.{BCodeHelpers, BackendInterface}
import dotty.tools.dotc.core._
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import java.io.{BufferedWriter, OutputStreamWriter}
import printing.XprintMode

import scala.annotation.tailrec
import scala.reflect.io.VirtualFile
import dotty.tools.io.VirtualFile
import scala.util.control.NonFatal

/** A compiler run. Exports various methods to compile source files */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/*
* Copyright (c) 2014 Contributor. All rights reserved.
*/
package dotty.tools.dotc.classpath
package dotty.tools
package dotc.classpath

import java.net.URL
import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer
import scala.reflect.internal.FatalError
import scala.reflect.io.AbstractFile
import dotty.tools.io.ClassPath
import dotty.tools.io.ClassRepresentation
import dotty.tools.io.{ AbstractFile, ClassPath, ClassRepresentation }

/**
* A classpath unifying multiple class- and sourcepath entries.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/classpath/ClassPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package dotty.tools.dotc.classpath

import scala.reflect.io.AbstractFile
import dotty.tools.io.AbstractFile
import dotty.tools.io.ClassRepresentation

case class ClassPathEntries(packages: Seq[PackageEntry], classesAndSources: Seq[ClassRepresentation])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/
package dotty.tools.dotc.classpath

import scala.reflect.io.{AbstractFile, VirtualDirectory}
import scala.reflect.io.Path.string2path
import dotty.tools.io.{AbstractFile, VirtualDirectory}
import dotty.tools.io.Path.string2path
import dotty.tools.dotc.config.Settings
import FileUtils.AbstractFileOps
import dotty.tools.io.ClassPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import java.util.function.IntFunction
import java.util
import java.util.Comparator

import scala.reflect.io.{AbstractFile, PlainFile}
import dotty.tools.io.{ClassPath, ClassRepresentation, PlainNioFile}
import dotty.tools.io.{AbstractFile, PlainFile, ClassPath, ClassRepresentation, PlainNioFile}
import FileUtils._
import scala.collection.JavaConverters._

Expand Down Expand Up @@ -118,7 +117,7 @@ trait JFileDirectoryLookup[FileEntryType <: ClassRepresentation] extends Directo
} else Array()
}
protected def getName(f: File): String = f.getName
protected def toAbstractFile(f: File): AbstractFile = new PlainFile(new scala.reflect.io.File(f))
protected def toAbstractFile(f: File): AbstractFile = new PlainFile(new dotty.tools.io.File(f))
protected def isPackage(f: File): Boolean = f.isPackage

assert(dir != null, "Directory file in DirectoryFileLookup cannot be null")
Expand Down Expand Up @@ -208,7 +207,7 @@ case class DirectoryClassPath(dir: File) extends JFileDirectoryLookup[ClassFileE
val relativePath = FileUtils.dirPath(className)
val classFile = new File(s"$dir/$relativePath.class")
if (classFile.exists) {
val wrappedClassFile = new scala.reflect.io.File(classFile)
val wrappedClassFile = new dotty.tools.io.File(classFile)
val abstractClassFile = new PlainFile(wrappedClassFile)
Some(abstractClassFile)
} else None
Expand All @@ -235,7 +234,7 @@ case class DirectorySourcePath(dir: File) extends JFileDirectoryLookup[SourceFil
.collectFirst { case file if file.exists() => file }

sourceFile.map { file =>
val wrappedSourceFile = new scala.reflect.io.File(file)
val wrappedSourceFile = new dotty.tools.io.File(file)
val abstractSourceFile = new PlainFile(wrappedSourceFile)
abstractSourceFile
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/classpath/FileUtils.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright (c) 2014 Contributor. All rights reserved.
*/
package dotty.tools.dotc.classpath
package dotty.tools
package dotc.classpath

import java.io.{File => JFile, FileFilter}
import java.net.URL
import scala.reflect.internal.FatalError
import scala.reflect.io.AbstractFile
import dotty.tools.io.AbstractFile

/**
* Common methods related to Java files and abstract files used in the context of classpath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package dotty.tools.dotc.classpath

import dotty.tools.io.ClassRepresentation
import scala.reflect.io.{AbstractFile, Path, PlainFile, VirtualDirectory}
import dotty.tools.io.{AbstractFile, Path, PlainFile, VirtualDirectory}
import FileUtils._
import java.net.URL

import scala.reflect.internal.util.AbstractFileClassLoader
import dotty.tools.io.ClassPath

case class VirtualDirectoryClassPath(dir: VirtualDirectory) extends ClassPath with DirectoryLookup[ClassFileEntryImpl] with NoSourcePaths {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ package dotty.tools.dotc.classpath
import java.io.File
import java.net.URL
import scala.annotation.tailrec
import scala.reflect.io.{AbstractFile, FileZipArchive, ManifestResources}
import dotty.tools.io.ClassPath
import dotty.tools.io.{AbstractFile, ClassPath, FileZipArchive, ManifestResources}
import dotty.tools.dotc.config.Settings
import dotty.tools.dotc.core.Contexts.Context
import FileUtils._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ package dotty.tools.dotc.classpath
import java.io.File
import java.net.URL
import scala.collection.Seq
import scala.reflect.io.AbstractFile
import scala.reflect.io.FileZipArchive
import dotty.tools.io.{ AbstractFile, FileZipArchive }
import FileUtils.AbstractFileOps
import dotty.tools.io.{ClassPath, ClassRepresentation}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import NameOps._, NameKinds._
import Scopes.Scope
import collection.mutable
import collection.BitSet
import scala.reflect.io.AbstractFile
import dotty.tools.io.AbstractFile
import Decorators.SymbolIteratorDecorator
import ast._
import annotation.tailrec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import scala.collection.mutable.{ListBuffer, HashSet, ArrayBuffer}

//import ast.parser.SyntaxAnalyzer
import io.{PlainFile, VirtualDirectory}
import scala.reflect.io.{PlainDirectory, Directory}
import dotty.tools.io.{PlainDirectory, Directory}
import reporting.{ConsoleReporter, Reporter}
import core.Flags
import util.{SourceFile, NameTransformer}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/repl/REPL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package repl
import core.Contexts.Context
import reporting.Reporter
import io.{AbstractFile, PlainFile, VirtualDirectory}
import scala.reflect.io.{PlainDirectory, Directory}
import dotty.tools.io.{PlainDirectory, Directory}
import java.io.{BufferedReader, File => JFile, FileReader, PrintWriter}
import java.net.{URL, URLClassLoader}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/sbt/ExtractDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Names._, NameOps._, StdNames._

import scala.collection.{Set, mutable}

import dotty.tools.io.{AbstractFile, Path, ZipArchive}
import dotty.tools.io.{AbstractFile, Path, ZipArchive, PlainFile}
import java.io.File

import java.util.{Arrays, Comparator}
Expand Down Expand Up @@ -101,7 +101,7 @@ class ExtractDependencies extends Phase {
val classSegments = Path(ze.path).segments
binaryDependency(zipFile, className(classSegments))
}
case pf: scala.reflect.io.PlainFile =>
case pf: PlainFile =>
val packages = dep.ownersIterator
.filter(x => x.is(PackageClass) && !x.isEffectiveRoot).length
// We can recover the fully qualified name of a classfile from
Expand Down
Loading