Skip to content

Enable more Scala.js tests, fix two issues #7112

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 4 commits into from
Aug 28, 2019
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
13 changes: 13 additions & 0 deletions compiler/src/dotty/tools/backend/sjs/JSDefinitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ final class JSDefinitions()(implicit ctx: Context) {
@threadUnsafe lazy val Reflect_registerInstantiatableClassR = ReflectModule.requiredMethodRef("registerInstantiatableClass")
def Reflect_registerInstantiatableClass(implicit ctx: Context) = Reflect_registerInstantiatableClassR.symbol

private[this] var allRefClassesCache: Set[Symbol] = _
def allRefClasses(implicit ctx: Context): Set[Symbol] = {
if (allRefClassesCache == null) {
val baseNames = List("Object", "Boolean", "Character", "Byte", "Short",
"Int", "Long", "Float", "Double")
val fullNames = baseNames.flatMap { base =>
List(s"scala.runtime.${base}Ref", s"scala.runtime.Volatile${base}Ref")
}
allRefClassesCache = fullNames.map(name => ctx.requiredClass(name)).toSet
}
allRefClassesCache
}

/** If `cls` is a class in the scala package, its name, otherwise EmptyTypeName */
private def scalajsClassName(cls: Symbol)(implicit ctx: Context): TypeName =
if (cls.isClass && cls.owner == ScalaJSJSPackageClass) cls.asClass.name
Expand Down
20 changes: 11 additions & 9 deletions compiler/src/dotty/tools/backend/sjs/JSEncoding.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package dotty.tools.backend.sjs

import scala.annotation.tailrec

import scala.collection.mutable

import dotty.tools.FatalError

import dotty.tools.dotc.core._
import Decorators._
import Periods._
import SymDenotations._
import Contexts._
import Flags._
import Types._
import Symbols._
import Denotations._
Expand Down Expand Up @@ -103,13 +107,6 @@ object JSEncoding {
js.Ident(localNames.localSymbolName(sym), Some(sym.unexpandedName.decoded))
}

private def allRefClasses(implicit ctx: Context): Set[Symbol] = {
//TODO
/*(Set(ObjectRefClass, VolatileObjectRefClass) ++
refClass.values ++ volatileRefClass.values)*/
Set()
}

def encodeFieldSym(sym: Symbol)(
implicit ctx: Context, pos: ir.Position): js.Ident = {
require(sym.owner.isClass && sym.isTerm && !sym.is(Flags.Method) && !sym.is(Flags.Module),
Expand All @@ -120,14 +117,19 @@ object JSEncoding {
if (name0.charAt(name0.length()-1) != ' ') name0
else name0.substring(0, name0.length()-1)

@tailrec
def superClassCount(sym: Symbol, acc: Int): Int =
if (sym == defn.ObjectClass) acc
else superClassCount(sym.asClass.superClass, acc + 1)

/* We have to special-case fields of Ref types (IntRef, ObjectRef, etc.)
* because they are emitted as private by our .scala source files, but
* they are considered public at use site since their symbols come from
* Java-emitted .class files.
*/
val idSuffix =
if (sym.is(Flags.Private) || allRefClasses.contains(sym.owner))
sym.owner.asClass.baseClasses.size.toString
if (sym.is(Flags.Private) || jsdefn.allRefClasses.contains(sym.owner))
superClassCount(sym.owner, 0).toString
else
"f"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class LinkScala2Impls extends MiniPhase with IdentityDenotTransformer { thisPhas
def currentClass = ctx.owner.enclosingClass.asClass
app match {
case Apply(sel @ Select(Super(_, _), _), args)
if sel.symbol.owner.is(Scala2x) && currentClass.mixins.contains(sel.symbol.owner) =>
if sel.symbol.owner.is(Scala2x) && currentClass.mixins.contains(sel.symbol.owner) && !ctx.settings.scalajs.value =>
Copy link
Member

@smarter smarter Aug 27, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could go further and use the default method even when not using Scala.js, going through the static methods is supposed to improve cold performance but based on the investigation I did, they shouldn't affect semantics (#5928)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't object, but I would argue that it is out of scope of this PR. I would keep this PR to be Scala.js-only. Changing the JVM behavior should be done in a separate PR I think.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your call, but I'd like to keep the difference in code paths taken when scala.js is enabled to a minimum.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't managed to make it work for the JVM in 20 minutes. I think changing the JVM should be best done by someone who understand the thing better than I do.

val impl = implMethod(sel.symbol)
if (impl.exists) Apply(ref(impl), This(currentClass) :: args).withSpan(app.span)
else app // could have been an abstract method in a trait linked to from a super constructor
Expand Down
1 change: 1 addition & 0 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ object Build {
val dir = fetchScalaJSSource.value / "test-suite"
(
(dir / "shared/src/test/scala/org/scalajs/testsuite/compiler" ** "IntTest.scala").get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/javalib/lang" ** (("IntegerTest.scala": FileFilter) || "ObjectTest.scala")).get
++ (dir / "shared/src/test/require-jdk8/org/scalajs/testsuite/javalib/util" ** "Base64Test.scala").get
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/utils" ** "*.scala").get
)
Expand Down