Skip to content

Commit 9845474

Browse files
committed
Merge pull request #19 from magarciaEPFL/b3
rewiring-dependencies on settings in the bytecode emitter
2 parents 0cdfa13 + 8374903 commit 9845474

8 files changed

+62
-44
lines changed

src/dotty/tools/dotc/backend/jvm/BCodeHelpers.scala

+14-21
Original file line numberDiff line numberDiff line change
@@ -209,26 +209,30 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
209209
* must-single-thread
210210
*/
211211
def initBytecodeWriter(entryPoints: List[Symbol])(implicit ctx: Context): BytecodeWriter = {
212+
213+
import ctx.base.settings
214+
import ctx.log
215+
212216
settings.outputDirs.getSingleOutput match {
213217
case Some(f) if f hasExtension "jar" =>
214218
// If no main class was specified, see if there's only one
215219
// entry point among the classes going into the jar.
216220
if (settings.mainClass.isDefault) {
217221
entryPoints map (_.fullName('.')) match {
218222
case Nil =>
219-
ctx.log("No Main-Class designated or discovered.")
223+
log("No Main-Class designated or discovered.")
220224
case name :: Nil =>
221-
ctx.log(s"Unique entry point: setting Main-Class to $name")
222-
settings.mainClass.value = name
225+
log(s"Unique entry point: setting Main-Class to $name")
226+
settings.mainClass.update(name)
223227
case names =>
224-
ctx.log(s"No Main-Class due to multiple entry points:\n ${names.mkString("\n ")}")
228+
log(s"No Main-Class due to multiple entry points:\n ${names.mkString("\n ")}")
225229
}
226230
}
227-
else ctx.log(s"Main-Class was specified: ${settings.mainClass.value}")
231+
else log(s"Main-Class was specified: ${settings.mainClass.value}")
228232

229233
new DirectToJarfileWriter(f.file)
230234

231-
case _ => factoryNonJarBytecodeWriter()
235+
case _ => factoryNonJarBytecodeWriter(ctx)
232236
}
233237
}
234238

@@ -295,17 +299,6 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
295299

296300
} // end of method addInnerClassesASM()
297301

