A Grounded Conceptual Model for Ownership Types in Rust (original) (raw)

Article No.: 265, Pages 1224 - 1252

Published: 16 October 2023 Publication History

Abstract

Programmers learning Rust struggle to understand ownership types, Rust’s core mechanism for ensuring memory safety without garbage collection. This paper describes our attempt to systematically design a pedagogy for ownership types. First, we studied Rust developers’ misconceptions of ownership to create the Ownership Inventory, a new instrument for measuring a person’s knowledge of ownership. We found that Rust learners could not connect Rust’s static and dynamic semantics, such as determining why an ill-typed program would (or would not) exhibit undefined behavior. Second, we created a conceptual model of Rust’s semantics that explains borrow checking in terms of flow-sensitive permissions on paths into memory. Third, we implemented a Rust compiler plugin that visualizes programs under the model. Fourth, we integrated the permissions model and visualizations into a broader pedagogy of ownership by writing a new ownership chapter for The Rust Programming Language, a popular Rust textbook. Fifth, we evaluated an initial deployment of our pedagogy against the original version, using reader responses to the Ownership Inventory as a point of comparison. Thus far, the new pedagogy has improved learner scores on the Ownership Inventory by an average of 9

References

[1]

Jonathan Aldrich, Valentin Kostadinov, and Craig Chambers. 2002. Alias Annotations for Program Understanding. In Proceedings of the 17th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA ’02). Association for Computing Machinery, New York, NY, USA. 311–330. isbn:1581134711 https://doi.org/10.1145/582419.582448

[2]

Marcelo Almeida, Grant Cole, Ke Du, Gongming Luo, Shulin Pan, Yu Pan, Kai Qiu, Vishnu Reddy, Haochen Zhang, Yingying Zhu, and Cyrus Omar. 2022. RustViz: Interactively Visualizing Ownership and Borrowing. In 2022 IEEE Symposium on Visual Languages and Human-Centric Computing (VL/HCC). IEEE, New York, USA. 1–10. https://doi.org/10.1109/VL/HCC53370.2022.9833121

[3]

Piraye Bayman and Richard E. Mayer. 1988. Using conceptual models to teach BASIC computer programming. Journal of Educational Psychology, 80 (1988), 291–298. issn:1939-2176(Electronic),0022-0663(Print) https://doi.org/10.1037/0022-0663.80.3.291 Place: US Publisher: American Psychological Association

[4]

David Blaser. 2019. Simple Explanation of Complex Lifetime Errors in Rust. ETH Zürich.

[5]

John Boyland. 2001. Alias burying: Unique variables without destructive reads. Software: Practice and Experience, 31, 6 (2001), 533–553. https://doi.org/10.1002/spe.370 arxiv:https://onlinelibrary.wiley.com/doi/pdf/10.1002/spe.370.

[6]

John Boyland. 2003. Checking Interference with Fractional Permissions. In Static Analysis, Radhia Cousot (Ed.). Springer Berlin Heidelberg, Berlin, Heidelberg. 55–72. isbn:978-3-540-44898-3

[7]

Olaf Chitil. 2001. Compositional Explanation of Types and Algorithmic Debugging of Type Errors. In Proceedings of the Sixth ACM SIGPLAN International Conference on Functional Programming (ICFP ’01). Association for Computing Machinery, New York, NY, USA. 193–204. isbn:1581134150 https://doi.org/10.1145/507635.507659

[8]

Dave Clarke, Johan Östlund, Ilya Sergey, and Tobias Wrigstad. 2013. Ownership Types: A Survey. Springer Berlin Heidelberg, Berlin, Heidelberg. 15–58. isbn:978-3-642-36946-9 https://doi.org/10.1007/978-3-642-36946-9\_3

[9]

David G. Clarke, John M. Potter, and James Noble. 1998. Ownership Types for Flexible Alias Protection. In Proceedings of the 13th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA ’98). Association for Computing Machinery, New York, NY, USA. 48–64. isbn:1581130058 https://doi.org/10.1145/286936.286947

[10]

Michael Coblenz, Michelle L. Mazurek, and Michael Hicks. 2022. Garbage Collection Makes Rust Easier to Use: A Randomized Controlled Trial of the Bronze Garbage Collector. In Proceedings of the 44th International Conference on Software Engineering (ICSE ’22). Association for Computing Machinery, New York, NY, USA. 1021–1032. isbn:9781450392211 https://doi.org/10.1145/3510003.3510107

