Built-in roles are meaningless names #1020

Util opened this Issue Nov 2, 2013 · 1 comment


None yet
3 participants

Util commented Nov 2, 2013

Reported by: zefram@fysh.org

There are some built-in roles such as "invokable" that can be referred to by name, but there isn't any substance to the role beyond its name. There are no Role metaobjects representing them, and so a user-defined class can't compose them.

First, try introspecting the Sub PMC class:

$ cat t55.pir
.sub main :main
        $P0 = get_global "main"
        $I1 = does $P0, "invokable"
        say $I1
        $P1 = typeof $P0
        say $P1
        $P2 = inspect $P1, "roles"
        $I0 = $P2
        say $I0
$ ./parrot t55.pir

Although a Sub "does" the "invokable" role, introspecting the Sub class clearly shows a list of no composed roles. Sub has some built-in recognition for the name "invokable", but no relationship to any Role object that goes by that name.

This is a problem if one wants to compose the built-in "invokable" role. Doing so is mandatory in at least one situation: adding a method to a MultiSub. The MultiSub will reject the addition of anything that doesn't "do" "invokable". However, because "invokable" is no more than a name, MultiSub will actually be satisfied by a class composing any Role that is labelled with that name. Its test corresponds to the test in this code:

$ cat t54.pir
.sub main :main
        $P0 = newclass "Foo"
        $P1 = new $P0
        $I0 = does $P1, "invokable"
        say $I0
        $P2 = new "Role"
        addrole $P0, $P2
        $I1 = does $P1, "invokable"
        say $I1
$ ./parrot t54.pir

So MultiSub can actually be satisfied by an empty formality. Empty because it is entirely unrelated to whether an object is actually invokable: one can override the "invoke" vtable entry without touching roles, or (as above) satisfy the role name test without touching the vtable entry.

Do roles achieve anything at all in Parrot?


Summary of my parrot 5.7.0 configuration:
  configdate='Sat Oct  5 12:42:43 2013 GMT'
    osname=linux, archname=x86_64-linux-gnu-thread-multi

rcook commented Mar 12, 2014

Shouldn't it be "invocable", anyway?

@rurban rurban added Sev-medium and removed Sev-low labels Apr 20, 2015

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