Many researchers have explored ways to bring static typing to dynamic languages. However, to date, such systems are not precise enough when types depend on values, which often arises when using certain Ruby libraries. For example, the type safety of a database query in Ruby on Rails depends on the table and column names used in the query. To address this issue, we introduce CompRDL, a type system for Ruby that allows library method type signatures to include type-level computations (or comp types for short). Combined with singleton types for table and column names, comp types let us give database query methods type signatures that compute a table's schema to yield very precise type information. Comp types for hash, array, and string libraries can also increase precision and thereby reduce the need for type casts. We formalize CompRDL and prove its type system sound. Rather than type check the bodies of library methods with comp types---those methods may include native code or be complex---CompRDL inserts run-time checks to ensure library methods abide by their computed types. We evaluated CompRDL by writing annotations with type-level computations for several Ruby core libraries and database query APIs. We then used those annotations to type check two popular Ruby libraries and four Ruby on Rails web apps. We found the annotations were relatively compact and could successfully type check 132 methods across our subject programs. Moreover, the use of type-level computations allowed us to check more expressive properties, with fewer manually inserted casts, than was possible without type-level computations. In the process, we found two type errors and a documentation error that were confirmed by the developers. Thus, we believe CompRDL is an important step forward in bringing precise static type checking to dynamic languages.
翻译:许多研究人员探索了将静态打字引入动态语言的方法。然而,到目前为止,当类型取决于值时,这种系统不够精确,因为类型取决于值,而值通常在使用某些Ruby 图书馆时往往会出现。例如,铁路Ruby 数据库查询的类型安全取决于查询中使用的表格和列名名称。为了解决这个问题,我们为Ruby 引入了CompRDL 类型系统,允许图书馆方法类型签名包括类型级计算(或简称的计算类型)。与表格和列名的单吨类型相结合,复合类型让我们提供数据库查询方法类型签名,用以计算表格的系统,以生成非常精确的类型信息。仓、阵列和字符串库的计算文档类型也能够提高精确性格,从而减少对类型文件的需要。我们正式化了CompRBL 并证明了其类型系统健全。我们不用键盘来检查图书馆机构的方法,包括本地代码或复杂(简称简称为缩略略) 插入运行时间检查,以确保其计算型号得到遵守。我们后来通过不使用格式的 RComdrevL,我们后来通过不使用类型进行类型进行格式的版本的计算,我们后来用类型来进行格式计算,我们用格式的 RComdrevdL 和格式的版本的版本来进行计算。我们用两个类型来进行格式计算,然后以打印的版本的计算。我们用类型来进行格式计算,我们用来的计算,我们用格式的版本的 Restrencerencerencerenceal 。我们用两个的版本的版本的版本的版本的 Restrence 。我们用的是,这些版本的版本的版本的版本的版本来为我们的版本的版本的版本的版本的版本的版本的版本的计算,我们用的是,我们用的是,我们用的是,我们用来的版本的版本的版本的 Restdrodrodrodrodrodrodrodrodrodro 。我们用的版本的计算,我们用的是,我们用的是,我们用的是,我们用的是,我们用的是,我们用的是,我们用两个realbalbalbrobalbal 。