mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.typeparams] cmd/compile: more incremental typecheck for unified IR
CL 332469 changed the unified IR reader to incrementally typecheck each statement as they're read/constructed. This CL goes further to incrementally typecheck each expression. While here, this CL reorganizes a few things to make this go more smoothly. In particular, it renames expr to expr0 and adds a new expr wrapper that applies typecheck.Expr; gets rid of exprTypeSwitchguard by moving that logic into switchStmt; and splits exprConvert out from exprCall, which simplifies the logic for typechecking the calleee expression somewhat. Change-Id: I6289de9388dc94a947971f4b7213aafeb2faa5dc Reviewed-on: https://go-review.googlesource.com/c/go/+/333730 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
a12ad27119
commit
3c3c1d8d28
3 changed files with 57 additions and 24 deletions
|
|
@ -1033,7 +1033,17 @@ func (w *writer) switchStmt(stmt *syntax.SwitchStmt) {
|
|||
w.openScope(stmt.Pos())
|
||||
w.pos(stmt)
|
||||
w.stmt(stmt.Init)
|
||||
w.expr(stmt.Tag)
|
||||
|
||||
if guard, ok := stmt.Tag.(*syntax.TypeSwitchGuard); w.bool(ok) {
|
||||
w.pos(guard)
|
||||
if tag := guard.Lhs; w.bool(tag != nil) {
|
||||
w.pos(tag)
|
||||
w.string(tag.Value)
|
||||
}
|
||||
w.expr(guard.X)
|
||||
} else {
|
||||
w.expr(stmt.Tag)
|
||||
}
|
||||
|
||||
w.len(len(stmt.Body))
|
||||
for i, clause := range stmt.Body {
|
||||
|
|
@ -1207,6 +1217,19 @@ func (w *writer) expr(expr syntax.Expr) {
|
|||
w.expr(expr.Y)
|
||||
|
||||
case *syntax.CallExpr:
|
||||
tv, ok := w.p.info.Types[expr.Fun]
|
||||
assert(ok)
|
||||
if tv.IsType() {
|
||||
assert(len(expr.ArgList) == 1)
|
||||
assert(!expr.HasDots)
|
||||
|
||||
w.code(exprConvert)
|
||||
w.typ(tv.Type)
|
||||
w.pos(expr)
|
||||
w.expr(expr.ArgList[0])
|
||||
break
|
||||
}
|
||||
|
||||
w.code(exprCall)
|
||||
|
||||
if inf, ok := w.p.info.Inferred[expr]; ok {
|
||||
|
|
@ -1223,15 +1246,6 @@ func (w *writer) expr(expr syntax.Expr) {
|
|||
w.pos(expr)
|
||||
w.exprs(expr.ArgList)
|
||||
w.bool(expr.HasDots)
|
||||
|
||||
case *syntax.TypeSwitchGuard:
|
||||
w.code(exprTypeSwitchGuard)
|
||||
w.pos(expr)
|
||||
if tag := expr.Lhs; w.bool(tag != nil) {
|
||||
w.pos(tag)
|
||||
w.string(tag.Value)
|
||||
}
|
||||
w.expr(expr.X)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue