Skip to content

Commit 5821362

Browse files
Merge pull request #6285 from sjrd/scalajs-1.0.0-M7
Upgrade to Scala.js 1.0.0-M7.
2 parents df3df95 + bbcb618 commit 5821362

File tree

5 files changed

+80
-63
lines changed

5 files changed

+80
-63
lines changed

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,8 @@ class JSCodeGen()(implicit ctx: Context) {
456456
}
457457
}*/
458458

459-
js.FieldDef(static = false, name, irTpe, f.is(Mutable))
459+
val flags = js.MemberFlags.empty.withMutable(f.is(Mutable))
460+
js.FieldDef(flags, name, irTpe)
460461
}).toList
461462
}
462463

@@ -514,7 +515,7 @@ class JSCodeGen()(implicit ctx: Context) {
514515
/*if (primitives.isPrimitive(sym)) {
515516
None
516517
} else*/ if (sym.is(Deferred)) {
517-
Some(js.MethodDef(static = false, methodName,
518+
Some(js.MethodDef(js.MemberFlags.empty, methodName,
518519
jsParams, toIRType(patchedResultType(sym)), None)(
519520
OptimizerHints.empty, None))
520521
} else /*if (isJSNativeCtorDefaultParam(sym)) {
@@ -549,15 +550,19 @@ class JSCodeGen()(implicit ctx: Context) {
549550
val body1 =
550551
if (!sym.isPrimaryConstructor) body0
551552
else moveAllStatementsAfterSuperConstructorCall(body0)
552-
js.MethodDef(static = false, methodName,
553+
js.MethodDef(js.MemberFlags.empty, methodName,
553554
jsParams, jstpe.NoType, body1)(optimizerHints, None)
554-
} else*/ if (sym.isConstructor) {
555-
js.MethodDef(static = false, methodName,
556-
jsParams, jstpe.NoType,
555+
} else*/ if (sym.isClassConstructor) {
556+
val namespace = js.MemberNamespace.Constructor
557+
js.MethodDef(js.MemberFlags.empty.withNamespace(namespace),
558+
methodName, jsParams, jstpe.NoType,
557559
Some(genStat(rhs)))(optimizerHints, None)
558560
} else {
561+
val namespace =
562+
if (sym.isPrivate) js.MemberNamespace.Private
563+
else js.MemberNamespace.Public
559564
val resultIRType = toIRType(patchedResultType(sym))
560-
genMethodDef(static = false, methodName,
565+
genMethodDef(namespace, methodName,
561566
params, resultIRType, rhs, optimizerHints)
562567
}
563568
}
@@ -576,7 +581,7 @@ class JSCodeGen()(implicit ctx: Context) {
576581
* Methods Scala.js-defined JS classes are compiled as static methods taking
577582
* an explicit parameter for their `this` value.
578583
*/
579-
private def genMethodDef(static: Boolean, methodName: js.PropertyName,
584+
private def genMethodDef(namespace: js.MemberNamespace, methodName: js.PropertyName,
580585
paramsSyms: List[Symbol], resultIRType: jstpe.Type,
581586
tree: Tree, optimizerHints: OptimizerHints): js.MethodDef = {
582587
implicit val pos = tree.span
@@ -595,10 +600,11 @@ class JSCodeGen()(implicit ctx: Context) {
595600
else genExpr(tree)
596601

597602
//if (!isScalaJSDefinedJSClass(currentClassSym)) {
598-
js.MethodDef(static, methodName, jsParams, resultIRType, Some(genBody()))(
603+
val flags = js.MemberFlags.empty.withNamespace(namespace)
604+
js.MethodDef(flags, methodName, jsParams, resultIRType, Some(genBody()))(
599605
optimizerHints, None)
600606
/*} else {
601-
assert(!static, tree.span)
607+
assert(!namespace.isStatic, tree.span)
602608
603609
withScopedVars(
604610
thisLocalVarIdent := Some(freshLocalIdent("this"))
@@ -962,7 +968,8 @@ class JSCodeGen()(implicit ctx: Context) {
962968
currentMethodSym.get.isClassConstructor) {
963969
isModuleInitialized = true
964970
val thisType = jstpe.ClassType(encodeClassFullName(currentClassSym))
965-
val initModule = js.StoreModule(thisType, js.This()(thisType))
971+
val initModule = js.StoreModule(encodeClassRef(currentClassSym),
972+
js.This()(thisType))
966973
js.Block(superCall, initModule)
967974
} else {
968975
superCall
@@ -1001,12 +1008,12 @@ class JSCodeGen()(implicit ctx: Context) {
10011008
else if (clsSym == jsdefn.JSArrayClass && args.isEmpty) js.JSArrayConstr(Nil)
10021009
else js.JSNew(genLoadJSConstructor(clsSym), genActualJSArgs(ctor, args))
10031010
} else {
1004-
toIRType(tpe) match {
1005-
case cls: jstpe.ClassType =>
1011+
toTypeRef(tpe) match {
1012+
case cls: jstpe.ClassRef =>
10061013
js.New(cls, encodeMethodSym(ctor), genActualArgs(ctor, args))
10071014

10081015
case other =>
1009-
throw new FatalError(s"Non ClassType cannot be instantiated: $other")
1016+
throw new FatalError(s"Non ClassRef cannot be instantiated: $other")
10101017
}
10111018
}
10121019
}
@@ -1030,7 +1037,7 @@ class JSCodeGen()(implicit ctx: Context) {
10301037
}
10311038
val newMethodIdent = js.Ident(newMethodName, origName)
10321039

1033-
js.Apply(genLoadModule(moduleClass), newMethodIdent, args)(
1040+
js.Apply(js.ApplyFlags.empty, genLoadModule(moduleClass), newMethodIdent, args)(
10341041
jstpe.ClassType(encodedName))
10351042
}
10361043

@@ -1575,11 +1582,8 @@ class JSCodeGen()(implicit ctx: Context) {
15751582
genApplyJSMethodGeneric(tree, sym, genExpr(receiver), genActualJSArgs(sym, args), isStat)
15761583
/*else
15771584
genApplyJSClassMethod(genExpr(receiver), sym, genActualArgs(sym, args))*/
1578-
} else if (sym.isClassConstructor) {
1579-
// Calls to constructors are always statically linked
1580-
genApplyMethodStatically(genExpr(receiver), sym, genActualArgs(sym, args))
15811585
} else {
1582-
genApplyMethod(genExpr(receiver), sym, genActualArgs(sym, args))
1586+
genApplyMethodMaybeStatically(genExpr(receiver), sym, genActualArgs(sym, args))
15831587
}
15841588
}
15851589

@@ -1789,7 +1793,7 @@ class JSCodeGen()(implicit ctx: Context) {
17891793

17901794
val genElems = tree.elems.map(genExpr)
17911795
val arrayTypeRef = toTypeRef(tree.tpe).asInstanceOf[jstpe.ArrayTypeRef]
1792-
js.ArrayValue(jstpe.ArrayType(arrayTypeRef), genElems)
1796+
js.ArrayValue(arrayTypeRef, genElems)
17931797
}
17941798

17951799
/** Gen JS code for a closure.
@@ -1877,7 +1881,8 @@ class JSCodeGen()(implicit ctx: Context) {
18771881

18781882
val genBody = {
18791883
val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref)
1880-
val call = genApplyMethod(thisCaptureRef, sym, argCaptureRefs ::: actualParams)
1884+
val call = genApplyMethodMaybeStatically(thisCaptureRef, sym,
1885+
argCaptureRefs ::: actualParams)
18811886
box(call, sym.info.finalResultType)
18821887
}
18831888

@@ -1892,7 +1897,7 @@ class JSCodeGen()(implicit ctx: Context) {
18921897
s"Invalid functional interface $funInterfaceSym reached the back-end")
18931898
val cls = "sjsr_AnonFunction" + formalParams.size
18941899
val ctor = js.Ident("init___sjs_js_Function" + formalParams.size)
1895-
js.New(jstpe.ClassType(cls), ctor, List(closure))
1900+
js.New(jstpe.ClassRef(cls), ctor, List(closure))
18961901
}
18971902
}
18981903

@@ -1993,30 +1998,41 @@ class JSCodeGen()(implicit ctx: Context) {
19931998
}
19941999
}
19952000

2001+
/** Gen a statically linked call to an instance method. */
2002+
private def genApplyMethodMaybeStatically(receiver: js.Tree, method: Symbol,
2003+
arguments: List[js.Tree])(implicit pos: Position): js.Tree = {
2004+
if (method.isPrivate || method.isClassConstructor)
2005+
genApplyMethodStatically(receiver, method, arguments)
2006+
else
2007+
genApplyMethod(receiver, method, arguments)
2008+
}
2009+
19962010
/** Gen a dynamically linked call to a Scala method. */
1997-
private def genApplyMethod(receiver: js.Tree,
1998-
methodSym: Symbol, arguments: List[js.Tree])(
2011+
private def genApplyMethod(receiver: js.Tree, method: Symbol,
2012+
arguments: List[js.Tree])(
19992013
implicit pos: Position): js.Tree = {
2000-
js.Apply(receiver, encodeMethodSym(methodSym), arguments)(
2001-
toIRType(patchedResultType(methodSym)))
2014+
assert(!method.isPrivate,
2015+
s"Cannot generate a dynamic call to private method $method at $pos")
2016+
js.Apply(js.ApplyFlags.empty, receiver, encodeMethodSym(method), arguments)(
2017+
toIRType(patchedResultType(method)))
20022018
}
20032019

20042020
/** Gen a statically linked call to an instance method. */
20052021
private def genApplyMethodStatically(receiver: js.Tree, method: Symbol,
20062022
arguments: List[js.Tree])(implicit pos: Position): js.Tree = {
2007-
val className = encodeClassFullName(method.owner)
2008-
val methodIdent = encodeMethodSym(method)
2009-
val resultType = toIRType(patchedResultType(method))
2010-
js.ApplyStatically(receiver, jstpe.ClassType(className),
2011-
methodIdent, arguments)(resultType)
2023+
val flags = js.ApplyFlags.empty
2024+
.withPrivate(method.isPrivate && !method.isClassConstructor)
2025+
.withConstructor(method.isClassConstructor)
2026+
js.ApplyStatically(flags, receiver, encodeClassRef(method.owner),
2027+
encodeMethodSym(method), arguments)(
2028+
toIRType(patchedResultType(method)))
20122029
}
20132030

20142031
/** Gen a call to a static method. */
20152032
private def genApplyStatic(method: Symbol, arguments: List[js.Tree])(
20162033
implicit pos: Position): js.Tree = {
2017-
val cls = jstpe.ClassType(encodeClassFullName(method.owner))
2018-
val methodIdent = encodeMethodSym(method)
2019-
js.ApplyStatic(cls, methodIdent, arguments)(
2034+
js.ApplyStatic(js.ApplyFlags.empty, encodeClassRef(method.owner),
2035+
encodeMethodSym(method), arguments)(
20202036
toIRType(patchedResultType(method)))
20212037
}
20222038

@@ -2264,7 +2280,7 @@ class JSCodeGen()(implicit ctx: Context) {
22642280
} else {
22652281
val inst = genLoadModule(sym.owner)
22662282
val method = encodeStaticMemberSym(sym)
2267-
js.Apply(inst, method, Nil)(toIRType(sym.info))
2283+
js.Apply(js.ApplyFlags.empty, inst, method, Nil)(toIRType(sym.info))
22682284
}
22692285
}
22702286

@@ -2279,13 +2295,13 @@ class JSCodeGen()(implicit ctx: Context) {
22792295

22802296
if (isJSType(sym)) {
22812297
if (isScalaJSDefinedJSClass(sym))
2282-
js.LoadJSModule(jstpe.ClassType(encodeClassFullName(sym)))
2298+
js.LoadJSModule(encodeClassRef(sym))
22832299
/*else if (sym.derivesFrom(jsdefn.JSGlobalScopeClass))
22842300
genLoadJSGlobal()*/
22852301
else
22862302
genLoadNativeJSModule(sym)
22872303
} else {
2288-
js.LoadModule(jstpe.ClassType(encodeClassFullName(sym)))
2304+
js.LoadModule(encodeClassRef(sym))
22892305
}
22902306
}
22912307

@@ -2294,7 +2310,7 @@ class JSCodeGen()(implicit ctx: Context) {
22942310
implicit pos: Position): js.Tree = {
22952311
assert(!isStaticModule(sym) && !sym.is(Trait),
22962312
s"genPrimitiveJSClass called with non-class $sym")
2297-
js.LoadJSConstructor(jstpe.ClassType(encodeClassFullName(sym)))
2313+
js.LoadJSConstructor(encodeClassRef(sym))
22982314
}
22992315

23002316
/** Gen JS code representing a native JS module. */
@@ -2331,11 +2347,12 @@ class JSCodeGen()(implicit ctx: Context) {
23312347
protected lazy val isHijackedClass: Set[Symbol] = {
23322348
/* This list is a duplicate of ir.Definitions.HijackedClasses, but
23332349
* with global.Symbol's instead of IR encoded names as Strings.
2350+
* We also add java.lang.Void, which BoxedUnit "erases" to.
23342351
*/
23352352
Set[Symbol](
23362353
defn.BoxedUnitClass, defn.BoxedBooleanClass, defn.BoxedCharClass, defn.BoxedByteClass,
23372354
defn.BoxedShortClass, defn.BoxedIntClass, defn.BoxedLongClass, defn.BoxedFloatClass,
2338-
defn.BoxedDoubleClass, defn.StringClass
2355+
defn.BoxedDoubleClass, defn.StringClass, jsdefn.JavaLangVoidClass
23392356
)
23402357
}
23412358

compiler/src/dotty/tools/backend/sjs/JSDefinitions.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ final class JSDefinitions()(implicit ctx: Context) {
2424
lazy val NoinlineAnnotType: TypeRef = ctx.requiredClassRef("scala.noinline")
2525
def NoinlineAnnot(implicit ctx: Context) = NoinlineAnnotType.symbol.asClass
2626

27+
lazy val JavaLangVoidType: TypeRef = ctx.requiredClassRef("java.lang.Void")
28+
def JavaLangVoidClass(implicit ctx: Context) = JavaLangVoidType.symbol.asClass
29+
2730
lazy val ScalaJSJSPackageVal = ctx.requiredPackage("scala.scalajs.js")
2831
lazy val ScalaJSJSPackageClass = ScalaJSJSPackageVal.moduleClass.asClass
2932
lazy val JSPackage_typeOfR = ScalaJSJSPackageClass.requiredMethodRef("typeOf")

compiler/src/dotty/tools/backend/sjs/JSEncoding.scala

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,17 @@ object JSEncoding {
146146
}
147147

148148
private def encodeMethodNameInternal(sym: Symbol,
149-
reflProxy: Boolean = false, inRTClass: Boolean = false)(
149+
reflProxy: Boolean = false)(
150150
implicit ctx: Context): (String, String) = {
151151
require(sym.is(Flags.Method), "encodeMethodSym called with non-method symbol: " + sym)
152152

153153
def name = encodeMemberNameInternal(sym)
154154

155-
val encodedName = {
156-
if (sym.isClassConstructor) {
157-
"init_"
158-
} else if (sym.is(Flags.Private)) {
159-
(mangleJSName(name) + SignatureSep + "p" +
160-
sym.owner.asClass.baseClasses.size.toString)
161-
} else {
162-
mangleJSName(name)
163-
}
164-
}
155+
val encodedName =
156+
if (sym.isClassConstructor) "init_"
157+
else mangleJSName(name)
165158

166-
val paramsString = makeParamsString(sym, reflProxy, inRTClass)
159+
val paramsString = makeParamsString(sym, reflProxy)
167160

168161
(encodedName, paramsString)
169162
}
@@ -195,13 +188,24 @@ object JSEncoding {
195188
}
196189
}
197190

191+
def encodeClassRef(sym: Symbol)(implicit ctx: Context): jstpe.ClassRef =
192+
jstpe.ClassRef(encodeClassFullName(sym))
193+
198194
def encodeClassFullNameIdent(sym: Symbol)(
199195
implicit ctx: Context, pos: ir.Position): js.Ident = {
200196
js.Ident(encodeClassFullName(sym), Some(sym.fullName.toString))
201197
}
202198

203-
def encodeClassFullName(sym: Symbol)(implicit ctx: Context): String =
204-
ir.Definitions.encodeClassName(sym.fullName.toString)
199+
def encodeClassFullName(sym: Symbol)(implicit ctx: Context): String = {
200+
if (sym == defn.BoxedUnitClass) {
201+
/* Rewire scala.runtime.BoxedUnit to java.lang.Void, as the IR expects.
202+
* BoxedUnit$ is a JVM artifact.
203+
*/
204+
ir.Definitions.BoxedUnitClass
205+
} else {
206+
ir.Definitions.encodeClassName(sym.fullName.toString)
207+
}
208+
}
205209

206210
private def encodeMemberNameInternal(sym: Symbol)(
207211
implicit ctx: Context): String = {
@@ -320,15 +324,13 @@ object JSEncoding {
320324

321325
// Encoding of method signatures
322326

323-
private def makeParamsString(sym: Symbol, reflProxy: Boolean,
324-
inRTClass: Boolean)(
327+
private def makeParamsString(sym: Symbol, reflProxy: Boolean)(
325328
implicit ctx: Context): String = {
326329
val tpe = sym.info
327330

328331
val paramTypeNames0 = tpe.firstParamTypes.map(internalName(_))
329332

330-
val hasExplicitThisParameter =
331-
inRTClass || isScalaJSDefinedJSClass(sym.owner)
333+
val hasExplicitThisParameter = isScalaJSDefinedJSClass(sym.owner)
332334
val paramTypeNames =
333335
if (!hasExplicitThisParameter) paramTypeNames0
334336
else encodeClassFullName(sym.owner) :: paramTypeNames0

project/Build.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,6 @@ object Build {
569569
IO.createDirectory(trgDir)
570570
IO.unzip(scalaJSIRSourcesJar, trgDir)
571571

572-
// Remove f interpolator macro call to avoid its expansion while compiling the compiler and the implementation of the f macro
573-
val utilsFile = trgDir / "org/scalajs/ir/Utils.scala"
574-
val patchedSource = IO.read(utilsFile).replace("""f"\\u$c%04x"""", """"\\u%04x".format(c)""")
575-
IO.write(utilsFile, patchedSource)
576-
577572
(trgDir ** "*.scala").get.toSet
578573
} (Set(scalaJSIRSourcesJar)).toSeq
579574
}.taskValue,

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Scala IDE project file generator
66
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "5.2.4")
77

8-
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.0-M6")
8+
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.0.0-M7")
99

1010
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.1")
1111

0 commit comments

Comments
 (0)