8000 Allocate all emitter var field strings statically · scala-js/scala-js@f1c8ee6 · GitHub
[go: up one dir, main page]

Skip to content

Commit f1c8ee6

Browse files
committed
Allocate all emitter var field strings statically
1 parent 006fd86 commit f1c8ee6

File tree

7 files changed

+590
-313
lines changed

7 files changed

+590
-313
lines changed

linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/ClassEmitter.scala

Lines changed: 54 additions & 54 deletions
Large diffs are not rendered by default.

linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/CoreJSLib.scala

Lines changed: 142 additions & 142 deletions
Large diffs are not rendered by default.

linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/FunctionEmitter.scala

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
400400

401401
private def newSyntheticVar()(implicit pos: Position): js.Ident = {
402402
syntheticVarCounter += 1
403-
fileLevelVarIdent("$x" + syntheticVarCounter)
403+
fileLevelVarIdent(VarFld.x, syntheticVarCounter.toString())
404404
}
405405

406406
@inline
@@ -482,7 +482,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
482482
implicit pos: Position): WithGlobals[js.Function] = {
483483

484484
performOptimisticThenPessimisticRuns {
485-
val thisIdent = fileLevelVarIdent("thiz", thisOriginalName)
485+
val thisIdent = fileLevelVarIdent(VarFld.thiz, thisOriginalName)
486486
val env = env0.withExplicitThis()
487487
val js.Function(jsArrow, jsParams, restParam, jsBody) =
488488
desugarToFunctionInternal(arrow = false, params, None, body, isStat, env)
@@ -667,7 +667,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
667667
unnest(superClass, qualifier, item, rhs) {
668668
(newSuperClass, newQualifier, newItem, newRhs, env0) =>
669669
implicit val env = env0
670-
genCallHelper("superSet", transformExprNoChar(newSuperClass),
670+
genCallHelper(VarFld.superSet, transformExprNoChar(newSuperClass),
671671
transformExprNoChar(newQualifier), transformExprNoChar(item),
672672
transformExprNoChar(rhs))
673673
}
@@ -678,7 +678,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
678678
if (needToUseGloballyMutableVarSetter(scope)) {
679679
unnest(rhs) { (rhs, env0) =>
680680
implicit val env = env0
681-
js.Apply(globalVar("u", scope), transformExpr(rhs, lhs.tpe) :: Nil)
681+
js.Apply(globalVar(VarFld.u, scope), transformExpr(rhs, lhs.tpe) :: Nil)
682682
}
683683
} else {
684684
// Assign normally.
@@ -692,7 +692,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
692692
case StoreModule(className, value) =>
693693
unnest(value) { (newValue, env0) =>
694694
implicit val env = env0
695-
js.Assign(globalVar("n", className), transformExprNoChar(newValue))
695+
js.Assign(globalVar(VarFld.n, className), transformExprNoChar(newValue))
696696
}
697697

698698
case While(cond, body) =>
@@ -773,7 +773,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
773773
} else {
774774
val superCtor = {
775775
if (globalKnowledge.hasStoredSuperClass(enclosingClassName)) {
776-
fileLevelVar("superClass")
776+
fileLevelVar(VarFld.superClass)
777777
} else {
778778
val superClass =
779779
globalKnowledge.getSuperClassOfJSClass(enclosingClassName)
@@ -879,9 +879,9 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
879879
case (PrimArray(srcPrimRef), PrimArray(destPrimRef)) if srcPrimRef == destPrimRef =>
880880
genUncheckedArraycopy(jsArgs)
881881
case (RefArray(), RefArray()) =>
882-
genCallHelper("systemArraycopyRefs", jsArgs: _*)
882+
genCallHelper(VarFld.systemArraycopyRefs, jsArgs: _*)
883883
case _ =>
884-
genCallHelper("systemArraycopyFull", jsArgs: _*)
884+
genCallHelper(VarFld.systemArraycopyFull, jsArgs: _*)
885885
}
886886
}
887887
}
@@ -2209,7 +2209,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
22092209
genSelect(transformExprNoChar(checkNotNull(qualifier)), className, field)
22102210

22112211
case SelectStatic(className, item) =>
2212-
globalVar("t", (className, item.name))
2212+
globalVar(VarFld.t, (className, item.name))
22132213

22142214
case SelectJSNativeMember(className, member) =>
22152215
val jsNativeLoadSpec =
@@ -2247,10 +2247,10 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
22472247
js.Apply(newReceiver(false) DOT transformMethodIdent(method), newArgs)
22482248

22492249
def genDispatchApply(): js.Tree =
2250-
js.Apply(globalVar("dp", methodName), newReceiver(false) :: newArgs)
2250+
js.Apply(globalVar(VarFld.dp, methodName), newReceiver(false) :: newArgs)
22512251

22522252
def genHijackedMethodApply(className: ClassName): js.Tree =
2253-
genApplyStaticLike("f", className, method, newReceiver(className == BoxedCharacterClass) :: newArgs)
2253+
genApplyStaticLike(VarFld.f, className, method, newReceiver(className == BoxedCharacterClass) :: newArgs)
22542254

22552255
if (isMaybeHijackedClass(receiver.tpe) &&
22562256
!methodName.isReflectiveProxy) {
@@ -2300,20 +2300,20 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
23002300
val transformedArgs = newReceiver :: newArgs
23012301

23022302
if (flags.isConstructor) {
2303-
genApplyStaticLike("ct", className, method, transformedArgs)
2303+
genApplyStaticLike(VarFld.ct, className, method, transformedArgs)
23042304
} else if (flags.isPrivate) {
2305-
genApplyStaticLike("p", className, method, transformedArgs)
2305+
genApplyStaticLike(VarFld.p, className, method, transformedArgs)
23062306
} else if (globalKnowledge.isInterface(className)) {
2307-
genApplyStaticLike("f", className, method, transformedArgs)
2307+
genApplyStaticLike(VarFld.f, className, method, transformedArgs)
23082308
} else {
23092309
val fun =
2310-
globalVar("c", className).prototype DOT transformMethodIdent(method)
2310+
globalVar(VarFld.c, className).prototype DOT transformMethodIdent(method)
23112311
js.Apply(fun DOT "call", transformedArgs)
23122312
}
23132313

23142314
case ApplyStatic(flags, className, method, args) =>
23152315
genApplyStaticLike(
2316-
if (flags.isPrivate) "ps" else "s",
2316+
if (flags.isPrivate) VarFld.ps else VarFld.s,
23172317
className,
23182318
method,
23192319
transformTypedArgs(method.name, args))
@@ -2354,7 +2354,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
23542354
else
23552355
genLongMethodApply(newLhs, LongImpl.toInt)
23562356
case DoubleToInt =>
2357-
genCallHelper("doubleToInt", newLhs)
2357+
genCallHelper(VarFld.doubleToInt, newLhs)
23582358
case DoubleToFloat =>
23592359
genFround(newLhs)
23602360

@@ -2366,14 +2366,14 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
23662366
genLongMethodApply(newLhs, LongImpl.toDouble)
23672367
case DoubleToLong =>
23682368
if (useBigIntForLongs)
2369-
genCallHelper("doubleToLong", newLhs)
2369+
genCallHelper(VarFld.doubleToLong, newLhs)
23702370
else
23712371
genLongModuleApply(LongImpl.fromDouble, newLhs)
23722372

23732373
// Long -> Float (neither widening nor narrowing)
23742374
case LongToFloat =>
23752375
if (useBigIntForLongs)
2376-
genCallHelper("longToFloat", newLhs)
2376+
genCallHelper(VarFld.longToFloat, newLhs)
23772377
else
23782378
genLongMethodApply(newLhs, LongImpl.toFloat)
23792379

@@ -2458,14 +2458,14 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
24582458
case IntLiteral(r) if r != 0 =>
24592459
or0(js.BinaryOp(JSBinaryOp./, newLhs, newRhs))
24602460
case _ =>
2461-
genCallHelper("intDiv", newLhs, newRhs)
2461+
genCallHelper(VarFld.intDiv, newLhs, newRhs)
24622462
}
24632463
case Int_% =>
24642464
rhs match {
24652465
case IntLiteral(r) if r != 0 =>
24662466
or0(js.BinaryOp(JSBinaryOp.%, newLhs, newRhs))
24672467
case _ =>
2468-
genCallHelper("intMod", newLhs, newRhs)
2468+
genCallHelper(VarFld.intMod, newLhs, newRhs)
24692469
}
24702470

24712471
case Int_| => js.BinaryOp(JSBinaryOp.|, newLhs, newRhs)
@@ -2513,7 +2513,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
25132513
case LongLiteral(r) if r != 0L =>
25142514
wrapBigInt64(js.BinaryOp(JSBinaryOp./, newLhs, newRhs))
25152515
case _ =>
2516-
genCallHelper("longDiv", newLhs, newRhs)
2516+
genCallHelper(VarFld.longDiv, newLhs, newRhs)
25172517
}
25182518
} else {
25192519
genLongMethodApply(newLhs, LongImpl./, newRhs)
@@ -2524,7 +2524,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
25242524
case LongLiteral(r) if r != 0L =>
25252525
wrapBigInt64(js.BinaryOp(JSBinaryOp.%, newLhs, newRhs))
25262526
case _ =>
2527-
genCallHelper("longMod", newLhs, newRhs)
2527+
genCallHelper(VarFld.longMod, newLhs, newRhs)
25282528
}
25292529
} else {
25302530
genLongMethodApply(newLhs, LongImpl.%, newRhs)
@@ -2631,7 +2631,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
26312631
case String_charAt =>
26322632
semantics.stringIndexOutOfBounds match {
26332633
case CheckedBehavior.Compliant | CheckedBehavior.Fatal =>
2634-
genCallHelper("charAt", newLhs, newRhs)
2634+
genCallHelper(VarFld.charAt, newLhs, newRhs)
26352635
case CheckedBehavior.Unchecked =>
26362636
js.Apply(genIdentBracketSelect(newLhs, "charCodeAt"), List(newRhs))
26372637
}
@@ -2672,7 +2672,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
26722672
extractWithGlobals(genAsInstanceOf(transformExprNoChar(expr), tpe))
26732673

26742674
case GetClass(expr) =>
2675-
genCallHelper("objectGetClass", transformExprNoChar(expr))
2675+
genCallHelper(VarFld.objectGetClass, transformExprNoChar(expr))
26762676

26772677
case Clone(expr) =>
26782678
val newExpr = transformExprNoChar(checkNotNull(expr))
@@ -2700,15 +2700,15 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
27002700
*/
27012701
case ClassType(CloneableClass) | ClassType(SerializableClass) |
27022702
ClassType(ObjectClass) | AnyType =>
2703-
genCallHelper("objectOrArrayClone", newExpr)
2703+
genCallHelper(VarFld.objectOrArrayClone, newExpr)
27042704

27052705
// Otherwise, it is known not to be an array.
27062706
case _ =>
2707-
genCallHelper("objectClone", newExpr)
2707+
genCallHelper(VarFld.objectClone, newExpr)
27082708
}
27092709

27102710
case IdentityHashCode(expr) =>
2711-
genCallHelper("systemIdentityHashCode", transformExprNoChar(expr))
2711+
genCallHelper(VarFld.systemIdentityHashCode, transformExprNoChar(expr))
27122712

27132713
case WrapAsThrowable(expr) =>
27142714
val newExpr = transformExprNoChar(expr).asInstanceOf[js.VarRef]
@@ -2727,7 +2727,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
27272727
// Transients
27282728

27292729
case Transient(CheckNotNull(obj)) =>
2730-
genCallHelper("n", transformExpr(obj, preserveChar = true))
2730+
genCallHelper(VarFld.n, transformExpr(obj, preserveChar = true))
27312731
case Transient(AssumeNotNull(obj)) =>
27322732
transformExpr(obj, preserveChar = true)
27332733

@@ -2753,7 +2753,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
27532753
}
27542754

27552755
case Transient(ObjectClassName(obj)) =>
2756-
genCallHelper("objectClassName", transformExprNoChar(obj))
2756+
genCallHelper(VarFld.objectClassName, transformExprNoChar(obj))
27572757

27582758
case Transient(ArrayToTypedArray(expr, primRef)) =>
27592759
val value = transformExprNoChar(checkNotNull(expr))
@@ -2800,7 +2800,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
28002800