298-
/**
299-
* All components (e.g. BCPickles, BCInnerClassGen) of the builder classes
300-
* extend this trait to have access to the context.
301-
*
302-
* The context is provided by the three leaf classes (PlainClassBuilder,
303-
* JMirrorBuilder and JBeanInfoBuilder) as class parameter.
304-
*/
305-
trait HasContext {
306-
implicit protected val ctx: Context
307-
}
308-
309302
/*
310303
* Custom attribute (JVMS 4.7.1) "ScalaSig" used as marker only
311304
* i.e., the pickle is contained in a custom annotation, see:
@@ -395,7 +388,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
395388

396389
trait BCInnerClassGen extends HasContext {
397390

398-
def debugLevel = settings.debuginfo.indexOfChoice
391+
def debugLevel = ctx.settings.g.indexOfChoice
399392

400393
val emitSource = debugLevel >= 1
401394
val emitLines = debugLevel >= 2
@@ -797,7 +790,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
797790
// without it. This is particularly bad because the availability of
798791
// generic information could disappear as a consequence of a seemingly
799792
// unrelated change.
800-
settings.Ynogenericsig
793+
ctx.settings.Ynogenericsig
801794
|| sym.isArtifact
802795
|| sym.isLiftedMethod
803796
|| sym.isBridge
@@ -829,7 +822,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
829822
catch { case _: Throwable => false }
830823
}
831824

832-
if (settings.Xverify) {
825+
if (ctx.settings.Xverify) {
833826
// Run the signature parser to catch bogus signatures.
834827
val isValidSignature = wrap {
835828
// Alternative: scala.tools.reflect.SigParser (frontend to sun.reflect.generics.parser.SignatureParser)
@@ -849,7 +842,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
849842
}
850843
}
851844

852-
if ((settings.check containsName phaseName)) {
845+
if ((ctx.settings.check containsName phaseName)) {
853846
val normalizedTpe = enteringErasure(erasure.prepareSigMap(memberTpe))
854847
val bytecodeTpe = owner.thisType.memberInfo(sym)
855848
if (!sym.isType && !sym.isConstructor && !(erasure.erasure(sym)(normalizedTpe) =:= bytecodeTpe)) {

src/dotty/tools/dotc/backend/jvm/BCodeIdiomatic.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import core.Symbols.{Symbol, NoSymbol}
2525
*/
2626
abstract class BCodeIdiomatic extends BCodeGlue {
2727

28-
val classfileVersion: Int = settings.target.value match {
28+
def classfileVersion(implicit ctx: Context): Int = ctx.settings.target.value match {
2929
case "jvm-1.5" => asm.Opcodes.V1_5
3030
case "jvm-1.6" => asm.Opcodes.V1_6
3131
case "jvm-1.7" => asm.Opcodes.V1_7

src/dotty/tools/dotc/backend/jvm/BCodeSkelBuilder.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ abstract class BCodeSkelBuilder extends BCodeHelpers {
171171

172172
} else {
173173

174-
val skipStaticForwarders = (claszSymbol.isInterface || settings.noForwarders)
174+
val skipStaticForwarders = (claszSymbol.isInterface || ctx.settings.noForwarders)
175175
if (!skipStaticForwarders) {
176176
val lmoc = claszSymbol.companionModule
177177
// add static forwarders if there are no name conflicts; see bugs #363 and #1735
@@ -605,7 +605,7 @@ abstract class BCodeSkelBuilder extends BCodeHelpers {
605605
case Return(_) => ()
606606
case EmptyTree =>
607607
globalError("Concrete method has no definition: " + dd + (
608-
if (settings.debug) "(found: " + methSymbol.owner.info.decls.toList.mkString(", ") + ")"
608+
if (ctx.settings.debug) "(found: " + methSymbol.owner.info.decls.toList.mkString(", ") + ")"
609609
else "")
610610
)
611611
case _ =>

src/dotty/tools/dotc/backend/jvm/BCodeTypes.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import StdNames.{nme, tpnme}
2929
abstract class BCodeTypes extends BCodeIdiomatic {
3030

3131
// when compiling the Scala library, some assertions don't hold (e.g., scala.Boolean has null superClass although it's not an interface)
32-
val isCompilingStdLib = !(settings.sourcepath.isDefault)
32+
def isCompilingStdLib(implicit ctx: Context) = !(ctx.settings.sourcepath.isDefault)
3333

3434
val srBoxedUnit = brefType("scala/runtime/BoxedUnit")
3535

src/dotty/tools/dotc/backend/jvm/BytecodeWriters.scala

+17-15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import java.io.{ DataOutputStream, FileOutputStream, IOException, OutputStream,
1212
import java.util.jar.Attributes.Name
1313

1414
import dotty.tools.io._
15+
import core.Contexts.Context
1516

1617
/** Can't output a file due to the state of the file system. */
1718
class FileConflictException(msg: String, val file: AbstractFile) extends IOException(msg)
@@ -22,8 +23,8 @@ class FileConflictException(msg: String, val file: AbstractFile) extends IOExcep
2223
*/
2324
trait BytecodeWriters {
2425

25-
def outputDirectory(sym: Symbol): AbstractFile =
26-
settings.outputDirs outputDirFor enteringFlatten(sym.sourceFile)
26+
def outputDirectory(sym: Symbol)(implicit ctx: Context): AbstractFile =
27+
ctx.settings.outputDirs outputDirFor enteringFlatten(sym.sourceFile)
2728

2829
/**
2930
* @param clsName cls.getName
@@ -40,26 +41,27 @@ trait BytecodeWriters {
4041
def getFile(sym: Symbol, clsName: String, suffix: String): AbstractFile =
4142
getFile(outputDirectory(sym), clsName, suffix)
4243

43-
def factoryNonJarBytecodeWriter(): BytecodeWriter = {
44-
val emitAsmp = settings.Ygenasmp.isSetByUser
45-
val doDump = settings.Ydumpclasses.isSetByUser
44+
def factoryNonJarBytecodeWriter(implicit ctx: Context): BytecodeWriter = {
45+
val emitAsmp = ctx.settings.Ygenasmp.isSetByUser
46+
val doDump = ctx.settings.Ydumpclasses.isSetByUser
4647
(emitAsmp, doDump) match {
47-
case (false, false) => new ClassBytecodeWriter { }
48-
case (false, true ) => new ClassBytecodeWriter with DumpBytecodeWriter { }
48+
case (false, false) => new ClassBytecodeWriter
49+
case (false, true ) => new ClassBytecodeWriter with DumpBytecodeWriter
4950
case (true, false) => new ClassBytecodeWriter with AsmpBytecodeWriter
50-
case (true, true ) => new ClassBytecodeWriter with AsmpBytecodeWriter with DumpBytecodeWriter { }
51+
case (true, true ) => new ClassBytecodeWriter with AsmpBytecodeWriter with DumpBytecodeWriter
5152
}
5253
}
5354

54-
trait BytecodeWriter {
55+
trait BytecodeWriter extends HasContext {
5556
def writeClass(label: String, jclassName: String, jclassBytes: Array[Byte], outfile: AbstractFile): Unit
5657
def close(): Unit = ()
5758
}
5859

59-
class DirectToJarfileWriter(jfile: JFile) extends BytecodeWriter {
60+
class DirectToJarfileWriter(jfile: JFile)(implicit protected val ctx: Context)
61+
extends BytecodeWriter {
6062
val jarMainAttrs = (
61-
if (settings.mainClass.isDefault) Nil
62-
else List(Name.MAIN_CLASS -> settings.mainClass.value)
63+
if (ctx.settings.mainClass.isDefault) Nil
64+
else List(Name.MAIN_CLASS -> ctx.settings.mainClass.value)
6365
)
6466
val writer = new Jar(jfile).jarWriter(jarMainAttrs: _*)
6567

@@ -88,7 +90,7 @@ trait BytecodeWriters {
8890
trait AsmpBytecodeWriter extends BytecodeWriter {
8991
import dotty.tools.asm
9092

91-
private val baseDir = Directory(settings.Ygenasmp.value).createDirectory()
93+
private val baseDir = Directory(ctx.settings.Ygenasmp.value).createDirectory()
9294

9395
private def emitAsmp(jclassBytes: Array[Byte], asmpFile: io.File): Unit = {
9496
val pw = asmpFile.printWriter()
@@ -114,7 +116,7 @@ trait BytecodeWriters {
114116
}
115117
}
116118

117-
trait ClassBytecodeWriter extends BytecodeWriter {
119+
class ClassBytecodeWriter(implicit protected val ctx: Context) extends BytecodeWriter {
118120
def writeClass(label: String, jclassName: String, jclassBytes: Array[Byte], outfile: AbstractFile): Unit = {
119121
assert(outfile != null,
120122
"Precisely this override requires its invoker to hand out a non-null AbstractFile.")
@@ -127,7 +129,7 @@ trait BytecodeWriters {
127129
}
128130

129131
trait DumpBytecodeWriter extends BytecodeWriter {
130-
val baseDir = Directory(settings.Ydumpclasses.value).createDirectory()
132+
val baseDir = Directory(ctx.settings.Ydumpclasses.value).createDirectory()
131133

132134
abstract override def writeClass(label: String, jclassName: String, jclassBytes: Array[Byte], outfile: AbstractFile): Unit = {
133135
super.writeClass(label, jclassName, jclassBytes, outfile)

src/dotty/tools/dotc/backend/jvm/GenBCode.scala

+3
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ object GenBCode extends BCodeSyncAndTry {
297297

298298
// clearing maps
299299
clearBCodeTypes()
300+
301+
// free the Context instance reachable from BytecodeWriter
302+
bytecodeWriter = null
300303
}
301304

302305
override def run(implicit ctx: Context): Unit = unsupported("run()")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/* NSC -- new Scala compiler
2+
* Copyright 2005-2012 LAMP/EPFL
3+
* @author Martin Odersky
4+
*/
5+
6+
package dotty.tools.dotc
7+
package backend.jvm
8+
9+
import core.Contexts.Context
10+
11+
/**
12+
* All components (e.g. BCPickles, BCInnerClassGen) of the builder classes
13+
* extend this trait to have access to the context.
14+
*
15+
* The context is provided by the three leaf classes (PlainClassBuilder,
16+
* JMirrorBuilder and JBeanInfoBuilder) as class parameter.
17+
*
18+
* Same goes for BytecodeWriter
19+
*/
20+
trait HasContext {
21+
implicit protected val ctx: Context
22+
}
23+
24+

src/dotty/tools/dotc/config/ScalaSettings.scala

100644100755
-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ class ScalaSettings extends Settings.SettingGroup {
4949
/** -X "Advanced" settings
5050
*/
5151
val Xhelp = BooleanSetting("-X", "Print a synopsis of advanced options.")
52-
val assemname = StringSetting("-Xassem-name", "file", "(Requires -target:msil) Name of the output assembly.", "").dependsOn(target, "msil")
53-
val assemrefs = StringSetting("-Xassem-path", "path", "(Requires -target:msil) List of assemblies referenced by the program.", ".").dependsOn(target, "msil")
54-
val assemextdirs = StringSetting("-Xassem-extdirs", "dirs", "(Requires -target:msil) List of directories containing assemblies. default:lib", Defaults.scalaLibDir.path).dependsOn(target, "msil")
55-
val sourcedir = StringSetting("-Xsourcedir", "directory", "(Requires -target:msil) Mirror source folder structure in output directory.", ".").dependsOn(target, "msil")
5652
val checkInit = BooleanSetting("-Xcheckinit", "Wrap field accessors to throw an exception on uninitialized access.")
5753
val noassertions = BooleanSetting("-Xdisable-assertions", "Generate no assertions or assumptions.")
5854
// val elidebelow = IntSetting("-Xelide-below", "Calls to @elidable methods are omitted if method priority is lower than argument",

0 commit comments

Comments
 (0)