[11]

Will Crichton. 2020. The Usability of Ownership. In Procedings of the 1st Workshop on Human Aspects of Types and Reasoning Assistants (HATRA). arxiv:arxiv:2011.06171.

[12]

Paul E. Dickson, Neil C. C. Brown, and Brett A. Becker. 2020. Engage Against the Machine: Rise of the Notional Machines as Effective Pedagogical Devices. In Proceedings of the 2020 ACM Conference on Innovation and Technology in Computer Science Education (ITiCSE ’20). Association for Computing Machinery, New York, NY, USA. 159–165. isbn:9781450368742 https://doi.org/10.1145/3341525.3387404

[13]

Werner Dietl, Sophia Drossopoulou, and Peter Müller. 2012. Separating Ownership Topology and Encapsulation with Generic Universe Types. ACM Trans. Program. Lang. Syst., 33, 6 (2012), Article 20, jan, 62 pages. issn:0164-0925 https://doi.org/10.1145/2049706.2049709

[14]

Dietler Dominik. 2018. Visualization of Lifetime Constraints in Rust. ETH Zürich.

[15]

Benedict du Boulay. 1986. Some Difficulties of Learning to Program. Journal of Educational Computing Research, 2, 1 (1986), 57–73. https://doi.org/10.2190/3LFX-9RRF-67T8-UVK9

[16]

Tristan Dyer, Tim Nelson, Kathi Fisler, and Shriram Krishnamurthi. 2022. Applying Cognitive Principles to Model-Finding Output: The Positive Value of Negative Information. Proc. ACM Program. Lang., 6, OOPSLA1 (2022), Article 79, apr, 29 pages. https://doi.org/10.1145/3527323

[17]

Matthew Heinsen Egan and Chris McDonald. 2021. An evaluation of SeeC: a tool designed to assist novice C programmers with program understanding and debugging. Computer Science Education, 31, 3 (2021), 340–373. https://doi.org/10.1080/08993408.2020.1777034

[18]

Mohammed F. Farghally, Kyu Han Koh, Jeremy V. Ernst, and Clifford A. Shaffer. 2017. Towards a Concept Inventory for Algorithm Analysis Topics. In Proceedings of the 2017 ACM SIGCSE Technical Symposium on Computer Science Education (SIGCSE ’17). Association for Computing Machinery, New York, NY, USA. 207–212. isbn:9781450346986 https://doi.org/10.1145/3017680.3017756

[19]

Joseph L Fleiss, Bruce Levin, and Myunghee Cho Paik. 2013. Statistical Methods for Rates and Proportions (3 ed.). Wiley-Interscience, Newy York.

[20]

Kelsey R. Fulton, Anna Chan, Daniel Votipka, Michael Hicks, and Michelle L. Mazurek. 2021. Benefits and Drawbacks of Adopting a Secure Programming Language: Rust as a Case Study. In Seventeenth Symposium on Usable Privacy and Security (SOUPS 2021). USENIX Association, Berkeley, CA. 597–616. isbn:978-1-939133-25-0 https://www.usenix.org/conference/soups2021/presentation/fulton

[21]

Jean-Yves Girard. 1987. Linear logic. Theoretical Computer Science, 50, 1 (1987), 1–101. https://doi.org/10.1016/0304-3975(87)90045-4

[22]

Dan Grossman, Greg Morrisett, Trevor Jim, Michael Hicks, Yanling Wang, and James Cheney. 2002. Region-Based Memory Management in Cyclone. In Proceedings of the ACM SIGPLAN 2002 Conference on Programming Language Design and Implementation (PLDI ’02). Association for Computing Machinery, New York, NY, USA. 282–293. isbn:1581134630 https://doi.org/10.1145/512529.512563

[23]

Guide to Rustc Development. 2023. The MIR (Mid-level IR). https://rustc-dev-guide.rust-lang.org/mir/index.html

[24]

Philip J. Guo. 2013. Online Python Tutor: Embeddable Web-Based Program Visualization for Cs Education. In Proceeding of the 44th ACM Technical Symposium on Computer Science Education (SIGCSE ’13). Association for Computing Machinery, New York, NY, USA. 579–584. isbn:9781450318686 https://doi.org/10.1145/2445196.2445368

