Expressive and Strongly Type-Safe Code Generation

被引:1
|
作者
Winant, Thomas [1 ]
Cockx, Jesper [1 ]
Devriese, Dominique [1 ]
机构
[1] Katholieke Univ Leuven, Imec, DistriNet, B-3001 Leuven, Belgium
基金
比利时弗兰德研究基金会;
关键词
meta-programming; dependent types;
D O I
10.1145/3131851.3131872
中图分类号
TP31 [计算机软件];
学科分类号
081202 ; 0835 ;
摘要
Meta-programs are programs that generate other programs, but in weakly type-safe systems, type-checking a meta-program only establishes its own type safety, and generated programs need additional type-checking after generation. Strong type safety of a meta-program implies type safety of any generated object program, a property with important engineering benefits. Current strongly type-safe systems suffer from expressivity limitations and cannot support many meta-programs found in practice, for example automatic generation of lenses. To overcome this, we move away from the idea of staged meta-programming. Instead, we use an off-the-shelf dependently-typed language as the meta-language and a relatively standard, intrinsically well-typed representation of the object language. We scale this approach to practical meta-programming, by choosing a high-level, explicitly typed intermediate representation as the object language, rather than a surface programming language. We implement our approach as a library for the Glasgow Haskell Compiler (GHC) and evaluate it on several meta-programs, including a deriveLenses meta-program taken from a real-world Haskell lens library. Our evaluation demonstrates expressivity beyond the state of the art and applicability to real settings, at little cost in terms of code size.
引用
收藏
页码:199 / 210
页数:12
相关论文
共 50 条
  • [1] Type-safe Runtime Code Generation: Accelerate to LLVM
    McDonell, Trevor L.
    Chakravarty, Manuel M. T.
    Grover, Vinod
    Newton, Ryan R.
    [J]. ACM SIGPLAN NOTICES, 2015, 50 (12) : 201 - 212
  • [2] Type-Safe Code Transformations in Haskell
    Guillemette, Louis-Julien
    Monnier, Stefan
    [J]. ELECTRONIC NOTES IN THEORETICAL COMPUTER SCIENCE, 2007, 174 (07) : 23 - 39
  • [3] WHAT IS TYPE-SAFE CODE REUSE
    PALSBERG, J
    SCHWARTZBACH, MI
    [J]. LECTURE NOTES IN COMPUTER SCIENCE, 1991, 512 : 325 - 341
  • [4] CCured: Type-safe retrofitting of legacy code
    Necula, GC
    McPeak, S
    Weimer, W
    [J]. ACM SIGPLAN NOTICES, 2002, 37 (01) : 128 - 139
  • [5] CCured: Type-Safe Retrofitting of Legacy Code
    Necula, George C.
    McPeak, Scott
    Weimer, Westley
    [J]. ACM SIGPLAN NOTICES, 2012, 47 (04) : 74 - 85
  • [6] A framework for building type-safe configurations for JVM using code generation techniques
    Puripunpinyo, Hussachai
    Samadzadeh, M. H.
    [J]. 2017 SYSTEMS AND INFORMATION ENGINEERING DESIGN SYMPOSIUM (SIEDS), 2017, : 50 - 55
  • [7] Fault-Safe Code Motion for Type-Safe Languages
    Murphy, Brian R.
    Menon, Vijay
    Schneider, Florian T.
    Shpeisman, Tatiana
    Adl-Tabatabai, Ali-Reza
    [J]. CGO 2008: SIXTH INTERNATIONAL SYMPOSIUM ON CODE GENERATION AND OPTIMIZATION, PROCEEDINGS, 2008, : 144 - 154
  • [8] Generate and Offshore: Type-Safe and Modular Code Generation for Low-Level Optimization
    Takashima, Naoki
    Sakamoto, Hiroki
    Kameyama, Yukiyoshi
    [J]. FHPC'15 PROCEEDINGS OF THE 4TH ACM SIGPLAN WORKSHOP ON FUNCTIONAL HIGH-PERFORMANCE COMPUTING, 2015, : 45 - 53
  • [9] Mnemonics: Type-safe Bytecode Generation at Run Time
    Rudolph, Johannes
    Thiemann, Peter
    [J]. PEPM '10: PROCEEDINGS OF THE 2010 ACM SIGPLAN WORKSHOP ON PARTIAL EVALUATION AND PROGRAM MANIPULATION, 2010, : 15 - 24
  • [10] Type-safe disks
    Sivathanu, Gopalan
    [J]. USENIX ASSOCIATION 7TH USENIX SYMPOSIUM ON OPERATING SYSTEMS DESIGN AND IMPLEMENTATION, 2006, : 15 - 28