Type-Level Computations for Ruby Libraries

04/06/2019
by   Milod Kazerounian, et al.
0

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.

READ FULL TEXT

page 1

page 2

page 3

page 4

research
01/28/2022

Large Scale Generation of Labeled Type Data for Python

Recently, dynamically typed languages, such as Python, have gained unpre...
research
05/18/2017

Exploiting Term Hiding to Reduce Run-time Checking Overhead

One of the most attractive features of untyped languages is the flexibil...
research
02/24/2023

Set-theoretic Types for Erlang

Erlang is a functional programming language with dynamic typing. The lan...
research
11/19/2021

Types for Tables: A Language Design Benchmark

Context: Tables are ubiquitous formats for data. Therefore, techniques f...
research
02/18/2019

A Dependently Typed Library for Static Information-Flow Control in Idris

Safely integrating third-party code in applications while protecting the...
research
11/02/2021

Do Names Echo Semantics? A Large-Scale Study of Identifiers Used in C++'s Named Casts

Developers relax restrictions on a type to reuse methods with other type...
research
03/16/2021

DDUO: General-Purpose Dynamic Analysis for Differential Privacy

Differential privacy enables general statistical analysis of data with f...

Please sign up or login with your details

Forgot password? Click here to reset