【24h】

Dynamic Inference of Static Types for Ruby

机译:Ruby静态类型的动态推断

获取原文
获取原文并翻译 | 示例

摘要

There have been several efforts to bring static type inference to object-oriented dynamic languages such as Ruby, Python, and Perl. In our experience, however, such type inference systems are extremely difficult to develop, because dynamic languages are typically complex, poorly specified, and include features, such as eval and reflection, that are hard to analyze. In this paper, we introduce constraint-based dynamic type inference, a technique that infers static types based on dynamic program executions. In our approach, we wrap each run-time value to associate it with a type variable, and the wrapper generates constraints on this type variable when the wrapped value is used. This technique avoids many of the often overly conservative approximations of static tools, as constraints are generated based on how values are used during actual program runs. Using wrappers is also easy to implement, since we need only write a constraint resolution algorithm and a transformation to introduce the wrappers. The best part is that we can eat our cake, too: our algorithm will infer sound types as long as it observes every path through each method body-note that the number of such paths may be dramatically smaller than the number of paths through the program as a whole. We have developed Rubydust. an implementation of our algorithm for Ruby. Rubydust takes advantage of Ruby's dynamic features to implement wrappers as a language library. We applied Rubydust to a number of small programs and found it to be both easy to use and useful: Rubydust discovered 1 real type error, and all other inferred types were correct and readable.
机译:为了将静态类型推断带到诸如Ruby,Python和Perl之类的面向对象的动态语言中,已经做了很多努力。但是,根据我们的经验,由于动态语言通常是复杂的,指定不明确的,并且包含难以分析的功能(例如评估和反射),因此此类类型推理系统极难开发。在本文中,我们介绍了基于约束的动态类型推断,这是一种基于动态程序执行来推断静态类型的技术。在我们的方法中,我们包装每个运行时值以将其与类型变量相关联,并且当使用包装的值时,包装器将对此类型变量生成约束。由于根据实际程序运行期间如何使用值来生成约束,因此该技术避免了许多通常过于保守的静态工具近似值。使用包装器也很容易实现,因为我们只需要编写一个约束解析算法和一个转换来引入包装器。最好的部分是我们也可以吃蛋糕:只要算法观察到通过每个方法主体的每条路径,我们的算法就会推断出声音类型,请注意,此类路径的数量可能比通过程序的路径的数量少得多作为一个整体。我们已经开发了Rubydust。我们针对Ruby的算法的实现。 Rubydust利用Ruby的动态功能将包装器实现为语言库。我们将Rubydust应用于许多小型程序,发现它既易于使用又有用:Rubydust发现1个实类型错误,所有其他推断的类型都是正确且可读的。

著录项

相似文献

  • 外文文献
  • 中文文献
  • 专利
获取原文

客服邮箱:kefu@zhangqiaokeyan.com

京公网安备:11010802029741号 ICP备案号:京ICP备15016152号-6 六维联合信息科技 (北京) 有限公司©版权所有
  • 客服微信

  • 服务号