# R Melts Brains -- An IR for First-Class Environments and Lazy Effectful   Arguments

**Authors:** Olivier Fl\"uckiger, Guido Chari, Jan Je\v{c}men, Ming-Ho Yee, Jakob, Hain, Jan Vitek

arXiv: 1907.05118 · 2019-09-09

## TL;DR

This paper introduces PIR, an intermediate representation designed to handle R's complex features like first-class environments and lazy evaluation, enabling more effective program analysis and optimization.

## Contribution

The work presents PIR, a novel IR that explicitly models R's environment and effectful features, facilitating static analysis and optimization techniques.

## Key findings

- PIR enables reasoning about variables and environments.
- It allows inference of argument evaluation points.
- It supports environment elision and function inlining.

## Abstract

The R programming language combines a number of features considered hard to analyze and implement efficiently: dynamic typing, reflection, lazy evaluation, vectorized primitive types, first-class closures, and extensive use of native code. Additionally, variable scopes are reified at runtime as first-class environments. The combination of these features renders most static program analysis techniques impractical, and thus, compiler optimizations based on them ineffective. We present our work on PIR, an intermediate representation with explicit support for first-class environments and effectful lazy evaluation. We describe two dataflow analyses on PIR: the first enables reasoning about variables and their environments, and the second infers where arguments are evaluated. Leveraging their results, we show how to elide environment creation and inline functions.

## Full text

_Full body text omitted from this summary view._ Fetch the complete paper as Markdown: https://tomesphere.com/paper/1907.05118/full.md

## Figures

17 figures with captions in the complete paper: https://tomesphere.com/paper/1907.05118/full.md

## References

21 references — full list in the complete paper: https://tomesphere.com/paper/1907.05118/full.md

---
Source: https://tomesphere.com/paper/1907.05118