Type Inference in PHP using Deep Learning

Samuel Klingström, Pontus Olsson · Lund University Publications Student Papers (Lund University) · 2020

Dynamically typed programming languages such as PHP, JavaScript and Python have recently started supporting gradual typing, where type annotations can be added to part of the code.Tools that can perform type inference are therefore becoming increasingly helpful as they could ease the labor intensive task of updating legacy code for developers.However, for PHP, most static code analysis tools have lacking or unsatisfactory type inference functionality.In this thesis, we use deep learning to predict type annotations for parameters in PHP.The neural network can, given a function or method, predict the type annotations for the parameters based on their usage.The predictions are then presented in the code comment.This approach builds upon the previous work, code vec, and is based on the idea of representing code as paths in its abstract syntax tree.After training the model with the , most popular PHP repositories from Github, it was able to correctly predict type annotations with a top-accuracy of 76.2 % and a top-accuracy of 84.2 %.These results are better than the current code analysis tool we tested for PHP.We conclude that deep learning can successfully be used for type inference in PHP with great results.

Read the paper · More papers on PaperTik