arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1109.0784cs.PLcs.DS
收藏

在嵌入式DSL中实现显式共享和发现隐式共享

Implementing Explicit and Finding Implicit Sharing in Embedded DSLs

Oleg Kiselyov

摘要:

别名或共享在许多领域都很突出,表示两个不同名称的对象实际上是相同的:一个对象(存储单元,电路端子,磁盘块)的变化会立即反映在另一个对象中。用于建模这些域的语言应该让程序员显式地定义对象或表达式之间的共享。DSL编译器可以找到其他相同的表达式并隐式地共享它们。这种公共子表达式的消除对于DSL的有效实现是至关重要的。共享在嵌入式DSL中是很棘手的,因为主机别名可能对应于底层对象的复制,而不是它们的共享。本教程总结了在汽车嵌入式系统和硬件描述语言的Haskell DSL中实现共享的讨论。该技术已被用于Haskell SAT求解器和DSL音乐合成。我们展示了一个简单的DSL的纯Haskell嵌入与显式共享的语言形式。DSL也有隐式共享,通过散列consing实现。显式共享大大加快了散列consing。散列consing看似命令式的本质隐藏在一个简单的组合子语言之下。整个实现仍然是纯功能的,易于推理。

英文摘要:

Aliasing, or sharing, is prominent in many domains, denoting that two differently-named objects are in fact identical: a change in one object (memory cell, circuit terminal, disk block) is instantly reflected in the other. Languages for modelling such domains should let the programmer explicitly define the sharing among objects or expressions. A DSL compiler may find other identical expressions and share them, implicitly. Such common subexpression elimination is crucial to the efficient implementation of DSLs. Sharing is tricky in embedded DSL, since host aliasing may correspond to copying of the underlying objects rather than their sharing. This tutorial summarizes discussions of implementing sharing in Haskell DSLs for automotive embedded systems and hardware description languages. The technique has since been used in a Haskell SAT solver and the DSL for music synthesis. We demonstrate the embedding in pure Haskell of a simple DSL with a language form for explicit sharing. The DSL also has implicit sharing, implemented via hash-consing. Explicit sharing greatly speeds up hash-consing. The seemingly imperative nature of hash-consing is hidden beneath a simple combinator language. The overall implementation remains pure functional and easy to reason about.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