runtime; program can fail because of type errors •even obvious errors are only detected at runtime, extensive testing is needed •duck typing / monkey patching statically typed languages dynamic languages •a program needs to be type-correct before it can be executed •little changes might create bigger inconsistency in the entire project •dynamic languages allow easy prototyping and testing without the need for overall consistency •type errors are deferred to runtime => static feedback is useful in big projects which should be stable => dynamic typing is good for fast prototyping •type checking is done at compile time •a program is proved to be correct using the constraints encoded by types •no type errors at runtime (exceptions: e.g. casting...) •compiler can do many optimizations •fast runtime 4
plugin which allows fast prototyping with Scala by deferring type errors to runtime • it doesn’t change the behavior of correctly typed programs • there is no overhead during execution ✤ the plugin can be used during early development phases for fast prototyping and testing • no need to refactor the entire code while doing multiple iterations • releases need to be type correct, work in progress doesn’t, thus can use the plugin 9
prototyping in Scala e.g. adding or removing fields, methods or classes ✤ makes it possible to focus only on one execution path in a program ✤ showing how the abstract syntax tree and symbol table consistency can be restored after encountering errors ✤ implementing the theory in a compiler plugin of less than 200 lines of code 10
2 resolve names, attach symbols to named trees packageobjects 3 load package objects typer 4 typing the AST dyno - ScalaDyno Plugin patmat 5 translate match expressions superaccessors 6 add super accessors in traits and nested classes extmethods 7 add extension methods for inline classes pickler 8 serialize symbol tables where the transformation happens 12
any kind the compilation process would be aborted ✤ during initialization, the reporter gets replaced with our own personalized reporter which suppresses some errors ✤ only errors from the typer and namer phase gets suppressed ✤ they get replaced with an warning which caries the same information ✤ in addition the error message gets recorder to be used later on Tricking the compiler 14
need to modify the AST such that it does no longer contain erroneously typed branches ✤ we replace the branches with error types with Exception statements which contain the corresponding error message ✤ we do not alter the AST if no error is present 15
and give special treatments to some AST branches ✤ We recursively run over the AST and look for erroneous branches ✤ Exceptions cannot be thrown any where in the code (e.g. pattern matching) ✤ we “bubble up” the error to a position where it is safe to throw the exception 16
the type Nothing which is the subtype of any other type ✤ Exception have type ErrorType and can thus be injected on any branch of the AST without breaking type correctness ✤ We can also remove erroneous symbols from the symbol table as they can only lead to spurious error messages 17
access: ➡ Scala-Virtualized: check if the scope contains the definition inflix_methodName(inst, args) ➡ look in the class of the instance as well as in the parents from the inheritance structure ➡ check for an implicit conversion ➡ Dynamic trait: check if the type is Dynamic and use inst.applyDynamic(“name”) 23
https://github.com/scaladyno/scaladyno-plugin big thanks to my supervisor Vlad Ureche who took time for our weekly meetings and giving me always good advice and help with the implementation 28