Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.1145/3609027.3609405acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article
Public Access

Semantic Encapsulation using Linking Types

Published: 31 August 2023 Publication History

Abstract

Interoperability pervades nearly all mainstream language implementations, as most systems leverage subcomponents written in different languages. And yet, such linking can expose a language to foreign behaviors that are internally inexpressible, which poses a serious threat to safety invariants and programmer reasoning. To preserve such invariants, a language may try to add features to limit the reliance on external libraries, but endless extensions can obscure the core abstractions the language was designed to provide.
In this paper, we outline an approach that encapsulates foreign code in a sound way—i.e., without disturbing the invariants promised by types of the core language. First, one introduces novel linking types that characterize the behaviors of foreign libraries that are inexpressible in the core language. To reason about the soundness of linking, one constructs a realizability model that captures the meaning of both core types and linking types as sets of target-language terms. Using this model, one can formally prove when foreign behavior is encapsulated; that is, unobservable to core code. We show one way to discharge such proofs automatically by augmenting the compiler to insert verified encapsulation wrappers around components that use foreign libraries.
Inspired by existing approaches to FFIs, we develop a pair of case studies that extend a pure, functional language: one extension for state, and another for exceptions. The first allows us to implement mutable references via a library, whereas the second allows us to implement try and catch as library functions. Both extensions and the overall system are proven sound using logical relations that use realizability techniques.

References

