• No results found

Generic programming in the mCRL2 toolset

N/A
N/A
Protected

Academic year: 2021

Share "Generic programming in the mCRL2 toolset"

Copied!
4
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

Generic programming in the mCRL2 toolset

Citation for published version (APA):

Wesselink, J. W., Wulp, van der, J., & Keiren, J. J. A. (2010). Generic programming in the mCRL2 toolset. In F. Gervais, & B. Fraikin (Eds.), Informal Proceedings of the 1st Workshop on Tool Building in Formal Methods (TBFM'10, Orford, Québec, Canada, February 22, 2010; in conjunction with ABZ 2010) (pp. 1-3)

Document status and date: Published: 01/01/2010

Document Version:

Publisher’s PDF, also known as Version of Record (includes final page, issue and volume numbers)

Please check the document version of this publication:

• A submitted manuscript is the version of the article upon submission and before peer-review. There can be important differences between the submitted version and the official published version of record. People interested in the research are advised to contact the author for the final version of the publication, or visit the DOI to the publisher's website.

• The final author version and the galley proof are versions of the publication after peer review.

• The final published version features the final layout of the paper including the volume, issue and page numbers.

Link to publication

General rights

Copyright and moral rights for the publications made accessible in the public portal are retained by the authors and/or other copyright owners and it is a condition of accessing publications that users recognise and abide by the legal requirements associated with these rights. • Users may download and print one copy of any publication from the public portal for the purpose of private study or research. • You may not further distribute the material or use it for any profit-making activity or commercial gain

• You may freely distribute the URL identifying the publication in the public portal.

If the publication is distributed under the terms of Article 25fa of the Dutch Copyright Act, indicated by the “Taverne” license above, please follow below link for the End User Agreement:

www.tue.nl/taverne

Take down policy

If you believe that this document breaches copyright please contact us at:

openaccess@tue.nl

providing details and we will investigate your claim.

(2)

Generic programming in the mCRL2 tool set

Wieger Wesselink, Jeroen van der Wulp and Jeroen Keiren

Technische Universiteit Eindhoven

Department of Mathematics and Computer Science P.O. Box 513, 5600 MB Eindhoven, The Netherlands

{j.w.wesselink, j.j.a.keiren}@tue.nl, jeroen.vanderwulp@gmail.com

1

Introduction

The mCRL2 tool set [GKM+08] is a tool set for verification and validation

of concurrent processes, based on process algebra specifications. The mCRL2 language is based on the Algebra of Communicating Processes (ACP), which is extended to include data and time. This paper reports on experiences with generic programming in C++ as applied in the implementation of the tool set. C++ concepts, a type system for templates [RS06], form a key ingredient of this style of programming. Using concept definitions, requirements on template types can be defined that are type checked during compile time. The main benefits for the mCRL2 tool set are uniform and flexible interfaces that operate on well-defined types, and a significant increase in code reuse. The use of concepts also promotes the writing of code that corresponds closely to pseudo code, since the chosen concepts correspond naturally with domain specific concepts. This will be illustrated by a simple use case, namely substitution functions.

Generic programming is about generalizing software components, to enable reuse in a wide variety of situations. In C++, generic programming is enabled using templates. C++ concepts are proposed as a means to type check template types. A concept is a set of requirements (valid expressions, associated types, semantic invariants, complexity guarantees, and so on) that a type must fulfill to be correctly used as an argument in a call to a generic algorithm, see [RS06]. Language support for concepts has been proposed [GJS+06] for the next version

of the C++ standard, C++0x. Concepts will be used to make the specification of the C++ standard library more complete and precise. A derivative of the GNU C++ compiler [Gre08] already implements language support for concepts. In the mCRL2 tool set we have used a portable library for concept checking.

Most uses of generic programming in general, and more specifically the use of concepts, that are described in the literature treat the construction of data structures and algorithms that operate on these, see e.g. [GL05].

2

The mCRL2 tool set

The mCRL2 tool set stores data structures like state spaces and parameterized boolean equation systems using terms. A frequent operation in algorithms on

(3)

2

these data structures is substitution on terms. A substitution concept has been defined, and applied throughout the tool set, together with a traversal framework for data structures. This has made quite a number of existing replace functions on terms obsolete, and many more ad hoc solutions for less general substitution problems as well. The introduction of the substitution concept has also opened the way to easily experiment with different implementations of substitution func-tions, instead of with a fixed number of predefined ones. C++ concepts have been applied at several other places. We have, for example, defined a rewriter concept that has helped to make the term rewriter fully replaceable.

3

Example

By means of example we take the substitution concept that has been defined in the tool set. A substitution is a function that maps variables from a domain V to terms of a range T. Let x be a variable, t a term, and σ : V → T a substitution that models a Substitution concept, that has the following requirements:

– Substitution::variable type is a valid C++ type – Substitution::term type is a valid C++ type

– σ(x) is a valid expression of type Substitution::term type – σ[x] = t is a valid C++ expression

The first three requirements correspond to the ordinary mathematical func-tion concept. We have used the domain specific names variable type and term type instead of the usual names argument type and result type. The third requirement defines the syntax for function application and expresses that the function call operator must be overloaded. The last requirement applies to mutable substitutions, and defines the syntax for updating a substitution. The semantics of the statement σ[x] = t is that σ := σ[x → t], where σ[x → t](y) = t if y = x and σ[x → t](y) = σ(y) otherwise.

An algorithm that takes an argument σ that models the Substitution con-cept, can only rely on the four requirements that are given here. Using a tech-nique called concept checking one can detect at compile time if an argument type satisfies all these requirements. Moreover, one can easily test if an algo-rithm does not inadvertently use other properties of a type. As an example we consider the implementation of a function f that applies the substitution x := t to a process p:

void f(process &p, variable x, term t) {

substitution sigma; // use a predefined map based substitution class sigma[x] = t; // add the substitution x -> t to sigma

substitute(p, sigma); // apply sigma globally to terms in p }

Here substitute is a generic function with the following interface:

template <typename Object, typename Substitution> void rewrite(Object& o, Substitution sigma);

(4)

3

It applies σ to an object o that may be one of the mCRL2 data structures containing terms. Overloads have been added for C++ standard containers and mCRL2 specific containers containing elements of these data structures. To im-plement the substitute function a reusable traversal framework for hierarchical mCRL2 data structures has been defined.

4

Discussion

The substitution concept that was discussed in the previous section may look deceptively simple. Applying this concept globally however has lead to a remark-able cleanup of the code. At many places interfaces have become simpler and at the same time more generic. Virtually all of the more complicated and less generic solutions for substitutions could be removed. An interesting and chal-lenging application was the definition of a term rewriter concept. Applying this concept globally took a significant effort, caused by problems in the existing in-terface. The result of this operation is that many algorithms in the mCRL2 tool set that require a rewriter for their computations have been parameterized with a Rewriter template argument. This has significant advantages. First of all it opens the possibility to experiment with different implementations of a rewriter without having to modify the code of these algorithms. This is useful for instance for doing benchmarks. Another advantage of using concepts in the interfaces of algorithms is the explicit documentation of type requirements. Having clear se-mantics of types is a necessary step towards making correct implementations. Finally, the usage of concepts promotes the writing of clean code that corre-sponds almost one to one to pseudo code descriptions of algorithms. For many algorithms in the mCRL2 tool set descriptions in pseudo code are available.

Concluding we can say that the application of generic programming tech-niques in the mCRL2 tool set attributes to increased productivity through uni-form and flexible interfaces, and to decreased maintenance costs through an increased level of reuse of code written at a higher level of abstraction.

References

[GJS+06] D. Gregor, J. J¨arvi, J. Siek, B. Stroustrup, G. Dos Reis, and A. Lumsdaine. Concepts: Linguistic support for generic programming in C++. In Proc. OOPSLA’06, pages 291–310. ACM Press, October 2006.

[GKM+08] J.F. Groote, J. Keiren, A. Mathijssen, B. Ploeger, F. Stappers, C. Tankink, Y. Usenko, M. van Weerdenburg, W. Wesselink, T. Willemse, and J. van der Wulp. The mCRL2 toolset. In Proc. WASDeTT’08), 2008.

[GL05] R. Garcia and A. Lumsdaine. MultiArray: a C++ library for generic pro-gramming with arrays. Softw., Pract. Exper., 35(2):159–188, 2005. [Gre08] D. Gregor. ConceptGCC — a prototype compiler for cpp

con-cepts. http://www.generic-programming.org/software/ConceptGCC/, January 2008.

[RS06] G. Dos Reis and B. Stroustrup. Specifying c++ concepts. In Proc. POPL’06, pages 295–308, New York, NY, USA, 2006. ACM.

Referenties

GERELATEERDE DOCUMENTEN

A valuation consists of a set of variable to value mappings, which is represented by σ in the deduction rules. In the meta notation we model a data valuation in two separate ways.

(2010): Modeling and reconfiguration of critical business processes for the purpose of a business continuity management respecting security, risk and compliance requirements at

Example 4.4 Consider a set of natural numbers s : Set (N).. In order to not overly complicate the data language, a conscious decision was made to forbid width-subtyping of

That model con- tains two Manager threads (which corresponds with a thread pool of size 2), one container and two components.. Note that more instances of these processes can be

The key to more understandable and reliable implementations, as well as a more swift development process lie in a high level of abstraction in the code and (more) detailed design

Financial analyses 1 : Quantitative analyses, in part based on output from strategic analyses, in order to assess the attractiveness of a market from a financial

3.3.10.a Employees who can submit (a) medical certificate(s) that SU finds acceptable are entitled to a maximum of eight months’ sick leave (taken either continuously or as

Now perform the same PSI blast search with the human lipocalin as a query but limit your search against the mammalian sequences (the databases are too large, if you use the nr