cmd/compile: better optimization of type switches in instantiated generic functions #59591
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
FeatureRequest
Issues asking for a new feature that does not need a proposal.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
Consider this test case:
This runs fine. It instantiates
F
twice:main.F[go.shape.[]uint8]
andmain.F[go.shape.string]
. Both versions take a dictionary, and both versions implement the type switch by loading the type descriptor from the dictionary and comparing it to the descriptors for[]byte
andstring
.In these instantiations, however, the type descriptor is a constant. We know this because the constraint does not use a
~
. It would be nice if the compiler were able to constant fold the dictionary value and eliminate the type switch.I came up with this example because of #38776. It would be nice if we could change some of the hash implementations to use generic functions, which largely works until they try to call assembly code. At that point it's necessary to get the pointer to the slice or string data. It would be nice to be able to do that reasonably safely, which is what the above code does, and also efficiently, which the above code is not.
CC @randall77 @mdempsky
The text was updated successfully, but these errors were encountered: