Integrating Haskell to.NET André Santos / Monique Monteiro Rotor Workshop Sep 2005 - MSR.

Slides:



Advertisements
Similar presentations
AGVISE Laboratories %Zone or Grid Samples – Northwood laboratory
Advertisements

ALAK ROY. Assistant Professor Dept. of CSE NIT Agartala
EuroCondens SGB E.
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
The Art of Avoiding Work
Addition and Subtraction Equations
Disability status in Ethiopia in 1984, 1994 & 2007 population and housing sensus Ehete Bekele Seyoum ESA/STAT/AC.219/25.
© 1998, Progress Software Corporation 1 Migration of a 4GL and Relational Database to Unicode Tex Texin International Product Manager.
1 Copyright © 2005, Oracle. All rights reserved. Introducing the Java and Oracle Platforms.
6 Copyright © 2005, Oracle. All rights reserved. Building Applications with Oracle JDeveloper 10g.
Add Governors Discretionary (1G) Grants Chapter 6.
CALENDAR.
A Fractional Order (Proportional and Derivative) Motion Controller Design for A Class of Second-order Systems Center for Self-Organizing Intelligent.
Numerical Analysis 1 EE, NCKU Tien-Hao Chang (Darby Chang)
The basics for simulations
EE, NCKU Tien-Hao Chang (Darby Chang)
Linear Lists – Linked List Representation
Modern Programming Languages, 2nd ed.
Chapter 1 Object Oriented Programming 1. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
SYMBOL TABLES &CODE GENERATION FOR EXECUTABLES. SYMBOL TABLES Compilers that produce an executable (or the representation of an executable in object module.
1 Lecture 16: Tables and OOP. 2 Tables -- get and put.
2007 Pearson Education, Inc. All rights reserved C Structures, Unions, Bit Manipulations and Enumerations.
2000 Deitel & Associates, Inc. All rights reserved. Chapter 16 – Bits, Characters, Strings, and Structures Outline 16.1Introduction 16.2Structure Definitions.
Chapter 10: Virtual Memory
Numerical Analysis 1 EE, NCKU Tien-Hao Chang (Darby Chang)
pa 1 Porting BETA to ROTOR ROTOR Projects Presentation Day, June by Peter Andersen.
Introduction to Compilation of Functional Languages Wanhe Zhang Computing and Software Department McMaster University 16 th, March, 2004.
MaK_Full ahead loaded 1 Alarm Page Directory (F11)
Procedures. 2 Procedure Definition A procedure is a mechanism for abstracting a group of related operations into a single operation that can be used repeatedly.
Part IV: Memory Management
Before Between After.
Chapter 9: Data Structures I
Chapter 9 Interactive Multimedia Authoring with Flash Introduction to Programming 1.
Types of selection structures
Static Equilibrium; Elasticity and Fracture
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 13 Pointers and Linked Lists.
1 Non Deterministic Automata. 2 Alphabet = Nondeterministic Finite Accepter (NFA)
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Based on Mike Feeley’s and Tamara Munzner’s original slides; Modified by George Tsiknis Parameters and Local Variables Relevant Information CPSC 213 Companion.
Schutzvermerk nach DIN 34 beachten 05/04/15 Seite 1 Training EPAM and CANopen Basic Solution: Password * * Level 1 Level 2 * Level 3 Password2 IP-Adr.
CPU Review and Programming Models CT101 – Computing Systems.
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
1 Compiler Construction Intermediate Code Generation.
CS 312 Spring 2004 Lecture 18 Environment Model. Substitution Model Represents computation as doing substitutions for bound variables at reduction of.
Previous finals up on the web page use them as practice problems look at them early.
CS 312 Spring 2002 Lecture 16 The Environment Model.
Run time vs. Compile time
Introduction to .Net Framework
JVM And CLR Dan Agar April 16, Outline Java and.NET Design Philosophies Overview of Virtual Machines Technical Look at JVM and CLR Comparison of.
.NET Framework & C#.
JIT in webkit. What’s JIT See time_compilation for more info. time_compilation.
C++ for Engineers and Scientists Second Edition Chapter 6 Modularity Using Functions.
Lecture 10 : Introduction to Java Virtual Machine
CPSC 388 – Compiler Design and Construction Runtime Environments.
Replay Compilation: Improving Debuggability of a Just-in Time Complier Presenter: Jun Tao.
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
Virtual Machines, Interpretation Techniques, and Just-In-Time Compilers Kostis Sagonas
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
PRIOR TO WEB SERVICES THE OTHER TECHNOLOGIES ARE:.
Md. Zahurul Islam Center for Research on Bangla Language Processing (CRBLP) BRAC University.
Haskell With Go Faster Stripes Neil Mitchell. Catch: Project Overview Catch checks that a Haskell program won’t raise a pattern match error head [] =
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
Type Checking and Type Inference
The University of Adelaide, School of Computer Science
CS360 Windows Programming
Stack Frame Linkage.
Course Overview PART I: overview material PART II: inside a compiler
RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science
CSc 453 Interpreters & Interpretation
Presentation transcript:

Integrating Haskell to.NET André Santos / Monique Monteiro Rotor Workshop Sep MSR

Motivation Advantages of having Haskell compiler for the.NET platformAdvantages of having Haskell compiler for the.NET platform –Easier interop with other languages –Stronger integration of Haskell to.NET components and tools –Performance –Limitation of previous implementations

Related work Previous Haskell implementations for.NETPrevious Haskell implementations for.NET –Little or no documentation –Partial implementations –(very) limited availability and documentation Implementation of other functional languages for.NETImplementation of other functional languages for.NET –Scheme, F#, SML.NET, Mondrian, etc. –But Haskell is a lazy functional language Implementations of Haskell for the JVMImplementations of Haskell for the JVM

JVM x.NET CLR Focus on OO Languages Focus on language interoperability Support for tail calls Support for function pointers JVM CLR

Main Design Decisions Evaluation strategyEvaluation strategy –uses push/enter model (instead of eval/apply) Data types representationData types representation –Use common container classes (instead of Classes for each constructor of each Haskell datatype) Closure representationClosure representation

Closure Representation One class per closureOne class per closure –Large number of classes: (expected) high overhead for class loading, verification routines, etc. Classes with Function PointersClasses with Function Pointers –Unverifiable code DelegatesDelegates –Type-safe –Better performance in.NET 2.0

One class / closure public class Closure_302 : Closure { public Closure value; public static Closure enter(){ // if value is available // return it // otherwise evaluate specific closure code, update it and return it } public class Closure_302 : Closure { public Closure value; public static Closure enter(){ // if value is available // return it // otherwise evaluate specific closure code, update it and return it }

Common closure class public class Closure : Delegate { public Closure value; public static IClosure Enter(){ // if value is available return it // otherwise save stacks state, evaluate (call to Delegate.Invoke), // update value, restore stacks state and return value... } } public class Closure : Delegate { public Closure value; public static IClosure Enter(){ // if value is available return it // otherwise save stacks state, evaluate (call to Delegate.Invoke), // update value, restore stacks state and return value... } }

Closure Representation Updateable closuresUpdateable closures –Keep a value field Non-updateable closuresNon-updateable closures –Keep an arity field –Keep a partial application field to encapsulate received arguments Both keep the free variablesBoth keep the free variables –Set to null after update Delegates point to the slow entry pointDelegates point to the slow entry point –Slow entry point X fast entry point

Runtime System - Closures

Example: map function map = {} \n {f,l} -> case l of Nil {} -> Nil {} Cons {x,xs} -> let fx = {f,x} \u {} -> f {x} fxs = {f,xs} \u {} -> map {f,xs} in Cons {fx,fxs} map = {} \n {f,l} -> case l of Nil {} -> Nil {} Cons {x,xs} -> let fx = {f,x} \u {} -> f {x} fxs = {f,xs} \u {} -> map {f,xs} in Cons {fx,fxs}

Example: generated code public static IClosure map(NonUpdatable clo){... } public static IClosure map(IClosure f,IClosure l){ Pack scrutinee = (Pack)l.Enter(); switch(scrutinee.tag){ case 1: return new Pack(1); case 2: Pack_2 cons = (Pack_2 ) scrutinee; IClosure x = cons.arg1; IClosure xs = cons.arg2; Updateable_2_FV fx_closure = new Updateable_2_FV(fx); fx_closure.fv1 = f; fx_closure.fv2 = x; Updateable_2_FV mfxs_closure = new Updateable_2_FV (mfxs); mfxs_closure.fv1 = f; mfxs_closure.fv2 = xs ; return new Pack_2 (2, fx_closure, mfxs_closure); } public static IClosure map(NonUpdatable clo){... } public static IClosure map(IClosure f,IClosure l){ Pack scrutinee = (Pack)l.Enter(); switch(scrutinee.tag){ case 1: return new Pack(1); case 2: Pack_2 cons = (Pack_2 ) scrutinee; IClosure x = cons.arg1; IClosure xs = cons.arg2; Updateable_2_FV fx_closure = new Updateable_2_FV(fx); fx_closure.fv1 = f; fx_closure.fv2 = x; Updateable_2_FV mfxs_closure = new Updateable_2_FV (mfxs); mfxs_closure.fv1 = f; mfxs_closure.fv2 = xs ; return new Pack_2 (2, fx_closure, mfxs_closure); } Slow entry point Fast entry point Nil tag Cons tag

Implementation Decisions Use existing optimizing compiler for HaskellUse existing optimizing compiler for Haskell –The Glasgow Haskell Compiler – GHC –STG Intermediate representation Language Generate code in CILGenerate code in CIL –No support for explicit tail-calls from C# –Cannot extend (Multicast)delegate class from C#

Current Status Support for parts of the Haskell preludeSupport for parts of the Haskell prelude –(GHC) modules Base, List, Num, Show, Real, Enum, … Currently performing tests and performance evaluation using some programs from Nofib Benchmark suiteCurrently performing tests and performance evaluation using some programs from Nofib Benchmark suite Limited performance results so farLimited performance results so far

Execution Times GHC.NETNative GHC.NET/Native Digits_e Digits_e2 13, Exp Primes Queens Wheel-sieve Wheel-sieve Tak CAFs (top-level constants)

Some Profiling Results CAFs (updateable closure + value) lead to long-lived objects (Gen 2) and large memory consumptionCAFs (updateable closure + value) lead to long-lived objects (Gen 2) and large memory consumption Delegates are the largest objectsDelegates are the largest objects Delegate constructors have the highest cost among runtime system methodsDelegate constructors have the highest cost among runtime system methods

Main Difficulties In-place updating is not supportedIn-place updating is not supported –It is not possible to store pointers to references Tail-callsTail-calls –Its not clear in which situations they are supported by the execution system Delegates? Virtual methods? Method in other assemblies?Delegates? Virtual methods? Method in other assemblies? –Disabled in fully-trusted environments

Main Difficulties CLR stack limitations:CLR stack limitations: –Push/enter approach requires the direct management of a stack for handling calls to unknown functions –Separate stack(s) had to be implemented –Possible solution: eval/apply approach

Main Difficulties.NET 2.0 in Beta version.NET 2.0 in Beta version Limited profiling tools for.NET 2.0Limited profiling tools for.NET 2.0 Rotor for.NET 2.0 is not available yetRotor for.NET 2.0 is not available yet Calls to C routines in Prelude modulesCalls to C routines in Prelude modules –implement.NET FFI convention

Next Steps Fix the CAF problemFix the CAF problem Evaluate changes in delegates inheritanceEvaluate changes in delegates inheritance Investigate tail-calls and their limitations/overhead in.NET 2.0Investigate tail-calls and their limitations/overhead in.NET 2.0 Extend Rotor with support for ClosuresExtend Rotor with support for Closures Investigate ways of exposing Haskell code to other.NET languages and vice-versaInvestigate ways of exposing Haskell code to other.NET languages and vice-versa

References MONTEIRO, M. L. B., ARAUJO, M., BORGES, R., SANTOS, A. Compiling Non-Strict Functional Languages for the.NET Platform. Journal of Universal Computer Science, v.11, n.7, p , 2005.MONTEIRO, M. L. B., ARAUJO, M., BORGES, R., SANTOS, A. Compiling Non-Strict Functional Languages for the.NET Platform. Journal of Universal Computer Science, v.11, n.7, p , 2005.

Questions? André Santos / Monique Monteiro