practical, pluggable types
DESCRIPTION
Most languages fall into one of two camps: either they adopt a unique, static type system, or they abandon static type-checks for run-time checks. Pluggable types blur this division by (i) making static type systems optional, and (ii) supporting a choice of type systems for reasoning about different kinds of static properties. Dynamic languages can then benefit from static-checking without sacrificing dynamic features or committing to a unique, static type system. But the overhead of adopting pluggable types can be very high, especially if all existing code must be decorated with type annotations before any type-checking can be performed. We propose a practical and pragmatic approach to introduce pluggable type systems to dynamic languages. First of all, only annotated code is type-checked. Second, limited type inference is performed on unannotated code to reduce the number of reported errors. Finally, external annotations can be used to type third-party code. We present Typeplug, a Smalltalk implementation of our framework, and report on experience applying the framework to three different pluggable type systems.TRANSCRIPT
![Page 1: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/1.jpg)
© Marcus Denker
TypePlug -- Practical, Pluggable Types
Nik HaldimanMarcus DenkerOscar Nierstrasz
University of Bern
![Page 2: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/2.jpg)
Types?
![Page 3: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/3.jpg)
© Marcus Denker
Static typing is Good!
> Programs with failures are rejected— Reduces errors detected at runtime
> Documentation
> Minor inconvenience, major payoff
![Page 4: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/4.jpg)
© Marcus Denker
Static typing is Evil!
> Exactly all cool programs are rejected— Reflection?!
> Inconvenience is not at all “minor”— Typed programs hard to change + evolve
> Only the most trivial errors are detected— False sense of security
![Page 5: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/5.jpg)
![Page 6: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/6.jpg)
Is it possible to have one’s cake and eat it, too?
![Page 7: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/7.jpg)
© Marcus Denker
Pluggable Types
> Optional: does not change the semantics
> Pluggable: many different ones— Especially exotic type-systems
> “Type-Systems as Tools”Gilad Bracha, OOPSLA 04: Pluggable Type-Systems
![Page 8: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/8.jpg)
© Marcus Denker
The Problem
> Large, untyped code-base
> Overhead for using pluggable types is high
— Existing code needs to be annotated with type information
![Page 9: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/9.jpg)
© Marcus Denker
TypePlug
> Pluggable types for Squeak
> Based on sub-method reflection framework (Demo on Wednesday!)
> Case-Studies:— Non-Nil Types — Class Based Types — Confined Types
![Page 10: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/10.jpg)
© Marcus Denker
Non-Nil Type-System
> Declare variables to never be nil
Object subclass: #Line typedInstanceVariables: ’startPoint endPoint <:nonNil:>’ typedClassVariables: ’’ poolDictionaries: '' category: 'Demo' DEMO
![Page 11: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/11.jpg)
© Marcus Denker
Non-Nil Type-System
moveHorizontally: anInteger
startPoint := self movePoint: startPoint horizontally: anInteger.
endPoint:=self movePoint: endPoint horizontally: anInteger
![Page 12: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/12.jpg)
© Marcus Denker
Non-Nil Type-System
moveHorizontally: anInteger
startPoint := self movePoint: startPoint horizontally: anInteger.
endPoint:=self movePoint: endPoint horizontally: anInteger <- type ’TopType’ of expression is not compatible with type ’nonNil’ of variable ’endPoint’.
![Page 13: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/13.jpg)
© Marcus Denker
Non-Nil Type-System
movePoint: aPoint horizontally: anInteger
↑ (aPoint addX: anInteger y: 0) <:nonNil :>
![Page 14: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/14.jpg)
© Marcus Denker
The Problem (again)
> Large, untyped code-base
> Overhead for using pluggable types is high
— Existing code needs to be annotated with type information
![Page 15: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/15.jpg)
© Marcus Denker
Solution
> Only type-check annotated code
> Use type-inference to infer types of non-annotated code
> Explicit type-casts
> Allow external annotations for foreign code
![Page 16: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/16.jpg)
© Marcus Denker
External Type Annotations
> We need to annotate existing code— Especially libraries and frameworks— Example: Object>>#hash is <: nonNil :>
> We do not want to change the program code!
> Solution: External Type Annotations— Added and modified in the TypesBrowser— Do not change the source— External representation: Type Packages
![Page 17: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/17.jpg)
© Marcus Denker
Browser
![Page 18: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/18.jpg)
© Marcus Denker
Future Work
> Improve Type-Inference— Better algorithms— Explore heuristical type inference (Roeltyper)
> Type Checking and Reflection— Use pluggable types to check reflective change
![Page 19: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/19.jpg)
© Marcus Denker
Conclusion
> TypePlug: Pragmatic framework for Pluggable Types
— Only type-check annotated code— Use type-inference— Explicit type-casts— External annotations for foreign code
![Page 20: Practical, Pluggable Types](https://reader033.vdocuments.us/reader033/viewer/2022052619/5554f7d7b4c90566278b54ee/html5/thumbnails/20.jpg)
© Marcus Denker
Conclusion
> TypePlug: Pragmatic framework for Pluggable Types
— Only type-check annotated code— Use type-inference— Explicit type-casts— External annotations for foreign code
Questions?