[1]
Amal Ahmed, Andrew W. Appel, Christopher D. Richards, Kedar N. Swadi, Gang Tan, and Daniel C. Wang. 2010. Semantic Foundations for Typed Assembly Languages. ACM Transactions on Programming Languages and Systems, 32, 3 (2010), March, 1–67.
[2]
Amal Ahmed and Matthias Blume. 2011. An equivalence-preserving CPS translation via multi-language semantics. In Proceeding of the 16th ACM SIGPLAN international conference on Functional Programming, ICFP 2011, Tokyo, Japan, September 19-21, 2011, Manuel M. T. Chakravarty, Zhenjiang Hu, and Olivier Danvy (Eds.). ACM, 431–444. https://doi.org/10.1145/2034773.2034830
[3]
Amal Jamil Ahmed. 2004. Semantics of Types for Mutable State. Ph. D. Dissertation. Princeton University.
[4]
Andrew W. Appel and David A. McAllester. 2001. An indexed model of recursive types for foundational proof-carrying code. ACM Trans. Program. Lang. Syst., 23, 5 (2001), 657–683. https://doi.org/10.1145/504709.504712
[5]
Vytautas Astrauskas, Christoph Matheja, Federico Poli, Peter Müller, and Alexander J Summers. 2020. How do programmers use unsafe Rust? Proceedings of the ACM on Programming Languages, 4, OOPSLA (2020), 1–27.
[6]
Edd Barrett, Carl Friedrich Bolz, Lukas Diekmann, and Laurence Tratt. 2016. Fine-grained Language Composition: A Case Study. In 30th European Conference on Object-Oriented Programming (ECOOP 2016), Shriram Krishnamurthi and Benjamin S. Lerner (Eds.) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 56). Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany. 3:1–3:27. isbn:978-3-95977-014-9 issn:1868-8969 https://doi.org/10.4230/LIPIcs.ECOOP.2016.3
[7]
Nick Benton. 2006. Abstracting allocation: The new new thing. In Computer Science Logic (CSL).
[8]
Nick Benton and Chung-Kil Hur. 2009. Biorthogonality, Step-indexing and Compiler Correctness. In Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming (ICFP ’09). ACM, New York, NY, USA. 97–108. isbn:978-1-60558-332-7 https://doi.org/10.1145/1596550.1596567
[9]
Nick Benton and Nicolas Tabareau. 2009. Compiling functional types to relational specifications for low level imperative code. In Proceedings of TLDI’09: 2009 ACM SIGPLAN International Workshop on Types in Languages Design and Implementation, Savannah, GA, USA, January 24, 2009. 3–14.
[10]
Nick Benton and Uri Zarfaty. 2007. Formalizing and Verifying Semantic Type Soundness of a Simple Compiler. In Proceedings of the 9th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming (PPDP ’07). Association for Computing Machinery, New York, NY, USA. 1–12. isbn:9781595937698 https://doi.org/10.1145/1273920.1273922
[11]
Karthikeyan Bhargavan, Barry Bond, Antoine Delignat-Lavaud, Cédric Fournet, Chris Hawblitzel, Catalin Hritcu, Samin Ishtiaq, Markulf Kohlweiss, Rustan Leino, Jay R. Lorch, Kenji Maillard, Jianyang Pan, Bryan Parno, Jonathan Protzenko, Tahina Ramananandro, Ashay Rane, Aseem Rastogi, Nikhil Swamy, Laure Thompson, Peng Wang, Santiago Zanella Béguelin, and Jean Karim Zinzindohoue. 2017. Everest: Towards a Verified, Drop-in Replacement of HTTPS. In 2nd Summit on Advances in Programming Languages, SNAPL 2017, May 7-10, 2017, Asilomar, CA, USA, Benjamin S. Lerner, Rastislav Bodík, and Shriram Krishnamurthi (Eds.) (LIPIcs, Vol. 71). Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 1:1–1:12. https://doi.org/10.4230/LIPIcs.SNAPL.2017.1
[12]
Matthias Blume. 2001. No-longer-foreign: Teaching an ML compiler to speak C “natively”. Electronic Notes in Theoretical Computer Science, 59, 1 (2001), 36–52.
[13]
Sylvain Boulmé and Thomas Vandendorpe. 2019. Embedding Untrusted Imperative ML Oracles into Coq Verified Code. July, https://hal.archives-ouvertes.fr/hal-02062288 This preprint has been largely rewritten and integrated into Sylvain Boulmé’s Habilitation in 2021, See http://www-verimag.imag.fr/ boulme/hdr.html.
[14]
Manuel MT Chakravarty. 1999. C->HASKELL, or Yet Another Interfacing Tool. In Symposium on Implementation and Application of Functional Languages. 131–148.
[15]
Byron Cook and John Launchbury. 1997. Disposable memo functions. In ICFP. 97, 310.
[16]
Olivier Danvy and Andrzej Filinski. 1990. Abstracting control. In Proceedings of the 1990 ACM Conference on LISP and Functional Programming. 151–160.
[17]
Derek Dreyer, Georg Neis, and Lars Birkedal. 2012. The Impact of Higher-Order State and Control Effects on Local Relational Reasoning. J. Funct. Program., 22, 4–5 (2012), aug, 477–528. issn:0956-7968 https://doi.org/10.1017/S095679681200024X
[18]
Mattias Felleisen. 1988. The Theory and Practice of First-Class Prompts. In Proceedings of the 15th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’88). Association for Computing Machinery, New York, NY, USA. 180–190. isbn:0897912527 https://doi.org/10.1145/73560.73576
[19]
Matthias Felleisen. 1990. On the expressive power of programming languages. In European Symposium on Programming. 134–151.
[20]
Sigbjorn Finne, Daan Leijen, Erik Meijer, and Simon Peyton Jones. 1998. H/Direct: a binary foreign language interface for Haskell. In Proceedings of the third ACM SIGPLAN international conference on Functional programming. 153–162.
[21]
The Rust Foundation. [n. d.]. The Rust Standard Library. https://doc.rust-lang.org/std/keyword.extern.html
[22]
Aymeric Fromherz, Nick Giannarakis, Chris Hawblitzel, Bryan Parno, Aseem Rastogi, and Nikhil Swamy. 2019. A verified, efficient embedding of a verifiable assembly language. PACMPL, 3, POPL (2019), 63:1–63:30. https://doi.org/10.1145/3290376
[23]
Michael Furr and Jeffrey S. Foster. 2005. Checking Type Safety of Foreign Function Calls. 62–72.
[24]
Michael Furr and Jeffrey S. Foster. 2008. Checking Type Safety of Foreign Function Calls.
[25]
Kathryn E Gray. 2008. Safe cross-language inheritance. In European Conference on Object-Oriented Programming. 52–75.
[26]
Kathryn E Gray, Robert Bruce Findler, and Matthew Flatt. 2005. Fine-grained interoperability through mirrors and contracts. ACM SIGPLAN Notices, 40, 10 (2005), 231–245.
[27]
Unsafe Code Guidelines Working Group. [n. d.]. Unsafe Code Guidelines Reference. https://rust-lang.github.io/unsafe-code-guidelines/introduction.html
[28]
Koen Jacobs, Dominique Devriese, and Amin Timany. 2022. Purity of an ST monad: full abstraction by semantically typed back-translation. Proceedings of the ACM on Programming Languages, 6, OOPSLA1 (2022), 1–27.
[29]
Jonas B. Jensen, Nick Benton, and Andrew Kennedy. 2013. High-Level Separation Logic for Low-Level Code. POPL ’13. Association for Computing Machinery, New York, NY, USA. 301–314. isbn:9781450318327 https://doi.org/10.1145/2429069.2429105
[30]
Simon Peyton Jones, Thomas Nordin, and Alastair Reid. 1997. GreenCard: a foreign-language interface for Haskell. In Proc. Haskell Workshop.
[31]
Simon Peyton Jones, Norman Ramsey, and Fermin Reig. 1999. C-—: A portable assembly language that supports garbage collection. In International Conference on Principles and Practice of Declarative Programming. 1–28.
[32]
Ralf Jung, Jacques-Henri Jourdan, Robbert Krebbers, and Derek Dreyer. 2018. RustBelt: Securing the Foundations of the Rust Programming Language. In ACM Symposium on Principles of Programming Languages (POPL).
[33]
Robert Kleffner. 2017. A Foundation for Typed Concatenative Languages. Master’s thesis. Northeastern University.
[34]
Neelakantan R. Krishnaswami, Pierre Pradic, and Nick Benton. 2015. Integrating Linear and Dependent Types. In Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2015, Mumbai, India, January 15-17, 2015, Sriram K. Rajamani and David Walker (Eds.). ACM, 17–30. https://doi.org/10.1145/2676726.2676969
[35]
Byeongcheol Lee, Ben Wiedermann, Martin Hirzel, Robert Grimm, and Kathryn S. McKinley. 2010. Jinn: synthesizing dynamic bug detectors for foreign language interfaces. In Proceedings of the 2010 ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2010, Toronto, Ontario, Canada, June 5-10, 2010, Benjamin G. Zorn and Alexander Aiken (Eds.). ACM, 36–49. https://doi.org/10.1145/1806596.1806601
[36]
Daan Leijen. 2014. Koka: Programming with Row Polymorphic Effect Types. In Proceedings 5th Workshop on Mathematically Structured Functional Programming, MSFP@ETAPS 2014, Grenoble, France, 12 April 2014, Paul Blain Levy and Neel Krishnaswami (Eds.) (EPTCS, Vol. 153). 100–126. https://doi.org/10.4204/EPTCS.153.8
[37]
Daan Leijen. 2017. Type Directed Compilation of Row-Typed Algebraic Effects. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL 2017). Association for Computing Machinery, New York, NY, USA. 486–499. isbn:9781450346603 https://doi.org/10.1145/3009837.3009872
[38]
Paul Blain Levy. 2001. Call-by-Push-Value. Queen Mary, University of London. London, UK.
[39]
Kenji Maillard, Danel Ahman, Robert Atkey, Guido Martínez, Cătălin Hriţcu, Exequiel Rivas, and Éric Tanter. 2019. Dijkstra Monads for All. Proc. ACM Program. Lang., 3, ICFP (2019), Article 104, jul, 29 pages. https://doi.org/10.1145/3341708
[40]
Jacob Matthews and Robert Bruce Findler. 2007. Operational semantics for multi-language programs. In Proceedings of the 34th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2007, Nice, France, January 17-19, 2007, Martin Hofmann and Matthias Felleisen (Eds.). ACM, 3–10. https://doi.org/10.1145/1190216.1190220
[41]
Robin Milner. 1978. A theory of type polymorphism in programming. J. Comput. Syst. Sci., 17 (1978), 348–375.
[42]
Max S. New and Amal Ahmed. 2018. Graduality from Embedding-Projection Pairs. In ICFP. Proceedings of the ACM on Programming Languages, 2, 73:1–73:30.
[43]
Max S. New, William J. Bowman, and Amal Ahmed. 2016. Fully abstract compilation via universal embedding. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming, ICFP 2016, Nara, Japan, September 18-22, 2016, Jacques Garrigue, Gabriele Keller, and Eijiro Sumii (Eds.). ACM, 103–116. https://doi.org/10.1145/2951913.2951941
[44]
Max S. New, Dustin Jamner, and Amal Ahmed. 2020. Graduality and Parametricity: Together Again for the First Time. Proceedings of the ACM on Programming Languages, 4, POPL, 46:1–46:32.
[45]
Max S New, Daniel R Licata, and Amal Ahmed. 2019. Gradual type theory. Proceedings of the ACM on Programming Languages, 3, POPL (2019), 15:1–15:31.
[46]
Peter-Michael Osera, Vilhelm Sjöberg, and Steve Zdancewic. 2012. Dependent interoperability. In Proceedings of the sixth workshop on Programming Languages meets Program Verification, PLPV 2012, Philadelphia, PA, USA, January 24, 2012, Koen Claessen and Nikhil Swamy (Eds.). ACM, 3–14. https://doi.org/10.1145/2103776.2103779
[47]
Bryan O’Sullivan, John Goerzen, and Donald Bruce Stewart. 2008. Real world Haskell: Code you can believe in. " O’Reilly Media, Inc.".
[48]
Daniel Patterson and Amal Ahmed. 2017. Linking Types for Multi-Language Software: Have Your Cake and Eat It Too. In 2nd Summit on Advances in Programming Languages (SNAPL 2017), Benjamin S. Lerner, Rastislav Bodík, and Shriram Krishnamurthi (Eds.) (Leibniz International Proceedings in Informatics (LIPIcs), Vol. 71). Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany. 12:1–12:15. isbn:978-3-95977-032-3 issn:1868-8969 https://doi.org/10.4230/LIPIcs.SNAPL.2017.12
[49]
Daniel Patterson, Noble Mushtak, Andrew Wagner, and Amal Ahmed. 2022. Semantic Soundness for Language Interoperability. In Proceedings of the 43rd ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2022, San Diego, California, June 13-17, 2022. ACM.
[50]
Daniel Patterson, Jamie Perconti, Christos Dimoulas, and Amal Ahmed. 2017. FunTAL: reasonably mixing a functional language with assembly. In Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2017, Barcelona, Spain, June 18-23, 2017, Albert Cohen and Martin T. Vechev (Eds.). ACM, 495–509. https://doi.org/10.1145/3062341.3062347
[51]
Daniel Patterson, Andrew Wagner, and Amal Ahmed. 2023. Semantic Encapsulation using Linking Types (Technical Appendix). July, Available at https://dbp.io/łinebreak [0]pubs/łinebreak [0]2023/łinebreak [0]lt-tr.pdf
[52]
James T. Perconti and Amal Ahmed. 2014. Verifying an Open Compiler Using Multi-language Semantics. In Programming Languages and Systems - 23rd European Symposium on Programming, ESOP 2014, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2014, Grenoble, France, April 5-13, 2014, Proceedings, Zhong Shao (Ed.) (Lecture Notes in Computer Science, Vol. 8410). Springer, 128–148. https://doi.org/10.1007/978-3-642-54833-8_8
[53]
Simon Peyton Jones, Simon Marlow, and Conal Elliott. 1999. Stretching the storage manager: weak pointers and stable names in Haskell. In Symposium on Implementation and Application of Functional Languages. 37–58.
[54]
Frank Pfenning and Dennis Griffith. 2015. Polarized substructural session types. In International Conference on Foundations of Software Science and Computation Structures. 3–22.
[55]
LLVM Project. [n. d.]. LLVM Reference. https://www.llvm.org/docs/GarbageCollection.html##gcroot
[56]
Jonathan Protzenko, Jean Karim Zinzindohoué, Aseem Rastogi, Tahina Ramananandro, Peng Wang, Santiago Zanella Béguelin, Antoine Delignat-Lavaud, Catalin Hritcu, Karthikeyan Bhargavan, Cédric Fournet, and Nikhil Swamy. 2017. Verified low-level programming embedded in F. PACMPL, 1, ICFP (2017), 17:1–17:29. https://doi.org/10.1145/3110261
[57]
Klaas Pruiksma, William Chargin, Frank Pfenning, and Jason Reed. 2018. Adjoint logic. Unpublished manuscript, April.
[58]
Michael Sammler, Deepak Garg, Derek Dreyer, and Tadeusz Litak. 2019. The High-Level Benefits of Low-Level Sandboxing. Proc. ACM Program. Lang., 4, POPL (2019), Article 32, dec, 32 pages. https://doi.org/10.1145/3371100
[59]
Gabriel Scherer, Max S. New, Nick Rioux, and Amal Ahmed. 2018. FabULous Interoperability for ML and a Linear Language. In Foundations of Software Science and Computation Structures - 21st International Conference, FOSSACS 2018, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2018, Thessaloniki, Greece, April 14-20, 2018, Proceedings, Christel Baier and Ugo Dal Lago (Eds.) (Lecture Notes in Computer Science, Vol. 10803). Springer, 146–162. https://doi.org/10.1007/978-3-319-89366-2_8
[60]
David Swasey, Deepak Garg, and Derek Dreyer. 2017. Robust and Compositional Verification of Object Capability Patterns. Proc. ACM Program. Lang., 1, OOPSLA (2017), Article 89, oct, 26 pages. https://doi.org/10.1145/3133913
[61]
Gang Tan, Andrew W. Appel, Srimat Chakradhar, Ravi Srivaths, Anand Raghunathan, and Daniel Wang. 2006. Safe Java Native interface. In Proceedings of the 2006 IEEE International Symposium on Secure Software Engineering. 97–106.
[62]
Gang Tan and Greg Morrisett. 2007. Ilea: Inter-language Analysis Across Java and C. In Proceedings of the 22Nd Annual ACM SIGPLAN Conference on Object-oriented Programming Systems and Applications (OOPSLA ’07). ACM, New York, NY, USA. 39–56. isbn:978-1-59593-786-5 https://doi.org/10.1145/1297027.1297031
[63]
Zachary Tatlock, Chris Tucker, David Shuffelton, Ranjit Jhala, and Sorin Lerner. 2008. Deep Typechecking and Refactoring. In Proceedings of the 23rd ACM SIGPLAN Conference on Object-oriented Programming Systems Languages and Applications (OOPSLA ’08). ACM, New York, NY, USA. 37–52. isbn:978-1-60558-215-3 https://doi.org/10.1145/1449764.1449768
[64]
Amin Timany, Léo Stefanesco, Morten Krogh-Jespersen, and Lars Birkedal. 2017. A logical relation for monadic encapsulation of state: Proving contextual equivalences in the presence of runST. Proceedings of the ACM on Programming Languages, 2, POPL (2017), 1–28.
[65]
Jesse Tov and Riccardo Pucella. 2010. Stateful Contracts for Affine Types. In Programming Languages and Systems, 19th European Symposium on Programming, ESOP 2010, Held as Part of the Joint European Conferences on Theory and Practice of Software, ETAPS 2010, Paphos, Cyprus, March 20-28, 2010. Proceedings.
[66]
Thomas Würthinger, Christian Wimmer, Andreas Wöß, Lukas Stadler, Gilles Duboscq, Christian Humer, Gregor Richards, Doug Simon, and Mario Wolczko. 2013. One VM to Rule Them All. In Proceedings of the 2013 ACM International Symposium on New Ideas, New Paradigms, and Reflections on Programming & Software (Onward! 2013). Association for Computing Machinery, New York, NY, USA. 187–204. isbn:9781450324724 https://doi.org/10.1145/2509578.2509581

