Skip to content

Commit

Permalink
Check proto version (#292)
Browse files Browse the repository at this point in the history
Adds a log warning if the proto version looks incompatible.
Also update the proto version to 2.
  • Loading branch information
ducky64 authored Sep 20, 2023
1 parent 57b7ea7 commit 0c058bd
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 12 deletions.
4 changes: 4 additions & 0 deletions compiler/src/main/scala/edg/compiler/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class AssignNamer() {
}
}

object Compiler {
final val kExpectedProtoVersion = 2
}

/** Compiler for a particular design, with an associated library to elaborate references from.
*
* During the compilation process, internal data structures are mutated.
Expand Down
22 changes: 19 additions & 3 deletions compiler/src/main/scala/edg/compiler/CompilerServerMain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,25 @@ class ForwardingPythonInterface(serverFile: Option[File], pythonPaths: Seq[Strin
}
}

override def onLibraryRequestComplete(
override protected def onLibraryRequestComplete(
element: ref.LibraryPath,
result: Errorable[(schema.Library.NS.Val, Option[edgrpc.Refinements])]
): Unit = {
forwardProcessOutput()
}

override def onElaborateGeneratorRequestComplete(
override protected def onElaborateGeneratorRequestComplete(
element: ref.LibraryPath,
values: Map[ref.LocalPath, ExprValue],
result: Errorable[elem.HierarchyBlock]
): Unit = {
forwardProcessOutput()
}

override def onRunBackendComplete(backend: ref.LibraryPath, result: Errorable[Map[DesignPath, String]]): Unit = {
override protected def onRunBackendComplete(
backend: ref.LibraryPath,
result: Errorable[Map[DesignPath, String]]
): Unit = {
forwardProcessOutput()
}
}
Expand All @@ -51,6 +54,8 @@ class ForwardingPythonInterface(serverFile: Option[File], pythonPaths: Seq[Strin
* long-term user interaction.
*/
object CompilerServerMain {
final val kHdlVersionMismatchDelayMs = 2000

private def constPropToSolved(vals: Map[IndirectDesignPath, ExprValue]): Seq[edgcompiler.CompilerResult.Value] = {
vals.map { case (path, value) =>
edgcompiler.CompilerResult.Value(
Expand Down Expand Up @@ -85,6 +90,17 @@ object CompilerServerMain {
val hdlServerOption = PythonInterface.serverFileOption(None) // local relative path
hdlServerOption.foreach { serverFile => println(s"Using local $serverFile") }
val pyIf = new ForwardingPythonInterface(hdlServerOption, Seq(new File(".").getAbsolutePath))
(pyIf.getProtoVersion() match {
case Errorable.Success(pyVersion) if pyVersion == Compiler.kExpectedProtoVersion => None
case Errorable.Success(pyMismatchVersion) => Some(pyMismatchVersion.toString)
case Errorable.Error(errMsg) => Some(s"error $errMsg")
}).foreach { pyMismatchVersion =>
System.err.println(f"WARNING: Python / compiler version mismatch, Python reported $pyMismatchVersion, " +
f"expected ${Compiler.kExpectedProtoVersion}.")
System.err.println(f"If you get unexpected errors or results, consider updating the Python library or compiler.")
Thread.sleep(kHdlVersionMismatchDelayMs)
}

val pyLib = new PythonInterfaceLibrary()
pyLib.withPythonInterface(pyIf) {
while (true) {
Expand Down
33 changes: 25 additions & 8 deletions compiler/src/main/scala/edg/compiler/PythonInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,35 @@ class PythonInterface(serverFile: Option[File], pythonPaths: Seq[String], python
}

// Hooks to implement when certain actions happen
def onLibraryRequest(element: ref.LibraryPath): Unit = {}
def onLibraryRequestComplete(
protected def onLibraryRequest(element: ref.LibraryPath): Unit = {}
protected def onLibraryRequestComplete(
element: ref.LibraryPath,
result: Errorable[(schema.Library.NS.Val, Option[edgrpc.Refinements])]
): Unit = {}
def onElaborateGeneratorRequest(element: ref.LibraryPath, values: Map[ref.LocalPath, ExprValue]): Unit = {}
def onElaborateGeneratorRequestComplete(
protected def onElaborateGeneratorRequest(element: ref.LibraryPath, values: Map[ref.LocalPath, ExprValue]): Unit = {}
protected def onElaborateGeneratorRequestComplete(
element: ref.LibraryPath,
values: Map[ref.LocalPath, ExprValue],
result: Errorable[elem.HierarchyBlock]
): Unit = {}

def getProtoVersion(): Errorable[Int] = {
val (reply, reqTime) = timeExec {
process.write(edgrpc.HdlRequest(
request = edgrpc.HdlRequest.Request.GetProtoVersion(0) // dummy argument
))
process.read()
}
reply.response match {
case edgrpc.HdlResponse.Response.GetProtoVersion(result) =>
Errorable.Success(result)
case edgrpc.HdlResponse.Response.Error(err) =>
Errorable.Error(s"while getting proto version: ${err.error}")
case _ =>
Errorable.Error(s"while getting proto version: invalid response")
}
}

def indexModule(module: String): Errorable[Seq[ref.LibraryPath]] = {
val request = edgrpc.ModuleName(module)
val (reply, reqTime) = timeExec {
Expand Down Expand Up @@ -246,16 +263,16 @@ class PythonInterface(serverFile: Option[File], pythonPaths: Seq[String], python
result
}

def onRunRefinementPass(refinementPass: ref.LibraryPath): Unit = {}
protected def onRunRefinementPass(refinementPass: ref.LibraryPath): Unit = {}

def onRunBackend(backend: ref.LibraryPath): Unit = {}
protected def onRunBackend(backend: ref.LibraryPath): Unit = {}

def onRunRefinementPassComplete(
protected def onRunRefinementPassComplete(
refinementPass: ref.LibraryPath,
result: Errorable[Map[DesignPath, ExprValue]]
): Unit = {}

def onRunBackendComplete(backend: ref.LibraryPath, result: Errorable[Map[DesignPath, String]]): Unit = {}
protected def onRunBackendComplete(backend: ref.LibraryPath, result: Errorable[Map[DesignPath, String]]): Unit = {}

def runRefinementPass(
refinementPass: ref.LibraryPath,
Expand Down
Binary file modified edg_core/resources/edg-compiler-precompiled.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion edg_hdl_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from edg_core.Core import NonLibraryProperty


EDG_PROTO_VERSION = 1
EDG_PROTO_VERSION = 2


class LibraryElementIndexer:
Expand Down

0 comments on commit 0c058bd

Please sign in to comment.