Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » OCL » Custom implementation of OCLstdlib(Extending a subset of default standard library)
Custom implementation of OCLstdlib [message #1800531] Tue, 01 January 2019 17:21 Go to next message
Sina MadaniFriend
Messages: 160
Registered: November 2015
Location: York, UK
Senior Member
Hi Ed,

I was wondering whether it is possible to provide a custom implementation for a subset of the operations in the standard library and if so, whether there is any documentation for it. In particular, I am interested in the iteration-based operations such as forAll, exists, select etc. as well as sum() and product(). I see that the PivotUtil.createOperation method allows to specify an implementation class, and I was wondering whether there are any requirements for custom implementation (e.g. is it mandatory that all first-order operations which have a for / while loop extend from AbstractIteration), and also what is the cleanest way to delegate to a custom implementation, since OCLstdlib is auto-generated and I only want to re-implement a subset of the standard library.

My motive for doing this is to make the operations parallel, and I wanted to see if OCL presents any impediments to parallel execution (in theory there is nothing in the specification which precludes this). If all is well then I'll compare the performance of sequential vs parallel as well as to Epsilon sequential vs parallel.

Kind Regards,
Sina
Re: Custom implementation of OCLstdlib [message #1800533 is a reply to message #1800531] Tue, 01 January 2019 18:17 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

In principle you can have other libraries and you will find that GIT\org.eclipse.ocl\tests\org.eclipse.ocl.examples.xtext.tests\models\oclstdlib\minimal.oclstdlib has evolved to contain enough to stop a few minimal tests blowing up. You might search for references.

The above tests demonstrate that it can be done, but https://bugs.eclipse.org/bugs/show_bug.cgi?id=415146 is an open bug on providing documentation and the discussion highlights that providing a math.oclstdlib was not as easy as I hoped. A few relevant bugs have been fixed since then so it might be easier now.

You will find that many of the Pivot OCL caches have 'synchronized' in the code. This is an indication of what needs to be worried about. It in no way indicates that the 'synchronized' was ever right or is still right. IMHO this kind of threadsafe code can only be genuinely threadsafe if autogenerated. On my stack of things to do, but not 'this' year.

Any implementation you extract performance information from will be embarrassing to the original authors, since for both Epsilon and Pivot OCL, functionality has been higher priority than speed and with limited resources, optimization has been severely neglected. Each new test I do uncovers an area where I could do much, often very much, better.

For OCL/EOL, but not QVTd/ETL there is a problem of knowing what the totality of user execution is. This tends to inhibit global analysis/optimization. QVTd has some global analyses of the transformation, and of the loaded input model. These can help, but there is a lot more that can be done.

If you come up with something that 'works', I might take a shot at optimizing it so that your results can present today's state of the art and an indication of typical deficiencies.

OCL typically requires full evaluation since you must guarantee that no invalid is overlooked. The Pivot OCL has quite a bit of static analysis that can prove that invalid is impossible allowing short-circuiting. Safe navigation is the hardest bit and is there; accurate for simple and some not-so-simple cases, pessimistic for horrible cases. Divide by zero etc are easy but missing. Index-out-of-range has an easy pessimistic solution but needs more work to detect that size() expressions give ok-indexes; this functionality is missing.

Regards

Ed Willink
Re: Custom implementation of OCLstdlib [message #1800534 is a reply to message #1800533] Tue, 01 January 2019 18:21 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

In principle you just need a custom version of: /org.eclipse.ocl.pivot/model/OCL-2.5.oclstdlib and all replaced classes.

Regards

Ed Willink
Re: Custom implementation of OCLstdlib [message #1800538 is a reply to message #1800534] Tue, 01 January 2019 19:44 Go to previous messageGo to next message
Sina MadaniFriend
Messages: 160
Registered: November 2015
Location: York, UK
Senior Member
Hi Ed,

Thank you for your insights and advice. It seems that it is non-trivial to extend the existing standard library without recompiling / regenerating the code, even though the actual implementations of, e.g. org.eclipse.ocl.pivot.library.iterator.* don't seem to be generated (there are no @Generated annotations even in generated code, but there are no comments stating that the actual operation implementations are generated).
Unless there is an alternative extensible version of org.eclipse.ocl.pivot.model.OCLstdlib where individual operations can be replaced or a similar facility I probably will not get around to it. I only wondered because the documentation indicates that OCLstdlib is extensible but it is not clear how. Also there is a typo: "Stndard" in "OCL or Pivot Programmers Guide" section.

Thanks,
Sina
Re: Custom implementation of OCLstdlib [message #1800551 is a reply to message #1800538] Wed, 02 January 2019 09:27 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

You don't seem to be trying very hard. You are not actually trying to extend, you are replacing which is really easy.

GIT\org.eclipse.ocl\examples\org.eclipse.ocl.examples.build\.launches\Generate OCL OCLstdlib Model.launch uses GIT\org.eclipse.ocl\examples\org.eclipse.ocl.examples.build\src\org\eclipse\ocl\examples\build\GenerateOCLstdlibModel.mwe2 to generate the built library. You just need to clone these and edit names to suit your variant of GIT\org.eclipse.ocl\plugins\org.eclipse.ocl.pivot\model\OCL-2.5.oclstdlib. Thereafter just invoke MyOCLstdLib.install() very early (and confirm that MyOCLstdLib rather than OCLstdlib is used). QVTd has an extension library that also uses these scripts, so you could try to declare an extension, but there is no support for an extension mutating.

The *.oclstdlib is just a set of declarations for underlying Java so it ought to be possible to just declare your variant *.oclstdlib just as the minimal.oclstdlib is in some tests.

Regards

Ed Willink

Previous Topic:Eclipse OCL latest P2 repos
Next Topic:Use OCL to validate non-Ecore objects at runtime
Goto Forum:
  


Current Time: Sat Apr 20 00:58:26 GMT 2024

Powered by FUDForum. Page generated in 0.03200 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top