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

Are instances local compile-time known? #1309

Open
jaehyun1ee opened this issue Sep 20, 2024 · 4 comments
Open

Are instances local compile-time known? #1309

jaehyun1ee opened this issue Sep 20, 2024 · 4 comments

Comments

@jaehyun1ee
Copy link
Contributor

A follow-up issue from #1305.

Section 18.1. Compile-time known and local compile-time known values lists,

Instances constructed by instance declarations (Section 11.3) and constructor invocations.

as a local compile-time known value.

But since constructor arguments are compile-time known, shouldn't instances also be compile-time known?
Or are there cases where we need instances to be local compile-time known?

@ChrisDodd
Copy link
Contributor

"local compile-time known" is more restrictive than "compile-time-known", so this is more a matter of instances being allowed to be local compile time known, even though their constructor arguments may not be.

@jaehyun1ee
Copy link
Contributor Author

I see, but I think allowing instances to be local compile-time known may some subtlety, since there are some cases where only local compile-time values are expected.

e.g., there are some cases like c in bit<c>(bitwidth) or <expr>[1:c](bitslice) where they expect local compile-time known values exclusively.

And of course, instances cannot be used in any places where local compile-time value is expected, as of the current spec. But for the sake of clarity and future language extensions, I believe defining instances as compile-time known also makes sense.

@ChrisDodd
Copy link
Contributor

ChrisDodd commented Sep 23, 2024

Well, those specific examples that require local compile-time known values also require numeric type values, and instances are non-numeric (they are controls, parsers, externs, or actions), so there's no intersection.

However, it does bring up a point -- should it be possible to define methods in an extern such that a call of such a method on a locally compile-time known instance is itself compile-time known (locally or not)? I don't think anyone has tried that yet, but it might well make sense for metaprogramming purposes to have methods defined on an extern that return constant info about the instance (its size, for example, or maybe something target specific, like precision).

@jafingerhut
Copy link
Collaborator

It seems to me that if one of these things:

  • instance declaration
  • constructor call

depends in any way upon the value of a constructor parameter of the enclosing parser or control, then it doesn't really make sense to call it local compile-time known.

My first question would be, should we move the bullet item "Instances constructed by instance declarations (Section 11.3) and constructor invocations." from the local compile-time known list, to the compile-time known list, as a correction to the spec?

If we wanted to have any instance declarations, or constructor calls, considered as local compile-time known, then it seems that we should further restrict it so that everything parameter to it is also local compile-time known.

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

3 participants