Annotations on generic types parameters

6 views
Skip to first unread message

John Demme

unread,
Mar 19, 2020, 9:38:26 PM3/19/20
to Cap'n Proto
Hi All-

Is is possible to annotate the UInt32 in List(UInt32)? In the following example the annotation applies to the whole list, but I'm interested in just annotating the contained type:

struct Ex1 {
     array1 @0 :List(UInt32) $hide();
}


My understanding is that UInt32 is just a generic type parameter and that parameters can be annotated. I also tried something like this: "annotation baz(parameter) :Int32;" but got "error: Not a valid annotation target.".

... I suspect I'm not interpreting "parameter" correctly. Is it method parameter? If so, is there any other way to do what I'm looking for? If not, I just change the semantics of my annotations but I wanted to check first.

Thanks,
John

Kenton Varda

unread,
Mar 20, 2020, 10:04:18 AM3/20/20
to John Demme, Cap'n Proto
Hi John,

Unfortunately, annotations apply only to declarations, not to types. So, you can't annotate the argument to a type function.

The "parameter" annotation target means parameters to RPC methods, like:

    interface Foo {
      bar @0 (baz :UInt32 $annotation);
    }

One thing you could try is wrapping your list elements in a struct:

    struct Ex1 {
      array1 @0 :List(Element);
      struct Element {
        value @0 :UInt32 $hide();
      }
    }

Unfortunately in this particular case, this will double the memory usage of your list, because elements of a struct list will be aligned to 8 bytes, whereas UInt32s are 4 bytes.

-Kenton

--
You received this message because you are subscribed to the Google Groups "Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email to capnproto+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/capnproto/d5e76b4b-819f-4c8c-9bff-8b43cb1a5ac5%40googlegroups.com.

John Demme

unread,
Mar 20, 2020, 1:20:43 PM3/20/20
to Kenton Varda, Cap'n Proto
Hi Kenton-

Yeah, that's what I thought. I'll just modify my annotation semantics.

Thanks!

~John
Reply all
Reply to author
Forward
0 new messages