Skip to content

Commit

Permalink
Fix: A parser-related config was needed by all services at startup ti…
Browse files Browse the repository at this point in the history
…me (#442)
  • Loading branch information
miguelbranco80 authored Jun 13, 2024
1 parent e57ef8e commit 05e9f42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
5 changes: 4 additions & 1 deletion snapi-frontend/src/main/scala/raw/compiler/base/Tree.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ abstract class Tree[N <: BaseNode: Manifest, P <: N: Manifest, E <: N: Manifest]
)(implicit programContext: ProgramContext)
extends BaseTree[N, P, E](ensureTree) {

private val checkSyntaxAnalyzers =
programContext.settings.getBooleanOpt("raw.check-syntax-analyzers").getOrElse(false)

protected def cloneWithPositions(): TreeWithPositions[N, P, E]

def checkSyntaxAnalyzer(): Boolean = {
Expand Down Expand Up @@ -66,7 +69,7 @@ abstract class Tree[N <: BaseNode: Manifest, P <: N: Manifest, E <: N: Manifest]

def checkTree(): Boolean = {
var r = true
if (programContext.settings.checkSyntaxAnalyzers) {
if (checkSyntaxAnalyzers) {
r &= checkSyntaxAnalyzer()
}
r &= checkSemanticAnalyzer()
Expand Down
48 changes: 19 additions & 29 deletions utils/src/main/scala/raw/utils/RawSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ import com.typesafe.scalalogging.StrictLogging

import java.time.Duration
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import scala.collection.JavaConverters._
import scala.collection.mutable

class SettingsException(message: String, cause: Throwable = null) extends RawException(message, cause)

object RawSettings extends StrictLogging {

private val alreadyLogged = new mutable.HashSet[(String, Any)]()
private val trainingWheelsLogged = new AtomicBoolean(false)
private val syntaxCheckingLogged = new AtomicBoolean(false)

private def logOneTime(key: String, value: Any, propertyType: String): Unit = {
if (alreadyLogged.add((key, value))) {
Expand Down Expand Up @@ -296,6 +294,23 @@ class RawSettings(
)
}

def getBooleanOpt(property: String): Option[Boolean] = {
withLogConfigException(
property,
() => {
try {
val v = config.getBoolean(property)
logOneTime(property, v, s"boolean")
Some(v)
} catch {
case _: ConfigException.Missing =>
logOneTime(property, None, s"boolean")
None
}
}
)
}

def getDuration(property: String): Duration = {
withLogConfigException(
property,
Expand Down Expand Up @@ -363,31 +378,6 @@ class RawSettings(
)
}

/** This is a val to display the warning once at start-up. */
val onTrainingWheels: Boolean = {
withLogConfigException(
"raw.training-wheels",
() => {
val v = config.getBoolean("raw.training-wheels")
if (v && !RawSettings.trainingWheelsLogged.getAndSet(true)) {
logger.warn("RAW is on TRAINING WHEELS!!! This leads to slower performance.")
}
v
}
)
}
val onTrainingWheels: Boolean = getBooleanOpt("raw.training-wheels").getOrElse(false)

/** This is a val to display the warning once at start-up. */
val checkSyntaxAnalyzers: Boolean = {
withLogConfigException(
"raw.check-syntax-analyzers",
() => {
val v = config.getBoolean("raw.check-syntax-analyzers")
if (v && !RawSettings.syntaxCheckingLogged.getAndSet(true)) {
logger.warn("RAW is CHECKING SYNTAX ANALYZERS!!! This leads to slower performance.")
}
v
}
)
}
}

0 comments on commit 05e9f42

Please sign in to comment.