Skip to content

Commit fa9074c

Browse files
committed
Merge pull request #16 from lrytz/contexts
LGTM
2 parents 5973bf9 + b9527bc commit fa9074c

13 files changed

+127
-129
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
* @author Martin Odersky
44
*/
55

6-
7-
package dotty.tools
8-
package dotc
9-
package backend
10-
package jvm
6+
package dotty.tools.dotc
7+
package backend.jvm
118

129
import scala.collection.{ mutable, immutable }
1310
import scala.annotation.switch
1411

1512
import dotty.tools.asm
1613

17-
import dotc.ast.Trees._
14+
import ast.Trees._
15+
import core.Contexts.Context
1816
import core.Flags
1917
import core.Types.Type
2018
import core.StdNames
@@ -36,8 +34,8 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
3634
/*
3735
* Functionality to build the body of ASM MethodNode, except for `synchronized` and `try` expressions.
3836
*/
39-
abstract class PlainBodyBuilder(cunit: CompilationUnit,
40-
implicit val ctx: dotc.core.Contexts.Context) extends PlainSkelBuilder(cunit) {
37+
abstract class PlainBodyBuilder(cunit: CompilationUnit)
38+
extends PlainSkelBuilder(cunit) {
4139

4240
import icodes.TestOp
4341
import icodes.opcodes.InvokeStyle

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
* @author Martin Odersky
44
*/
55

6-
package dotty.tools
7-
package dotc
6+
package dotty.tools.dotc
87
package backend.jvm
98

109
import dotty.tools.asm
1110
import scala.annotation.switch
1211
import scala.collection.{ immutable, mutable }
1312

14-
import dotc.ast.Trees.Tree
15-
import dotc.core.Types.Type
16-
import dotc.core.Symbols.{Symbol, NoSymbol}
13+
import ast.Trees.Tree
14+
import core.Types.Type
15+
import core.Symbols.{Symbol, NoSymbol}
1716

1817
/*
1918
* Immutable representations of bytecode-level types.

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

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
* @author Martin Odersky
44
*/
55

6-
package dotty.tools
7-
package dotc
6+
package dotty.tools.dotc
87
package backend.jvm
98

109
import dotty.tools.asm
1110
import scala.annotation.switch
1211
import scala.collection.{ immutable, mutable }
1312
import dotty.tools.io.AbstractFile
1413

15-
import dotc.ast.Trees._
16-
17-
import dotc.core.StdNames
18-
import dotc.core.Types.Type
19-
import dotc.core.Symbols.{Symbol, NoSymbol}
20-
import dotc.core.SymDenotations._
21-
import dotc.core.Flags
22-
import dotc.core.StdNames.{nme, tpnme}
14+
import ast.Trees._
15+
import core.Contexts.Context
16+
import core.StdNames
17+
import core.Types.Type
18+
import core.Symbols.{Symbol, NoSymbol}
19+
import core.SymDenotations._
20+
import core.Flags
21+
import core.StdNames.{nme, tpnme}
2322

2423
/*
2524
* Traits encapsulating functionality to convert Scala AST Trees into ASM ClassNodes.
@@ -209,7 +208,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
209208
/*
210209
* must-single-thread
211210
*/
212-
def initBytecodeWriter(entryPoints: List[Symbol])(implicit ctx: core.Contexts.Context): BytecodeWriter = {
211+
def initBytecodeWriter(entryPoints: List[Symbol])(implicit ctx: Context): BytecodeWriter = {
213212
settings.outputDirs.getSingleOutput match {
214213
case Some(f) if f hasExtension "jar" =>
215214
// If no main class was specified, see if there's only one
@@ -236,7 +235,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
236235
/*
237236
* must-single-thread
238237
*/
239-
def fieldSymbols(cls: Symbol)(implicit ctx: core.Contexts.Context): List[Symbol] = {
238+
def fieldSymbols(cls: Symbol)(implicit ctx: Context): List[Symbol] = {
240239
for (f <- cls.info.decls.toList ;
241240
if !(f is Flags.Method) && f.isTerm && !(f is Flags.ModuleVal)
242241
) yield f;
@@ -296,6 +295,17 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
296295

297296
} // end of method addInnerClassesASM()
298297

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+
299309
/*
300310
* Custom attribute (JVMS 4.7.1) "ScalaSig" used as marker only
301311
* i.e., the pickle is contained in a custom annotation, see:
@@ -308,7 +318,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
308318
* while the "Signature" attribute can be associated to classes, methods, and fields.)
309319
*
310320
*/
311-
trait BCPickles {
321+
trait BCPickles extends HasContext {
312322

313323
import scala.reflect.internal.pickling.{ PickleFormat, PickleBuffer }
314324

@@ -383,7 +393,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
383393

384394
} // end of trait BCPickles
385395

386-
trait BCInnerClassGen {
396+
trait BCInnerClassGen extends HasContext {
387397

388398
def debugLevel = settings.debuginfo.indexOfChoice
389399

@@ -405,14 +415,14 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
405415
*
406416
* must-single-thread
407417
*/
408-
final def internalName(sym: Symbol)(implicit ctx: core.Contexts.Context): String = asmClassType(sym).getInternalName
418+
final def internalName(sym: Symbol): String = asmClassType(sym).getInternalName
409419

410420
/*
411421
* Tracks (if needed) the inner class given by `sym`.
412422
*
413423
* must-single-thread
414424
*/
415-
final def asmClassType(sym: Symbol)(implicit ctx: core.Contexts.Context): BType = {
425+
final def asmClassType(sym: Symbol): BType = {
416426
assert(
417427
hasInternalName(sym),
418428
{
@@ -438,10 +448,8 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
438448
* Tracks (if needed) the inner class given by `t`.
439449
*
440450
* must-single-thread
441-
*
442-
* TODO(lry): check if `ctx` should be a paramter of the class instead.
443451
*/
444-
final def toTypeKind(t: Type)(implicit ctx: dotc.core.Contexts.Context): BType = {
452+
final def toTypeKind(t: Type): BType = {
445453

446454
/* Interfaces have to be handled delicately to avoid introducing spurious errors,
447455
* but if we treat them all as AnyRef we lose too much information.
@@ -535,7 +543,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
535543
/*
536544
* must-single-thread
537545
*/
538-
def asmMethodType(msym: Symbol)(implicit ctx: core.Contexts.Context): BType = {
546+
def asmMethodType(msym: Symbol): BType = {
539547
assert(msym is Flags.Method, s"not a method-symbol: $msym")
540548
val resT: BType =
541549
if (msym.isClassConstructor || msym.isConstructor) BType.VOID_TYPE
@@ -550,7 +558,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
550558
*
551559
* must-single-thread
552560
*/
553-
final def trackMemberClasses(csym: Symbol, lateClosuresBTs: List[BType])(implicit ctx: core.Contexts.Context): List[BType] = {
561+
final def trackMemberClasses(csym: Symbol, lateClosuresBTs: List[BType]): List[BType] = {
554562
val lateInnerClasses = exitingErasure {
555563
for (sym <- List(csym, csym.linkedClassOfClass); memberc <- sym.info.decls.map(innerClassSymbolFor) if memberc.isClass)
556564
yield memberc
@@ -574,14 +582,14 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
574582
*
575583
* must-single-thread
576584
*/
577-
final def descriptor(t: Type)(implicit ctx: core.Contexts.Context): String = (toTypeKind(t).getDescriptor)
585+
final def descriptor(t: Type): String = (toTypeKind(t).getDescriptor)
578586

579587
/*
580588
* Tracks (if needed) the inner class given by `sym`.
581589
*
582590
* must-single-thread
583591
*/
584-
final def descriptor(sym: Symbol)(implicit ctx: core.Contexts.Context): String = (asmClassType(sym).getDescriptor)
592+
final def descriptor(sym: Symbol): String = (asmClassType(sym).getDescriptor)
585593

586594
} // end of trait BCInnerClassGen
587595

@@ -774,7 +782,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
774782

775783
} // end of trait BCAnnotGen
776784

777-
trait BCJGenSigGen {
785+
trait BCJGenSigGen extends HasContext {
778786

779787
// @M don't generate java generics sigs for (members of) implementation
780788
// classes, as they are monomorphic (TODO: ok?)
@@ -996,7 +1004,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
9961004

9971005
} // end of trait BCForwardersGen
9981006

999-
trait BCClassGen extends BCInnerClassGen {
1007+
trait BCClassGen extends BCInnerClassGen with HasContext {
10001008

10011009
// Used as threshold above which a tableswitch bytecode instruction is preferred over a lookupswitch.
10021010
// There's a space tradeoff between these multi-branch instructions (details in the JVM spec).
@@ -1081,15 +1089,18 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
10811089

10821090
} // end of class JBuilder
10831091

1084-
/* functionality for building plain and mirror classes */
1092+
/* functionality for building plain and mirror classes
1093+
* TODO(lrytz): it seems only `JMirrorBuilder` extends `JCommonBuilder`.
1094+
* So this class could be removed.
1095+
*/
10851096
abstract class JCommonBuilder
10861097
extends JBuilder
10871098
with BCAnnotGen
10881099
with BCForwardersGen
10891100
with BCPickles { }
10901101

10911102
/* builder of mirror classes */
1092-
class JMirrorBuilder extends JCommonBuilder {
1103+
class JMirrorBuilder(implicit protected val ctx: Context) extends JCommonBuilder {
10931104

10941105
private var cunit: CompilationUnit = _
10951106
def getCurrentCUnit(): CompilationUnit = cunit;
@@ -1144,7 +1155,7 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
11441155
} // end of class JMirrorBuilder
11451156

11461157
/* builder of bean info classes */
1147-
class JBeanInfoBuilder extends JBuilder {
1158+
class JBeanInfoBuilder(implicit protected val ctx: Context) extends JBuilder {
11481159

11491160
/*
11501161
* Generate a bean info class that describes the given class.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
* @author Martin Odersky
44
*/
55

6-
package dotty.tools
7-
package dotc
6+
package dotty.tools.dotc
87
package backend.jvm
98

109
import dotty.tools.asm
1110
import scala.annotation.switch
1211
import scala.collection.{ immutable, mutable }
1312
import collection.convert.Wrappers.JListWrapper
1413

15-
import dotc.ast.Trees.Tree
16-
import dotc.core.Types.Type
17-
import dotc.core.Symbols.{Symbol, NoSymbol}
14+
import ast.Trees.Tree
15+
import core.Contexts.Context
16+
import core.Types.Type
17+
import core.Symbols.{Symbol, NoSymbol}
1818

1919
/*
2020
* A high-level facade to the ASM API for bytecode generation.
@@ -692,7 +692,7 @@ abstract class BCodeIdiomatic extends BCodeGlue {
692692
}
693693
}
694694

695-
def abort(msg: => AnyRef)(implicit ctx: core.Contexts.Context): Nothing = {
695+
def abort(msg: => AnyRef)(implicit ctx: Context): Nothing = {
696696
ctx.error(msg)
697697
throw new FatalError(msg)
698698
}

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@
33
* @author Martin Odersky
44
*/
55

6-
7-
package dotty.tools
8-
package dotc
9-
package backend
10-
package jvm
6+
package dotty.tools.dotc
7+
package backend.jvm
118

129
import scala.collection.{ mutable, immutable }
13-
import scala.tools.nsc.symtab._
1410
import scala.annotation.switch
1511

1612
import dotty.tools.asm
1713

18-
import dotc.ast.Trees._
19-
import dotc.core.Types.Type
20-
import dotc.core.Symbols.{Symbol, NoSymbol}
14+
import ast.Trees._
15+
import core.Contexts.Context
16+
import core.Types.Type
17+
import core.Symbols.{Symbol, NoSymbol}
2118

2219
/*
2320
*

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@
33
* @author Martin Odersky
44
*/
55

6-
7-
package dotty.tools
8-
package dotc
9-
package backend
10-
package jvm
6+
package dotty.tools.dotc
7+
package backend.jvm
118

129
import scala.collection.{ mutable, immutable }
1310
import scala.annotation.switch
1411

1512
import dotty.tools.asm
1613

17-
import dotc.ast.Trees._
18-
import dotc.core.Types.Type
19-
import dotc.core.Symbols.{Symbol, NoSymbol}
14+
import ast.Trees._
15+
import core.Contexts.Context
16+
import core.Types.Type
17+
import core.Symbols.{Symbol, NoSymbol}
2018

2119
/*
2220
*
@@ -29,8 +27,8 @@ abstract class BCodeSyncAndTry extends BCodeBodyBuilder {
2927
/*
3028
* Functionality to lower `synchronized` and `try` expressions.
3129
*/
32-
abstract class SyncAndTryBuilder(cunit: CompilationUnit,
33-
ctx: dotc.core.Contexts.Context) extends PlainBodyBuilder(cunit, ctx) {
30+
abstract class SyncAndTryBuilder(cunit: CompilationUnit)
31+
extends PlainBodyBuilder(cunit) {
3432

3533
import ast.tpd._
3634

0 commit comments

Comments
 (0)