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

Avoid needless concatenations of warning/error messages #3465

Merged
merged 8 commits into from
May 24, 2022
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
signatures][3444]
- [Generate boilerplate classes related to error handling and varargs in
builtins from method signatures][3454]
- [Avoid needless concatenations of warning/error messages][3465]

[3227]: https://github.com/enso-org/enso/pull/3227
[3248]: https://github.com/enso-org/enso/pull/3248
Expand All @@ -234,6 +235,7 @@
[3444]: https://github.com/enso-org/enso/pull/3444
[3453]: https://github.com/enso-org/enso/pull/3453
[3454]: https://github.com/enso-org/enso/pull/3454
[3465]: https://github.com/enso-org/enso/pull/3465

# Enso 2.0.0-alpha.18 (2021-10-12)

Expand Down
94 changes: 94 additions & 0 deletions engine/runtime/src/main/scala/org/enso/compiler/core/IR.scala
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ object IR {
override def message: String =
"Empty IR: Please report this as a compiler bug."

/** @inheritdoc */
override def diagnosticKeys(): Array[Any] = Array()

/** @inheritdoc */
override def showCode(indent: Int): String = "IR.Empty"
}
Expand Down Expand Up @@ -6357,6 +6360,45 @@ object IR {

/** The location at which the diagnostic occurs. */
val location: Option[IdentifiedLocation]

/** Equals based on returned keys.
*/
override def equals(other: Any): Boolean = {
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
other match {
case o: Diagnostic => {
if (getClass() != other.getClass()) {
return false
}
val myKeys = diagnosticKeys()
val otherKeys = o.diagnosticKeys()

if (myKeys.length != otherKeys.length) {
return false;
}

for (i <- myKeys.indices) {
if (myKeys(i) != otherKeys(i)) {
return false;
}
}
return true
}
case _ => false
}
}

/** Hascode computed on returned keys */
override def hashCode(): Int = {
var sum = 0
for (k <- diagnosticKeys()) {
sum += k.hashCode
}
return sum
}

/** The important keys identifying identity of the diagnostic
*/
def diagnosticKeys(): Array[Any]
}
object Diagnostic {

Expand Down Expand Up @@ -6396,6 +6438,8 @@ object IR {
extends Unused {
override def message: String = s"Unused function argument ${name.name}."

override def diagnosticKeys(): Array[Any] = Array(name.name)

override def toString: String = s"Unused.FunctionArgument(${name.name})"

override val location: Option[IdentifiedLocation] = name.location
Expand All @@ -6404,6 +6448,8 @@ object IR {
sealed case class PatternBinding(override val name: Name) extends Unused {
override def message: String = s"Unused pattern binding ${name.name}."

override def diagnosticKeys(): Array[Any] = Array(name.name)

override def toString: String = s"Unused.PatternBinding(${name.name})"

override val location: Option[IdentifiedLocation] = name.location
Expand All @@ -6416,6 +6462,8 @@ object IR {
sealed case class Binding(override val name: Name) extends Unused {
override def message: String = s"Unused variable ${name.name}."

override def diagnosticKeys(): Array[Any] = Array(name.name)

override def toString: String = s"Unused.Binding(${name.name})"

override val location: Option[IdentifiedLocation] = name.location
Expand All @@ -6440,6 +6488,8 @@ object IR {
else { "" }

override def message: String = s"Unreachable case branches$atLocation."

override def diagnosticKeys(): Array[Any] = Array(atLocation)
}
}

Expand All @@ -6451,6 +6501,8 @@ object IR {
extends Warning {
override def message: String =
"A @Tail_Call annotation was placed in a non-tail-call position."

override def diagnosticKeys(): Array[Any] = Array()
}

/** A warning about a `@Builtin_Method` annotation placed in a method
Expand All @@ -6462,6 +6514,8 @@ object IR {
) extends Warning {
override def message: String =
"A @Builtin_Method annotation allows only the name of the builtin node in the body."

override def diagnosticKeys(): Array[Any] = Array()
}

/** Warnings about shadowing names. */
Expand All @@ -6486,6 +6540,9 @@ object IR {
) extends Shadowed {
override def message: String =
s"The argument $shadowedName is shadowed by $shadower."

override def diagnosticKeys(): Array[Any] =
Array(shadowedName, shadower)
}

/** A warning that a later-defined pattern variable shadows an
Expand All @@ -6502,6 +6559,9 @@ object IR {
) extends Shadowed {
override def message: String =
s"The pattern field $shadowedName is shadowed by $shadower."

override def diagnosticKeys(): Array[Any] =
Array(shadowedName, shadower)
}
}

Expand All @@ -6518,6 +6578,8 @@ object IR {
override val location: Option[IdentifiedLocation] = ir.location
override def message: String =
s"The expression ${ir.showCode()} could not be parallelised: $reason."

override def diagnosticKeys(): Array[Any] = Array(ir.showCode(), reason)
}
}

Expand Down Expand Up @@ -6630,6 +6692,8 @@ object IR {
/** @inheritdoc */
override def message: String = reason.explain

override def diagnosticKeys(): Array[Any] = Array(reason.explain)

/** @inheritdoc */
override val location: Option[IdentifiedLocation] = storedIr.location
}
Expand Down Expand Up @@ -6757,6 +6821,8 @@ object IR {
/** @inheritdoc */
override def message: String = reason.explain(originalName)

override def diagnosticKeys(): Array[Any] = Array(reason)

/** @inheritdoc */
override val location: Option[IdentifiedLocation] = originalName.location
}
Expand Down Expand Up @@ -6924,6 +6990,8 @@ object IR {

override def message: String = reason.explain

override def diagnosticKeys(): Array[Any] = Array(reason)

override val location: Option[IdentifiedLocation] =
originalPattern.location

Expand Down Expand Up @@ -7046,6 +7114,8 @@ object IR {
/** @inheritdoc */
override def message: String = reason.explanation

override def diagnosticKeys(): Array[Any] = Array(reason)

/** @inheritdoc */
override def showCode(indent: Int): String = "Syntax_Error"
}
Expand Down Expand Up @@ -7260,6 +7330,8 @@ object IR {
override def message: String =
"InvalidIR: Please report this as a compiler bug."

override def diagnosticKeys(): Array[Any] = Array()

/** @inheritdoc */
override def showCode(indent: Int): String = "Invalid_Ir"
}
Expand Down Expand Up @@ -7350,6 +7422,8 @@ object IR {
"Methods must have only one definition of the `this` argument, and " +
"it must be the first."

override def diagnosticKeys(): Array[Any] = Array()

/** @inheritdoc */
override def children: List[IR] = List()

Expand Down Expand Up @@ -7447,6 +7521,9 @@ object IR {
s"Method overloads are not supported: ${targetType.name}.from " +
s"${sourceType.showCode()} is defined multiple times in this module."

override def diagnosticKeys(): Array[Any] =
Array(targetType.name, sourceType.showCode())

/** @inheritdoc */
override def mapExpressions(fn: Expression => Expression): Conversion =
this
Expand Down Expand Up @@ -7557,6 +7634,9 @@ object IR {
s"Method overloads are not supported: ${atomName.name}." +
s"${methodName.name} is defined multiple times in this module."

override def diagnosticKeys(): Array[Any] =
Array(atomName.name, methodName.name)

/** @inheritdoc */
override def mapExpressions(fn: Expression => Expression): Method = this

Expand Down Expand Up @@ -7674,6 +7754,9 @@ object IR {
s"Method definitions with the same name as atoms are not supported. " +
s"Method ${methodName.name} clashes with the atom ${atomName.name} in this module."

override def diagnosticKeys(): Array[Any] =
Array(methodName.name, atomName.name)

/** @inheritdoc */
override def mapExpressions(
fn: Expression => Expression
Expand Down Expand Up @@ -7775,6 +7858,8 @@ object IR {
s"Redefining atoms is not supported: ${atomName.name} is " +
s"defined multiple times in this module."

override def diagnosticKeys(): Array[Any] = Array(atomName.name)

/** @inheritdoc */
override def mapExpressions(fn: Expression => Expression): Atom = this

Expand Down Expand Up @@ -7889,6 +7974,10 @@ object IR {
override def message: String =
s"Variable ${invalidBinding.name.name} is being redefined."

override def diagnosticKeys(): Array[Any] = Array(
invalidBinding.name.name
)

/** @inheritdoc */
override def showCode(indent: Int): String =
s"(Redefined (Binding $invalidBinding))"
Expand All @@ -7909,6 +7998,9 @@ object IR {
/** @inheritdoc */
override def message: String = s"Unexpected $entity."

/** @inheritdoc */
override def diagnosticKeys(): Array[Any] = Array(entity)

/** @inheritdoc */
override def mapExpressions(fn: Expression => Expression): Unexpected

Expand Down Expand Up @@ -8130,6 +8222,8 @@ object IR {
/** @inheritdoc */
override def message: String = reason.message

override def diagnosticKeys(): Array[Any] = Array(reason)

/** @inheritdoc */
override def showCode(indent: Int): String = "Import_Export_Error"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ case object GatherDiagnostics extends IRPass {
case x => x.diagnostics.toList
}.flatten
DiagnosticsMeta(
diagnostics.distinctBy(d => (d.location, d.message))
diagnostics.distinctBy(d => d)
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ class JobExecutionEngine(
logger.log(Level.FINE, s"Submitting job: $job...")
val future = jobExecutor.submit(() => {
logger.log(Level.FINE, s"Executing job: $job...")
val before = System.currentTimeMillis()
try {
val result = job.run(runtimeContext)
logger.log(Level.FINE, s"Job $job finished.")
val took = System.currentTimeMillis() - before
logger.log(Level.FINE, s"Job $job finished in $took ms.")
promise.success(result)
} catch {
case NonFatal(ex) =>
Expand Down