[25]

Sally Hamouda, Stephen H. Edwards, Hicham G. Elmongui, Jeremy V. Ernst, and Clifford A. Shaffer. 2017. A basic recursion concept inventory. Computer Science Education, 27, 2 (2017), 121–148. https://doi.org/10.1080/08993408.2017.1414728 arxiv:https://doi.org/10.1080/08993408.2017.1414728.

[26]

John Hattie. 2008. Visible learning. Routledge, London, England.

[27]

Geoffrey L. Herman, Michael C. Loui, and Craig Zilles. 2010. Creating the Digital Logic Concept Inventory. In Proceedings of the 41st ACM Technical Symposium on Computer Science Education (SIGCSE ’10). Association for Computing Machinery, New York, NY, USA. 102–106. isbn:9781450300063 https://doi.org/10.1145/1734263.1734298

[28]

David Hestenes, Malcolm Wells, and Gregg Swackhamer. 1992. Force concept inventory. The Physics Teacher, 30, 3 (1992), 141–158. https://doi.org/10.1119/1.2343497

[29]

Ryosuke Ishizue, Kazunori Sakamoto, Hironori Washizaki, and Yoshiaki Fukazawa. 2018. PVC: Visualizing C Programs on Web Browsers for Novices. In Proceedings of the 49th ACM Technical Symposium on Computer Science Education (SIGCSE ’18). Association for Computing Machinery, New York, NY, USA. 245–250. isbn:9781450351034 https://doi.org/10.1145/3159450.3159566

[30]

Katy Jordan. 2015. MOOC Completion Rates. http://www.katyjordan.com/MOOCproject.html

[31]

Lisa C. Kaczmarczyk, Elizabeth R. Petrick, J. Philip East, and Geoffrey L. Herman. 2010. Identifying Student Misconceptions of Programming. In Proceedings of the 41st ACM Technical Symposium on Computer Science Education (SIGCSE ’10). Association for Computing Machinery, New York, NY, USA. 107–111. isbn:9781450300063 https://doi.org/10.1145/1734263.1734299

[32]

Steve Klabnik and Carol Nichols. 2022. The Rust Programming Language. https://doc.rust-lang.org/book

[33]

Neel Krishnaswami and Jonathan Aldrich. 2005. Permission-Based Ownership: Encapsulating State in Higher-Order Typed Languages. In Proceedings of the 2005 ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI ’05). Association for Computing Machinery, New York, NY, USA. 96–106. isbn:1595930566 https://doi.org/10.1145/1065010.1065023

[34]

Jessica Lam, Elias Fang, Majed Almansoori, Rahul Chatterjee, and Adalbert Gerald Soosai Raj. 2022. Identifying Gaps in the Secure Programming Knowledge and Skills of Students. In Proceedings of the 53rd ACM Technical Symposium on Computer Science Education - Volume 1 (SIGCSE 2022). Association for Computing Machinery, New York, NY, USA. 703–709. isbn:9781450390705 https://doi.org/10.1145/3478431.3499391

[35]

J. Richard Landis and Gary G. Koch. 1977. The Measurement of Observer Agreement for Categorical Data. Biometrics, 33, 1 (1977), 159–174. issn:0006341X, 15410420 http://www.jstor.org/stable/2529310

[36]

Rebecca S. Lindell, Elizabeth Peak, and Thomas M. Foster. 2007. Are They All Created Equal? A Comparison of Different Concept Inventory Development Methodologies. AIP Conference Proceedings, 883, 1 (2007), 14–17. https://doi.org/10.1063/1.2508680

[37]

Justin Lubin and Sarah E. Chasins. 2021. How Statically-Typed Functional Programmers Write Code. Proc. ACM Program. Lang., 5, OOPSLA (2021), Article 155, oct, 30 pages. https://doi.org/10.1145/3485532

[38]

Guillaume Marceau, Kathi Fisler, and Shriram Krishnamurthi. 2011. Do Values Grow on Trees? Expression Integrity in Functional Programming. In Proceedings of the Seventh International Workshop on Computing Education Research (ICER ’11). Association for Computing Machinery, New York, NY, USA. 39–44. isbn:9781450308298 https://doi.org/10.1145/2016911.2016921

