-
Notifications
You must be signed in to change notification settings - Fork 1.5k
var
of type FacetType
#5241
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
Comments
The implementation of
...so this is not correct. Perhaps this should be valid?
And the value repr of a facet value would just be copy/itself? |
The Making it possible to initialize a value from an EphemeralRef to a class member var of a facet value also seems to improve that test, so mentioning it here.
|
I want to raise one consequence on the toolchain implementation if facet values can indeed be passed around as runtime values, stored in var etc, which is that it seems we would need to support narrowing runtime facet values (e.g. from |
What we do elsewhere for such types (eg, If we have good reasons to disallow it, I don't think it'd be a great loss, but we'd need some description of how that disallowance would fit into the bigger picture -- for example, would we treat these types as being abstract? Or introduce some new set of rules for types that are complete, concrete, but still not usable as the type of a I could imagine cases arising in the future that would motivate stopping treating facets as empty at runtime -- for example, if we have some way to indicate that an associated function in an interface is intentionally object-safe, it might make sense for the corresponding facet to include a runtime version of the witness table that contains just the object-safe functions. But I think that's a compatible extension. |
Given the relatively small amount of known utility here, I think we should pick whatever rule is easiest to implement -- if we want to say that conversion between different facet types always requires that the source to be constant, I think that's OK. |
…alue Perhaps we will disallow member lookup on and conversion of runtime facet values. For now, leave a TODO and produce a TODO diagnostic instead of crashing. Related to carbon-language#5241.
Give them a value representation of copy, and allow conversions between two facet values of the same type to work. Convert was assuming that facet values are compile time constants, but thye can also be runtime values. In that case, we have no support for converting to a different facet value of a different facet type. But if the types are equal then it's all fine. In theory it seems that we should be able to convert if the target facet type can be found through the source value's FacetType. But currently that happens through impl lookup and it requires constant values. Adding a test for this. Related to #5241
…alue Perhaps we will disallow member lookup on and conversion of runtime facet values. For now, leave a TODO and produce a TODO diagnostic instead of crashing. Related to carbon-language#5241.
Summary of issue:
Is it legal in the design to declare a
var
pattern with a type of aFacetType
?A small example:
Here the code has no idea how big
n
should be, so this seems like it should not be possible.Whereas, a type of a "type defined by a FacetType" aka a
FacetAccessType
in the toolchain impl, seems fine:The values design only says the type portion of the
var
pattern is an "expression": https://docs.carbon-lang.dev/docs/design/values.html#local-variablesThe generics design has no example or mention of a
var
of a facet type afaict: https://docs.carbon-lang.dev/docs/design/generics/details.htmlA full example that typechecks in the current impl, using a FacetAccessType, rather than a FacetType:
Details:
No response
Any other information that you want to share?
No response
The text was updated successfully, but these errors were encountered: