Skip to content

Add explicit return types to public members #5203

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 7 commits into from
Oct 5, 2018
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
4 changes: 2 additions & 2 deletions compiler/sjs/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@ class JSCodeGen()(implicit ctx: Context) {
nme.UNARY_! -> js.JSUnaryOp.!
)

def unapply(name: Names.TermName): Option[js.JSUnaryOp.Code] =
def unapply(name: TermName): Option[js.JSUnaryOp.Code] =
map.get(name)
}

Expand Down Expand Up @@ -1732,7 +1732,7 @@ class JSCodeGen()(implicit ctx: Context) {
nme.ZOR -> js.JSBinaryOp.||
)

def unapply(name: Names.TermName): Option[js.JSBinaryOp.Code] =
def unapply(name: TermName): Option[js.JSBinaryOp.Code] =
map.get(name)
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/sjs/backend/sjs/JSEncoding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ object JSEncoding {
private final val ScalaJSEnvironmentName = "ScalaJS"

implicit class SymOps(val self: Symbol) extends AnyVal {
def unexpandedName(implicit ctx: Context): Names.Name =
def unexpandedName(implicit ctx: Context): Name =
self.name.unexpandedName
}

implicit class MyNameOps(val self: Names.Name) extends AnyVal {
implicit class MyNameOps(val self: Name) extends AnyVal {
def decoded: String = self.decode.toString
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/sjs/backend/sjs/JSPositions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.scalajs.core.ir
class JSPositions()(implicit ctx: Context) {

/** Implicit conversion from dotty Position to ir.Position. */
implicit def pos2irPos(pos: Positions.Position): ir.Position = {
implicit def pos2irPos(pos: Position): ir.Position = {
if (!pos.exists) ir.Position.NoPosition
else {
val source = pos2irPosCache.toIRSource(ctx.compilationUnit.source)
Expand All @@ -23,7 +23,7 @@ class JSPositions()(implicit ctx: Context) {

/** Implicitly materializes an ir.Position from an implicit dotty Position. */
implicit def implicitPos2irPos(
implicit pos: Positions.Position): ir.Position = {
implicit pos: Position): ir.Position = {
pos2irPos(pos)
}

Expand Down
20 changes: 2 additions & 18 deletions compiler/src/dotty/tools/backend/jvm/CollectEntryPoints.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,15 @@ import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Types
import dotty.tools.dotc.transform.MegaPhase._
import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc
import dotty.tools.dotc.core.Flags.FlagSet
import dotty.tools.dotc.transform.Erasure
import dotty.tools.dotc.transform.SymUtils._
import java.io.{File => JFile}
import java.io.{File => _}

import scala.collection.generic.Clearable
import scala.collection.mutable
import scala.reflect.ClassTag
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._
import Periods._
import SymDenotations._
import Contexts._
import Types._
import Symbols._
import Denotations._
import Phases._
import java.lang.AssertionError
import dotty.tools.dotc.util.Positions.Position
import Decorators._
import tpd._
import StdNames.nme

/**
Expand All @@ -46,7 +31,7 @@ class CollectEntryPoints extends MiniPhase {
}

object CollectEntryPoints{
def isJavaMainMethod(sym: Symbol)(implicit ctx: Context) = {
def isJavaMainMethod(sym: Symbol)(implicit ctx: Context): Boolean = {
(sym.name == nme.main) && (sym.info match {
case r@MethodTpe(_, List(defn.ArrayOf(t)), _) =>
(t.widenDealias =:= defn.StringType) && (
Expand All @@ -56,7 +41,6 @@ object CollectEntryPoints{
}

def isJavaEntryPoint(sym: Symbol)(implicit ctx: Context): Boolean = {
import Types.MethodType
val d = ctx.definitions
val StringType = d.StringType
// The given class has a main method.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dotty.tools.backend.jvm

import dotty.tools.dotc.ast.tpd
import dotty.tools.dotc.ast.Trees._
import dotty.tools.dotc.core.Contexts.Context
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.core.Flags.Trait
Expand Down
78 changes: 35 additions & 43 deletions compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,29 @@ import dotty.tools.dotc
import dotty.tools.dotc.core.Flags.FlagSet
import dotty.tools.dotc.transform.{Erasure, GenericSignatures}
import dotty.tools.dotc.transform.SymUtils._
import java.io.{File => JFile}
import java.io.{File => _}

import scala.collection.generic.Clearable
import scala.collection.mutable
import scala.reflect.ClassTag
import scala.reflect.internal.util.WeakHashSet
import dotty.tools.io.{AbstractFile, Directory, PlainDirectory}
import scala.tools.asm.{AnnotationVisitor, ClassVisitor, FieldVisitor, MethodVisitor}
import dotty.tools.io.AbstractFile
import scala.tools.asm.AnnotationVisitor
import scala.tools.nsc.backend.jvm.{BCodeHelpers, BackendInterface}
import dotty.tools.dotc.core._
import Periods._
import SymDenotations._
import Contexts._
import Types._
import Symbols._
import Denotations._
import Phases._
import java.lang.AssertionError

import dotty.tools.dotc.util.{DotClass, Positions}
import dotty.tools.dotc.util.Positions
import Decorators._
import tpd._

import scala.tools.asm
import StdNames.{nme, str}
import NameOps._
import NameKinds.{DefaultGetterName, ExpandedName}
import dotty.tools.dotc.core
import dotty.tools.dotc.core.Names.TypeName

import scala.annotation.tailrec
import Names.TermName

class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Map[Symbol, Set[ClassSymbol]])(implicit ctx: Context) extends BackendInterface{
import Symbols.{toDenot, toClassDenot}
Expand Down Expand Up @@ -84,7 +76,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
type LabelDef = tpd.DefDef
type Closure = tpd.Closure

val NoSymbol = Symbols.NoSymbol
val NoSymbol: Symbol = Symbols.NoSymbol
val NoPosition: Position = Positions.NoPosition
val EmptyTree: Tree = tpd.EmptyTree

Expand Down Expand Up @@ -112,11 +104,11 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
val nme_EQEQ_LOCAL_VAR: Name = StdNames.nme.EQEQ_LOCAL_VAR

// require LambdaMetafactory: scalac uses getClassIfDefined, but we need those always.
override lazy val LambdaMetaFactory = ctx.requiredClass("java.lang.invoke.LambdaMetafactory")
override lazy val MethodHandle = ctx.requiredClass("java.lang.invoke.MethodHandle")
override lazy val LambdaMetaFactory: ClassSymbol = ctx.requiredClass("java.lang.invoke.LambdaMetafactory")
override lazy val MethodHandle: ClassSymbol = ctx.requiredClass("java.lang.invoke.MethodHandle")

val nme_valueOf: Name = StdNames.nme.valueOf
val nme_apply = StdNames.nme.apply
val nme_apply: TermName = StdNames.nme.apply
val NothingClass: Symbol = defn.NothingClass
val NullClass: Symbol = defn.NullClass
val ObjectClass: Symbol = defn.ObjectClass
Expand All @@ -136,7 +128,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
val LongClass: Symbol = defn.LongClass
val FloatClass: Symbol = defn.FloatClass
val DoubleClass: Symbol = defn.DoubleClass
def isArrayClone(tree: Tree) = tree match {
def isArrayClone(tree: Tree): Boolean = tree match {
case Select(qual, StdNames.nme.clone_) if qual.tpe.widen.isInstanceOf[JavaArrayType] => true
case _ => false
}
Expand All @@ -154,19 +146,19 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
val String_valueOf: Symbol = defn.String_valueOf_Object
lazy val Predef_classOf: Symbol = defn.ScalaPredefModule.requiredMethod(nme.classOf)

lazy val AnnotationRetentionAttr = ctx.requiredClass("java.lang.annotation.Retention")
lazy val AnnotationRetentionSourceAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE")
lazy val AnnotationRetentionClassAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("CLASS")
lazy val AnnotationRetentionRuntimeAttr = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME")
lazy val JavaAnnotationClass = ctx.requiredClass("java.lang.annotation.Annotation")
lazy val AnnotationRetentionAttr: ClassSymbol = ctx.requiredClass("java.lang.annotation.Retention")
lazy val AnnotationRetentionSourceAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("SOURCE")
lazy val AnnotationRetentionClassAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("CLASS")
lazy val AnnotationRetentionRuntimeAttr: TermSymbol = ctx.requiredClass("java.lang.annotation.RetentionPolicy").linkedClass.requiredValue("RUNTIME")
lazy val JavaAnnotationClass: ClassSymbol = ctx.requiredClass("java.lang.annotation.Annotation")

def boxMethods: Map[Symbol, Symbol] = defn.ScalaValueClasses().map{x => // @darkdimius Are you sure this should be a def?
(x, Erasure.Boxing.boxMethod(x.asClass))
}.toMap
def unboxMethods: Map[Symbol, Symbol] =
defn.ScalaValueClasses().map(x => (x, Erasure.Boxing.unboxMethod(x.asClass))).toMap

override def isSyntheticArrayConstructor(s: Symbol) = {
override def isSyntheticArrayConstructor(s: Symbol): Boolean = {
s eq defn.newArrayMethod
}

Expand Down Expand Up @@ -317,7 +309,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
}

override def emitAnnotations(cw: asm.ClassVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
val typ = annot.atp
val assocs = annot.assocs
Expand All @@ -334,7 +326,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
}

override def emitAnnotations(mw: asm.MethodVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
val typ = annot.atp
val assocs = annot.assocs
Expand All @@ -344,7 +336,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
}

override def emitAnnotations(fw: asm.FieldVisitor, annotations: List[Annotation], bcodeStore: BCodeHelpers)
(innerClasesStore: bcodeStore.BCInnerClassGen) = {
(innerClasesStore: bcodeStore.BCInnerClassGen): Unit = {
for(annot <- annotations; if shouldEmitAnnotation(annot)) {
val typ = annot.atp
val assocs = annot.assocs
Expand Down Expand Up @@ -400,7 +392,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma

def emitAsmp: Option[String] = None

def shouldEmitJumpAfterLabels = true
def shouldEmitJumpAfterLabels: Boolean = true

def dumpClasses: Option[String] =
if (ctx.settings.Ydumpclasses.isDefault) None
Expand Down Expand Up @@ -428,7 +420,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma

val MODULE_INSTANCE_FIELD: String = str.MODULE_INSTANCE_FIELD

def dropModule(str: String) =
def dropModule(str: String): String =
if (!str.isEmpty && str.last == '$') str.take(str.length - 1) else str

def newTermName(prefix: String): Name = prefix.toTermName
Expand Down Expand Up @@ -479,7 +471,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
}

// todo: remove
def isMaybeBoxed(sym: Symbol) = {
def isMaybeBoxed(sym: Symbol): Boolean = {
(sym == ObjectClass) ||
(sym == JavaSerializableClass) ||
(sym == defn.ComparableClass) ||
Expand Down Expand Up @@ -1055,13 +1047,13 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma

// todo: this product1s should also eventually become name-based pattn matching
object Literal extends LiteralDeconstructor {
def get = field.const
def get: Constant = field.const
}

object Throw extends ThrowDeconstructor {
def get = field.args.head
def get: Tree = field.args.head

override def unapply(s: Throw): DottyBackendInterface.this.Throw.type = {
override def unapply(s: Throw): Throw.type = {
if (s.fun.symbol eq defn.throwMethod) {
field = s
} else {
Expand All @@ -1072,11 +1064,11 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
}

object New extends NewDeconstructor {
def get = field.tpt.tpe
def get: Type = field.tpt.tpe
}

object This extends ThisDeconstructor {
def get = field.qual.name
def get: Name = field.qual.name
def apply(s: Symbol): This = tpd.This(s.asClass)
}

Expand All @@ -1096,15 +1088,15 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
}

object Ident extends IdentDeconstructor {
def get = field.name
def get: Name = field.name
}

object Alternative extends AlternativeDeconstructor {
def get = field.trees
def get: List[Tree] = field.trees
}

object Constant extends ConstantDeconstructor {
def get = field.value
def get: Any = field.value
}
object ThrownException extends ThrownException {
def unapply(a: Annotation): Option[Symbol] = None // todo
Expand All @@ -1121,7 +1113,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
def _2: List[Symbol] = field.vparamss.flatMap(_.map(_.symbol))
def _3: Tree = field.rhs

override def unapply(s: LabelDef): DottyBackendInterface.this.LabelDef.type = {
override def unapply(s: LabelDef): LabelDef.type = {
if (s.symbol is Flags.Label) this.field = s
else this.field = null
this
Expand Down Expand Up @@ -1199,9 +1191,9 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
}

object Closure extends ClosureDeconstructor {
def _1 = field.env
def _2 = field.meth
def _3 = {
def _1: List[Tree] = field.env
def _2: Tree = field.meth
def _3: Symbol = {
val t = field.tpt.tpe.typeSymbol
if (t.exists) t
else {
Expand All @@ -1214,5 +1206,5 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
}
}

def currentUnit = ctx.compilationUnit
def currentUnit: CompilationUnit = ctx.compilationUnit
}
Loading