A New FunctionalLogic Compiler for Curry Sprite Andy
- Slides: 58
A New Functional-Logic Compiler for Curry: Sprite Andy Jost Portland State University and Synopsys, Inc. In collaboration with Sergio Antoy Supported by NSF grant #1317249 | LOPSTR: Sept. 7, 2016
≈ Haskell with logic • • Logic variables. Unification. Explicit non-determinism. Functional patterns, i. e. , functions may be applied in patterns.
Sprite is a new Curry compiler. Its goals are to demonstrate the Fair Scheme in practice, and produce better results with a simpler implementation.
i a F e h e m e h c S r T • A sound, complete, optimal, and deterministic compilation scheme. • Transforms Limited-Overlapping Inductively Sequential (LOIS) systems into equivalent rewriting systems. Curry LOIS Graph Rewriting System (Implemented in LLVM) • Can probably be extended to narrowing (not yet published).
What does fair mean? No part of a computation is neglected forever. . which leads to completeness: any result is eventually produced (given enough resources).
Fair Scheme Topics The Pull-Tab Transformation Fair Evaluation Consistent Evaluation
Fair Scheme Topics The Pull-Tab Transformation Fair Evaluation Consistent Evaluation
In a LOIS system, all non-determinism is in the choice operator. a ? b = a a ? b = b
Pull-tabbing provides a structural representation of non-determinism. easy to implement efficient parallelizable correct stepwise local
f u The Pull-Tab transformation ? a b v
? f The Pull-Tab transformation u a f b v
f u ? v a b The Pull-Tab transformation ? f u a f b v
Pull-tabbing duplicates choices. . . 1 2 ?
Pull-tabbing duplicates choices. . . so each choice is labeled with an identifier. 1 2 ? i
Fair Scheme Topics The Pull-Tab Transformation Fair Evaluation Consistent Evaluation
Fair Scheme Topics The Pull-Tab Transformation Fair Evaluation Consistent Evaluation
control block Queue ? a b Computations are arranged into a queue. computation states
? a b active An computation receives work.
? a b After a timeout, Sprite forces a context switch.
? a b After a timeout, Sprite forces a context switch.
? a b After a timeout, Sprite forces a context switch.
? a b After a timeout, Sprite forces a context switch.
? a b After a timeout, Sprite forces a context switch.
? a b After a timeout, Sprite forces a context switch.
? a b When a choice reaches the root. . .
? a b When a choice reaches the root. . . the computation forks.
a b When a choice reaches the root. . . the computation forks.
a b When a choice reaches the root. . . the computation forks.
L R a b When a choice reaches the root. . . the computation forks.
a b When a value reaches the root. . .
(print a) b When a value reaches the root. . . it is yielded.
Fair Scheme Topics The Pull-Tab Transformation Fair Evaluation Consistent Evaluation
Fair Scheme Topics The Pull-Tab Transformation Fair Evaluation Consistent Evaluation
Choice decisions must be consistent. L ? i R ? i (a duplicate of ? i )
Fingerprints hold consistency information.
i ? i a b a Discard the rightward alternative because it is inconsistent.
Implementation “How can Sprite hope to be both simple and fast? ”
A high-quality compiler infrastructure with financial support from Apple. Competitive on quality-of-results. • Co-dominant (w/ GCC) for C/C++. • An optional backend for GHC.
With LLVM, we can giving up simplify the implementation without speed.
Plus, no coupling to another language.
Let’s use LLVM!
LLVM IR L L se ! M V integer floating struct pointer branch instruction call load array vector function label store static inline extern u s ’ t Le optimizer backends x 86 Power. PC ARM GPU machine code 01101001 01010010 00010011 01000110
frontends machine code LLVM IR 01101001 01010010 00010011 01000110
Fibonacci Example Sprite LLVM DSL code LLVM IR output
The Sprite frontend 1. Convert to Flat. Curry. • Makes the pattern-matching strategy explicit. • Makes the representation uniform. 2. Compile to LLVM IR. • Defines the link from Flat. Curry to LLVM IR. • Needs a data model and evaluation strategy.
Implementation Topics Case Evaluation Fingerprint Representation
Implementation Topics Case Evaluation Fingerprint Representation
Source code Flat. Curry Implementatio n
Implementation Topics Case Evaluation Fingerprint Representation
Implementation Topics Case Evaluation Fingerprint Representation
d Fingerprint Considerations 1. The number of choices is unbounded (in principle). 2. The entire fingerprint is copied often. 3. Insertions and lookups occur frequently. Also, the fingerprint should be efficient for large and small programs.
. . Solution: Uniform-depth trees N <= 16 N <= 8 N <= 4 … 0. . 3 4. . 7 8. . 11 12. . 16 Optimizations 1. Store all leafs in a static table (256 bytes). 2. Expand trees lazily. 3. COPY-ON-WRITE semantic for branches. 0. . 3 4. . 7 … 0. . 3 Complexity 4. . 7
MCC – Implements Curry as C. • Uses backtracking. • Very fast, but not complete. PAKCS – Translates Curry to Prolog. • • Uses backtracking. Relies on built-in search for non-determinism. No control over the search strategy. Must simulate functional features. Ki. CS 2 – Translates Curry to Haskell. • Uses pull-tabbing. • Must simulate logic features.
Benchmarks Factor of Change (less means Sprite is faster)
Future work Insert a pre-LLVM optimization pass to leverage GHC: LOIS GHC Core LOIS Idea: 1. Declare choices as external functions that GHC cannot optimize. 2. Extract optimized GHC core.
Summary Sprite is a new Curry compiler. Sprite implements the Fair Scheme. Sprite uses LLVM for speed, simplicity.
- Yacc tutorial
- Cross compiler in compiler design
- Delete it
- King prawn curry or fat greasy sausages
- Scuttle costume ideas
- Barber paradox statement
- Sources of finance leaving cert business
- Methods of promoting intrapreneurship leaving cert
- Diane curry
- Curry guinn
- Stephan curry biography
- Cathy curry
- Charles curry austin tx
- Haskell curried functions
- Spook bridge quitman ga
- Terry curry msu
- Curry absn
- Haskell curry
- Doug curry
- Haskell
- Is lettuce countable or uncountable
- C# curry
- Bean costume
- Gina curry
- Oliver curry evolution
- Kellie curry
- Obey your thirst slogan
- Sprite batching
- Snake game in scratch
- Scratch pico test
- Jump over it game
- Gun sprite for scratch
- Construct 2 platformer
- Sprite skład
- Sprite outline
- What is a sprite
- Untuk merekam suara pada sprite adalah…
- How to make a bouncing ball in scratch
- Harry potter sprite for scratch
- Scratch simple game
- Fighter sprite sheet
- Severe pong game cards
- Scratch toolbar
- Sprite history acronym
- Sprite duo
- Interface scratch
- Witch sprite scratch
- Looks in scratch
- Pong sprite
- Formuö
- Typiska novell drag
- Nationell inriktning för artificiell intelligens
- Returpilarna
- Shingelfrisyren
- En lathund för arbete med kontinuitetshantering
- Kassaregister ideell förening
- Vilotidsbok
- Anatomi organ reproduksi
- Förklara densitet för barn