-
Notifications
You must be signed in to change notification settings - Fork 18k
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
proposal: go/types: Export UntypedZero
and Value
#62124
Comments
cc: @findleyr |
I think this is the simplest change implementing support for However, I've thought about this a bit more since our brainstorming session, and am concerned that by not introducing a new node type, code could become subtly broken rather than panicking. For example, I grepped x/tools for When encountering So, alas, we probably need a new object type |
I'm sure I don't have sufficient context here, but what is it about the identifier "Value" that suggests zero- or nil-ness ? |
Not sure I interpret the question correctly, but if we introduce a new types.Object Value, it simply stands for some value (like Const stands for a constant, Func stands for a function, etc.). Since it's not a constant, we don't know the explicit value, but we know the type. So nil would be represented as a Value with Value.typ = types.Typ[UntypedNil], and zero would be represented as a Value with Value.typ = types.Typ[Untyped.Zero]. Currently, the CL makes Nil and alias of the new Value. Alternatively, we can keep Nil as is. (I'd still prefer introducing Value as a general value object than having a Zero object.) |
Per discussion, perhaps it's OK to use Rationale: |
I think that would be better: just add a doc comment to |
I understand the concerns about the name Unfortunately, I can't think of anything better than |
Closing this as #61372 was declined and closed. We can always revive if needed. |
This proposal has been added to the active column of the proposals project |
If this is active, shouldn't it be reopened? |
This proposal has been declined as retracted. |
Proposal
The
go/types
package shall export the following new declarations:and
such that
go/types
clients have easy access to the type and object for the new predeclared valuezero
(approved in #61372).Discussion
The
zero
object can be found viaUniverse.Lookup("zero")
and thus it's type isUniverse.Lookup("zero").Type()
. But we provideBasicKind
values for all other predeclared types, soTyp[UntypedZero]
will provide direct access to the type forzero
. Importers may need access to the actual kind value.Until Go 1.21, Go defined only a single predeclared value,
nil
.go/types
used a special object,Nil
to represent this value. Now that we have bothnil
andzero
, rather than introduce a new object kind (sayZero
), it makes sense to use aValue
object to represent both. The distinguishing feature betweennil
andzero
is their type, so no extra information needs to be stored withValue
. We could simply use theNil
object for both, but it seems cleaner to rename it toValue
and makeNil
an alias forValue
for backward-compatibility.None of these changes are strictly necessary (
Universe.Lookup("zero")
will provide thezero
object and type), but it makes sense to make these changes to keep thego/types
API directly in sync with the language.The text was updated successfully, but these errors were encountered: