Skip to content

Use inline val for inlined final vals #13989

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 1 commit into from
Nov 24, 2021
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
262 changes: 131 additions & 131 deletions compiler/src/dotty/tools/backend/ScalaPrimitivesOps.scala

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/backend/jvm/AsmUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ object AsmUtils {
/**
* Print the bytecode of classes generated by GenBCode to the standard output.
*/
final val traceClassEnabled = false
final val traceClassPattern = ""
inline val traceClassEnabled = false
inline val traceClassPattern = ""

/**
* Print the bytedcode of classes as they are serialized by the ASM library. The serialization
* performed by `asm.ClassWriter` can change the code generated by GenBCode. For example, it
* introduces stack map frames, it computes the maximal stack sizes, and it replaces dead
* code by NOPs (see also https://github.com/scala/scala/pull/3726#issuecomment-42861780).
*/
final val traceSerializedClassEnabled = false
final val traceSerializedClassPattern = ""
inline val traceSerializedClassEnabled = false
inline val traceSerializedClassPattern = ""

def traceMethod(mnode: MethodNode1): Unit = {
println(s"Bytecode for method ${mnode.name}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
with BCJGenSigGen {

// Strangely I can't find this in the asm code 255, but reserving 1 for "this"
final val MaximumJvmParameters = 254
inline val MaximumJvmParameters = 254

// current class
var cnode: ClassNode1 = null
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4369,7 +4369,7 @@ class JSCodeGen()(using genCtx: Context) {
js.LoadJSConstructor(encodeClassName(sym))
}

private final val GenericGlobalObjectInformationMsg = {
private inline val GenericGlobalObjectInformationMsg = {
"\n " +
"See https://www.scala-js.org/doc/interoperability/global-scope.html " +
"for further information."
Expand Down
50 changes: 25 additions & 25 deletions compiler/src/dotty/tools/backend/sjs/JSPrimitives.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,42 @@ import scala.collection.mutable

object JSPrimitives {

final val FirstJSPrimitiveCode = 300
inline val FirstJSPrimitiveCode = 300

final val DYNNEW = FirstJSPrimitiveCode + 1 // Instantiate a new JavaScript object
inline val DYNNEW = FirstJSPrimitiveCode + 1 // Instantiate a new JavaScript object

final val ARR_CREATE = DYNNEW + 1 // js.Array.apply (array literal syntax)
inline val ARR_CREATE = DYNNEW + 1 // js.Array.apply (array literal syntax)

final val TYPEOF = ARR_CREATE + 1 // typeof x
final val JS_NATIVE = TYPEOF + 1 // js.native. Marker method. Fails if tried to be emitted.
inline val TYPEOF = ARR_CREATE + 1 // typeof x
inline val JS_NATIVE = TYPEOF + 1 // js.native. Marker method. Fails if tried to be emitted.

final val UNITVAL = JS_NATIVE + 1 // () value, which is undefined
inline val UNITVAL = JS_NATIVE + 1 // () value, which is undefined

final val JS_IMPORT = UNITVAL + 1 // js.import.apply(specifier)
final val JS_IMPORT_META = JS_IMPORT + 1 // js.import.meta
inline val JS_IMPORT = UNITVAL + 1 // js.import.apply(specifier)
inline val JS_IMPORT_META = JS_IMPORT + 1 // js.import.meta

final val CONSTRUCTOROF = JS_IMPORT_META + 1 // runtime.constructorOf(clazz)
final val CREATE_INNER_JS_CLASS = CONSTRUCTOROF + 1 // runtime.createInnerJSClass
final val CREATE_LOCAL_JS_CLASS = CREATE_INNER_JS_CLASS + 1 // runtime.createLocalJSClass
final val WITH_CONTEXTUAL_JS_CLASS_VALUE = CREATE_LOCAL_JS_CLASS + 1 // runtime.withContextualJSClassValue
final val LINKING_INFO = WITH_CONTEXTUAL_JS_CLASS_VALUE + 1 // runtime.linkingInfo
inline val CONSTRUCTOROF = JS_IMPORT_META + 1 // runtime.constructorOf(clazz)
inline val CREATE_INNER_JS_CLASS = CONSTRUCTOROF + 1 // runtime.createInnerJSClass
inline val CREATE_LOCAL_JS_CLASS = CREATE_INNER_JS_CLASS + 1 // runtime.createLocalJSClass
inline val WITH_CONTEXTUAL_JS_CLASS_VALUE = CREATE_LOCAL_JS_CLASS + 1 // runtime.withContextualJSClassValue
inline val LINKING_INFO = WITH_CONTEXTUAL_JS_CLASS_VALUE + 1 // runtime.linkingInfo

final val STRICT_EQ = LINKING_INFO + 1 // js.special.strictEquals
final val IN = STRICT_EQ + 1 // js.special.in
final val INSTANCEOF = IN + 1 // js.special.instanceof
final val DELETE = INSTANCEOF + 1 // js.special.delete
final val FORIN = DELETE + 1 // js.special.forin
final val DEBUGGER = FORIN + 1 // js.special.debugger
inline val STRICT_EQ = LINKING_INFO + 1 // js.special.strictEquals
inline val IN = STRICT_EQ + 1 // js.special.in
inline val INSTANCEOF = IN + 1 // js.special.instanceof
inline val DELETE = INSTANCEOF + 1 // js.special.delete
inline val FORIN = DELETE + 1 // js.special.forin
inline val DEBUGGER = FORIN + 1 // js.special.debugger

final val THROW = DEBUGGER + 1
inline val THROW = DEBUGGER + 1

final val UNION_FROM = THROW + 1 // js.|.from
final val UNION_FROM_TYPE_CONSTRUCTOR = UNION_FROM + 1 // js.|.fromTypeConstructor
inline val UNION_FROM = THROW + 1 // js.|.from
inline val UNION_FROM_TYPE_CONSTRUCTOR = UNION_FROM + 1 // js.|.fromTypeConstructor

final val REFLECT_SELECTABLE_SELECTDYN = UNION_FROM_TYPE_CONSTRUCTOR + 1 // scala.reflect.Selectable.selectDynamic
final val REFLECT_SELECTABLE_APPLYDYN = REFLECT_SELECTABLE_SELECTDYN + 1 // scala.reflect.Selectable.applyDynamic
inline val REFLECT_SELECTABLE_SELECTDYN = UNION_FROM_TYPE_CONSTRUCTOR + 1 // scala.reflect.Selectable.selectDynamic
inline val REFLECT_SELECTABLE_APPLYDYN = REFLECT_SELECTABLE_SELECTDYN + 1 // scala.reflect.Selectable.applyDynamic

final val LastJSPrimitiveCode = REFLECT_SELECTABLE_APPLYDYN
inline val LastJSPrimitiveCode = REFLECT_SELECTABLE_APPLYDYN

def isJSPrimitive(code: Int): Boolean =
code >= FirstJSPrimitiveCode && code <= LastJSPrimitiveCode
Expand Down
26 changes: 13 additions & 13 deletions compiler/src/dotty/tools/dotc/core/Constants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import Decorators._

object Constants {

final val NoTag = 0
final val UnitTag = 1
final val BooleanTag = 2
final val ByteTag = 3
final val ShortTag = 4
final val CharTag = 5
final val IntTag = 6
final val LongTag = 7
final val FloatTag = 8
final val DoubleTag = 9
final val StringTag = 10
final val NullTag = 11
final val ClazzTag = 12
inline val NoTag = 0
inline val UnitTag = 1
inline val BooleanTag = 2
inline val ByteTag = 3
inline val ShortTag = 4
inline val CharTag = 5
inline val IntTag = 6
inline val LongTag = 7
inline val FloatTag = 8
inline val DoubleTag = 9
inline val StringTag = 10
inline val NullTag = 11
inline val ClazzTag = 12

class Constant(val value: Any, val tag: Int) extends printing.Showable with Product1[Any] {
import java.lang.Double.doubleToRawLongBits
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ object Decorators {
NoSymbol
}

final val MaxFilterRecursions = 10
inline val MaxFilterRecursions = 10

/** Implements filterConserve, zipWithConserve methods
* on lists that avoid duplication of list nodes where feasible.
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Hashable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ object Hashable {
/** A hash value indicating that the underlying type is not
* cached in uniques.
*/
final val NotCached = 0
inline val NotCached = 0

/** An alternative value returned from `hash` if the
* computed hashCode would be `NotCached`.
*/
private[core] final val NotCachedAlt = Int.MinValue
private[core] inline val NotCachedAlt = Int.MinValue

/** A value that indicates that the hash code is unknown
*/
private[core] final val HashUnknown = 1234
private[core] inline val HashUnknown = 1234

/** An alternative value if computeHash would otherwise yield HashUnknown
*/
private[core] final val HashUnknownAlt = 4321
private[core] inline val HashUnknownAlt = 4321
}

trait Hashable {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/NameOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object NameOps {
object compactify {
lazy val md5: MessageDigest = MessageDigest.getInstance("MD5")

final val CLASSFILE_NAME_CHAR_LIMIT = 240
inline val CLASSFILE_NAME_CHAR_LIMIT = 240

/** COMPACTIFY
*
Expand Down
22 changes: 11 additions & 11 deletions compiler/src/dotty/tools/dotc/core/NameTags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ import dotty.tools.tasty.TastyFormat
/** The possible tags of a NameKind */
object NameTags extends TastyFormat.NameTags {

final val FLATTENED = 5 // A flat name, generated by Flatten
inline val FLATTENED = 5 // A flat name, generated by Flatten

final val TRAITSETTER = 6 // A Scala-2 trait setter, generated by AugmentScala2Traits
inline val TRAITSETTER = 6 // A Scala-2 trait setter, generated by AugmentScala2Traits

final val OUTERSELECT = 13 // A name `<num>_outer`, used by the inliner to indicate an
inline val OUTERSELECT = 13 // A name `<num>_outer`, used by the inliner to indicate an
// outer accessor that will be filled in by ExplicitOuter.
// <num> indicates the number of hops needed to select the outer field.

final val PROTECTEDACCESSOR = 24 // The name of a protected accesor `protected$<name>` created by ProtectedAccessors.
inline val PROTECTEDACCESSOR = 24 // The name of a protected accesor `protected$<name>` created by ProtectedAccessors.

final val INITIALIZER = 26 // A mixin initializer method
inline val INITIALIZER = 26 // A mixin initializer method

final val FIELD = 29 // Used by Memoize to tag the name of a class member field.
inline val FIELD = 29 // Used by Memoize to tag the name of a class member field.

final val EXTMETH = 30 // Used by ExtensionMethods for the name of an extension method
inline val EXTMETH = 30 // Used by ExtensionMethods for the name of an extension method
// implementing a value class method.

final val ADAPTEDCLOSURE = 31 // Used in Erasure to adapt closures over primitive types.
inline val ADAPTEDCLOSURE = 31 // Used in Erasure to adapt closures over primitive types.

final val DIRECT = 32 // Used to define implementations of methods with
inline val DIRECT = 32 // Used to define implementations of methods with
// erased context function results that can override some
// other method.

final val PARAMACC = 33 // Used for a private parameter alias
inline val PARAMACC = 33 // Used for a private parameter alias

final val SETTER = 34 // A synthesized += suffix.
inline val SETTER = 34 // A synthesized += suffix.

def nameTagToString(tag: Int): String = tag match {
case UTF8 => "UTF8"
Expand Down
18 changes: 9 additions & 9 deletions compiler/src/dotty/tools/dotc/core/Periods.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ object Periods {

/** An ordinal number for compiler runs. First run has number 1. */
type RunId = Int
final val NoRunId = 0
final val InitialRunId = 1
final val RunWidth = java.lang.Integer.SIZE - PhaseWidth * 2 - 1/* sign */
final val MaxPossibleRunId = (1 << RunWidth) - 1
inline val NoRunId = 0
inline val InitialRunId = 1
inline val RunWidth = java.lang.Integer.SIZE - PhaseWidth * 2 - 1/* sign */
inline val MaxPossibleRunId = (1 << RunWidth) - 1

/** An ordinal number for phases. First phase has number 1. */
type PhaseId = Int
final val NoPhaseId = 0
final val FirstPhaseId = 1
inline val NoPhaseId = 0
inline val FirstPhaseId = 1

/** The number of bits needed to encode a phase identifier. */
final val PhaseWidth = 7
final val PhaseMask = (1 << PhaseWidth) - 1
final val MaxPossiblePhaseId = PhaseMask
inline val PhaseWidth = 7
inline val PhaseMask = (1 << PhaseWidth) - 1
inline val MaxPossiblePhaseId = PhaseMask
}
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Scopes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ import collection.mutable
object Scopes {

/** Maximal fill factor of hash table */
private final val FillFactor = 2.0/3.0
private inline val FillFactor = 2.0/3.0

/** A hashtable is created once current size exceeds MinHash * FillFactor
* The initial hash table has twice that size (i.e 16).
* This value must be a power of two, so that the index of an element can
* be computed as element.hashCode & (hashTable.length - 1)
*/
final val MinHashedScopeSize = 8
inline val MinHashedScopeSize = 8

/** The maximal permissible number of recursions when creating
* a hashtable
*/
private final val MaxRecursions = 1000
private inline val MaxRecursions = 1000

/** A function that optionally produces synthesized symbols with
* the given name in the given context. Returns `NoSymbol` if the
Expand Down
54 changes: 27 additions & 27 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@ object StdNames {
/** Base strings from which synthetic names are derived. */

object str {
final val SETTER_SUFFIX = "_="
final val EXPAND_SEPARATOR = "$$"
final val TRAIT_SETTER_SEPARATOR = "$_setter_$"
final val SUPER_PREFIX = "super$"
final val INITIALIZER_PREFIX = "initial$"
final val AVOID_CLASH_SUFFIX = "$_avoid_name_clash_$"
final val MODULE_SUFFIX = "$"
final val TOPLEVEL_SUFFIX = "$package"
final val NAME_JOIN = "$"
final val DEFAULT_GETTER = "$default$"
final val LOCALDUMMY_PREFIX = "<local " // owner of local blocks
final val ANON_CLASS = "$anon"
final val ANON_FUN = "$anonfun"

final val REPL_SESSION_LINE = "rs$line$"
final val REPL_ASSIGN_SUFFIX = "$assign"
final val REPL_RES_PREFIX = "res"

final val MODULE_INSTANCE_FIELD = "MODULE$"

final val Function = "Function"
final val ErasedFunction = "ErasedFunction"
final val ContextFunction = "ContextFunction"
final val ErasedContextFunction = "ErasedContextFunction"
final val AbstractFunction = "AbstractFunction"
final val Tuple = "Tuple"
final val Product = "Product"
inline val SETTER_SUFFIX = "_="
inline val EXPAND_SEPARATOR = "$$"
inline val TRAIT_SETTER_SEPARATOR = "$_setter_$"
inline val SUPER_PREFIX = "super$"
inline val INITIALIZER_PREFIX = "initial$"
inline val AVOID_CLASH_SUFFIX = "$_avoid_name_clash_$"
inline val MODULE_SUFFIX = "$"
inline val TOPLEVEL_SUFFIX = "$package"
inline val NAME_JOIN = "$"
inline val DEFAULT_GETTER = "$default$"
inline val LOCALDUMMY_PREFIX = "<local " // owner of local blocks
inline val ANON_CLASS = "$anon"
inline val ANON_FUN = "$anonfun"

inline val REPL_SESSION_LINE = "rs$line$"
inline val REPL_ASSIGN_SUFFIX = "$assign"
inline val REPL_RES_PREFIX = "res"

inline val MODULE_INSTANCE_FIELD = "MODULE$"

inline val Function = "Function"
inline val ErasedFunction = "ErasedFunction"
inline val ContextFunction = "ContextFunction"
inline val ErasedContextFunction = "ErasedContextFunction"
inline val AbstractFunction = "AbstractFunction"
inline val Tuple = "Tuple"
inline val Product = "Product"

def sanitize(str: String): String = str.replaceAll("""[<>]""", """\$""")
}
Expand Down
Loading