In go1.18, the compiler output for this program (https://go.dev/play/p/GVufoDzAG5-) on tested targets {openbsd,linux}/{amd64,arm64,386} the generic version does not use runtime.mapclear, instead it iterates over the map deleting each element, I expected both functions generate a very similar code, instead clear generates (roughly):
The extra CONVNOP is because i can be anything of string shape, but the type of the map key must be exactly string. I think we can expand the mapclear optimization to allow nop conversions on the arguments.
That said, there may be a larger issue here, which is that I think the type of m should be map[go.shape.string_1]go.shape.bool_2, not go.shape.map[string]bool_0. Something about making shape types out of type parameters that are dependent on other type parameters might need some tweaking.
In go1.18, the compiler output for this program (https://go.dev/play/p/GVufoDzAG5-) on tested targets {openbsd,linux}/{amd64,arm64,386} the generic version does not use runtime.mapclear, instead it iterates over the map deleting each element, I expected both functions generate a very similar code, instead
clear
generates (roughly):clear2 (copied from exp/maps.Clear) generates (roughly):
go env
OutputThe text was updated successfully, but these errors were encountered: