Aliasing vs cloning doc unclarity #1000

Open
Util opened this Issue Oct 3, 2013 · 0 comments

Projects

None yet

1 participant

Owner
Util commented Oct 3, 2013

Reported by: zefram@fysh.org

The op documentation is often unclear about whether an op performs aliasing or cloning of PMCs. That is, whether the op changes which PMC object a $Pn register points to or changes the content of the PMC object that the register already points to. For example, set_p_p aliases, but set_p_s mutates (cloning the string), despite both being documented as just "Set $1 to $2.".

Demonstration:

$ cat t25.pir
.sub main :main
        $P0 = new "String"
        assign $P0, "foo"
        $P1 = new "String"
        set $P1, $P0
        set $P0, "bar"
        say $P1
.end
$ ./parrot t25.pir
bar

Getting "bar" out of $P1 there shows that (a) $P1 was aliased to $P0 by 'set $P1, $P0' and (b) 'set $P0, "bar"' mutated the PMC referenced by $P0 rather than making $P0 refer to a new PMC.

Things are made worse by having "assign" opcodes separate from "set", which appear to be making an aliasing/cloning distinction but in most cases don't. Also made worse by the use of "$P0 = ..." syntax in PIR for both kinds of operation. If you can countenance some incompatible change here, you could make things much clearer by using "set" and "=" only for alias-type operations and "assign" only for clone-type operations.

With so much mutability in the system, it's vitally important to be clear about which things are aliased and which are not.

-zefram

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment