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

Rename rql2 to snapi #497

Merged
merged 4 commits into from
Aug 24, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 0 additions & 15 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,6 @@ target/
/.project
*.iml

language/version
extensions/version
utils/version
client/version
snapi-client/version
sql-client/version
snapi-frontend/version
snapi-truffle/version
sql-parser/version
snapi-parser/version
python-client/version

snapi-parser/src/main/java/raw/compiler/rql2/generated
sql-parser/src/main/java/raw/client/sql/generated

**/pom.xml.versionsBackup

version
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/main/scala/com/rawlabs/compiler/Docs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ final case class ExampleDoc(
result: Option[String] = None
) {
if (example.contains("```")) throw new AssertionError(
"Example code contains ``` and this isn't supported. Must only contain RQL2 code."
"Example code contains ``` and this isn't supported. Must only contain Snapi code."
)
// if (
// !example.contains("s3://") && !example.contains("https://") && !example
Expand Down
2 changes: 1 addition & 1 deletion launcher/src/main/java/raw/cli/MultilineParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// compilerService.parse(line)
//
//
// case Success(result: Rql2Program, _) =>
// case Success(result: SnapiProgram, _) =>
// // If success, let's just check it is a program with an expression.
// // If so, we keep going and ask for more input.
// // This handles cases like:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PythonCompilerService(engineDefinition: (Engine, Boolean))(implicit protec
// This is actually the "default constructor" which obtains a new engine or reuses an existing one.
// Note that the engine will be released when the service is stopped only IF this auxiliary constructor created it.
// Otherwise, we expect the external party - e.g. the test framework - to close it.
// Refer to Rql2TruffleCompilerServiceTestContext to see the engine being created and released from the test
// Refer to SnapiTruffleCompilerServiceTestContext to see the engine being created and released from the test
// framework, so that every test suite instance has a fresh engine.
def this()(implicit settings: RawSettings) = {
this(CompilerService.getEngine)
Expand Down
4 changes: 2 additions & 2 deletions snapi-compiler/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/

import com.rawlabs.compiler.CompilerServiceBuilder;
import com.rawlabs.snapi.compiler.Rql2CompilerServiceBuilder;
import com.rawlabs.snapi.compiler.SnapiCompilerServiceBuilder;

module raw.snapi.client {
requires scala.library;
Expand All @@ -29,5 +29,5 @@
uses CompilerServiceBuilder;

provides CompilerServiceBuilder with
Rql2CompilerServiceBuilder;
SnapiCompilerServiceBuilder;
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
com.rawlabs.snapi.compiler.Rql2CompilerServiceBuilder
com.rawlabs.snapi.compiler.SnapiCompilerServiceBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import com.rawlabs.compiler.{
ValidateResponse
}
import com.rawlabs.compiler.writers.{PolyglotBinaryWriter, PolyglotTextWriter}
import com.rawlabs.snapi.compiler.writers.{Rql2CsvWriter, Rql2JsonWriter}
import com.rawlabs.snapi.compiler.writers.{SnapiCsvWriter, SnapiJsonWriter}
import com.rawlabs.utils.core.{RawSettings, RawUid, RawUtils}
import org.bitbucket.inkytonik.kiama.relation.LeaveAlone
import org.bitbucket.inkytonik.kiama.util.{Position, Positions}
Expand All @@ -63,32 +63,32 @@ import com.rawlabs.snapi.frontend.base
import com.rawlabs.snapi.frontend.base.errors._
import com.rawlabs.snapi.frontend.base.source.{BaseNode, Type}
import com.rawlabs.snapi.frontend.base.{CompilerContext, TreeDeclDescription, TreeDescription, TreeParamDescription}
import com.rawlabs.snapi.frontend.rql2.source.{SourceNode, SourceProgram}
import com.rawlabs.snapi.frontend.rql2._
import com.rawlabs.snapi.frontend.rql2.antlr4.{Antlr4SyntaxAnalyzer, ParseProgramResult, ParseTypeResult, ParserErrors}
import com.rawlabs.snapi.frontend.rql2.errors._
import com.rawlabs.snapi.frontend.rql2.source._
import com.rawlabs.snapi.frontend.snapi.source.{SourceNode, SourceProgram}
import com.rawlabs.snapi.frontend.snapi._
import com.rawlabs.snapi.frontend.snapi.antlr4.{Antlr4SyntaxAnalyzer, ParseProgramResult, ParseTypeResult, ParserErrors}
import com.rawlabs.snapi.frontend.snapi.errors._
import com.rawlabs.snapi.frontend.snapi.source._
import com.rawlabs.snapi.frontend.inferrer.api.InferrerServiceProvider
import com.rawlabs.snapi.frontend.rql2.extensions.builtin.{BinaryPackage, CsvPackage, JsonPackage, StringPackage}
import com.rawlabs.snapi.frontend.snapi.extensions.builtin.{BinaryPackage, CsvPackage, JsonPackage, StringPackage}

import java.io.{IOException, OutputStream}
import scala.collection.mutable
import scala.util.control.NonFatal

object Rql2CompilerService {
val LANGUAGE: Set[String] = Set("rql2", "rql2-truffle", "snapi")
object SnapiCompilerService {
val LANGUAGE: Set[String] = Set("snapi")

val JARS_PATH = "raw.snapi.compiler.jars-path"
}

class Rql2CompilerService(engineDefinition: (Engine, Boolean))(implicit protected val settings: RawSettings)
class SnapiCompilerService(engineDefinition: (Engine, Boolean))(implicit protected val settings: RawSettings)
extends CompilerService
with CustomClassAndModuleLoader
with Rql2TypeUtils {
with SnapiTypeUtils {

private val maybeTruffleClassLoader: Option[ClassLoader] = {
// If defined, contains the path used to create a classloader for the Truffle language runtime.
val maybeJarsPath = settings.getStringOpt(Rql2CompilerService.JARS_PATH)
val maybeJarsPath = settings.getStringOpt(SnapiCompilerService.JARS_PATH)

// If the jars path is defined, create a custom class loader.
maybeJarsPath.map(jarsPath => createCustomClassAndModuleLoader(jarsPath))
Expand All @@ -101,21 +101,21 @@ class Rql2CompilerService(engineDefinition: (Engine, Boolean))(implicit protecte
// This is actually the "default constructor" which obtains a new engine or reuses an existing one.
// Note that the engine will be released when the service is stopped only IF this auxiliary constructor created it.
// Otherwise, we expect the external party - e.g. the test framework - to close it.
// Refer to Rql2TruffleCompilerServiceTestContext to see the engine being created and released from the test
// Refer to SnapiTruffleCompilerServiceTestContext to see the engine being created and released from the test
// framework, so that every test suite instance has a fresh engine.
def this()(implicit settings: RawSettings) = {
this(CompilerService.getEngine)
}

override def language: Set[String] = Rql2CompilerService.LANGUAGE
override def language: Set[String] = SnapiCompilerService.LANGUAGE

// Map of users to compiler context.
private val compilerContextCaches = new mutable.HashMap[RawUid, CompilerContext]
private val compilerContextCachesLock = new Object

private def getCompilerContext(user: RawUid): CompilerContext = {
compilerContextCachesLock.synchronized {
compilerContextCaches.getOrElseUpdate(user, createCompilerContext(user, "rql2-truffle"))
compilerContextCaches.getOrElseUpdate(user, createCompilerContext(user, "snapi"))
}
}

Expand Down Expand Up @@ -199,19 +199,19 @@ class Rql2CompilerService(engineDefinition: (Engine, Boolean))(implicit protecte
case (idn, programDecls) =>
val formattedDecls = programDecls.map {
case TreeDeclDescription(None, outType, comment) =>
DeclDescription(None, rql2TypeToRawType(outType), comment)
DeclDescription(None, snapiTypeToRawType(outType), comment)
case TreeDeclDescription(Some(params), outType, comment) =>
val formattedParams = params.map {
case TreeParamDescription(idn, tipe, required) =>
ParamDescription(idn, rql2TypeToRawType(tipe), defaultValue = None, comment = None, required)
ParamDescription(idn, snapiTypeToRawType(tipe), defaultValue = None, comment = None, required)
}
DeclDescription(Some(formattedParams), rql2TypeToRawType(outType), comment)
DeclDescription(Some(formattedParams), snapiTypeToRawType(outType), comment)
}
(idn, formattedDecls)
}
val programDescription = ProgramDescription(
formattedDecls,
maybeType.map(t => DeclDescription(None, rql2TypeToRawType(t), None)),
maybeType.map(t => DeclDescription(None, snapiTypeToRawType(t), None)),
comment
)
GetProgramDescriptionSuccess(programDescription)
Expand All @@ -233,19 +233,19 @@ class Rql2CompilerService(engineDefinition: (Engine, Boolean))(implicit protecte
maxRows: Option[Long]
): ExecutionResponse = {
val ctx = buildTruffleContext(environment, maybeOutputStream = Some(outputStream))
ctx.initialize("rql")
ctx.initialize("snapi")
ctx.enter()
try {
val (v, tipe) = maybeDecl match {
case Some(decl) =>
// Eval the code and extract the function referred to by 'decl'
val truffleSource = Source
.newBuilder("rql", source, "unnamed")
.newBuilder("snapi", source, "unnamed")
.cached(false) // Disable code caching because of the inferrer.
.build()
ctx.eval(truffleSource)
// 'decl' is found in the context bindings (by its name)
val bindings = ctx.getBindings("rql")
val bindings = ctx.getBindings("snapi")
val f = bindings.getMember(decl)
// its type is found in the polyglot bindings as '@type:<name>'
val funType = {
Expand Down Expand Up @@ -289,7 +289,7 @@ class Rql2CompilerService(engineDefinition: (Engine, Boolean))(implicit protecte
(result, tipe)
case None =>
val truffleSource = Source
.newBuilder("rql", source, "unnamed")
.newBuilder("snapi", source, "unnamed")
.cached(false) // Disable code caching because of the inferrer.
.build()
val result = ctx.eval(truffleSource)
Expand All @@ -311,9 +311,9 @@ class Rql2CompilerService(engineDefinition: (Engine, Boolean))(implicit protecte
case _ => false
}
val lineSeparator = if (windowsLineEnding) "\r\n" else "\n"
val w = new Rql2CsvWriter(outputStream, lineSeparator, maxRows)
val w = new SnapiCsvWriter(outputStream, lineSeparator, maxRows)
try {
w.write(v, tipe.asInstanceOf[Rql2TypeWithProperties])
w.write(v, tipe.asInstanceOf[SnapiTypeWithProperties])
w.flush()
ExecutionSuccess(w.complete)
} catch {
Expand All @@ -325,9 +325,9 @@ class Rql2CompilerService(engineDefinition: (Engine, Boolean))(implicit protecte
if (!JsonPackage.outputWriteSupport(tipe)) {
return ExecutionRuntimeFailure("unsupported type")
}
val w = new Rql2JsonWriter(outputStream, maxRows)
val w = new SnapiJsonWriter(outputStream, maxRows)
try {
w.write(v, tipe.asInstanceOf[Rql2TypeWithProperties])
w.write(v, tipe.asInstanceOf[SnapiTypeWithProperties])
w.flush()
ExecutionSuccess(w.complete)
} catch {
Expand Down Expand Up @@ -663,7 +663,7 @@ class Rql2CompilerService(engineDefinition: (Engine, Boolean))(implicit protecte
s"""let x: interval = Interval.Build(years=$years, months=$months, weeks=$weeks, days=$days, hours=$hours, minutes=$minutes, seconds=$seconds, millis=$millis) in x"""
case _ => throw new CompilerServiceException("type not supported")
}
val value = ctx.eval("rql", code)
val value = ctx.eval("snapi", code)
ctx.asValue(value)
}

Expand All @@ -673,15 +673,15 @@ class Rql2CompilerService(engineDefinition: (Engine, Boolean))(implicit protecte
): Context = {
// Add environment settings as hardcoded environment variables.
val ctxBuilder = Context
.newBuilder("rql")
.newBuilder("snapi")
.engine(engine)
.environment("RAW_PROGRAM_ENVIRONMENT", ProgramEnvironment.serializeToString(environment))
.allowExperimentalOptions(true)
.allowPolyglotAccess(PolyglotAccess.ALL)
environment.options.get("staged-compiler").foreach { stagedCompiler =>
ctxBuilder.option("rql.staged-compiler", stagedCompiler)
ctxBuilder.option("snapi.staged-compiler", stagedCompiler)
}
ctxBuilder.option("rql.settings", settings.renderAsString)
ctxBuilder.option("snapi.settings", settings.renderAsString)
// If the jars path is defined, create a custom class loader and set it as the host class loader.
maybeTruffleClassLoader.map { classLoader =>
// Set the module class loader as the Truffle runtime classloader.
Expand All @@ -699,7 +699,7 @@ class Rql2CompilerService(engineDefinition: (Engine, Boolean))(implicit protecte
f: Context => T
): T = {
val ctx = buildTruffleContext(environment)
ctx.initialize("rql")
ctx.initialize("snapi")
ctx.enter()
try {
f(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import com.rawlabs.compiler.CompilerServiceBuilder
import com.rawlabs.compiler.CompilerService
import com.rawlabs.utils.core.RawSettings

class Rql2CompilerServiceBuilder extends CompilerServiceBuilder {
override def language: Set[String] = Rql2CompilerService.LANGUAGE
class SnapiCompilerServiceBuilder extends CompilerServiceBuilder {
override def language: Set[String] = SnapiCompilerService.LANGUAGE

override def build()(implicit settings: RawSettings): CompilerService = {
new Rql2CompilerService
new SnapiCompilerService
}
}
Loading