cmd/compile: missed devirtualization #51554
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
In the following snippet, the compiler should be able to devirtualize the
fi.Foo()
call, but currently this does not happen (godbolt):The example is obviously artificial, but this definitely occurs in real code: e.g. see the code generated by envoyproxy/protoc-gen-validate, e.g. https://github.com/envoyproxy/go-control-plane/blob/99c9ceb26c9d7bf1705833b7debdebe9ae67c0ae/envoy/data/tap/v2alpha/transport.pb.validate.go.
Another use case that will become increasingly important with generics in 1.18 is to distinguish1 between different types provided in type unions, e.g.:
As above, this missed devirtualization opportunity currently prevents (godbolt) the compiler from statically deducing the correct branch at compile-time, and pruning the dead branches.
This is somewhat related to #38992 in that also in this specific case it would be beneficial to run inlining again after devirtualization. For example, in the first example above, inlining after devirtualization would open up significant inlining opportunities in case an embedded message does not have validation rules (in which case its
Validate*
functions would simply returnnil
, potentially allowing to prune whole branches of the validation call tree)Footnotes
AFAICT this wouldn't currently be possible if the type constraint includes approximation elements (
~T
); the example does not use approximation elements for this reason ↩The text was updated successfully, but these errors were encountered: