eelco-visser-compiler-const.../lecture/10.html

1093 lines
21 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="Eelco Visser">
<meta name="generator" content="Jekyll v3.8.5">
<title>Lecture 10: Program Transformation by Term Rewriting</title>
<!-- <base href="/2021"> -->
<!--link rel="canonical" href="https://getbootstrap.com/docs/4.3/examples/starter-template/"-->
<link rel="icon" href="../img/logo/pl_ico2_2B3_icon.ico" type="image/x-icon">
<!-- Bootstrap core CSS -->
<!--link href="https://getbootstrap.com/docs/4.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
.bd-placeholder-img {
font-size: 1.125rem;
text-anchor: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@media (min-width: 768px) {
.bd-placeholder-img-lg {
font-size: 3.5rem;
}
}
</style>
<!-- Custom styles for this template -->
<link href="../css/main.css" rel="stylesheet">
<link href="../css/borders-responsive.css" rel="stylesheet">
<link rel="stylesheet" href="../css/pl.css">
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
<a class="navbar-brand" href="../index.html">
TU Delft | CS4200
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="../lectures/index.html" tabindex="-1" aria-disabled="true">Lectures</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="../homework/index.html" tabindex="-1" aria-disabled="true">Homework</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="../project/index.html" tabindex="-1" aria-disabled="true">Project</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="../news/index.html" tabindex="-1" aria-disabled="true">News</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="../blog/index.html" tabindex="-1" aria-disabled="true">Blog</a>
</li>
</ul>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 col-xl-12">
<a href="../lectures/2021/10-transformation/CS4200-2021-10-transformation.pdf">
<img class="border border-dark" width="100%" src="../lectures/2021/10-transformation/CS4200-2021-10-transformation/CS4200-2021-10-transformation.001.png"/>
</a>
<div class="mt-3 mb-3 pt-3 pb-3 text-dark border-top border-bottom border-grey">
<div class="text-dark font-weight-bold">
<h1>
Lecture 10: Program Transformation by Term Rewriting
</h1>
</div>
<div>
Eelco Visser
</div>
<div>
Lecture
| <a class="text-primary" href="../lectures/2021/10-transformation/CS4200-2021-10-transformation.pdf">PDF</a>
</div>
<div>
November 11, 2021
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-9 border-lg-right border-grey">
<p>In this lecture we start with the second part of the compiler course in which we will study the construction of compiler back-ends.</p>
<p>We start with the study of term rewrite rules to define program transformations. And we look at the use of programmable strategies in the Stratego transformations to control application of rewrite rules.</p>
<h3 id="slides">Slides</h3>
<ul>
<li><a href="https://tudelft-cs4200.github.io/2021/lecture/2021/lectures/2021/10-transformation/CS4200-2021-10-transformation.pdf">PDF</a></li>
<li><a href="https://tudelft-cs4200.github.io/2021/lecture/2021/lectures/2021/10-transformation/CS4200-2021-10-transformation-builds.pdf">PDF with builds</a></li>
</ul>
<h3 id="references">References</h3>
<ul class="list-group list-group-flush pb-3">
<li class="list-group-item pl-lg-0 border-0 pb-0">
<div class="bd-callout border-info pl-3">
<div>
<a name="Siek2021"></a>
Essentials of Compilation. An Incremental Approach in Racket
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
<a class="text-secondary" href="https://researchr.org/alias/jeremy-g.-siek">Jeremy G. Siek</a>.
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
[<a class="text-secondary" target="_blank" href="https://researchr.org/publication/Siek2021/bibtex">bib</a>, <a href="https://researchr.org/publication/Siek2021" class="text-secondary" target="_blank">researchr</a>]
<!-- Siek2021 -->
</div>
</div>
</li>
<li class="list-group-item pl-lg-0 border-0 pb-0">
<div class="bd-callout border-primary pl-3">
<div>
<a name="SmitsV20"></a>
<a class="font-weight-bold text-dark" target="_blank" href="https://doi.org/10.1145/3426425.3426928">Gradually typing strategies</a>
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
<a class="text-secondary" href="https://researchr.org/profile/jeffsmits/publications">Jeff Smits</a>, <a class="text-secondary" href="http://eelcovisser.org">Eelco Visser</a>.
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
SLE 2020
[<a class="text-secondary" href="https://doi.org/10.1145/3426425.3426928" target="_blank">doi</a>, <a class="text-secondary" target="_blank" href="https://researchr.org/publication/SmitsV20/bibtex">bib</a>, <a href="https://researchr.org/publication/SmitsV20" class="text-secondary" target="_blank">researchr</a>, <a class="text-secondary" data-toggle="collapse" href="10.html#AbstractSmitsV20" role="button" aria-expanded="false" aria-controls="AbstractSmitsV20"">abstract</a>]
<!-- SmitsV20 -->
</div>
<div class="collapse mt-1 mb-2" id="AbstractSmitsV20">
<div class="">
The Stratego language supports program transformation by means of term rewriting with programmable rewriting strategies. Stratego's traversal primitives support concise definition of generic tree traversals. Stratego is a dynamically typed language because its features cannot be captured fully by a static type system. While dynamic typing makes for a flexible programming model, it also leads to unintended type errors, code that is harder to maintain, and missed opportunities for optimization. In this paper, we introduce a gradual type system for Stratego that combines the flexibility of dynamically typed generic programming, where needed, with the safety of statically declared and enforced types, where possible. To make sure that statically typed code cannot go wrong, all access to statically typed code from dynamically typed code is protected by dynamic type checks (casts). The type system is backwards compatible such that types can be introduced incrementally to existing Stratego programs. We formally define a type system for Core Gradual Stratego, discuss its implementation in a new type checker for Stratego, and present an evaluation of its impact on Stratego programs.
</div>
</div>
</div>
</li>
<li class="list-group-item pl-lg-0 border-0 pb-0">
<div class="bd-callout border-primary pl-3">
<div>
<a name="KatsV10"></a>
<a class="font-weight-bold text-dark" target="_blank" href="https://doi.org/10.1145/1869459.1869497">The Spoofax language workbench: rules for declarative specification of languages and IDEs</a>
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
<a class="text-secondary" href="http://www.lclnet.nl/">Lennart C. L. Kats</a>, <a class="text-secondary" href="http://eelcovisser.org">Eelco Visser</a>.
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
OOPSLA 2010
[<a href="../publications/2010/KatsV10.pdf" class="text-secondary" target="_blank">pdf</a>, <a class="text-secondary" href="https://doi.org/10.1145/1869459.1869497" target="_blank">doi</a>, <a class="text-secondary" target="_blank" href="https://researchr.org/publication/KatsV10/bibtex">bib</a>, <a href="https://researchr.org/publication/KatsV10" class="text-secondary" target="_blank">researchr</a>, <a class="text-secondary" data-toggle="collapse" href="10.html#AbstractKatsV10" role="button" aria-expanded="false" aria-controls="AbstractKatsV10"">abstract</a>]
<!-- -->
</div>
<div class="collapse mt-1 mb-2" id="AbstractKatsV10">
<div class="">
Spoofax is a language workbench for efficient, agile development of textual domain-specific languages with state-of-the-art IDE support. Spoofax integrates language processing techniques for parser generation, meta-programming, and IDE development into a single environment. It uses concise, declarative specifications for languages and IDE services. In this paper we describe the architecture of Spoofax and introduce idioms for high-level specifications of language semantics using rewrite rules, showing how analyses can be reused for transformations, code generation, and editor services such as error marking, reference resolving, and content completion. The implementation of these services is supported by language-parametric editor service classes that can be dynamically loaded by the Eclipse IDE, allowing new languages to be developed and used side-by-side in the same Eclipse environment.
</div>
</div>
</div>
</li>
<li class="list-group-item pl-lg-0 border-0 pb-0">
<div class="bd-callout border-danger pl-3">
<div>
<a name="BravenboerDOV06"></a>
<a class="font-weight-bold text-dark" target="_blank" href="https://content.iospress.com/articles/fundamenta-informaticae/fi69-1-2-06">Program Transformation with Scoped Dynamic Rewrite Rules</a>
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
<a class="text-secondary" href="http://martin.bravenboer.name/">Martin Bravenboer</a>, <a class="text-secondary" href="https://researchr.org/profile/arthurvandam/publications">Arthur van Dam</a>, <a class="text-secondary" href="https://researchr.org/profile/karinaolmos/publications">Karina Olmos</a>, <a class="text-secondary" href="http://eelcovisser.org">Eelco Visser</a>.
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
FUIN 69(1-2) 2006
[<a href="../publications/2020/BravenboerDOV06.pdf" class="text-secondary" target="_blank">pdf</a>, <a class="text-secondary" href="https://content.iospress.com/articles/fundamenta-informaticae/fi69-1-2-06" target="_blank">doi</a>, <a class="text-secondary" target="_blank" href="https://researchr.org/publication/BravenboerDOV06/bibtex">bib</a>, <a href="https://researchr.org/publication/BravenboerDOV06" class="text-secondary" target="_blank">researchr</a>, <a class="text-secondary" data-toggle="collapse" href="10.html#AbstractBravenboerDOV06" role="button" aria-expanded="false" aria-controls="AbstractBravenboerDOV06"">abstract</a>]
<!-- -->
</div>
<div class="collapse mt-1 mb-2" id="AbstractBravenboerDOV06">
<div class="">
The applicability of term rewriting to program transformation is limited by the lack of control over rule application and by the context-free nature of rewrite rules. The first problem is addressed by languages supporting user-definable rewriting strategies. The second problem is addressed by the extension of rewriting strategies with scoped dynamic rewrite rules. Dynamic rules are defined at run-time and can access variables available from their definition context. Rules defined within a rule scope are automatically retracted at the end of that scope. In this paper, we explore the design space of dynamic rules, and their application to transformation problems. The technique is formally defined by extending the operational semantics underlying the program transformation language Stratego, and illustrated by means of several program transformations in Stratego, including constant propagation, bound variable renaming, dead code elimination, function inlining, and function specialization.
</div>
</div>
</div>
</li>
<li class="list-group-item pl-lg-0 border-0 pb-0">
<div class="bd-callout border-primary pl-3">
<div>
<a name="Visser03"></a>
<a class="font-weight-bold text-dark" target="_blank" href="https://doi.org/10.1007/978-3-540-25935-0_13">Program Transformation with Stratego/XT: Rules, Strategies, Tools, and Systems in Stratego/XT 0.9</a>
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
<a class="text-secondary" href="http://eelcovisser.org">Eelco Visser</a>.
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
Dagstuhl 2003
[<a class="text-secondary" href="https://doi.org/10.1007/978-3-540-25935-0_13" target="_blank">doi</a>, <a class="text-secondary" target="_blank" href="https://researchr.org/publication/Visser03/bibtex">bib</a>, <a href="https://researchr.org/publication/Visser03" class="text-secondary" target="_blank">researchr</a>, <a class="text-secondary" data-toggle="collapse" href="10.html#AbstractVisser03" role="button" aria-expanded="false" aria-controls="AbstractVisser03"">abstract</a>]
<!-- Visser03 -->
</div>
<div class="collapse mt-1 mb-2" id="AbstractVisser03">
<div class="">
Stratego/XT is a framework for the development of transformation systems aiming to support a wide range of program transformations. The framework consists of the transformation language Stratego and the XT collection of transformation tools. Stratego is based on the paradigm of rewriting under the control of programmable rewriting strategies. The XT tools provide facilities for the infrastructure of transformation systems including parsing and pretty-printing. The framework addresses the entire range of the development process; from the specification of transformations to their composition into transformation systems. This chapter gives an overview of the main ingredients involved in the composition of transformation systems with Stratego/XT, where we distinguish the abstraction levels of rules, strategies, tools, and systems.
</div>
</div>
</div>
</li>
<li class="list-group-item pl-lg-0 border-0 pb-0">
<div class="bd-callout border-primary pl-3">
<div>
<a name="VisserBT98"></a>
<a class="font-weight-bold text-dark" target="_blank" href="http://doi.acm.org/10.1145/289423.289425">Building Program Optimizers with Rewriting Strategies</a>
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
<a class="text-secondary" href="http://eelcovisser.org">Eelco Visser</a>, <a class="text-secondary" href="http://web.archive.org/web/20010515202744/www.cse.ogi.edu/~benaissa/">Zine-El-Abidine Benaissa</a>, <a class="text-secondary" href="http://www.cs.pdx.edu/~apt">Andrew P. Tolmach</a>.
</div>
<div class="font-weight-light text-secondary" style="font-size:90%;">
ICFP 1998
[<a class="text-secondary" href="http://doi.acm.org/10.1145/289423.289425" target="_blank">doi</a>, <a class="text-secondary" target="_blank" href="https://researchr.org/publication/VisserBT98/bibtex">bib</a>, <a href="https://researchr.org/publication/VisserBT98" class="text-secondary" target="_blank">researchr</a>, <a class="text-secondary" data-toggle="collapse" href="10.html#AbstractVisserBT98" role="button" aria-expanded="false" aria-controls="AbstractVisserBT98"">abstract</a>]
<!-- VisserBT98 -->
</div>
<div class="collapse mt-1 mb-2" id="AbstractVisserBT98">
<div class="">
We describe a language for defining term rewriting strategies, and its application to the production of program optimizers. Valid transformations on program terms can be described by a set of rewrite rules; rewriting strategies are used to describe when and how the various rules should be applied in order to obtain the desired optimization effects. Separating rules from strategies in this fashion makes it easier to reason about the behavior of the optimizer as a whole, compared to traditional monolithic optimizer implementations. We illustrate the expressiveness of our language by using it to describe a simple optimizer for an ML-like intermediate representation.The basic strategy language uses operators such as sequential composition, choice, and recursion to build transformers from a set of labeled unconditional rewrite rules. We also define an extended language in which the side-conditions and contextual rules that arise in realistic optimizer specifications can themselves be expressed as strategy-driven rewrites. We show that the features of the basic and extended languages can be expressed by breaking down the rewrite rules into their primitive building blocks, namely matching and building terms in variable binding environments. This gives us a low-level core language which has a clear semantics, can be implemented straightforwardly and can itself be optimized. The current implementation generates C code from a strategy specification.
</div>
</div>
</div>
</li>
</ul>
</div>
<div class="col-sm-12 col-md-12 col-lg-3 col-xl-3 " >
<div class="sticky-top top70 d-none d-lg-block d-xl-block">
<div class="pb4 mb3 border-bottom border-grey ">
<nav>
<ul class="pagination justify-content-left">
<li class="page-item">
<a class="page-link" href="9.html">
&laquo;
</a>
</li>
<li class="page-item">
<a class="page-link" href="../lectures/index.html">
^
</a>
</li>
<li class="page-item">
<a class="page-link" href="11.html">&raquo;</a>
</li>
</ul>
</nav>
</div>
<ul id="my_toc" class="toc list-group list-group-flush d-none d-lg-block d-xl-block p-0 ml-0 mt-3">
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#slides">Slides</a></li>
<li class="list-group-item pl-0 ml-0 border-0 pl-0 pt-0 pb-1 pr-0 m-0 mr-3"><a href="10.html#references">References</a></li>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="border-top border-bottom border-grey mt-3 pt-3">
<nav>
<ul class="pagination justify-content-center">
<li class="page-item">
<a class="page-link" href="9.html">
Previous
</a>
</li>
<li class="page-item">
<a class="page-link" href="11.html">Next</a>
</li>
<li class="page-item">
<a class="page-link" href="../lectures/index.html">
Index
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>