Can ATS support LMS style embedded compiler?

60 views
Skip to first unread message

H Zhang

unread,
Feb 8, 2015, 2:20:23 PM2/8/15
to ats-lan...@googlegroups.com
LMS stands for Lightweight Modular Staging. For a definitive guide see Tiark Rompf's Ph.D. dissertation: Lightweight Modular Staging and Embedded Compilers: Abstraction Without Regret for High-Level High-Performance Programming
I am still studying it but this seems like a very interesting approach to solve the expression problem without sacrificing performance. Let me quote from the tutorial page:

"Why Generative Programming ?

Because it enables abstraction without regret: the key idea is to write very high-level
and generic programs that generate specialized and extremely fast low-level code at runtime.

Programming abstractions that would usually be avoided in performance-sensitive code
(objects, type classes, higher-order functions) can be used during generation without
affecting performance of the generated code.

Why LMS ?

Because it is lightweight and modular: LMS is just a Scala library. With types, it distinguishes
expressions that are evaluated now (type T) vs later (type Rep[T]).

LMS comes with batteries included: it provides many optimizations such as common subexpression elimination out of the box, and it goes beyond purely generative approaches by
providing an extensible intermediate representation that can be used to implement
sophisticated domain-specific compiler pipelines.

At the same time LMS is hackable: since it is just a library, all aspects can be
modified or extended to suit a particular purpose."

I wonder if ATS's very expressive approach can support such a paradigm. For a motivational example (motivation for me anyway) see:A SQL Query Compiler. This approach is used in LegoBase to very good effect. I think it is very attractive if we can mix in relational declarative programming this way with imperative programming that can supply large amount of libraries and take care of side effects.

gmhwxi

unread,
Feb 8, 2015, 5:11:56 PM2/8/15
to ats-lan...@googlegroups.com
I took a quick look at LMS.

I feel that the template system of ATS is already a kind of LMS.
Instead of using an intermediate representation, ATS uses a small set of
C and then relies on an optimizing C compiler to get efficient object code.
Compared to LMS, the template-based approach of ATS is more
direct and flexible.

I am not familiar with compiling query languages, though.

gmhwxi

unread,
Feb 8, 2015, 5:27:04 PM2/8/15
to ats-lan...@googlegroups.com

Haitao Zhang

unread,
Feb 8, 2015, 6:04:00 PM2/8/15
to ats-lan...@googlegroups.com
Yes that is what I vaguely understood as well and why I asked the question here. However a LMS program is a user defined specializer that generates another program so you can start with a query string and end with a C program (another string). The underlying virtualized Scala is used to ensure type safety. LMS also provides facilities to rewrite the code using the IR. How can one achieve the same with ATS? ATS itself is a code transformer (at compile time) but can it also easily let users write a domain specific transformer (at run time) on their own? Can ATS's dependent type system provide a better tool?
 

--
You received this message because you are subscribed to a topic in the Google Groups "ats-lang-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ats-lang-users/vgjuDIMcXYI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ats-lang-user...@googlegroups.com.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/ats-lang-users/b3b30b9b-d081-4638-8a52-d62825990526%40googlegroups.com.

Haitao Zhang

unread,
Feb 8, 2015, 6:20:54 PM2/8/15
to ats-lan...@googlegroups.com
Also I think one of the argument for LMS is that once code is transformed into low level code (C for example) many optimization opportunities are lost esp if one starts with high level representations (high order functions, polymorphism e.g.), so their motto is "abstraction without regret". I don't know how well that can be achieved but it certainly is a very admirable goal.

On Sun, Feb 8, 2015 at 2:11 PM, gmhwxi <gmh...@gmail.com> wrote:

Hongwei Xi

unread,
Feb 8, 2015, 7:10:55 PM2/8/15
to ats-lan...@googlegroups.com
>>ATS itself is a code transformer (at compile time) but can it also easily let users write a domain specific transformer (at run time) on their own? Can ATS's dependent type system provide a better tool?

Yes, I would think so.

The type system of ATS makes it highly suitable for dealing with (typeful) syntax trees.

Also, I suppose that the compiler for a query language should itself be efficient if it is used on-line.
 

--
You received this message because you are subscribed to the Google Groups "ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ats-lang-user...@googlegroups.com.

To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at http://groups.google.com/group/ats-lang-users.

gmhwxi

unread,
Feb 8, 2015, 7:32:07 PM2/8/15
to ats-lan...@googlegroups.com
To put on the hat of a devil's advocate:

Using LMS to generate efficient C code is incredibly hard; so LMS will become more and more
complex; so people will find out later that writing efficient C code directly is probably more cost-effective.

Haitao Zhang

unread,
Feb 9, 2015, 2:40:02 AM2/9/15
to ats-lan...@googlegroups.com
RelC as described in this dissertation http://theory.stanford.edu/~aiken/publications/theses/hawkins.pdf is a good approximation of what I would like to see in synthesizing code from relational descriptions. The dissertation does not give implementation details.

On Sun, Feb 8, 2015 at 2:11 PM, gmhwxi <gmh...@gmail.com> wrote:

Haitao Zhang

unread,
Feb 9, 2015, 2:53:46 AM2/9/15
to ats-lan...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages