Flow-sensitive typing: Difference between revisions

Content deleted Content added
Tags: Mobile edit Mobile web edit Advanced mobile edit
Implementations: Reference an early form of this idea in a 1966 work of Hoare, and make explicit Tobin-Hochstadt's name for stylistic consistency within the section.
 
(5 intermediate revisions by 2 users not shown)
Line 74:
|quote=I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language ([[ALGOL W]]). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.}}</ref>
 
From a Programming Languages perspective, it's reasonable to say that flow-sensitive typing is the feature that finally made it possible to build usable type-safe programming languages with union types and without rampant dynamic checking. Until this point, attempts to add this feature to languages such as Scheme generally resulted in intractably large type representations. One example of a system with limited support for union types is Wright and Cartwright's "Soft Scheme."<ref>{{cite journal |last1=Wright |first1=Andrew |last2=Cartwright |first2=Robert |title=A practical soft type system for scheme |journal=ACM Transactions on Programming Languages and Systems |date=1 Jan 1997 |volume=19 |issue=1 |pages=87--152 |doi=10.1145/239912.239917 |url=https://dl.acm.org/doi/abs/10.1145/239912.239917 |access-date=2024-05-04}}</ref>
==Implementations==
 
==History and Implementations==
Typed Scheme, a type system for [[Scheme (programming language)|Scheme]], was the first type system with this feature.<ref>{{cite web |title=The Design and Implementation of Typed Scheme {{!}} Lambda the Ultimate, 2008 |url=http://lambda-the-ultimate.org/node/2622 |website=lambda-the-ultimate.org}}</ref> Its successor, Typed Racket (a dialect of [[Racket (programming language)|Racket]]), still makes extensive use of occurrence typing.<ref>{{cite web |title=5 Occurrence Typing |url=https://docs.racket-lang.org/ts-guide/occurrence-typing.html |website=docs.racket-lang.org}}</ref> Shortly after Typed Scheme, David J. Pearce independently reinvented flow-typing in [[Whiley (programming language)|Whiley]].<ref>{{cite web | url=http://whiley.org/2010/09/22/on-flow-sensitive-types-in-whiley/ | title=On Flow-Sensitive Types in Whiley | publisher=whiley.org | date=22 September 2010 | access-date=11 March 2016 | author=David J. Pearce}}</ref><ref>{{cite web | url=http://whiley.org/guide/typing/flow-typing/ | title=Whiley - Flow Typing | publisher=whiley.org | date=8 April 2012 | access-date=11 March 2016 | author=David J. Pearce}}</ref>
 
The history of the idea goes back at least to [[Tony Hoare]]'s "record class discriminators" from the mid-1960s.<ref>{{cite conference |last=Hoare |first=C. A. R. |date=September 12–16, 1966 |title=Record Handling |url=https://archive.computerhistory.org/resources/text/Knuth_Don_X4100/PDF_index/k-9-pdf/k-9-u2293-Record-Handling-Hoare.pdf |conference=NATO Summer School |___location=Villard-de-Lans |access-date=2025-08-16 |quote-page=18, section 3.4 |quote=The result of using a construction of this form is that whichever of the alternative sections of program is selected at run time, the translator knows at compile time which subclass of record is actually referenced by the variable e at the time when execution of that section of program is initiated. Thus within each of the sections of program, the variable e may safely be used in field designators for private fields of the relevant subclass, exactly as if it had been restricted by declaration to point only to records of that subclass.}}</ref> However, practical type systems including it as a feature are much more recent.
 
Typed Scheme, a type system for [[Scheme (programming language)|Scheme]] developed by Sam Tobin-Hochstadt and first published in 2008, was the first type system withto thisinclude featureoccurrence typing.<ref>{{cite web |title=The Design and Implementation of Typed Scheme {{!}} Lambda the UltimatePOPL, 2008 |url=httphttps://lambda-the-ultimatedl.acm.org/nodedoi/262210.1145/1328438.1328486 |website=lambda-the-ultimatedl.acm.org}}</ref> Its successor, Typed Racket (a dialect of [[Racket (programming language)|Racket]]), stillis makesalso extensivebased use ofon occurrence typing.<ref>{{cite web |title=5 Occurrence Typing |url=https://docs.racket-lang.org/ts-guide/occurrence-typing.html |website=docs.racket-lang.org}}</ref> Shortly after Typed Scheme, David J. Pearce independently reinvented flow-typing in [[Whiley (programming language)|Whiley]].<ref>{{cite web | url=http://whiley.org/2010/09/22/on-flow-sensitive-types-in-whiley/ | title=On Flow-Sensitive Types in Whiley | publisher=whiley.org | date=22 September 2010 | access-date=11 March 2016 | author=David J. Pearce | archive-date=11 March 2016 | archive-url=https://web.archive.org/web/20160311184700/http://whiley.org/2010/09/22/on-flow-sensitive-types-in-whiley/ | url-status=dead }}</ref><ref>{{cite web | url=http://whiley.org/guide/typing/flow-typing/ | title=Whiley - Flow Typing | publisher=whiley.org | date=8 April 2012 | access-date=11 March 2016 | author=David J. Pearce | archive-date=11 March 2016 | archive-url=https://web.archive.org/web/20160311184703/http://whiley.org/guide/typing/flow-typing/ | url-status=dead }}</ref>
 
Typed JavaScript observed that in "scripting" languages, flow-typing depends on more than conditional predicates; it also depends on state and control flow.<ref>{{cite web | url=https://cs.brown.edu/~sk/Publications/Papers/Published/gsk-flow-typing-theory/ | title=Typing Local Control and State Using Flow Analysis | access-date=14 November 2016}}</ref> This style has since been adopted in languages like [[Ceylon (programming language)|Ceylon]],<ref>{{cite web | url=http://ceylon-lang.org/documentation/1.2/introduction/#typesafe_null_and_flow_sensitive_typing | title=Ceylon - Quick introduction - Typesafe null and flow-sensitive typing | publisher=ceylon-lang.org | access-date=11 March 2016}}</ref> [[TypeScript]]<ref>{{cite web |url=https://blogs.msdn.microsoft.com/typescript/2014/11/18/typescript-1-4-sneak-peek-union-types-type-guards-and-more | title=TypeScript 1.4 sneak peek: union types, type guards, and more | publisher=blogs.msdn.microsoft.com | date=18 November 2014 | access-date=11 March 2016 | author=Ryan Cavanaugh}}</ref> and [[Facebook]] Flow.<ref>{{cite web | url=https://code.facebook.com/posts/1505962329687926/flow-a-new-static-type-checker-for-javascript | title=Flow, a new static type checker for JavaScript | publisher=code.facebook.com | date=18 November 2014 | access-date=11 March 2016 |author=Avik Chaudhuri |author2=Basil Hosmer |author3=Gabriel Levi}}</ref>