28012801
case Transient(JSNewVararg(constr, argsArray)) =>
28022802
assert(!es2015, s"generated a JSNewVargs with ES 2015+ at ${tree.pos}")
2803-
genCallHelper("newJSObjectWithVarargs",
2803+
genCallHelper(VarFld.newJSObjectWithVarargs,
28042804
transformExprNoChar(constr), transformExprNoChar(argsArray))
28052805

28062806
case JSPrivateSelect(qualifier, className, field) =>
@@ -2840,7 +2840,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
28402840
transformExprNoChar(method)), args.map(transformJSArg))
28412841

28422842
case JSSuperSelect(superClass, qualifier, item) =>
2843-
genCallHelper("superGet", transformExprNoChar(superClass),
2843+
genCallHelper(VarFld.superGet, transformExprNoChar(superClass),
28442844
transformExprNoChar(qualifier), transformExprNoChar(item))
28452845

28462846
case JSImportCall(arg) =>
@@ -2902,7 +2902,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
29022902
js.UnaryOp(JSUnaryOp.typeof, transformExprNoChar(globalRef))
29032903

29042904
case JSLinkingInfo() =>
2905-
globalVar("linkingInfo", CoreVar)
2905+
globalVar(VarFld.linkingInfo, CoreVar)
29062906

29072907
// Literals
29082908

@@ -2943,18 +2943,18 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
29432943
js.This()
29442944

29452945
case VarKind.ExplicitThisAlias =>
2946-
fileLevelVar("thiz")
2946+
fileLevelVar(VarFld.thiz)
29472947

29482948
case VarKind.ClassCapture =>
2949-
fileLevelVar("cc", genName(name.name))
2949+
fileLevelVar(VarFld.cc, genName(name.name))
29502950
}
29512951

29522952
case Transient(JSVarRef(name, _)) =>
29532953
js.VarRef(name)
29542954

