On Wed, Jan 14, 2004 at 10:59:52AM -0500, Melvin Smith wrote:
> I think Perl6 will allow a hint like so:
>
> my int $max_reached;
>
> The important thing is that $max_reached is used simply as a conditional,
> and you don't pass it to a routine or otherwise use it in a way to cause it
> to be promoted to a PMC
What uses would cause it to be promoted to a PMC?
Any use that doesn't allow a native type. Currently: passing it to a non-prototyped
routine or storing it into a hash/list might trigger this.
It depends on how well the optimizer handles hints. Since the optimizer could decide it only needs to create a temporary PMC for the uses in question, but leave the base variable as a native. If the optimizer is too aggressive it might decide that it is less expensive to just declare it as a PMC, so that is where we have to decide how serious we take hints. :)
If the hint we are talking about becomes a directive, then the compiler just
does what it is told. Any expression needing a coercion will get a temporary
created, but all simple uses of $max_reached (increment, evaluation, conditional
tests) will still work with a native int register, and this is probably what you
want in this case.
On the flip side, for a standard declaration: my $max_reached; (no hint) it should be possible with data-dependency analysis to decide $max_reached should be a native, without the hint. We shall see.
-Melvin