scieee AI-readable full text Open interactive document viewer

Concurrency primitives in Haskell

Martí I Peiró, Daniel

Full text

Concurrency primitives in Haskell Daniel Mart´ı Advisor: Jordi Petit (Computation) June 27th, 2016 Computer Engineering - Computation Barcelona School of Informatics (FIB) Polytechnic University of Catalonia (UPC BarcelonaTech) Receiving Insitution: University of Newcastle Abstract Asynchronous circuits are digital logic circuits not governed by a global clock signal. This makes them potentially more powerful, power efficient and modular in large systems. They have lots of realworld applications, although they are yet to be widely adopted in the industry. The main reason behind this is the lack of a simple way for developers to design asynchronous circuits to solve real problems. Current methods involve graphs that quickly grow in size, making development of complex systems infeasible. We were able to simplify and modernize the process by allowing developers to formally define their circuit in a way that is understandable and maintainable. This new method is also compatible with state of the art tools like Worcraft for the circuits to become real hardware. Contents 1 Introduction 4 1.1 Asynchronous circuits . . . . . . . . . . . . . . . . . . . . . . . 4 1.2 Anewapproach.......................... 4 1.3 Location and context . . . . . . . . . . . . . . . . . . . . . . . 5 1.4 Personal motivation . . . . . . . . . . . . . . . . . . . . . . . . 6 2 Scope 7 2.1 Objectives............................. 7 2.2 Obstacles ............................. 7 2.2.1 Domain Specific Language (DSL) . . . . . . . . . . . . 7 2.2.2 Workcraft ......................... 7 2.3 Outsideofscope.......................... 8 3 Methodology 9 3.1 Sourcecontrol........................... 9 3.2 Test-driven development . . . . . . . . . . . . . . . . . . . . . 9 3.3 Continuous integration . . . . . . . . . . . . . . . . . . . . . . 9 3.4 Directfeedback .......................... 10 3.5 Progress monitoring . . . . . . . . . . . . . . . . . . . . . . . . 10 4 Temporal planning 11 4.1 Description of tasks . . . . . . . . . . . . . . . . . . . . . . . . 11 4.1.1 Viability tests . . . . . . . . . . . . . . . . . . . . . . . 11 4.1.2 Project formalization . . . . . . . . . . . . . . . . . . . 12 4.1.3 Initialsetup........................ 12 4.1.4 Porting from Launchpad . . . . . . . . . . . . . . . . . 12 4.1.5 Design........................... 12 4.1.6 Coding........................... 13 4.1.7 Finaltask ......................... 14 4.2 Alternatives............................ 14 4.2.1 DSL ............................ 14 4.2.2 Workcraft ......................... 14 4.3 Resourcesused .......................... 14 4.3.1 Hardware ......................... 14 4.3.2 Software.......................... 15 4.3.3 Other(cloud)....................... 15 1 4.4 Actionplan ............................ 15 5 Budget and sustainability 16 5.1 Budget estimation . . . . . . . . . . . . . . . . . . . . . . . . 16 5.1.1 Hardware resources . . . . . . . . . . . . . . . . . . . . 16 5.1.2 Software resources . . . . . . . . . . . . . . . . . . . . 16 5.1.3 Human resources . . . . . . . . . . . . . . . . . . . . . 17 5.1.4 Totalbudget ....................... 17 5.2 Budgetcontrol .......................... 17 5.3 Sustainability ........................... 17 5.3.1 Economic sustainability . . . . . . . . . . . . . . . . . 18 5.3.2 Social sustainability . . . . . . . . . . . . . . . . . . . . 18 5.3.3 Environmental sustainability . . . . . . . . . . . . . . . 19 6 Design 20 6.1 Command line program . . . . . . . . . . . . . . . . . . . . . . 20 6.2 Workcraftplugin ......................... 20 7 Implementation 21 7.1 From Launchpad to GitHub . . . . . . . . . . . . . . . . . . . 21 7.1.1 Porting information over . . . . . . . . . . . . . . . . . 21 7.1.2 Continuous integration . . . . . . . . . . . . . . . . . . 23 7.2 Simpleprogram.......................... 24 7.2.1 STGformat........................ 24 7.2.2 Required information . . . . . . . . . . . . . . . . . . . 25 7.2.3 Unittests ......................... 25 7.3 Input concepts at runtime . . . . . . . . . . . . . . . . . . . . 26 7.3.1 Writing a compiler . . . . . . . . . . . . . . . . . . . . 26 7.3.2 Hintlibrary ........................ 26 7.3.3 Changes to Hint . . . . . . . . . . . . . . . . . . . . . . 27 7.3.4 Changes to Concepts . . . . . . . . . . . . . . . . . . . 29 7.4 Taking the user’s circuit . . . . . . . . . . . . . . . . . . . . . 30 7.4.1 Changes to Concepts . . . . . . . . . . . . . . . . . . . 30 7.4.2 Executable binary . . . . . . . . . . . . . . . . . . . . . 32 7.5 Extensive testing of the program . . . . . . . . . . . . . . . . 33 7.6 Independent binary . . . . . . . . . . . . . . . . . . . . . . . . 33 7.7 Workcraftplugin ......................... 34 7.7.1 GHC dependency . . . . . . . . . . . . . . . . . . . . . 35 2 7.7.2 Program compilation . . . . . . . . . . . . . . . . . . . 35 7.7.3 SimplifySTG....................... 35 8 Conclusions 36 3 1 Introduction 1.1 Asynchronous circuits Asynchronous circuits are event-driven, i.e. they react to changes in a system when the changes occur [1], which may be at any point in the future. This makes them particularly useful for on-chip power management, where the ability to quickly respond to dynamically changing loads across the chip is essential for reliable operation and efficiency [2]. Signal Transition Graphs (STGs)[3] are commonly used for the specification of asynchronous circuits. To put it simply, an STG can be thought of a form of Petri Net, which is a graph with nodes (places) and vertices (transitions). An example of an STG (of a C-Element) can be seen at Figure 1. We can represent circuits using those mathematical models. There exist tools such as Petrify [4] and Mpsat [5] that take an STG of a complete controller and produce a speed-independent circuit implementation [6]. This means that one can design entire circuits and chips on a computer, and have them become real hardware. This approach to designing asynchronous circuits has poor scalability: as the system grows in complexity its monolithic specification becomes challenging to grasp and debug. STGs cannot be easily split into pieces and re-used, and thus each new design must be built from the ground up. This further adds to the design time, hence making asynchronous circuits undesirable for use in industry. Figure 1: STG of a C-element 1.2 A new approach To address this issue, researchers at the University of Newcastle propose a new method of asynchronous circuit design. The method splits a specification 4 into several parts corresponding to operational modes of the circuit (scenarios). The features, constraints and requirements of each scenario (concepts), are described in a formal notation, which is being implemented as a Domain Specific Language (DSL) embedded in Haskell [7]. Concepts can be composed and one concept can be made up of multiple smaller concepts, thus supporting the design reuse at the level of system specification. Figure 2 shows a concept for a C-Element, which is equivalent to the STG in Figure 1. A set of concepts describing the operation of a scenario is then passed to a translation program that automatically converts it into an equivalent STG, which satisfies all given concepts and can be model-checked using standard tools like Workcraft [8] as defined in [9]. When all scenarios have been translated to STGs and verified, they can be combined to produce a complete specification. All of these steps will be automatic and, ideally, transparent to the user. This project will focus on the translation program mentioned above. This program can be thought of as the missing piece - there already are tools to work with STGs and produce complete circuit specifications, such as Workcraft. As soon as our formal specification of asynchronous circuits can be automatically transformed into an STG, developers will be able to seamlessly go from a high-level formal definition to an actual circuit usable in real life. 1cElement :: a −>a−>a−>CircuitConcept a 2cElement a b c = b u ff er a c <> b uf f e r b c Figure 2: C-element concept 1.3 Location and context This project is taking place in the University of Newcastle, in Northern England. With the help of teachers from UPC BarcelonaTech, the student found that a research group in England was looking for a student to help with their research. The project was agreed upon before the arrival of the student, and the entire project is being conducted in the visiting university with the help of professor Andrey Mokhov. It should also be noted that it is the same research group that develops Workcraft. The tool is used not only in subjects and labs at Newcastle Uni- 5 versity, but also throughout many universities around Europe where circuit design is taught. 1.4 Personal motivation The student chose the location and university because he wanted to do the entirety of the project in English, not just the paper and presentation. It was also a great opportunity to improve his English skills, living and working for half a year in the country that spawned the language. As for the theme of the project, both functional programming and circuit design were of interest to the student. Moreover, these fields are filled with very talented people who offer many opportunities. In fact, Newcastle University is in close research collaboration with Microsoft, who are avid Haskell users and employ some of the most popular Haskell developers in the world. 6 2 Scope 2.1 Objectives This section will give an overview of the objectives of this project. The temporal planning will give a more in-depth, step by step description of each of the tasks and objectives in the temporal planning. The main objective of this project is to develop the translation program. Taking the high-level definition of an asynchronous circuit, it will generate an STG. It should be in a generic and useful format that can be imported and used by other tools. The secondary objective is to integrate the tool that implements this program into Workcraft. That will be done in the form of a plugin for Workcraft, written in Java. It will have to integrate well with the entire program, being able to easily import a formal definition and obtain an STG directly. 2.2 Obstacles 2.2.1 Domain Specific Language (DSL) There is plenty of design to be done, since the language is not specific enough yet. For example, signals need to be differentiated between input, output and internal signals. This is required since an STG without defined input and output signals will not be sufficient. The DSL implementation being worked on at Newcastle University will also need work. The first implementation simply allows you to define your circuit combining concepts and then simulate it. This serves a great purpose since you can actually check that your definition is correct, but it’s not what we need. The translation program needs to walk through the definition of the circuit, much like a compiler walks through an AST of a program. 2.2.2 Workcraft Since the high-level formal definition is in a Haskell DSL, the user would need an entire Haskell compiler to make use of it. GHC weighs nearly a gigabyte, so it would be best to not have it as a hard dependency on the user’s machine. 7 This is a rather big obstacle, as right now there is no way in Haskell to parse and evaluate Haskell source code without having to install GHC in its entirety - not even via a library. 2.3 Outside of scope Producing a simplified version of the STG is not part of the scope of this project. This is what existing tools such as the already mentioned Petrify do. Our tool will similarly not optimize nor treat the resulting STG in any way; this is all done on the Workcraft side, with tools like Petrify. Helping the circuit developer write better asynchronous circuits, or producing any sort of warnings if they are not well defined enough, is also not part of the project. This will be done as part of the DSL, before we grab hold of the circuit definition. 8 4.3.2 Software •Arch Linux - used in all tasks •GHC 8.0 - used in all tasks concerning Haskell •OpenJDK/JRE 1.7 - used in all tasks concerning Java •Workcraft - used to test STGs translated by hand •Gradle - used to build Workcraft 4.3.3 Other (cloud) •GitHub - Git repositories, issue tracking •Travis - Continuous integration 4.4 Action plan We already are and will continue to have weekly team meetings over lunch on Thursdays. On these, there are regular progress reports and discussion on the status of the project. They will help us keep our focus, as well as keep our mentor in the loop as to what is happening with the currently ongoing task or stage. We have defined a clear set of tasks, which we already set expiration dates for on Github. We will use these dates and the progress in the milestones to keep track of our performance and to make sure that we finish the project in the time we have. 15 5 Budget and sustainability This section treats the budget and the sustainability of the project. It contains a detailed description of the costs of the project, describing both material and human costs. As in previous sections, this budget described is subject to modifications depending on the development of the project. 5.1 Budget estimation In this section we estimate the budget needed in order to make our project possible. We are going to divide the budget in three sections, depending on the kind of resources that we are taking into account. To calculate the amortisation we are going to take into account two factors, the first one being the useful life and the second one being the fact that our project is going to last for approximately six months. 5.1.1 Hardware resources The following table contains the costs of the hardware that we are going to use in the development of the project. Product Price Useful life Amortisation Laptop 2000e4 years 250e Virtual Private Server 200e2 years 50e Total 2200e300e 5.1.2 Software resources The table 2 contains the costs of the software that we are going to use in the development of the project. Product Price Useful life Amortisation Arch Linux 0eIndefinite 0e GHC 8.0 0eIndefinite 0e OpenJDK 7 0eIndefinite 0e Latex 0eIndefinite 0e Total 0e0e 16 5.1.3 Human resources A single person will be working on the project, working on both the planning and designing aspects of it as well as all the coding and testing. All of these tasks amount to a total of 750 hours, as previously mentioned. At an hourly rate of 20e/hour, this will amount to 15.000e. 5.1.4 Total budget Using data shown in the tables above, we can use the following table to describe the total cost of the project. Concept Cost Hardware resources 300e Software resources 0e Human resources 15.000e Total 15.300e 5.2 Budget control Our budget could need a modification if the development of the project makes it impossible to follow the plan established, which is something that is likely to happen. We could have difficulties in our project, although it is unlikely that we will need any hardware resource apart from the resources that have been already listed in the budget estimations shown in the previous section. We might need more software resources, but we will probably cover those needs with free and open source software just like we have already been doing. Since we have no human resource costs, even if further programming or design hours are needed, they will come at no budget cost increases. 5.3 Sustainability In this section we are going to evaluate the sustainability of our project in three different areas: •Economic •Social •Environmental 17 5.3.1 Economic sustainability In this document we already can find an assessment of the costs of our project, taking into account both material and human resources. The cost stated in the Budget estimation section of this document could be the only cost spent in the project, since we aim to create a working program, so it should not need maintenance in the case that we do not create any update. It would be difficult to do a similar project with a lower cost. We are not spending any money on software nor on human resources, so the only way to reduce costs would be to use worse hardware. Which could be accomplished, but at the expense of worse conditions for the person doing the actual development of the project, potentially worsening its quality. We can not assure that the cost of the project would make it competitive, but we can say that it depends on how it is going to be distributed. We could make it a free application, so it would be very competitive, but then we would need a way (for example, advertisements) to get paid every time that the application is downloaded so we can recover the money invested. In the other hand, we could make it a paid application, but its price should not be high. It is not the case, but is important to remark that this project could have been executed with collaboration of companies in the hardware manufacturing industry, since they may be interested in developing an application like this very one. 5.3.2 Social sustainability The application that we are going to develop in this project is going to be used in the countries which are developed enough so that everyone can have access to a computer, since our goal is that it can be used by everyone who can have access to a decent computer. Everyone desiring to design an asynchronous circuit is going to be able to use the program resulting of the development of our project. The program gives the developer a way to design it in a simple and scalable way - before its creation he or she had to use a graph manually, which would get complex quickly and not scale well. 18 5.3.3 Environmental sustainability The resources used in the project have been detailed in the Budget estimation in this document. During all the development of our project we are going to have a laptop running. The devices used and the energy spent running them are going to be the only resources used. Knowing that, we can estimate the energy spent developing the project. We can suppose that our computer consumes an average of 40 W when we are working in the project. Since we need to use the computer in all the development of the project, which is 750 hours long, the energy we need is 30 kWh, which is equivalent to 11.3 kg of CO2. It is a moderate amount of energy, but since we need to make constant use of a computer there is no way to reduce it. 19 6 Design In this section we will come up with an outline of the program, designing both how it will work on its own as well as how it will integrate with Workcraft. 6.1 Command line program For the program to be useful as a standalone command line utility, users will have to be able to feed it input via files or standard input. That is, the circuit concepts described in the Haskell DSL. It will also have to produce its result to an output file or standard output. If the input concept is valid Haskell that compiles, the program should work correctly without any human interaction. Note that the program does not need to specifically run any checks to verify that the circuit is well defined, as that is already done thanks to the Haskell DSL. Any incorrect definition of a circuit will simply not compile. This type of input/output tool follows the Unix philosophy of doing one thing and doing it well, so it will be easy to reuse it at later stages. There are two major obstacles to face in the implementation of this program. Unfortunately, we cannot investigate them much further without diving into implementation details. Thus, these obstacles are dealt with in the implementation stage. 6.2 Workcraft plugin As stated in the project timeline, we will be writing a Workcraft plugin that will allow users to input a circuit concept defined in the Haskell DSL directly into Workcraft, obtaining an STG that they can then test, simulate and otherwise work with. Workcraft already has a number of plugins, adding up to 17. These are all built on top of the WorkcraftCore package, which provides a base and a set of interfaces to interact with the whole program and graphical interface. Thankfully, there are already a handful of plugins that simply wrap command-line binaries. For example, there already is a plugin that wraps Petrify, which we have mentioned before. This sort of plugin is rather simple, as it does not have any complicated logic in itself. Since Petrify also works on input and output files, our approach of writing the command-line program in this way will conjugate well with Workcraft. 20 7 Implementation 7.1 From Launchpad to GitHub As described in the temporal planning, one of the first key tasks will be moving Workcraft from its Launchpad [22] repository to a Github [12] one. This will simplify the workflow in the team, as Github integrates tools such as code review better. But most importantly, it will allow for the use of key components such as continuous integration via Travis. Launchpad and GitHub use different source control management systems - Bazaar [11] and Git [23], respectively. Luckily enough, a Bazaar repository is very similar to a Git one, and can be semi-automatically converted to one. The bigger problem lies in all the information on Launchpad outside of the source control, such as bug reports and milestones. Over on GitHub, we register the Tuura organization [24] where all of the research group’s code and products will live from this point onwards. 7.1.1 Porting information over To port all the information over from Launchpad, scripting will be needed. Python is the language choosen for the job, as development speed is a much higher priority than runtime performance for such a one-day tool. The key components that the software will do are as such: •Download Bazaar source repository from Launchpad •Download all bugs, blueprints and milestones from Launchpad •Convert the Bazaar repo to a Git repo •Fix all the commit author names and e-mail addresses to match commits with GitHub users properly •Assign all bugs, blueprints and milestones unique ids that will be used when importing them on GitHub •Rewrite all the Git commit messages to port all references to bugs, blueprints and milestones •Use a bot GitHub account to push the git repository 21 •Use a bot GitHub account to submit all the bugs and blueprints •Use a bot GitHub account to submit all the milestones and assign the respective issues to them In total, it took little over a week to write the tool and finish the task. The tool itself took about an hour to do the entire thing, mainly because GitHub has rate limits in place that made the tool sit around for most of the time. As one can expect, there were lots of little details that needed correction. After a handful of retries from scratch, the switch over to GitHub is done. The new repository can be found at tuura/workcraft [13]. The old and new repositories can be found at Figure 3 and Figure 4, respectively. Figure 3: Abandoned Launchpad repository [14] Figure 4: New GitHub repository [13] We also added issue and pull request templates [15], further simplifying the process for users and developers who wish to contribute. 22 7.1.2 Continuous integration As described previously in the methodology, we want to use continuous integration as part of our development process. As such, we want to set up Workcraft with Travis [16], which will let us run a number of commands or scripts at each commit and pull request. Workcraft already has some JUnit unit tests, which Travis will run. On top of these, we add: •Testing on multiple JDKs (OpenJDK 7, OracleJDK 7 and 8) •Format checks via Checkstyle [18] •Java checks via PMD [19] Keeping a consistent code format across the codebase is very important to keep the project maintainable and easy to develop, especially since there are multiple people involved. And PMD adds many static code analysis checks that many IDEs already perform, but with the advantage that no GUI is needed and especially that they can be checked by Travis. The Checkstyle configuration file for Workcraft can be found in the git repository [20], as can the PMD one [21]. 23 7.2 Simple program The main objective of this task is to get familiar with what the inputs and outputs of our program will be. The first question we should ask is how we will feed the output STG to Workcraft. 7.2.1 STG format We will use Workcraft to draw simple STGs and observe the export formats, to see which one is the correct one for us. The format should: •Be in plain text, to ease debugging and development •Be easy to generate •Not be overly verbose •Not contain any graphical nor UI information Workcraft supports multiple import and export formats for STGs. One such example is the .work format, which is the default in use when exporting an STG. It is way too complicated for our needs, though. Another format, called dotG, fits our needs. It is plaintext, only contains the STG - no graphical interface information - and it is represented in simple plain text. We can see an example of an STG in the dotG format in Figure 5. 1. model Untitled 2. inputs in1 in2 3. outputs out 4. graph 5in1+ out+ 6in1−out− 7in2+ out+ 8in2−out− 9out+ in1−in2− 10 out−in1+ in2+ 11 . marking {<out−, in1+> <out−, in2+>} 12 . end Figure 5: C-element STG in the dotG format 24 As we outlined in the required input for our translation to an STG in the dotG format, we need the arcs between all the signals (nodes). Such arcs are themselves concepts, the most basic kind - they are represented with the string >. For example, we can combine two arcs to form a buffer as seen in Figure 10. 1bu f f e r : : a −>a−>CircuitConcept a 2bu ffe r a b = r i s e a ˜>r i s e b <> f a l l a ˜>f a l l b Figure 10: Buffer concept <> is used to combine the two concepts at each end, forming a new concept. What we need to do is list all the >concepts that form any concept. As said, the simulation uses a Haskell Monoid that combines concepts by creating new concepts that AND all the components. And since it represents arcs as functions, an arbitrary concept combined with this Monoid contains a function that can simulate all the transitions and arcs, but can not list them. As such, we will develop a separate Monoid that will behave differently. Instead of representing >(arcs) as a function, it will represent them as tuples from transition to transition as seen in Figure 11. 1r i s e a ˜>r i s e b 2{− would become −} 3( Transition a True , Transition b True) 4{− and −} 5f a l l b ˜>f a l l c 6{− would become −} 7( Transition b False , Transition c False) Figure 11: Arcs as tuples Each concept will contain a list of such tuples. Then, when two concepts are to be combined in the Monoid, the lists will simply be appended. Were there to be any duplicates, we can deal with them at a later stage. This simple approach will let us parse and evaluate a concept, and then obtain all the atomic causalities or arcs from it. This was one of the obstacles described, in the DSL category. We have successfully overcome this obstacle. 31 7.4.2 Executable binary Now that we know how we will extract the needed information from a concept, we need to write an executable program similar to the simulate executable that we wrote with Hint earlier. Thankfully, we can reuse much of the code. The only difference is that when using the concept, we must use our new ”inspection” monad instead of the simulation one. Inspecting the concept also gives us the initial states of each of the signals, as that is baked into a circuit concept in our Haskell DSL. And lastly, for the list of unique signals, we are already gathering them via Hint since we needed to list them for our simulation program. Now that we have all the bits needed for our previously defined and written program, we simply have to wire it up. Figure 12 shows a sample of the usage of the program. 1$ runghc transform /Main . hs examples/Concept . hs 2. model concept 3. graph 4A+ C+ 5A−C− 6B+ C+ 7B−C− 8C+ A− 9C+ B− 10 C−A+ 11 C−B+ 12 . marking {<C−,A+> <C−,B+>} 13 . end Figure 12: Transform executable usage with a C-element This STG is complete with all the arcs and the initial states. Now we face the other obstacle defined in the DSL category - knowing which signals are input and which are output. Since STGs in Workcraft can work without this information in them, we are postponing this part as it is not a crucial part in finishing our project. Once we get the rest of key components working well, we will move on to it. 32 7.5 Extensive testing of the program As described in the timeline, we now need to set up a series of test cases with user inputs and desired outputs. The two goals here are to test for edge cases and to ensure that no current features are broken in the future, i.e. regression tests. We set these up via Cabal, so that they can be easily run via cabal test. One of the edge cases that we stumble upon is causalities involving more than two signals. So far we have only seen causalities involving two signals, which can be represented via a single arc from the first transition to the second transition. But one may specify causalities from multiple transitions into a single transition, either with the AND or the OR operand. The former can be rewritten as multiple simple causalities, which we can already handle. The latter, though, is not as simple. We will need to figure out a way to represent it in terms of simple arcs. Fortunately, though, a wide variety of circuits can be expressed in simple causalities. Only certain very specific cases need an OR causality involving more than two signals. As such, we can also delay this piece of work as it is not a key component in our tool that blocks moving forward. 7.6 Independent binary This section concerns the remaining obstacle defined when formalising this project. Now that we have developed our programs that compile and evaluate concepts using Hint, we can investigate this further. Our programs are compilers themselves, but they still depend on GHC being installed. What we want is for them to be truly static and independent - for them to work even if the running system is a Linux box only with the bare minimum installed programs and libraries, such as an interactive shell. The programs can be compiled statically, and they weigh around 50 MiB. They are still not truly independent though, as they still require a path pointing at the directory holding all the Haskell libraries (modules) that any compiled program might import. When making improvements to Hint, we already made it possible for it to take such a libdir at runtime. So we have two options: •Use the libdir from the user’s GHC setup 33 •Bundle a libdir along with our executable in a tarball The first option is a bad idea on two accounts. First, the user’s GHC version would have to match the GHC version to compile the binary, which is not portable at all. But most importantly, we would require that the user have GHC installed again, as having only a libdir does not make much sense. The second option seems like a good idea at first sight. If we were to include the base library, which includes basic modules such as Prelude, the size of our distributed tarball would rise to just under 100 MiB. But even if the increased size is acceptable, this setup would be very crippled. If the user’s concept were to use any module outside of the base package, it would simply not work. This greatly limits the possibilities of writing circuits in the form of concepts in our Haskell DSL. Having those considerations in mind, we decide to give up on the possibility to not require that the user have GHC installed. After all, if the user wants to develop circuits using Haskell, they most likely already have GHC installed or would not mind installing it. This obstacle is not overcome simply because we have deemed the disadvantages to be greater than the advantages. 7.7 Workcraft plugin As mentioned in the design stage, there already exist Workcraft plugins that simply wrap around command-line utilities that work on input and output files. One such plugin is the PetrifyPlugin. Like it, our plugin will not have much complex logic in itself. All it will do is: •Add an option to the ”Open” menu to deal with circuit concepts (Haskell files) •Feed the file to our standalone program and obtain the output STG in the dotG format •Load the STG in the dotG format into memory (Workcraft already supports the format) •Display the STG in a new work (document) on the graphical interface There are various subtleties and possible issues to take care of, though. We describe them below. 34 7.7.1 GHC dependency Since we require GHC to be installed on the user’s machine, the plugin should check whether it is installed and provide a useful error message if it isn’t. It should also point the user to instructions on how to install GHC properly on their machine. The plugin should also check what GHC version is installed in the user’s machine, to make sure that it’s new enough for it to be able to run our translating program. In particular, our use of Hint and the Concepts libraries (our Haskell DSL) means that we require at least GHC 7.8. 7.7.2 Program compilation Since our program is itself a compiler, as previously explained it will need access to a GHC setup to make use of any packages and libraries that the compiled module may use. As such, the program must be compiled in the user’s machine, since it must be compiled for the user’s platform and architecture as well as with the exact same GHC version. Since we require GHC anyway, the simplest solution is to make the plugin compile the program on first use. It should also re-compile it if the GHC version changes. 7.7.3 Simplify STG The STGs produced by our translation from a concept will often be verbose. They may have lots of unnecessary places and arcs, and there might be a simpler STG that is equivalent to it. This is exactly what Petrify does, which Workcraft already has support for via a plugin. Instead of reinventing the wheel, our plugin will depend on the Petrify plugin and make use of its features to get the STGs to be simple and understandable by the time they get shown on the user’s screen. 7.7.4 Shipping into a release and feedback The main reason behind writing a plugin is for the tool to be easily accessible through a graphical interface to all Workcraft users. As such, the plugin should get shipped into a Workcraft release along with the rest of the plugins. Once that is done, feedback can be gathered from real users, both on the Haskell DSL as well as its translation into STGs for use in Workcraft. 35 Since this document and the presentation of the project are all to be done three weeks prior to the end of the project, this final stage is not yet finished. As such, we will use our limited internal feedback on an unfinished version of the plugin to make our conclusions in the next section. 36 8 Conclusions This project was ambitious because the student had limited experience both in Haskell and in the world of circuit design. At the same time, the objectives and timeline were realistic and the potential obstacles had been in mind since the very beginning. Given that the project has followed its timeline closely and has reached its goals successfully, one can say that it has been a success. The fact that one of the obstacles hasn’t been overcome may seem like a failure, but it is not - a decision was made balancing the pros and cons of the possible solution that was found to the obstacle. The student has learned a great deal about Haskell and the world of circuit design thanks to the mentorship and help of the research group at the visiting organization. As such, this project has also been a personal success and a good learning experience. Finally, the shipped product meets its initial requirements and is actually useful, as envisioned when formalising the project. It is worth keeping in mind that the time invested in the software will be of use to researchers and students using Workcraft at many universities including Newcastle university. From our internal feedback, the tool meets its purpose correctly and does not get in the way. It is nothing too special on its own, but together with the circuit design in the Concepts DSL in Haskell it opens up new ways to design simple yet reusable circuits in the real world. 37 References [1] Jens Sparsø and Stephen B Furber. Principles of asynchronous circuit design: a systems perspective. Springer Netherlands, 2001. [2] Jonathan Audy. Navigating the path to a successful IC switching regulator design. Tutorial at IEEE International Solid-State Circuits Conference (ISSCC), 2008. [3] A. Yakovlev, L. Lavagno,. A unified signal transition graph model for asynchronous control circuit synthes ICCAD, 1992. [4] J. Cortadella, M. Kishinevsky, A. Kondratyev, L. Lavagno, and A. Yakovlev. Logic Synthesis for Asynchronous Controllers and Interfaces. Springer, 2002. [5] Victor Khomenko, Maciej Koutny, and Alex Yakovlev. Detecting state encoding conflicts in STG unfoldings using SAT. Fundamenta Informaticae, 62(2):221-241, 2004. [6] W. Bartky D. Muller. A theory of asynchronous circuits. International Symposium of the Theory of Switching, 1959. [7] P. Hudak. Building domain-specific embedded languages. ACM Computing Surveys, 28(4):196, 1996. [8] http://www.workcraft.org/, March 2016 [9] Ivan Poliakov, Victor Khomenko, and Alex Yakovlev. Workcraft - a framework for interpreted graph models. In Applications and Theory of Petri Nets (ATPN), pages 333-342. Springer, 2009. [10] http://upx.sourceforge.net/, March 2016 [11] http://bazaar.canonical.com/en/, April 2016 [12] https://github.com/, April 2016 [13] https://github.com/tuura/workcraft, April 2016 [14] https://launchpad.net/workcraft, April 2016 38 [15] https://github.com/blog/2111-issue-and-pull-request-templates, April 2016 [16] https://travis-ci.org/, April 2016 [17] https://travis-ci.org/tuura/workcraft, April 2016 [18] https://github.com/checkstyle/checkstyle, April 2016 [19] https://github.com/pmd/pmd, April 2016 [20] https://github.com/tuura/workcraft/blob/v3.1.0/config/ checkstyle/checkstyle.xml, April 2016 [21] https://github.com/tuura/workcraft/blob/v3.1.0/config/pmd/ rules.xml, April 2016 [22] https://launchpad.net/workcraft, March 2016 [23] https://git-scm.com/, April 2016 [24] https://github.com/tuura, March 2016 [25] https://hackage.haskell.org/package/hint, April 2016 [26] http://hub.darcs.net/jcpetruzza/hint, April 2016 [27] https://github.com/mvdan/hint, April 2016 [28] https://hackage.haskell.org/package/ghc-paths, April 2016 [29] https://github.com/tuura/concepts, April 2016 [30] https://www.haskell.org/cabal/, April 2016 39