Sound, Heuristic Type Annotation Inference for Ruby

Total Page:16

File Type:pdf, Size:1020Kb

Sound, Heuristic Type Annotation Inference for Ruby Sound, Heuristic Type Annotation Inference for Ruby Milod Kazerounian Brianna M. Ren Jeffrey S. Foster University of Maryland University of Maryland Tufts University College Park, Maryland, USA College Park, Maryland, USA Medford, MA, USA [email protected] [email protected] [email protected] Abstract Keywords: type inference, dynamic languages, Ruby Many researchers have explored retrofitting static type sys- ACM Reference Format: tems to dynamic languages. This raises the question of how Milod Kazerounian, Brianna M. Ren, and Jeffrey S. Foster. 2020. to add type annotations to code that was previously untyped. Sound, Heuristic Type Annotation Inference for Ruby. In Proceed- One obvious solution is type inference. However, in com- ings of the 16th ACM SIGPLAN International Symposium on Dynamic plex type systems, in particular those with structural types, Languages (DLS ’20), November 17, 2020, Virtual, USA. ACM, New type inference typically produces most general types that York, NY, USA, 14 pages. https://doi.org/10.1145/3426422.3426985 are large, hard to understand, and unnatural for program- mers. To solve this problem, we introduce InferDL, a novel Ruby type inference system that infers sound and useful type 1 Introduction annotations by incorporating heuristics that guess types. Many researchers have explored ways to add static types to For example, we might heuristically guess that a parame- dynamic languages [3, 4, 15, 19, 29, 31, 36, 37], to help pro- ter whose name ends in count is an integer. InferDL works grammers find and prevent type errors. One key challenge by first running standard type inference and then applying in using such retrofitted type systems is finding type anno- heuristics to any positions for which standard type infer- tations for code that was previously untyped. Type inference, ence produces overly-general types. Heuristic guesses are which aims to type check programs with few or no type added as constraints to the type inference problem to ensure annotations, is an obvious solution, and indeed there are sev- they are consistent with the rest of the program and other eral type inference systems for dynamic languages [2–4, 15]. heuristic guesses; inconsistent guesses are discarded. We for- Beyond type checking, type inference can also be extended malized InferDL in a core type and constraint language. We to generate type annotations for program values. These an- implemented InferDL on top of RDL, an existing Ruby type notations provide a useful form of documentation, and can checker. To evaluate InferDL, we applied it to four Ruby on be used in other forms of program analysis such as code Rails apps that had been previously type checked with RDL, completion for IDEs. and hence had type annotations. We found that, when using However, type inference systems typically aim to find the heuristics, InferDL inferred 22% more types that were as or most general type for every position, i.e., the least restrictive more precise than the previous annotations, compared to possible type. If the type language is rich—particularly if standard type inference without heuristics. We also found it includes structural types—the most general possible an- one new type error. We further evaluated InferDL by ap- notations might be large, hard to read, and unnatural for plying it to six additional apps, finding five additional type programmers. For example, An et al.[2] describe a type in- errors. Thus, we believe InferDL represents a promising ap- ference system for Ruby that infers that a certain position proach for inferring type annotations in dynamic languages. accepts any object with >, <<, >>, &, and ˆ methods. In contrast, a programmer would mostly likely, and much more CCS Concepts: • Software and its engineering ! Data concisely, say that position takes an Integer. Moreover, even types and structures. if we are not interested in producing annotations, large, com- plex types can lead to difficult-to-understand error messages. Permission to make digital or hard copies of all or part of this work for In this paper, we present InferDL, a novel Ruby type in- personal or classroom use is granted without fee provided that copies ference system that aims to infer sound and useful type anno- are not made or distributed for profit or commercial advantage and that InferDL copies bear this notice and the full citation on the first page. Copyrights tations. More specifically, allows the programmer for components of this work owned by others than the author(s) must to specify heuristics for guessing type annotations. For ex- be honored. Abstracting with credit is permitted. To copy otherwise, or ample, one simple but effective heuristic is to guess the type republish, to post on servers or to redistribute to lists, requires prior specific Integer for any variables whose names end with id, num, or permission and/or a fee. Request permissions from [email protected]. count. InferDL runs such heuristics for positions for which DLS ’20, November 17, 2020, Virtual, USA standard type inference is overly-general (meaning, among © 2020 Copyright held by the owner/author(s). Publication rights licensed to ACM. others, positions with inferred structural types). Heuristic ACM ISBN 978-1-4503-8175-8/20/11...$15.00 guesses are added as additional type constraints and checked https://doi.org/10.1145/3426422.3426985 for consistency with the rest of the program. Only consistent DLS ’20, November 17, 2020, Virtual, USA Milod Kazerounian, Brianna M. Ren, and Jeffrey S. Foster solutions are kept. In this way, InferDL maintains sound- 1 class User < ActiveRecord::Base ness while producing a less general, but potentially more 2 # α ! β useful, solution than standard type inference. (§2 gives an 3 def self.normalize_username (name) overview of InferDL.) 4 name.unicode_normalize.downcase if name.present? We describe InferDL more formally on a core type and 5 end constraint language. We present standard constraint reso- 6 # γ ! δ lution rules, which rewrite a set of constraints into solved 7 def self.find_by_name (name) form from which most general solutions can be extracted. 8 find_by(name_lower: normalize_username(name)) end We describe that solution extraction procedure in detail and 9 10 end then show how to incorporate heuristics. (See §3 for our formal description.) (a) Source code from Discourse app. We implemented InferDL as an extension to RDL, an ex- isting Ruby type checker [13, 19, 31]. We modified RDL to Constraints Generated generate and resolve type constraints, run heuristics, and (1) α ≤ »unicode_normalize : ?! ϵ¼ extract solutions to produce annotations. InferDL currently (2) α ≤ »present? : ?! ζ ¼ includes eight heuristics: one that replaces structural types (3) ϵ ≤ »downcase : ?! η¼ with nominal types that match the structure; six that look at (4) η ≤ β variable names, such as the one mentioned above for names (5) γ ≤ α ending in id, num, or count; and one that produces precise (6) User ≤ δ hash types. We also extended RDL with choice types, an idea Resolved Constraints inspired by variational typing [7] that helps type inference (7) γ ≤ »unicode_normalize : ?! ϵ¼ work in the presence of overloaded methods. (§4 describes (8) γ ≤ »present? : ?! ζ ¼ the implementation of InferDL.) We evaluated InferDL by applying it to four Ruby on Rails (b) Constraints generated on type variables. apps for which RDL type annotations already existed [19, 31]. We note that our results are preliminary, and further work Figure 1. Inferring method types in Discourse. is needed to affirm they generalize beyond our benchmarks. For these apps, InferDL inferred 496 type annotations. Of Suppose we wish to infer types for these two methods these, 399 exactly matched or were more precise than the using the standard, constraint-based approach. We first gen- programmer-supplied annotations, compared to only 290 erate a type variable for the method argument and return such annotations when not using heuristics. InferDL also types, as shown in the comments on lines2 and6, e.g., nor- found one previously unknown type error. We also applied malize_username takes a value of type α and returns type InferDL to six additional Ruby programs for which we did β. Then we analyze the method body, generating constraints InferDL not have annotations, and found five previously of the form x ≤ y, indicating that x must be a subtype of y. unknown type errors. (§5 discusses our evaluation.) In this case we also say x is a lower bound on y and y is an InferDL We believe that is an effective type inference upper bound on x. system and represents a promising approach to generating The top portion of Figure 1b shows the constraints gener- useful, sound type annotations. ated from this example. Constraint (1) arises from the call name.unicode_normalize1. In this constraint, the structural 2 Overview type »unicode_normalize : ?! ϵ¼ represents an object with We begin by discussing standard type inference, which gen- a unicode_normalize method that takes no argument (here erates and solves type constraints to yield type annotations. written ?) and returns ϵ, a fresh type variable generated We then discuss why this approach alone can be inadequate at the call. Hence, by standard subtyping rules, α must be and give a high-level overview of how InferDL uses heuris- a type that contains at least this method with appropriate tics to infer more precise, useful types. argument and return types. Constraint (2) is similar. Constraint (3) arises from calling downcase on the re- sult of . Constraint (4) arises because the 2.1 Standard Type Inference unicode_normalize result of the call to downcase is returned. Note that normal- Figure 1a shows a code snippet taken from Discourse, a Ruby ize_username may also return nil (if the conditional guard is on Rails web app used in our evaluation (§5). The code de- false), but nil is a subtype of all other types in InferDL, so we fines two methods, normalize_username and find_by_name, omit this constraint here.
Recommended publications
  • The Jungle Through Javascript Frameworks
    The jungle through Javascript frameworks. Jonatan Karlsson Henrik Ölund Web Programming Web Programming 2013, BTH, Blekinge institute of 2013, BTH, Blekinge institute of technology technology Advanced topic in Web development, PA1426 Advanced topic in Web development, PA1426 HT15 HT15 Karlskrona, Sweden Karlskrona, Sweden [email protected] [email protected] PA1426 Revision C, Advanced topic in Web development 2015-11-05 Abstract In this article we have planned to dive into Javascripts world where new framework comes out “every day”. We will take the reader into a world where nothing are for granted and everything is a non-standard. In the current situation, there is a [3] tremendous amount of Javascript frameworks ​ and that makes it difficult for a ​ layman to choose the right framework, for the right task and this is something we will try figure out and explain to the reader. Keywords: Javascript, Framework, MV*, Client-side, React, Mithril, Backbone.js, ​ Ember.js 1 PA1426 Revision C, Advanced topic in Web development 2015-11-05 Abstract 1. Introduction 1.1 Background 1.2 Intention 1.3 Method First part Does the framework follow the MV*-pattern? Is the framework popular on google? Have the framework risen in popularity since 2013? Does the framework have any corporation that backs them? Second part 2. Result 2.1 Which frameworks did we select? 2.2 Not included 2.3 React What philosophies have pushed this framework forward? What kind of problem does this framework solve? Which famous products has been created with this framework?
    [Show full text]
  • Enough Documentation Release 2.1.22
    Enough Documentation Release 2.1.22 Enough Community Sep 11, 2021 Infrastructure guide 1 Introduction 3 1.1 Requirements...............................................3 1.2 Quick start................................................4 2 Using Enough 5 2.1 Knowledge................................................5 2.2 Using the cloud or physical machines..................................5 2.3 Installation of the Enough CLI......................................5 2.4 Upgrade.................................................6 2.5 OpenStack Enough instance.......................................6 2.6 libvirt Enough instance..........................................7 2.7 Connecting libvirt and OpenStack Enough instances..........................8 2.8 Create or update a service........................................9 2.9 Restore a service............................................. 10 2.10 OpenStack infrastructure services and access.............................. 10 2.11 Certificates................................................ 11 2.12 OpenStack Attached volumes...................................... 12 2.13 Background tasks............................................. 13 2.14 Access.................................................. 13 2.15 OpenStack backups........................................... 13 2.16 Low level commands........................................... 15 3 Services 17 3.1 Nextcloud................................................ 17 3.2 Forum.................................................. 17 3.3 Mattermost...............................................
    [Show full text]
  • Linking Platforms, Practices, and Developer Ethics: Levers for Privacy Discourse in Mobile Application Development
    J Bus Ethics DOI 10.1007/s10551-017-3504-8 ORIGINAL PAPER Linking Platforms, Practices, and Developer Ethics: Levers for Privacy Discourse in Mobile Application Development 1 2 Katie Shilton • Daniel Greene Received: 10 August 2016 / Accepted: 7 March 2017 Ó The Author(s) 2017. This article is an open access publication Abstract Privacy is a critical challenge for corporate managers who wish to promote ethical practices in mobile social responsibility in the mobile device ecosystem. development. Mobile application firms can collect granular and largely unregulated data about their consumers, and must make Keywords Corporate social responsibility Á Occupational ethical decisions about how and whether to collect, store, ethics Á Privacy Á Qualitative analysis Á Technology ethics and share these data. This paper conducts a discourse analysis of mobile application developer forums to dis- cover when and how privacy conversations, as a repre- Introduction: Investigating Work Dynamics sentative of larger ethical debates, arise during that Impact Privacy Reflection development. It finds that online forums can be useful spaces for ethical deliberations, as developers use these Mobile technologies enable new forms of access to infor- spaces to define, discuss, and justify their values. It also mation and communication. But even as the capabilities of discovers that ethical discussions in mobile development mobile technologies advance, many fail to reflect and are prompted by work practices which vary considerably support the values of their users. Studies demonstrate a between iOS and Android, today’s two major mobile striking discord between user values such as privacy and platforms. For educators, regulators, and managers inter- implementation of these values in mobile technologies ested in encouraging more ethical discussion and deliber- (Martin and Shilton 2015).
    [Show full text]
  • Gradual Write-Barrier Insertion Into a Ruby Interpreter
    Gradual Write-Barrier Insertion into a Ruby Interpreter Koichi Sasada Cookpad Inc. Japan [email protected] Abstract older generation objects (old objects) to younger generation Ruby is a popular object-oriented programming language, objects (young objects) [2, 6]. If we forget to insert even one and the performance of the Ruby garbage collector (GC) di- WB, the young objects may be wrongly collected. Of course, rectly affects the execution time of Ruby programs. Ruby2.0 this would be a critical GC bug. and earlier versions employed an inefficient non-generational If you need to implement a generational GC on an inter- conservative mark-and-sweep GC. To improve this and make preter which does not have WBs yet, how can you implement it a generational collector, it is necessary to introduce write it? One straightforward approach is to completely introduce barriers (WBs), but this requires huge modification to exist- all WBs at once. However, if you cannot modify parts of the ing source code, including third-party C-extensions. To avoid source code writing to objects (e.g., in C-extensions), it is the need for adding WBs around legacy code, we invented a not possible to add all required WBs. new concept called “WB-unprotected objects”, which indi- This was the case for the Ruby interpreter in 2013 and cates to the GC to treat such objects more conservatively. By before. leveraging this design, we were able to improve the perfor- The Ruby object-oriented programming language [4] is mance of Ruby 2.1 with a generational GC and of Ruby 2.2 used worldwide, especially for web application development with an incremental GC while preserving compatibility with with the Ruby on Rails framework [11].
    [Show full text]
  • Cross-Platform Language Design
    Cross-Platform Language Design THIS IS A TEMPORARY TITLE PAGE It will be replaced for the final print by a version provided by the service academique. Thèse n. 1234 2011 présentée le 11 Juin 2018 à la Faculté Informatique et Communications Laboratoire de Méthodes de Programmation 1 programme doctoral en Informatique et Communications École Polytechnique Fédérale de Lausanne pour l’obtention du grade de Docteur ès Sciences par Sébastien Doeraene acceptée sur proposition du jury: Prof James Larus, président du jury Prof Martin Odersky, directeur de thèse Prof Edouard Bugnion, rapporteur Dr Andreas Rossberg, rapporteur Prof Peter Van Roy, rapporteur Lausanne, EPFL, 2018 It is better to repent a sin than regret the loss of a pleasure. — Oscar Wilde Acknowledgments Although there is only one name written in a large font on the front page, there are many people without which this thesis would never have happened, or would not have been quite the same. Five years is a long time, during which I had the privilege to work, discuss, sing, learn and have fun with many people. I am afraid to make a list, for I am sure I will forget some. Nevertheless, I will try my best. First, I would like to thank my advisor, Martin Odersky, for giving me the opportunity to fulfill a dream, that of being part of the design and development team of my favorite programming language. Many thanks for letting me explore the design of Scala.js in my own way, while at the same time always being there when I needed him.
    [Show full text]
  • Blossom: a Language Built to Grow
    Macalester College DigitalCommons@Macalester College Mathematics, Statistics, and Computer Science Honors Projects Mathematics, Statistics, and Computer Science 4-26-2016 Blossom: A Language Built to Grow Jeffrey Lyman Macalester College Follow this and additional works at: https://digitalcommons.macalester.edu/mathcs_honors Part of the Computer Sciences Commons, Mathematics Commons, and the Statistics and Probability Commons Recommended Citation Lyman, Jeffrey, "Blossom: A Language Built to Grow" (2016). Mathematics, Statistics, and Computer Science Honors Projects. 45. https://digitalcommons.macalester.edu/mathcs_honors/45 This Honors Project - Open Access is brought to you for free and open access by the Mathematics, Statistics, and Computer Science at DigitalCommons@Macalester College. It has been accepted for inclusion in Mathematics, Statistics, and Computer Science Honors Projects by an authorized administrator of DigitalCommons@Macalester College. For more information, please contact [email protected]. In Memory of Daniel Schanus Macalester College Department of Mathematics, Statistics, and Computer Science Blossom A Language Built to Grow Jeffrey Lyman April 26, 2016 Advisor Libby Shoop Readers Paul Cantrell, Brett Jackson, Libby Shoop Contents 1 Introduction 4 1.1 Blossom . .4 2 Theoretic Basis 6 2.1 The Potential of Types . .6 2.2 Type basics . .6 2.3 Subtyping . .7 2.4 Duck Typing . .8 2.5 Hindley Milner Typing . .9 2.6 Typeclasses . 10 2.7 Type Level Operators . 11 2.8 Dependent types . 11 2.9 Hoare Types . 12 2.10 Success Types . 13 2.11 Gradual Typing . 14 2.12 Synthesis . 14 3 Language Description 16 3.1 Design goals . 16 3.2 Type System . 17 3.3 Hello World .
    [Show full text]
  • Distributive Disjoint Polymorphism for Compositional Programming
    Distributive Disjoint Polymorphism for Compositional Programming Xuan Bi1, Ningning Xie1, Bruno C. d. S. Oliveira1, and Tom Schrijvers2 1 The University of Hong Kong, Hong Kong, China fxbi,nnxie,[email protected] 2 KU Leuven, Leuven, Belgium [email protected] Abstract. Popular programming techniques such as shallow embeddings of Domain Specific Languages (DSLs), finally tagless or object algebras are built on the principle of compositionality. However, existing program- ming languages only support simple compositional designs well, and have limited support for more sophisticated ones. + This paper presents the Fi calculus, which supports highly modular and compositional designs that improve on existing techniques. These im- provements are due to the combination of three features: disjoint inter- section types with a merge operator; parametric (disjoint) polymorphism; and BCD-style distributive subtyping. The main technical challenge is + Fi 's proof of coherence. A naive adaptation of ideas used in System F's + parametricity to canonicity (the logical relation used by Fi to prove co- herence) results in an ill-founded logical relation. To solve the problem our canonicity relation employs a different technique based on immediate substitutions and a restriction to predicative instantiations. Besides co- herence, we show several other important meta-theoretical results, such as type-safety, sound and complete algorithmic subtyping, and decidabil- ity of the type system. Remarkably, unlike F<:'s bounded polymorphism, + disjoint polymorphism in Fi supports decidable type-checking. 1 Introduction Compositionality is a desirable property in programming designs. Broadly de- fined, it is the principle that a system should be built by composing smaller sub- systems.
    [Show full text]
  • Bs-6026-0512E.Pdf
    THERMAL PRINTER SPEC BAS - 6026 1. Basic Features 1.) Type : PANEL Mounting or DESK top type 2.) Printing Type : THERMAL PRINT 3.) Printing Speed : 25mm / SEC 4.) Printing Column : 24 COLUMNS 5.) FONT : 24 X 24 DOT MATRIX 6.) Character : English, Numeric & Others 7.) Paper width : 57.5mm ± 0.5mm 8.) Character Size : 5times enlarge possible 9.) INTERFACE : CENTRONICS PARALLEL I/F SERIAL I/F 10.) DIMENSION : 122(W) X 90(D) X 129(H) 11.) Operating Temperature range : 0℃ - 50℃ 12.) Storage Temperature range : -20℃ - 70℃ 13.) Outlet Power : DC 12V ( 1.6 A )/ DC 5V ( 2.5 A) 14.) Application : Indicator, Scale, Factory automation equipments and any other data recording, etc.,, - 1 - 1) SERIAL INTERFACE SPECIFICATION * CONNECTOR : 25 P FEMALE PRINTER : 4 P CONNECTOR 3 ( TXD ) ----------------------- 2 ( RXD ) 2 2 ( RXD ) ----------------------- 1 ( TXD ) 3 7 ( GND ) ----------------------- 4 ( GND ) 5 DIP SWITCH BUAD RATE 1 2 3 ON ON ON 150 OFF ON ON 300 ON OFF ON 600 OFF OFF ON 1200 ON ON OFF 2400 OFF ON OFF 4800 ON OFF OFF 9600 OFF OFF OFF 19200 2) BAUD RATE SELECTION * PROTOCOL : XON / XOFF Type DIP SWITCH (4) ON : Combination type * DATA BIT : 8 BIT STOP BIT : 1 STOP BIT OFF: Complete type PARITY CHECK : NO PARITY * DEFAULT VALUE : BAUD RATE (9600 BPS) - 2 - PRINTING COMMAND * Explanation Command is composed of One Byte Control code and ESC code. This arrangement is started with ESC code which is connected by character & numeric code The control code in Printer does not be still in standardization (ESC Control Code). All printers have a code structure by themselves.
    [Show full text]
  • Cormac Flanagan Fritz Henglein Nate Nystrom Gavin Bierman Jan Vitek Gilad Bracha Philip Wadler Jeff Foster Tobias Wrigstad Peter Thiemann Sam Tobin-Hochstadt
    PC: Amal Ahmed SC: Matthias Felleisen Robby Findler (chair) Cormac Flanagan Fritz Henglein Nate Nystrom Gavin Bierman Jan Vitek Gilad Bracha Philip Wadler Jeff Foster Tobias Wrigstad Peter Thiemann Sam Tobin-Hochstadt Organizers: Tobias Wrigstad and Jan Vitek Schedule Schedule . 3 8:30 am – 10:30 am: Invited Talk: Scripting in a Concurrent World . 5 Language with a Pluggable Type System and Optional Runtime Monitoring of Type Errors . 7 Position Paper: Dynamically Inferred Types for Dynamic Languages . 19 10:30 am – 11:00 am: Coffee break 11:00 am – 12:30 pm: Gradual Information Flow Typing . 21 Type Inference with Run-time Logs . 33 The Ciao Approach to the Dynamic vs. Static Language Dilemma . 47 12:30 am – 2:00 pm: Lunch Invited Talk: Scripting in a Concurrent World John Field IBM Research As scripting languages are used to build increasingly complex systems, they must even- tually confront concurrency. Concurrency typically arises from two distinct needs: han- dling “naturally” concurrent external (human- or software-generated) events, and en- hancing application performance. Concurrent applications are difficult to program in general; these difficulties are multiplied in a distributed setting, where partial failures are common and where resources cannot be centrally managed. The distributed sys- tems community has made enormous progress over the past few decades designing specialized systems that scale to handle millions of users and petabytes of data. How- ever, combining individual systems into composite applications that are scalable—not to mention reliable, secure, and easy to develop maintain—remains an enormous chal- lenge. This is where programming languages should be able to help: good languages are designed to facilitate composing large applications from smaller components and for reasoning about the behavior of applications modularly.
    [Show full text]
  • Discord Music Bot Bad Request
    Discord Music Bot Bad Request MishnaicGuido consult Gabriel creditably. denounces Marc gnostically remains cultured and purblindly. after Tony autolyze well or rotes any riempie. Tremain usually infuriate eighth or revalidated groggily when This comes into discord music bot Botisimo Chatbot & Streamer Tools for Twitch YouTube. We never went through an odd idea but exercise, Built for Developers. To discord bot will mean for gamers and then attempt to malformed syntax. Keep your discord music bots that add localized video that. They were capable of sending stickers videos music locations documents and. 10 Best Discord Music Bots You business Use 2020 Beebom. Show you generate a bot in nature or swaying trees. Skype is deserve of salt high-definition video calls HD calls have clear video quality the audio is in sync and the experience is void as with you're bean in front bench the other person for full-HD Skype calls have some technical requirements. How to record better audio on only phone Popular Science. An automated processes, discord bots is arguably one request? It even when people on discord bot is bad video could not request has a way. But became really shouldn't cause that is one kiss Sends a gif of a fresh for mentioned. How discord bot user requests that have any comments cannot be patience for discord bot! Hydra lets you with critical reviews and not make the discord bot that monitor will code looks like top music, atom a token for membership and make the discord. Block this does not support the requester.
    [Show full text]
  • Download the JSR-000202 Java Class File Specification
    CHAPTER 4 The class File Format THIS chapter describes the Java virtual machine class file format. Each class file contains the definition of a single class or interface. Although a class or interface need not have an external representation literally contained in a file (for instance, because the class is generated by a class loader), we will colloquially refer to any valid representation of a class or interface as being in the class file format. A class file consists of a stream of 8-bit bytes. All 16-bit, 32-bit, and 64-bit quantities are constructed by reading in two, four, and eight consecutive 8-bit bytes, respectively. Multibyte data items are always stored in big-endian order, where the high bytes come first. In the Java and Java 2 platforms, this format is supported by interfaces java.io.DataInput and java.io.DataOutput and classes such as java.io.DataInputStream and java.io.DataOutputStream. This chapter defines its own set of data types representing class file data: The types u1, u2, and u4 represent an unsigned one-, two-, or four-byte quantity, respectively. In the Java and Java 2 platforms, these types may be read by methods such as readUnsignedByte, readUnsignedShort, and readInt of the interface java.io.DataInput. This chapter presents the class file format using pseudostructures written in a C- like structure notation. To avoid confusion with the fields of classes and class instances, etc., the contents of the structures describing the class file format are referred to as items. Successive items are stored in the class file sequentially, without padding or alignment.
    [Show full text]
  • Type Systems
    A Simple Language <t> ::= true | false | if <t> then <t> else <t> | 0 | succ <t> | pred <t> | iszero <t> Type Systems . Simple untyped expressions . Natural numbers encoded as succ … succ 0 . E.g. succ succ succ 0 represents 3 . Pierce Ch. 3, 8, 11, 15 . term: a string from this language . To improve readability, we will sometime write parentheses: e.g. iszero (pred (succ 0)) CSE 6341 1 CSE 6341 2 Semantics (informally) Equivalent Ways to Define the Syntax . A term evaluates to a value . Inductive definition: the smallest set S s.t. Values are terms themselves . { true, false, 0 } S . Boolean constants: true and false . if t1S, then {succ t1, pred t1, iszero t1 } S . Natural numbers: 0, succ 0, succ (succ 0), … . if t1 , t2 , t3 S, then if t1 then t2 else t3 S . Given a program (i.e., a term), the result . Same thing, written as inference rules of “running” this program is a boolean trueS falseS 0S axioms (no premises) value or a natural number t1S t1S t1St2St3S . if false then 0 else succ 0 succ 0 succ t1 S pred t1 S if t1 then t2 else t3 S . iszero (pred (succ 0)) true t S If we have established the premises . Problematic: succ true or if 0 then 0 else 0 1 (above the line), we can derive the iszero t1 S CSE 6341 3 conclusion (below the line) 4 Why Does This Matter? Inductive Proofs . Key property: for any tS, one of three things . Structural induction – used very often must be true: .
    [Show full text]