Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [CLOSED] How to optimize generated code?
[CLOSED] How to optimize generated code? [message #1737558] Sat, 09 July 2016 19:12 Go to next message
Eclipse UserFriend
Hi all.

In my DSL, I have:
protected def caller {
     getSkill(C1).myfunction(Integer)
     getSkill(C1).myfunction(Float, 1)
     getSkill(C1).myfunction(String, 2, 3)
}


The generated Java code is:
protected void caller() {
    C1 _skill = this.getSkill(C1.class);
    _skill.myfunction(Integer.class);
    C1 _skill_1 = this.getSkill(C1.class);
    _skill_1.myfunction(Float.class, 1);
    C1 _skill_2 = this.getSkill(C1.class);
    _skill_2.myfunction(String.class, 2, 3);
  }


In the generated code, the three variables _skill, _skill_1, _skill_2 are pointing to the same C1 instance; because there is no setSkill call.

I would like to know if the Xbase expression generator is able to optimize the generated Java code? Is a documentation that explain optimization of the generated code?

At the end I would like to obtain:
protected void caller() {
    C1 _skill = this.getSkill(C1.class);
    _skill.myfunction(Integer.class);
    _skill.myfunction(Float.class, 1);
    _skill.myfunction(String.class, 2, 3);
  }


Thank you.
Stéphane.

[Updated on: Mon, 11 July 2016 07:09] by Moderator

Re: How to optimize generated code? [message #1737563 is a reply to message #1737558] Sun, 10 July 2016 01:28 Go to previous messageGo to next message
Eclipse UserFriend
Hi

In Java, the optimization you request is unsafe and so invalid for two
reasons:

a) getSkill() might have a side effect, e.g. a static counter of the
number of calls
b) there is no synchronize to inhibit a context switch to another thread
that mutates this (e.g. does setSkill())

If you want this CSE optimization to be reliable, you need to use a
technology such as OCL that is transitively side-effect free.

I think that Xbase has some abilities to exploit no side effects, but
they depend on programmer discipline rather than language principles.

Regards

Ed Willink



On 10/07/2016 00:12, Stephane Galland wrote:
> Hi all.
>
> In my DSL, I have:
>
> protected def caller {
> getSkill(C1).myfunction(Integer)
> getSkill(C1).myfunction(Float, 1)
> getSkill(C1).myfunction(String, 2, 3)
> }
>
>
> The generated Java code is:
>
> protected void caller() {
> C1 _skill = this.getSkill(C1.class);
> _skill.myfunction(Integer.class);
> C1 _skill_1 = this.getSkill(C1.class);
> _skill_1.myfunction(Float.class, 1);
> C1 _skill_2 = this.getSkill(C1.class);
> _skill_2.myfunction(String.class, 2, 3);
> }
>
>
> In the generated code, the three variables _skill, _skill_1, _skill_2
> are pointing to the same C1 instance; because there is no setSkill call.
>
> I would like to know if the Xbase expression generator is able to
> optimize the generated Java code? Is a documentation that explain
> optimization of the generated code?
>
> At the end I would like to obtain:
>
> protected void caller() {
> C1 _skill = this.getSkill(C1.class);
> _skill.myfunction(Integer.class);
> _skill.myfunction(Float.class, 1);
> _skill.myfunction(String.class, 2, 3);
> }
>
>
> Thank you.
> Stéphane.
Re: How to optimize generated code? [message #1737595 is a reply to message #1737558] Mon, 11 July 2016 03:01 Go to previous messageGo to next message
Eclipse UserFriend
To avoid creation of multiple variables, assign the result of the repeating expression to a constant:
protected def caller {
     val skill = getSkill(C1)
     skill.myfunction(Integer)
     skill.myfunction(Float, 1)
     skill.myfunction(String, 2, 3)
}

Re: How to optimize generated code? [message #1737601 is a reply to message #1737595] Mon, 11 July 2016 03:42 Go to previous messageGo to next message
Eclipse UserFriend
Dear all.

Thank you for your replies. Indeed, I'm writting my DSL code with a local constant. But some of the users of my DSL do not. It may be helpful to have an optimizer of generated code, as for standard compilers.

Currently, getSkill() is annotated with @Pure. It may help the compiler for its optimization tasks. I will work with my students on an optimizer.

Stéphane.
Re: How to optimize generated code? [message #1737604 is a reply to message #1737601] Mon, 11 July 2016 04:19 Go to previous messageGo to next message
Eclipse UserFriend
This sounds reasonable on first sight. Before starting with the actual work, file an issue for Xbase that describes the proposed approach. This will allow the Xtext team to discuss it.

Please file it to:
https://github.com/eclipse/xtext-extras/issues
Re: How to optimize generated code? [message #1737610 is a reply to message #1737604] Mon, 11 July 2016 04:59 Go to previous message
Eclipse UserFriend
Done: https://github.com/eclipse/xtext-extras/issues/20
Previous Topic:Error markers in the outline
Next Topic:Two projects for one extension
Goto Forum:
  


Current Time: Fri Jul 25 21:06:40 EDT 2025

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

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

Back to the top