Ticket Created
over 3 years ago

WERETECH-12795

feature request: implement class inheritance elimination in the monkey c optimization

A technique I often apply is to use a jungle in combination with inheritance (see https://starttorun.info/tackling-connect-iq-versions-screen-shapes-and-memory-limitations-the-jungle-way/ )  to be able to support multiple technologies, yet keep my code readable and managable . The extra classes add a bit of overhead due to the extra objects being used.

It would be good to have the monkey C optimizer be smart enough to detect this pattern and let the optimizer combine the classes into the upper class in the optimization pass. 

Constraints:

- the optimizer should handle function overrrides and function inheritance

- the optimizer should only do this optimization if there's no direct use of 1 of the base classes

example:

class A {

    function base_method1 () {

             System.println("A.base_method1");

   }

    function base_method2 () {

             System.println("A.base_method2");

   }

}

class B extends A {

    function base_method1 () {   // inherit base functionality

             A.base_method1();    

             System.println("B.base_method1");

   }

    function base_method2 () {  // override base functionality

             System.println("B.base_method2");

   }

}

The result of the optimizer pass should be:

// class A no longer exists

class B {  // class B no longer extends

    function base_method1 () {   

             System.println("A.base_method1");

             System.println("B.base_method1");

   }

    function base_method2 () {  

             System.println("B.base_method2");

   }

}

  • Also thought about this. If it's too complicated (could be for example in barrel code) then maybe Garmin can add new ways for the developer to add hints to the compiler. One way could be to enrich the annotations. The easiest could be to be able to use (:inline) (on the base class in this case, but on any function in general). This would give the decision to the developer and also provide a clear way to have more readable code.