Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a way to specify type ids in constants. #926

Open
zenhack opened this issue Jan 23, 2020 · 1 comment
Open

Provide a way to specify type ids in constants. #926

zenhack opened this issue Jan 23, 2020 · 1 comment

Comments

@zenhack
Copy link
Contributor

zenhack commented Jan 23, 2020

It's not uncommon to define structs where one of the fields is supposed to be a type id for some other type, but afaik there's currently no way in the schema language to just say "use the id of this type" in a constant definition. This affects Sandstorm's powerbox requests, since if they are generated from schema files they end up looking like this:

const descriptor :Powerbox.PowerboxDescriptor = (
  tags = [
    (
      id = 0xc879e379c625cdc7,
      # The type id for ApiSession.

      value = .tagValue
    ),
  ],
);

Developers shouldn't have to look up and insert the magic constant themselves. Ideally you could just write:

const descriptor :Powerbox.PowerboxDescriptor = (
  tags = [
    (
     id = ApiSession,
     value = .tagValue
    ),
  ],
);

i.e, if a type name is used in a context where a value is expected, treat is as the type id of that name.

@kentonv
Copy link
Member

kentonv commented Feb 4, 2020

I'd use an intrinsic function like typeId(ApiSession), but otherwise I agree this would be very useful.

(Or, another alternative might be to introduce a TypeId built-in type, which is encoded like UInt64, but uses type names as its literal values. But that'd be more complicated to implement.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants