Wow, it has been a while since I posted here. I have been really busy with other projects, assignments and the COMP413 exam, but now I have a few days to work on this project and have made some progress.

I now have my optimiser actually moving method calls out of loops, in a (relatively) simple but still useful case. It is possible to safely move a method call if the method is annotated as @pure and for each argument to the method call (including the target object):

  • The variable (primitive value or reference) is invariant within the loop, i.e. it always has the same value or points to the same object, and
  • either:
    • It is of a primitive type, or
    • the class type is immutable (annotated as @immutable at the class declaration)

I have successfully implemented the code to check for this case and factor the method call out of the loop (as I earlier did for @moveable methods and dereferences of Array.length under certain conditions).

The more general case is when, rather than the class being immutable, the compiler can check that

  • The reference (variable) is annotated as @unique, meaning that there are guaranteed to be no aliases, and
  • there are no statements in the loop which change the object via the reference (i.e. no calls to non-@const methods), and
  • there is nothing to change objects referenced within the object.

It is fairly clear how to check the first two parts, but I cannot yet see how to check the third condition.

I probably have not described this very well. Oh well. I will have to write a full report eventually.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: