From 874f74a407d8de716f916a91a0b8594ba19ea3c7 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 4 Feb 2025 13:58:35 +0100 Subject: [PATCH] remove generating logs for slow slice types Signed-off-by: Andres Taylor --- go/tools/astfmtgen/main.go | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/go/tools/astfmtgen/main.go b/go/tools/astfmtgen/main.go index 44a34b12b00..d1a8c6b3bb3 100644 --- a/go/tools/astfmtgen/main.go +++ b/go/tools/astfmtgen/main.go @@ -247,7 +247,7 @@ func (r *Rewriter) rewriteAstPrintf(cursor *astutil.Cursor, expr *ast.CallExpr) Args: []ast.Expr{&ast.BasicLit{Value: `"%d"`, Kind: gotoken.STRING}, expr.Args[2+fieldnum]}, } cursor.InsertBefore(r.rewriteLiteral(callexpr.X, "WriteString", call)) - case 'n': // new directive for slices of AST nodes checked at code generation time + case 'n': // directive for slices of AST nodes checked at code generation time inputExpr := expr.Args[2+fieldnum] inputType := r.pkg.TypesInfo.Types[inputExpr].Type sliceType, ok := inputType.(*types.Slice) @@ -266,31 +266,7 @@ func (r *Rewriter) rewriteAstPrintf(cursor *astutil.Cursor, expr *ast.CallExpr) cursor.InsertBefore(&ast.ExprStmt{X: call}) break } - log.Printf("slow path for `n` directive with type %T", types.TypeString(inputType, noQualifier)) - // Slow path: slice elements do not implement Expr - cursor.InsertBefore(&ast.ExprStmt{ - X: &ast.CallExpr{ - Fun: &ast.SelectorExpr{ - X: &ast.Ident{Name: "log"}, - Sel: &ast.Ident{Name: "Printf"}, - }, - Args: []ast.Expr{ - &ast.BasicLit{ - Kind: gotoken.STRING, - Value: strconv.Quote("slow path for %n with type %T"), - }, - inputExpr, - }, - }, - }) - call := &ast.CallExpr{ - Fun: &ast.SelectorExpr{ - X: callexpr.X, - Sel: &ast.Ident{Name: "formatNodes"}, - }, - Args: []ast.Expr{inputExpr}, - } - cursor.InsertBefore(&ast.ExprStmt{X: call}) + panic("slow path for `n` directive for slice of type other than Expr") default: panic(fmt.Sprintf("unsupported escape %q", token)) }