29552955
case This() =>
29562956
if (env.hasExplicitThis)
2957-
fileLevelVar("thiz")
2957+
fileLevelVar(VarFld.thiz)
29582958
else
29592959
js.This()
29602960

@@ -2971,7 +2971,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
29712971
for ((value, expectedType) <- captureValues.zip(expectedTypes))
29722972
yield transformExpr(value, expectedType)
29732973
}
2974-
js.Apply(globalVar("a", className), transformedArgs)
2974+
js.Apply(globalVar(VarFld.a, className), transformedArgs)
29752975

29762976
// Invalid trees
29772977

@@ -2984,7 +2984,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
29842984
if (preserveChar || tree.tpe != CharType)
29852985
baseResult
29862986
else
2987-
genCallHelper("bC", baseResult)
2987+
genCallHelper(VarFld.bC, baseResult)
29882988
}
29892989

29902990
private def transformApplyDynamicImport(tree: ApplyDynamicImport)(
@@ -3012,7 +3012,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
30123012
}
30133013

30143014
val innerCall = extractWithGlobals {
3015-
withDynamicGlobalVar("s", (className, method.name)) { v =>
3015+
withDynamicGlobalVar(VarFld.s, (className, method.name)) { v =>
30163016
js.Apply(v, newArgs)
30173017
}
30183018
}
@@ -3232,7 +3232,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
32323232
keepOnlyDangerousVarNames = false)
32333233
}
32343234

3235-
private def genApplyStaticLike(field: String, className: ClassName,
3235+
private def genApplyStaticLike(field: VarFld, className: ClassName,
32363236
method: MethodIdent, args: List[js.Tree])(
32373237
implicit pos: Position): js.Tree = {
32383238
js.Apply(globalVar(field, (className, method.name)), args)

linker/shared/src/main/scala/org/scalajs/linker/backend/emitter/PolyfillableBuiltin.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package org.scalajs.linker.backend.emitter
1515
import org.scalajs.linker.interface.ESVersion
1616

1717
private[emitter] sealed abstract class PolyfillableBuiltin(
18-
val builtinName: String, val availableInESVersion: ESVersion)
18+
val polyfillField: VarFld, val availableInESVersion: ESVersion)
1919

2020
private[emitter] object PolyfillableBuiltin {
2121
lazy val All: List[PolyfillableBuiltin] = List(
@@ -27,18 +27,18 @@ private[emitter] object PolyfillableBuiltin {
2727
)
2828

2929
sealed abstract class GlobalVarBuiltin(val globalVar: String,
30-
builtinName: String, availableInESVersion: ESVersion)
31-
extends PolyfillableBuiltin(builtinName, availableInESVersion)
30+
polyfillField: VarFld, availableInESVersion: ESVersion)
31+
extends PolyfillableBuiltin(polyfillField, availableInESVersion)
3232

3333
sealed abstract class NamespacedBuiltin(val namespaceGlobalVar: String,
34-
builtinName: String, availableInESVersion: ESVersion)
35-
extends PolyfillableBuiltin(builtinName, availableInESVersion)
34+
val builtinName: String, polyfillField: VarFld, availableInESVersion: ESVersion)
35+
extends PolyfillableBuiltin(polyfillField, availableInESVersion)
3636

37-
case object ObjectIsBuiltin extends NamespacedBuiltin("Object", "is", ESVersion.ES2015)
38-
case object ImulBuiltin extends NamespacedBuiltin("Math", "imul", ESVersion.ES2015)
39-
case object FroundBuiltin extends NamespacedBuiltin("Math", "fround", ESVersion.ES2015)
37+
case object ObjectIsBuiltin extends NamespacedBuiltin("Object", "is", VarFld.is, ESVersion.ES2015)
38+
case object ImulBuiltin extends NamespacedBuiltin("Math", "imul", VarFld.imul, ESVersion.ES2015)
39+
case object FroundBuiltin extends NamespacedBuiltin("Math", "fround", VarFld.fround, ESVersion.ES2015)
4040
case object PrivateSymbolBuiltin
41-
extends GlobalVarBuiltin("Symbol", "privateJSFieldSymbol", ESVersion.ES2015)
42-
case object GetOwnPropertyDescriptorsBuiltin
43-
extends NamespacedBuiltin("Object", "getOwnPropertyDescriptors", ESVersion.ES2017)
41+
extends GlobalVarBuiltin("Symbol", VarFld.privateJSFieldSymbol, ESVersion.ES2015)
42+
case object GetOwnPropertyDescriptorsBuiltin extends NamespacedBuiltin("Object",
43+
"getOwnPropertyDescriptors", VarFld.getOwnPropertyDescriptors, ESVersion.ES2017)
4444
}

0 commit comments

Comments
 (0)
0