Preview

Proceedings of the Institute for System Programming of the RAS (Proceedings of ISP RAS)

Advanced search

Automated Type Contracts Generation in Ruby

https://doi.org/10.15514/ISPRAS-2017-29(4)-1

Abstract

Elegant syntax of the Ruby language pays back when it comes to finding bugs in large codebases. Static analysis is hindered by specific capabilities of Ruby, such as defining methods dynamically and evaluating string expressions. Even in dynamically typed languages, type information is very useful as it ensures better type safety and more reliable checking whether the called method is defined for the object or whether the arguments of the correct types are passed to it. One may annotate the code with YARD (Ruby documentation tool) to declare the input and output types of methods or even declare methods that are added dynamically. These annotations improve the capabilities of tooling such as code completion. This paper reports a new approach to type annotations generation. We trace direct method calls while the program is running, evaluate types of input and output variables and use this information to derive implicit type contracts. Each method or function is associated with a finite-state automaton consisting of all variants of typed signatures for this method. An effective compression technique is applied to the automaton to reduce the cost of storage and allows to display the collected information in a human-readable form. The exhaustiveness of the contract defined by the generated automaton depends on the diversity of the traced method usages. Therefore, it is also important to be able to merge all the automatons received from users into one, which is further covered in this paper.

About the Authors

N. Y. Viuginov
St. Petersburg State University; JetBrains
Russian Federation


V. S. Fondaratov
JetBrains
Russian Federation


References

1. Brianna M. Ren., J. Toman, T. Stephen Strickland and Jeffrey S. Foster. The ruby type

2. checker. Available: http://www.cs.umd.edu/~jfoster/papers/oops13.pdf

3. blog.codeclimate. Gradual type checking for ruby, 2014. [Online]. Available:

4. blog.codeclimate.com/blog/2014/05/06/gradual-type-checking-for-ruby/

5. O. Shivers. Control flow analysis in scheme. ACM SIGPLAN 1988 conference on

6. Programming language design and implementation, 1988.

7. Bozhidar Batsov. Rubocop, 2017. [Online]. Available: http://batsov.com/rubocop/

8. Jeff Foster, Mike Hicks, Mike Furr, David An. Diamond-back ruby guide, 2009.[Online].

9. Available: http://www.cs.umd.edu/projects/PL/druby/manual/manual.pdf

10. Pat Shaughnessy. Ruby Under a Microscope. No Starch Press, 2013.

11. Madsen M. Static Analysis of Dynamic Languages. Available:

12. http://pure.au.dk/ws/files/85299449/Thesis.pdf

13. Duck Typing [Online]. Available: http://rubylearning.com/satishtalim/duck_typing.html


Review

For citations:


Viuginov N.Y., Fondaratov V.S. Automated Type Contracts Generation in Ruby. Proceedings of the Institute for System Programming of the RAS (Proceedings of ISP RAS). 2017;29(4):7-20. https://doi.org/10.15514/ISPRAS-2017-29(4)-1



Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 License.


ISSN 2079-8156 (Print)
ISSN 2220-6426 (Online)