【24h】

Profile-Guided Static Typing for Dynamic Scripting Languages

机译:动态脚本语言的配置文件引导的静态键入

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

摘要

Many popular scripting languages such as Ruby, Python, and Perl include highly dynamic language constructs, such as an e v a l method that evaluates a string as program text. While these constructs allow terse and expressive code, they have traditionally obstructed static analysis. In this paper we present P Ruby, an extension to Diamondback Ruby (DRuby), a static type inference system for Ruby. P Ruby augments DRuby with a novel dynamic analysis and transformation that allows us to precisely type uses of highly dynamic constructs. P Ruby's analysis proceeds in three steps. First, we use run-time instrumentation to gather per-application profiles of dynamic feature usage. Next, we replace dynamic features with statically analyzable alternatives based on the profile. We also add instrumentation to safely handle cases when subsequent runs do not match the profile. Finally, we run DRuby's static type inference on the transformed code to enforce type safety. We used P Ruby to gather profiles for a benchmark suite of sample Ruby programs. We found that dynamic features are pervasive throughout the benchmarks and the libraries they include, but that most uses of these features are highly constrained and hence can be effectively profiled. Using the profiles to guide type inference, we found that DRuby can generally statically type our benchmarks modulo some refactoring, and we discovered several previously unknown type errors. These results suggest that profiling and transformation is a lightweight but highly effective approach to bring static typing to highly dynamic languages.
机译:许多流行的脚本语言(例如Ruby,Python和Perl)都包含高度动态的语言构造,例如将字符串评估为程序文本的e v l方法。虽然这些结构允许简洁和表达力强的代码,但传统上它们阻碍了静态分析。在本文中,我们介绍了P Ruby,它是对Diamondback Ruby(DRuby)(Ruby的静态类型推断系统)的扩展。 P Ruby通过新颖的动态分析和转换增强了DRuby,该动态分析和转换使我们能够精确键入高度动态构造的用法。 P Ruby的分析分为三个步骤。首先,我们使用运行时检测来收集动态功能使用情况的每个应用程序配置文件。接下来,我们根据配置文件将动态特征替换为可静态分析的替代方案。当后续运行与配置文件不匹配时,我们还会添加检测工具以安全地处理案例。最后,我们在转换后的代码上运行DRuby的静态类型推断以增强类型安全性。我们使用P Ruby收集了示例Ruby程序的基准测试套件的配置文件。我们发现动态特性在基准测试及其所包含的库中无处不在,但是这些特性的大多数使用受到高度限制,因此可以有效地进行配置。使用配置文件来指导类型推断,我们发现DRuby通常可以以某种重构的方式静态地对基准进行类型化,并且发现了一些以前未知的类型错误。这些结果表明,概要分析和转换是将静态类型引入高度动态语言的一种轻量级但非常有效的方法。

著录项

相似文献

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

客服邮箱:kefu@zhangqiaokeyan.com

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

  • 服务号