]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: support inlining of type switches
authorMatthew Dempsky <mdempsky@google.com>
Thu, 29 Oct 2020 08:13:16 +0000 (01:13 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Fri, 6 Nov 2020 20:49:11 +0000 (20:49 +0000)
commit5736eb0013cb8c9b67432c98b08f68e9f370810c
tree3f3c0d5e330409476bf37cf3a7707d75e28911fc
parent362d25f2c82980860cb4eb5bfd0648116504788d
cmd/compile: support inlining of type switches

This CL adds support for inlining type switches, including exporting
and importing them.

Type switches are represented mostly the same as expression switches.
However, if the type switch guard includes a short variable
declaration, then there are two differences: (1) there's an ONONAME
(in the OTYPESW's Left) to represent the overall pseudo declaration;
and (2) there's an ONAME (in each OCASE's Rlist) to represent the
per-case variables.

For simplicity, this CL simply writes out each variable separately
using iimport/iiexport's normal Vargen mechanism for disambiguating
identically named variables within a function. This could be improved
somewhat, but inlinable type switches are probably too uncommon to
merit the complexity.

While here, remove "case OCASE" from typecheck1. We only type check
"case" clauses as part of a "select" or "switch" statement, never as
standalone statements.

Fixes #37837

Change-Id: I8f42f6c9afdd821d6202af4a6bf1dbcbba0ef424
Reviewed-on: https://go-review.googlesource.com/c/go/+/266203
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/iexport.go
src/cmd/compile/internal/gc/iimport.go
src/cmd/compile/internal/gc/inl.go
src/cmd/compile/internal/gc/typecheck.go
test/fixedbugs/issue37837.dir/a.go [new file with mode: 0644]
test/fixedbugs/issue37837.dir/b.go [new file with mode: 0644]
test/fixedbugs/issue37837.go [new file with mode: 0644]
test/inline.go