Scala编译器是否可重入? [英] Is the Scala compiler reentrant?

查看:193
本文介绍了Scala编译器是否可重入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于多玩家编程游戏,我正在为Scala工作一个背景编译服务器,它支持由玩家提交的多个独立源代码树的编译。我成功地运行快速,顺序编译,无需通过

实例化 Global 编译器对象重新加载编译器

  val compilerGlobal = new Global(settings,reporter)

作业通过

  val run = new compilerGlobal.Run 
run.compile(sourceFilePathList)
解决方案

是的,编译器运行共享状态,线程。这是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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