A sufficiently smart compiler for procedural records

Andrew W. Keep, R. Kent Dybvig
2012 Proceedings of the 2012 Annual Workshop on Scheme and Functional Programming - Scheme '12  
Many languages include a syntax for declaring programmerdefined structured data types, i.e., structs or records. R6RS supports syntactic record definitions but also allows records to be defined procedurally, i.e., via a set of run-time operations. Indeed, the procedural interface is considered to be the primitive interface, and the syntactic interface is designed to be macro expandable into code that uses the procedural interface. Run-time creation of record types has a potentially significant
more » ... mpact. In particular, record creation, field access, and field mutation cannot generally be open coded, as it can be with syntactically specified records. Often, however, the shape of a record type can be determined statically, and in such a case, performance equivalent to that of syntactically specified record types can be attained. This paper describes an efficient run-time implementation of procedural record types, discusses its overhead, and describes a set of compiler optimizations that eliminate the overhead when record-type information can be determined statically. The optimizations improve the performance of a set of representative benchmark programs by over 20% on average. The flexibility of the procedural interface and the simplicity of implementing the syntactic interface via the procedural interface comes at a price. Because RTDs, RCDs, constructors, predicates, accessors, and mutators are all created at run time, record creation, access, and mutation are out-of-line operations requiring indirect jumps and possible pipeline stalls, possibly along with memory overhead beyond that which would be necessary in a straightforward implementation of a syntactic interface, e.g., to extract the RTD (for type checking) and field index from the closure of an accessor or mutator. In addition, record-definition code must be put at the top level of a program or library if creation of the RTDs, RCDs, constructors, predicates, accessors, and mutators is to happen only at initialization time-an unfortunate constraint and not an obvious one when the syntactic interface is used.
doi:10.1145/2661103.2661107 dblp:conf/icfp/KeepD12 fatcat:lp3iltsnrffmlbqdpg3zarmare