Skip to content
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

Low-hanging perf improvements #10462

Merged
merged 3 commits into from
Jul 8, 2024
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
2 changes: 0 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ val scalacticVersion = "3.3.0-SNAP4"
val scalaLoggingVersion = "3.9.4"
val scalameterVersion = "0.19"
val scalatestVersion = "3.3.0-SNAP4"
val shapelessVersion = "2.3.10"
val slf4jVersion = JPMSUtils.slf4jVersion
val sqliteVersion = "3.42.0.0"
val tikaVersion = "2.4.1"
Expand Down Expand Up @@ -2226,7 +2225,6 @@ lazy val `runtime-compiler` =
annotationProcSetting,
(Test / fork) := true,
libraryDependencies ++= Seq(
"com.chuusai" %% "shapeless" % shapelessVersion % "provided",
Copy link
Member

Choose a reason for hiding this comment

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

I don't see any other usages of shapelessVersion. I guess:

val shapelessVersion        = "2.3.10"

should also be removed then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, thanks

"junit" % "junit" % junitVersion % Test,
"com.github.sbt" % "junit-interface" % junitIfVersion % Test,
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ import java.net.URI
import java.nio.charset.StandardCharsets
import java.time.Clock

import scala.concurrent.duration._
import scala.concurrent.duration.DurationInt

/** A main module containing all components of the server.
*
Expand All @@ -91,7 +91,7 @@ class MainModule(serverConfig: LanguageServerConfig, logLevel: Level) {
new File(serverConfig.contentRootPath)
)

private val openAiKey = sys.env.get("OPENAI_API_KEY")
private val openAiKey = Option(java.lang.System.getenv("OPENAI_API_KEY"))
private val openAiCfg = openAiKey.map(AICompletionConfig)

val languageServerConfig = Config(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import org.enso.compiler.core.{CompilerError, IR, Identifier}
import org.enso.compiler.core.ir.ProcessingPass
import org.enso.compiler.core.ir.Module
import org.enso.compiler.core.ir.Expression
import shapeless.=:!=

import java.util.UUID
import scala.annotation.unused
Expand Down Expand Up @@ -129,7 +128,7 @@ object IRPass {
* @return `ev`, cast to `T` if it is a `T`
*/
def as[T <: Metadata: ClassTag](implicit
@unused ev: T =:!= Metadata
@unused ev: T =!= Metadata
): Option[T] = {
this match {
case p: T => Some(p)
Expand All @@ -146,7 +145,7 @@ object IRPass {
*/
@throws[CompilerError]
def unsafeAs[T <: Metadata: ClassTag](implicit
@unused ev: T =:!= Metadata
@unused ev: T =!= Metadata
Copy link
Member

Choose a reason for hiding this comment

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

Is this a Scala way of doing Kotlin's reified classes?

Wouldn't it be simpler to just delete the method implicit magic altogether and just pass in the argument explicitly?

Btw. Why is the method called unsafeAs then? Reified classes can be checked during runtime in Kotlin and I see some runtime check here as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The sole purpose of this logic is to ensure at compile time that neither type inferencer nor explicit type argument result in T being Metadata rather than its subclass.

I don't think providing explicit argument to every usage site is better, plus it doesn't prevent incorrect usage this implicit prevents from.

): T = {
this
.as[T]
Expand Down Expand Up @@ -183,4 +182,18 @@ object IRPass {
override def duplicate(): Option[Metadata] = Some(this)
}
}

// https://stackoverflow.com/questions/6909053/enforce-type-difference

sealed class =!=[A, B]
Copy link
Member

Choose a reason for hiding this comment

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

Not that copying this code into our repository would simplify the magic...


trait LowerPriorityImplicits {
implicit def equal[A]: =!=[A, A] = sys.error("should not be called")
}
object =!= extends LowerPriorityImplicits {
implicit def nequal[A, B](implicit same: A =:= B = null): =!=[A, B] =
if (same != null)
sys.error("should not be called explicitly with same type")
else new =!=[A, B]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -418,20 +418,21 @@ case object LambdaConsolidate extends IRPass {
): List[DefinitionArgument] = {
argsWithShadowed.map {
case (
spec @ DefinitionArgument.Specified(name, _, _, _, _, _, _),
spec: DefinitionArgument.Specified,
isShadowed
) =>
val oldName = spec.name
val newName =
if (isShadowed) {
freshNameSupply
.newName(from = Some(name))
.newName(from = Some(oldName))
.copy(
location = name.location,
passData = name.passData,
diagnostics = name.diagnostics,
id = name.getId
location = oldName.location,
passData = oldName.passData,
diagnostics = oldName.diagnostics,
id = oldName.getId
)
} else name
} else oldName

spec.copy(name = newName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import java.nio.file.Path
*/
class ThreadSafeFileLockManager(locksRoot: Path) extends ThreadSafeLockManager {
val fileLockManager = new FileLockManager(locksRoot)
val localLocks =
lazy val localLocks =
collection.concurrent.TrieMap.empty[String, ThreadSafeLock]

/** A thread-safe wrapper for a file lock - ensures that the process holds at
Expand Down
Loading