Safe & Efficient Gradual Typing for TypeScript

Current proposals for adding gradual typing to JavaScript, such as Closure, TypeScript and Dart, forgo soundness to deal with issues of scale, code reuse, and popular programming patterns. We show how to address these issues in practice while retaining soundness. We design and implement a new gradua...

Ausführliche Beschreibung

Gespeichert in:
Bibliographische Detailangaben
Veröffentlicht in:SIGPLAN notices 2015-05, Vol.50 (1), p.167-180
Hauptverfasser: Rastogi, Aseem, Swamy, Nikhil, Fournet, Cédric, Bierman, Gavin, Vekris, Panagiotis
Format: Artikel
Sprache:eng
Schlagworte:
Online-Zugang:Volltext
Tags: Tag hinzufügen
Keine Tags, Fügen Sie den ersten Tag hinzu!
container_end_page 180
container_issue 1
container_start_page 167
container_title SIGPLAN notices
container_volume 50
creator Rastogi, Aseem
Swamy, Nikhil
Fournet, Cédric
Bierman, Gavin
Vekris, Panagiotis
description Current proposals for adding gradual typing to JavaScript, such as Closure, TypeScript and Dart, forgo soundness to deal with issues of scale, code reuse, and popular programming patterns. We show how to address these issues in practice while retaining soundness. We design and implement a new gradual type system, prototyped for expediency as a 'Safe' compilation mode for TypeScript. Our compiler achieves soundness by enforcing stricter static checks and embedding residual runtime checks in compiled code. It emits plain JavaScript that runs on stock virtual machines. Our main theorem is a simulation that ensures that the checks introduced by Safe TypeScript (1) catch any dynamic type error, and (2) do not alter the semantics of type-safe TypeScript code. Safe TypeScript is carefully designed to minimize the performance overhead of runtime checks. At its core, we rely on two new ideas: differential subtyping, a new form of coercive subtyping that computes the minimum amount of runtime type information that must be added to each object; and an erasure modality, which we use to safely and selectively erase type information. This allows us to scale our design to full-fledged TypeScript, including arrays, maps, classes, inheritance, overloading, and generic types. We validate the usability and performance of Safe TypeScript empirically by type-checking and compiling around 120,000 lines of existing TypeScript source code. Although runtime checks can be expensive, the end-to-end overhead is small for code bases that already have type annotations. For instance, we bootstrap the Safe TypeScript compiler (90,000 lines including the base TypeScript compiler): we measure a 15% runtime overhead for type safety, and also uncover programming errors as type safety violations. We conclude that, at least during development and testing, subjecting JavaScript/TypeScript programs to safe gradual typing adds significant value to source type annotations at a modest cost.
doi_str_mv 10.1145/2775051.2676971
format Article
fullrecord <record><control><sourceid>acm_cross</sourceid><recordid>TN_cdi_crossref_primary_10_1145_2775051_2676971</recordid><sourceformat>XML</sourceformat><sourcesystem>PC</sourcesystem><sourcerecordid>2676971</sourcerecordid><originalsourceid>FETCH-LOGICAL-a190t-a45bc2cb7fb566650e2acf97bb37fba909d283a88e13e172b7d51cb0e86057583</originalsourceid><addsrcrecordid>eNo9jz1PwzAQhi0EEqEwIzFlYkt6Z-dsZ0RVKUiVGFrm6OzYKKgfkROG_ntatTDd6d73OekR4hGhRKxoKo0hICylNro2eCUyJLIFooZrkYHSskBVwa24G4ZvAFAgbSbKFceQP-fzGDvfhd2YLxK3P7zJ14e-233lcZ9Oa1j51PXjvbiJvBnCw2VOxOfrfD17K5Yfi_fZy7JgrGEsuCLnpXcmOtJaEwTJPtbGOXU8cQ11K61iawOqgEY60xJ6B8FqIENWTcT0_Nen_TCkEJs-dVtOhwahOek2F93monskns4E--1_-S_8BbMdTmA</addsrcrecordid><sourcetype>Aggregation Database</sourcetype><iscdi>true</iscdi><recordtype>article</recordtype></control><display><type>article</type><title>Safe &amp; Efficient Gradual Typing for TypeScript</title><source>ACM Digital Library</source><creator>Rastogi, Aseem ; Swamy, Nikhil ; Fournet, Cédric ; Bierman, Gavin ; Vekris, Panagiotis</creator><creatorcontrib>Rastogi, Aseem ; Swamy, Nikhil ; Fournet, Cédric ; Bierman, Gavin ; Vekris, Panagiotis</creatorcontrib><description>Current proposals for adding gradual typing to JavaScript, such as Closure, TypeScript and Dart, forgo soundness to deal with issues of scale, code reuse, and popular programming patterns. We show how to address these issues in practice while retaining soundness. We design and implement a new gradual type system, prototyped for expediency as a 'Safe' compilation mode for TypeScript. Our compiler achieves soundness by enforcing stricter static checks and embedding residual runtime checks in compiled code. It emits plain JavaScript that runs on stock virtual machines. Our main theorem is a simulation that ensures that the checks introduced by Safe TypeScript (1) catch any dynamic type error, and (2) do not alter the semantics of type-safe TypeScript code. Safe TypeScript is carefully designed to minimize the performance overhead of runtime checks. At its core, we rely on two new ideas: differential subtyping, a new form of coercive subtyping that computes the minimum amount of runtime type information that must be added to each object; and an erasure modality, which we use to safely and selectively erase type information. This allows us to scale our design to full-fledged TypeScript, including arrays, maps, classes, inheritance, overloading, and generic types. We validate the usability and performance of Safe TypeScript empirically by type-checking and compiling around 120,000 lines of existing TypeScript source code. Although runtime checks can be expensive, the end-to-end overhead is small for code bases that already have type annotations. For instance, we bootstrap the Safe TypeScript compiler (90,000 lines including the base TypeScript compiler): we measure a 15% runtime overhead for type safety, and also uncover programming errors as type safety violations. We conclude that, at least during development and testing, subjecting JavaScript/TypeScript programs to safe gradual typing adds significant value to source type annotations at a modest cost.</description><identifier>ISSN: 0362-1340</identifier><identifier>EISSN: 1558-1160</identifier><identifier>DOI: 10.1145/2775051.2676971</identifier><language>eng</language><publisher>New York, NY, USA: ACM</publisher><subject>Classes and objects ; Formal language definitions ; General programming languages ; Inheritance ; Language features ; Polymorphism ; Program semantics ; Semantics ; Semantics and reasoning ; Software and its engineering ; Software notations and tools ; Theory of computation</subject><ispartof>SIGPLAN notices, 2015-05, Vol.50 (1), p.167-180</ispartof><rights>ACM</rights><woscitedreferencessubscribed>false</woscitedreferencessubscribed><citedby>FETCH-LOGICAL-a190t-a45bc2cb7fb566650e2acf97bb37fba909d283a88e13e172b7d51cb0e86057583</citedby><cites>FETCH-LOGICAL-a190t-a45bc2cb7fb566650e2acf97bb37fba909d283a88e13e172b7d51cb0e86057583</cites></display><links><openurl>$$Topenurl_article</openurl><openurlfulltext>$$Topenurlfull_article</openurlfulltext><thumbnail>$$Tsyndetics_thumb_exl</thumbnail><linktopdf>$$Uhttps://dl.acm.org/doi/pdf/10.1145/2775051.2676971$$EPDF$$P50$$Gacm$$H</linktopdf><link.rule.ids>314,780,784,2282,27924,27925,40196,76100</link.rule.ids></links><search><creatorcontrib>Rastogi, Aseem</creatorcontrib><creatorcontrib>Swamy, Nikhil</creatorcontrib><creatorcontrib>Fournet, Cédric</creatorcontrib><creatorcontrib>Bierman, Gavin</creatorcontrib><creatorcontrib>Vekris, Panagiotis</creatorcontrib><title>Safe &amp; Efficient Gradual Typing for TypeScript</title><title>SIGPLAN notices</title><addtitle>ACM SIGPLAN</addtitle><description>Current proposals for adding gradual typing to JavaScript, such as Closure, TypeScript and Dart, forgo soundness to deal with issues of scale, code reuse, and popular programming patterns. We show how to address these issues in practice while retaining soundness. We design and implement a new gradual type system, prototyped for expediency as a 'Safe' compilation mode for TypeScript. Our compiler achieves soundness by enforcing stricter static checks and embedding residual runtime checks in compiled code. It emits plain JavaScript that runs on stock virtual machines. Our main theorem is a simulation that ensures that the checks introduced by Safe TypeScript (1) catch any dynamic type error, and (2) do not alter the semantics of type-safe TypeScript code. Safe TypeScript is carefully designed to minimize the performance overhead of runtime checks. At its core, we rely on two new ideas: differential subtyping, a new form of coercive subtyping that computes the minimum amount of runtime type information that must be added to each object; and an erasure modality, which we use to safely and selectively erase type information. This allows us to scale our design to full-fledged TypeScript, including arrays, maps, classes, inheritance, overloading, and generic types. We validate the usability and performance of Safe TypeScript empirically by type-checking and compiling around 120,000 lines of existing TypeScript source code. Although runtime checks can be expensive, the end-to-end overhead is small for code bases that already have type annotations. For instance, we bootstrap the Safe TypeScript compiler (90,000 lines including the base TypeScript compiler): we measure a 15% runtime overhead for type safety, and also uncover programming errors as type safety violations. We conclude that, at least during development and testing, subjecting JavaScript/TypeScript programs to safe gradual typing adds significant value to source type annotations at a modest cost.</description><subject>Classes and objects</subject><subject>Formal language definitions</subject><subject>General programming languages</subject><subject>Inheritance</subject><subject>Language features</subject><subject>Polymorphism</subject><subject>Program semantics</subject><subject>Semantics</subject><subject>Semantics and reasoning</subject><subject>Software and its engineering</subject><subject>Software notations and tools</subject><subject>Theory of computation</subject><issn>0362-1340</issn><issn>1558-1160</issn><fulltext>true</fulltext><rsrctype>article</rsrctype><creationdate>2015</creationdate><recordtype>article</recordtype><recordid>eNo9jz1PwzAQhi0EEqEwIzFlYkt6Z-dsZ0RVKUiVGFrm6OzYKKgfkROG_ntatTDd6d73OekR4hGhRKxoKo0hICylNro2eCUyJLIFooZrkYHSskBVwa24G4ZvAFAgbSbKFceQP-fzGDvfhd2YLxK3P7zJ14e-233lcZ9Oa1j51PXjvbiJvBnCw2VOxOfrfD17K5Yfi_fZy7JgrGEsuCLnpXcmOtJaEwTJPtbGOXU8cQ11K61iawOqgEY60xJ6B8FqIENWTcT0_Nen_TCkEJs-dVtOhwahOek2F93monskns4E--1_-S_8BbMdTmA</recordid><startdate>20150511</startdate><enddate>20150511</enddate><creator>Rastogi, Aseem</creator><creator>Swamy, Nikhil</creator><creator>Fournet, Cédric</creator><creator>Bierman, Gavin</creator><creator>Vekris, Panagiotis</creator><general>ACM</general><scope>AAYXX</scope><scope>CITATION</scope></search><sort><creationdate>20150511</creationdate><title>Safe &amp; Efficient Gradual Typing for TypeScript</title><author>Rastogi, Aseem ; Swamy, Nikhil ; Fournet, Cédric ; Bierman, Gavin ; Vekris, Panagiotis</author></sort><facets><frbrtype>5</frbrtype><frbrgroupid>cdi_FETCH-LOGICAL-a190t-a45bc2cb7fb566650e2acf97bb37fba909d283a88e13e172b7d51cb0e86057583</frbrgroupid><rsrctype>articles</rsrctype><prefilter>articles</prefilter><language>eng</language><creationdate>2015</creationdate><topic>Classes and objects</topic><topic>Formal language definitions</topic><topic>General programming languages</topic><topic>Inheritance</topic><topic>Language features</topic><topic>Polymorphism</topic><topic>Program semantics</topic><topic>Semantics</topic><topic>Semantics and reasoning</topic><topic>Software and its engineering</topic><topic>Software notations and tools</topic><topic>Theory of computation</topic><toplevel>online_resources</toplevel><creatorcontrib>Rastogi, Aseem</creatorcontrib><creatorcontrib>Swamy, Nikhil</creatorcontrib><creatorcontrib>Fournet, Cédric</creatorcontrib><creatorcontrib>Bierman, Gavin</creatorcontrib><creatorcontrib>Vekris, Panagiotis</creatorcontrib><collection>CrossRef</collection><jtitle>SIGPLAN notices</jtitle></facets><delivery><delcategory>Remote Search Resource</delcategory><fulltext>fulltext</fulltext></delivery><addata><au>Rastogi, Aseem</au><au>Swamy, Nikhil</au><au>Fournet, Cédric</au><au>Bierman, Gavin</au><au>Vekris, Panagiotis</au><format>journal</format><genre>article</genre><ristype>JOUR</ristype><atitle>Safe &amp; Efficient Gradual Typing for TypeScript</atitle><jtitle>SIGPLAN notices</jtitle><stitle>ACM SIGPLAN</stitle><date>2015-05-11</date><risdate>2015</risdate><volume>50</volume><issue>1</issue><spage>167</spage><epage>180</epage><pages>167-180</pages><issn>0362-1340</issn><eissn>1558-1160</eissn><abstract>Current proposals for adding gradual typing to JavaScript, such as Closure, TypeScript and Dart, forgo soundness to deal with issues of scale, code reuse, and popular programming patterns. We show how to address these issues in practice while retaining soundness. We design and implement a new gradual type system, prototyped for expediency as a 'Safe' compilation mode for TypeScript. Our compiler achieves soundness by enforcing stricter static checks and embedding residual runtime checks in compiled code. It emits plain JavaScript that runs on stock virtual machines. Our main theorem is a simulation that ensures that the checks introduced by Safe TypeScript (1) catch any dynamic type error, and (2) do not alter the semantics of type-safe TypeScript code. Safe TypeScript is carefully designed to minimize the performance overhead of runtime checks. At its core, we rely on two new ideas: differential subtyping, a new form of coercive subtyping that computes the minimum amount of runtime type information that must be added to each object; and an erasure modality, which we use to safely and selectively erase type information. This allows us to scale our design to full-fledged TypeScript, including arrays, maps, classes, inheritance, overloading, and generic types. We validate the usability and performance of Safe TypeScript empirically by type-checking and compiling around 120,000 lines of existing TypeScript source code. Although runtime checks can be expensive, the end-to-end overhead is small for code bases that already have type annotations. For instance, we bootstrap the Safe TypeScript compiler (90,000 lines including the base TypeScript compiler): we measure a 15% runtime overhead for type safety, and also uncover programming errors as type safety violations. We conclude that, at least during development and testing, subjecting JavaScript/TypeScript programs to safe gradual typing adds significant value to source type annotations at a modest cost.</abstract><cop>New York, NY, USA</cop><pub>ACM</pub><doi>10.1145/2775051.2676971</doi><tpages>14</tpages></addata></record>
fulltext fulltext
identifier ISSN: 0362-1340
ispartof SIGPLAN notices, 2015-05, Vol.50 (1), p.167-180
issn 0362-1340
1558-1160
language eng
recordid cdi_crossref_primary_10_1145_2775051_2676971
source ACM Digital Library
subjects Classes and objects
Formal language definitions
General programming languages
Inheritance
Language features
Polymorphism
Program semantics
Semantics
Semantics and reasoning
Software and its engineering
Software notations and tools
Theory of computation
title Safe & Efficient Gradual Typing for TypeScript
url https://sfx.bib-bvb.de/sfx_tum?ctx_ver=Z39.88-2004&ctx_enc=info:ofi/enc:UTF-8&ctx_tim=2025-01-08T03%3A03%3A50IST&url_ver=Z39.88-2004&url_ctx_fmt=infofi/fmt:kev:mtx:ctx&rfr_id=info:sid/primo.exlibrisgroup.com:primo3-Article-acm_cross&rft_val_fmt=info:ofi/fmt:kev:mtx:journal&rft.genre=article&rft.atitle=Safe%20&%20Efficient%20Gradual%20Typing%20for%20TypeScript&rft.jtitle=SIGPLAN%20notices&rft.au=Rastogi,%20Aseem&rft.date=2015-05-11&rft.volume=50&rft.issue=1&rft.spage=167&rft.epage=180&rft.pages=167-180&rft.issn=0362-1340&rft.eissn=1558-1160&rft_id=info:doi/10.1145/2775051.2676971&rft_dat=%3Cacm_cross%3E2676971%3C/acm_cross%3E%3Curl%3E%3C/url%3E&disable_directlink=true&sfx.directlink=off&sfx.report_link=0&rft_id=info:oai/&rft_id=info:pmid/&rfr_iscdi=true