Node child/children relation change during Runtime
Christian Wirth
christian.wirth at oracle.com
Tue Jul 15 12:39:09 UTC 2014
Hi Gero,
why do you want to change the order of nodes dynamically; what is the
reasoning for doing so? We have not yet seen any use-case for that.
Ad 1) It SHOULD count as alteration of the AST. Are you working with
@Child or with @Children? In any case, you need to invalidate the
compiled code when you do that (the API does that for you, if it has a
chance to). E.g. just exchanging two pointers in an @Children array is
not enough, you manually need to call
CompilerDirectives.transferToInterpreterAndInvalidate().
Ad 2) and 3) it is very relevant. Again, there is a difference whether
you use @Child (where you have more controll over what is executed in
what order) or @Children. Truffle assumes the @Child and the @Children
array to be constant. If you change it, you have to invalidate your
code. You can, however, express the execute method(s) in a way that they
dynamically adopt to your ordering (or control flow). A very simple
example example is an "IF" node: depending on the result of
conditionNode, either thenNode or elseNode is executed.
Regards,
Christian Wirth
Am 15.07.2014 14:12, schrieb Gero Leinemann:
> Hello everyone,
>
> I'm new to Graal/Truffle and currently working for Michael Haupt on
> FastR. While trying to understand the FastR code base I've got some
> questions regarding the creation and mutation of child/children of a
> Truffle-Node.
>
> As far as I understand it, the aim in language implementations using
> Truffle is to keep the AST stable to get it compiled some time by Graal.
> Therefore one should avoid adding new children during the lifetime of a
> Node, as this alters the AST.
>
> Now there is a piece of code where a Node is once added to the tree
> whose children's order is permuted frequently (every 'execute'). My
> questions are:
> 1) Does this count as alteration?
> 2) If no: Is the change of order of children during execution really
> irrelevant for Truffle/Graal?
> 3) If no: Is the only thing Truffle/Graal depends on for compilation the
> proper bidirectional parent <-> child relation which is established by
> 'Node.insert'/'replace'?
>
> Thank you in advance!
>
> Best Regards,
> Gero
More information about the graal-dev
mailing list