Scala编译器是否可重入? [英] Is the Scala compiler reentrant?
问题描述
对于多玩家编程游戏,我正在为Scala工作一个背景编译服务器,它支持由玩家提交的多个独立源代码树的编译。我成功地运行快速,顺序编译,无需通过
实例化 Global
编译器对象重新加载编译器 val compilerGlobal = new Global(settings,reporter)
作业通过
val run = new compilerGlobal.Run
run.compile(sourceFilePathList)
$我现在理想地希望并行化服务器(即使多个编译并发运行),但仍然没有重新加载编译器(主要是为了避免每次重新解析lib)从头开始。这是可能的,即是上面显示的第二部分(安全地:-) re-entrant,还是它保持全局状态?如果没有,还有什么我可以试试吗?我目前专注于支持Scala 2.9.1。解决方案是的,编译器运行共享状态,线程。这是Eclipse插件中出现的问题之一。如@EJP所指出的,符号表是共享的。
这在你的情况下并不重要,但在IDE中出现:编译器在类型中使用延迟,意味着调用方法时可能会发生额外的计算符号
。由于可见性问题,重要的是这些方法在创建它们的相同线程中调用。
For a multi-player programming game, I'm working on a background compilation server for Scala that supports compilation of multiple, independent source trees submitted by the players. I succeeded in running fast, sequential compilations without reloading the compiler by instantiating the Global
compiler object via
val compilerGlobal = new Global(settings, reporter)
and then running individual compile jobs via
val run = new compilerGlobal.Run
run.compile(sourceFilePathList)
I would now ideally like to parallelize the server (i.e. make multiple compilation runs concurrently), but still without reloading the compiler (primarily to avoid re-parsing the lib) from scratch each time. Is this possible, i.e. is the second part shown above (safely :-) re-entrant, or does it hold global state? If not, is there something else I can try? I am currently focused on supporting Scala 2.9.1.
解决方案 Yes, compiler Runs share state, so you should not share them between threads. It's one of the issues that comes up in the Eclipse plugin. As @EJP noted, the symbol table is shared.
This is not so important in your case, but comes up in an IDE: the compiler uses laziness in types, meaning additional computation (and mutation) may happen when calling methods on Symbol
. Because of visibility issues, it's important that these methods are called on the same thread as the one that created them.
这篇关于Scala编译器是否可重入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!