Cited By

View all
  • (2024)Behavioural Types for Heterogeneous Systems (Position Paper)Electronic Proceedings in Theoretical Computer Science10.4204/EPTCS.401.4401(37-48)Online publication date: 6-Apr-2024
  • (2024)Realistic Realizability: Specifying ABIs You Can Count OnProceedings of the ACM on Programming Languages10.1145/36897558:OOPSLA2(1249-1278)Online publication date: 8-Oct-2024
  • (2024)RichWasm: Bringing Safe, Fine-Grained, Shared-Memory Interoperability Down to WebAssemblyProceedings of the ACM on Programming Languages10.1145/36564448:PLDI(1656-1679)Online publication date: 20-Jun-2024

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
TyDe 2023: Proceedings of the 8th ACM SIGPLAN International Workshop on Type-Driven Development
August 2023
70 pages
ISBN:9798400702990
DOI:10.1145/3609027
Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for third-party components of this work must be honored. For all other uses, contact the Owner/Author.

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 31 August 2023

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. language interoperability
  2. linking
  3. logical relations
  4. semantics
  5. type soundness

Qualifiers

  • Research-article

Funding Sources

Conference

TyDe '23
Sponsor:

Upcoming Conference

ICFP '25
ACM SIGPLAN International Conference on Functional Programming
October 12 - 18, 2025
Singapore , Singapore

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)69
  • Downloads (Last 6 weeks)22
Reflects downloads up to 26 Jan 2025

Other Metrics

Citations

Cited By

View all
  • (2024)Behavioural Types for Heterogeneous Systems (Position Paper)Electronic Proceedings in Theoretical Computer Science10.4204/EPTCS.401.4401(37-48)Online publication date: 6-Apr-2024
  • (2024)Realistic Realizability: Specifying ABIs You Can Count OnProceedings of the ACM on Programming Languages10.1145/36897558:OOPSLA2(1249-1278)Online publication date: 8-Oct-2024
  • (2024)RichWasm: Bringing Safe, Fine-Grained, Shared-Memory Interoperability Down to WebAssemblyProceedings of the ACM on Programming Languages10.1145/36564448:PLDI(1656-1679)Online publication date: 20-Jun-2024

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media