[39]

Guillaume Marceau, Kathi Fisler, and Shriram Krishnamurthi. 2011. Measuring the Effectiveness of Error Messages Designed for Novice Programmers. In Proceedings of the 42nd ACM Technical Symposium on Computer Science Education (SIGCSE ’11). Association for Computing Machinery, New York, NY, USA. 499–504. isbn:9781450305006 https://doi.org/10.1145/1953163.1953308

[40]

Niko Matsakis. 2018. An alias-based formulation of the borrow checker. http://smallcultfollowing.com/babysteps/blog/2018/04/27/an-alias-based-formulation-of-the-borrow-checker

[41]

Tim McNamara. 2021. Rust in Action. Manning Publications, New York, NY.

[42]

MSRC Team. 2019. We need a safer systems programming language. https://msrc-blog.microsoft.com/2019/07/18/we-need-a-safer-systems-programming-language/

[43]

Niko Matsakis. 2023. nikomatsakis/a-mir-formality: a model of MIR and the Rust type/trait system. https://github.com/nikomatsakis/a-mir-formality

[44]

Diego Ongaro and John Ousterhout. 2014. In Search of an Understandable Consensus Algorithm. In 2014 USENIX Annual Technical Conference (USENIX ATC 14). USENIX Association, Philadelphia, PA. 305–319. isbn:978-1-931971-10-2 https://www.usenix.org/conference/atc14/technical-sessions/presentation/ongaro

[45]

Johan Östlund, Tobias Wrigstad, Dave Clarke, and Beatrice Åkerblom. 2008. Ownership, Uniqueness, and Immutability. In Objects, Components, Models and Patterns, Richard F. Paige and Bertrand Meyer (Eds.). Springer Berlin Heidelberg, Berlin, Heidelberg. 178–197. isbn:978-3-540-69824-1

[46]

Leo Porter, Daniel Zingaro, Soohyun Nam Liao, Cynthia Taylor, Kevin C. Webb, Cynthia Lee, and Michael Clancy. 2019. BDSI: A Validated Concept Inventory for Basic Data Structures. In Proceedings of the 2019 ACM Conference on International Computing Education Research (ICER ’19). Association for Computing Machinery, New York, NY, USA. 111–119. isbn:9781450361859 https://doi.org/10.1145/3291279.3339404

[47]

Seth Poulsen, Geoffrey L. Herman, Peter A. H. Peterson, Enis Golaszewski, Akshita Gorti, Linda Oliva, Travis Scheponik, and Alan T. Sherman. 2021. Psychometric Evaluation of the Cybersecurity Concept Inventory. ACM Trans. Comput. Educ., 22, 1 (2021), Article 6, oct, 18 pages. https://doi.org/10.1145/3451346

[48]

Ralf Jung. 2023. RalfJung/minirust: A precise specification for "Rust lite / MIR plus". https://github.com/RalfJung/minirust

[49]

Talia Ringer, Alex Sanchez-Stern, Dan Grossman, and Sorin Lerner. 2020. REPLica: REPL Instrumentation for Coq Analysis. In Proceedings of the 9th ACM SIGPLAN International Conference on Certified Programs and Proofs (CPP 2020). Association for Computing Machinery, New York, NY, USA. 99–113. isbn:9781450370974 https://doi.org/10.1145/3372885.3373823

[50]

Elijah Rivera and Shriram Krishnamurthi. 2022. Structural versus Pipeline Composition of Higher-Order Functions (Experience Report). Proc. ACM Program. Lang., 6, ICFP (2022), Article 102, aug, 14 pages. https://doi.org/10.1145/3547633

[51]

Juha Sorva, Ville Karavirta, and Lauri Malmi. 2013. A Review of Generic Program Visualization Systems for Introductory Programming Education. ACM Trans. Comput. Educ., 13, 4 (2013), Article 15, nov, 64 pages. https://doi.org/10.1145/2490822

[52]

Andrew Taylor, Jake Renzella, and Alexandra Vassar. 2023. Foundations First: Improving C’s Viability in Introductory Programming Courses with the Debugging C Compiler. In Proceedings of the 54th ACM Technical Symposium on Computer Science Education V. 1 (SIGCSE 2023). Association for Computing Machinery, New York, NY, USA. 346–352. isbn:9781450394314

[53]

The Rust Programming Language. 2023. rust-lang/miri: An interpreter for Rust’s mid-level intermediate representation. https://github.com/rust-lang/miri/

[54]

The Rust Programming Language. 2023. rust-lang/polonius: Defines the rust borrow checker. https://github.com/rust-lang/polonius

[55]

The Rust Survey Team. 2020. Rust Survey 2020 Results. https://blog.rust-lang.org/2020/12/16/rust-survey-2020.html

[56]

Jeffrey Vander Stoep. 2022. Memory Safe Languages in Android 13. https://security.googleblog.com/2022/12/memory-safe-languages-in-android-13.html

[57]

Mitchell Wand. 1986. Finding the Source of Type Errors. In Proceedings of the 13th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages (POPL ’86). Association for Computing Machinery, New York, NY, USA. 38–43. isbn:9781450373470 https://doi.org/10.1145/512644.512648

[58]

Kevin C. Webb and Cynthia Taylor. 2014. Developing a Pre- and Post-Course Concept Inventory to Gauge Operating Systems Learning. In Proceedings of the 45th ACM Technical Symposium on Computer Science Education (SIGCSE ’14). Association for Computing Machinery, New York, NY, USA. 103–108. isbn:9781450326056 https://doi.org/10.1145/2538862.2538886

[59]

Aaron Weiss, Olek Gierczak, Daniel Patterson, and Amal Ahmed. 2021. Oxide: The Essence of Rust. arxiv:arXiv:1903.00982.

[60]

Lea Wittie, Anastasia Kurdia, and Meriel Huggard. 2017. Developing a concept inventory for computer science 2. In 2017 IEEE Frontiers in Education Conference (FIE). IEEE, New York, USA. 1–4. https://doi.org/10.1109/FIE.2017.8190459

[61]

Herbert Wolverson. 2021. Hands-on rust. Pragmatic Programmers, Raleigh, NC.

[62]

Joshua Yanovski, Hoang-Hai Dang, Ralf Jung, and Derek Dreyer. 2021. GhostCell: Separating Permissions from Data in Rust. Proc. ACM Program. Lang., 5, ICFP (2021), Article 92, aug, 30 pages. https://doi.org/10.1145/3473597

[63]

Anna Zeng and Will Crichton. 2019. Identifying Barriers to Adoption for Rust through Online Discourse. In 9th Workshop on Evaluation and Usability of Programming Languages and Tools (PLATEAU 2018), Titus Barik, Joshua Sunshine, and Sarah Chasins (Eds.) (OpenAccess Series in Informatics (OASIcs), Vol. 67). Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik, Dagstuhl, Germany. 5:1–5:6. isbn:978-3-95977-091-0 issn:2190-6807 https://doi.org/10.4230/OASIcs.PLATEAU.2018.5

[64]

Danfeng Zhang and Andrew C. Myers. 2014. Toward General Diagnosis of Static Errors. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’14). Association for Computing Machinery, New York, NY, USA. 569–581. isbn:9781450325448 https://doi.org/10.1145/2535838.2535870

[65]

Shuofei Zhu, Ziyi Zhang, Boqin Qin, Aiping Xiong, and Linhai Song. 2022. Learning and Programming Challenges of Rust: A Mixed-Methods Study. In Proceedings of the 44th International Conference on Software Engineering (ICSE ’22). Association for Computing Machinery, New York, NY, USA. 1269–1281. isbn:9781450392211 https://doi.org/10.1145/3510003.3510164

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages

Proceedings of the ACM on Programming Languages Volume 7, Issue OOPSLA2

October 2023

2250 pages

Copyright © 2023 Owner/Author.

This work is licensed under a Creative Commons Attribution 4.0 International License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 16 October 2023

Published in PACMPL Volume 7, Issue OOPSLA2

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. Rust
  2. concept inventory
  3. ownership types
  4. program state visualization

Qualifiers

Funding Sources

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

Reflects downloads up to 14 Oct 2024

Other Metrics

Citations

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Check if you have access through your login credentials or your institution to get full access on this article.

Sign in

Full Access

Media

Figures

Other

Tables

Affiliations

Will Crichton

Brown University, Providence, USA

Gavin Gray

ETH Zurich, Zurich, Switzerland

Shriram Krishnamurthi

Brown University, Providence, USA