Debian Codegraph @

go/analysis/passes/inline/inline.go

raw symbols SCIP
1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package inline
6
7 import (
8 "fmt"
9 "go/ast"
10 "go/types"
11 "slices"
12 "strings"
13
14 _ "embed"
15
16 "golang.org/x/tools/go/analysis"
17 "golang.org/x/tools/go/analysis/passes/inspect"
18 "golang.org/x/tools/go/analysis/passes/internal/gofixdirective"
19 "golang.org/x/tools/go/ast/edge"
20 "golang.org/x/tools/go/ast/inspector"
21 "golang.org/x/tools/go/types/typeutil"
22 "golang.org/x/tools/internal/analysis/analyzerutil"
23 typeindexanalyzer "golang.org/x/tools/internal/analysis/typeindex"
24 "golang.org/x/tools/internal/astutil"
25 "golang.org/x/tools/internal/moreiters"
26 "golang.org/x/tools/internal/packagepath"
27 "golang.org/x/tools/internal/refactor"
28 "golang.org/x/tools/internal/refactor/inline"
29 "golang.org/x/tools/internal/typesinternal"
30 "golang.org/x/tools/internal/typesinternal/typeindex"
31 )
32
33 //go:embed doc.go
34 var doc string
35
36 var Analyzer = &analysis.Analyzer{
37 Name: "inline",
38 Doc: analyzerutil.MustExtractDoc(doc, "inline"),
39 URL: "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/inline",
40 Run: run,
41 FactTypes: []analysis.Fact{
42 (*goFixInlineFuncFact)(nil),
43 (*goFixInlineConstFact)(nil),
44 (*goFixInlineAliasFact)(nil),
45 },
46 Requires: []*analysis.Analyzer{
47 inspect.Analyzer,
48 typeindexanalyzer.Analyzer,
49 },
50 }
51
52 var (
53 allowBindingDecl bool
54 lazyEdits bool
55 )
56
57 func init() {
58 Analyzer.Flags.BoolVar(&allowBindingDecl, "allow_binding_decl", false,
59 "permit inlinings that require a 'var params = args' declaration")
60 Analyzer.Flags.BoolVar(&lazyEdits, "lazy_edits", false,
61 "compute edits lazily (only meaningful to gopls driver)")
62 }
63
64 // analyzer holds the state for this analysis.
65 type analyzer struct {
66 pass *analysis.Pass
67 root inspector.Cursor
68 index *typeindex.Index
69 // memoization of repeated calls for same file.
70 fileContent map[string][]byte
71 // memoization of fact imports (nil => no fact)
72 inlinableFuncs map[*types.Func]*inline.Callee
73 inlinableConsts map[*types.Const]*goFixInlineConstFact
74 inlinableAliases map[*types.TypeName]*goFixInlineAliasFact
75 }
76
77 func run(pass *analysis.Pass) (any, error) {
78 a := &analyzer{
79 pass: pass,
80 root: pass.ResultOf[inspect.Analyzer].(*inspector.Inspector).Root(),
81 index: pass.ResultOf[typeindexanalyzer.Analyzer].(*typeindex.Index),
82 fileContent: make(map[string][]byte),
83 inlinableFuncs: make(map[*types.Func]*inline.Callee),
84 inlinableConsts: make(map[*types.Const]*goFixInlineConstFact),
85 inlinableAliases: make(map[*types.TypeName]*goFixInlineAliasFact),
86 }
87 gofixdirective.Find(pass, a.root, a)
88 a.inline()
89 return nil, nil
90 }
91
92 // HandleFunc exports a fact for functions marked with go:fix.
93 func (a *analyzer) HandleFunc(decl *ast.FuncDecl) {
94 content, err := a.readFile(decl)
95 if err != nil {
96 a.pass.Reportf(decl.Doc.Pos(), "invalid inlining candidate: cannot read source file: %v", err)
97 return
98 }
99 callee, err := inline.AnalyzeCallee(discard, a.pass.Fset, a.pass.Pkg, a.pass.TypesInfo, decl, content)
100 if err != nil {
101 a.pass.Reportf(decl.Doc.Pos(), "invalid inlining candidate: %v", err)
102 return
103 }
104 fn := a.pass.TypesInfo.Defs[decl.Name].(*types.Func)
105 a.pass.ExportObjectFact(fn, &goFixInlineFuncFact{callee})
106 a.inlinableFuncs[fn] = callee
107 }
108
109 // HandleAlias exports a fact for aliases marked with go:fix.
110 func (a *analyzer) HandleAlias(spec *ast.TypeSpec) {
111 // Remember that this is an inlinable alias.
112 typ := &goFixInlineAliasFact{}
113 lhs := a.pass.TypesInfo.Defs[spec.Name].(*types.TypeName)
114 a.inlinableAliases[lhs] = typ
115 // Create a fact only if the LHS is exported and defined at top level.
116 // We create a fact even if the RHS is non-exported,
117 // so we can warn about uses in other packages.
118 if lhs.Exported() && typesinternal.IsPackageLevel(lhs) {
119 a.pass.ExportObjectFact(lhs, typ)
120 }
121 }
122
123 // HandleConst exports a fact for constants marked with go:fix.
124 func (a *analyzer) HandleConst(nameIdent, rhsIdent *ast.Ident) {
125 lhs := a.pass.TypesInfo.Defs[nameIdent].(*types.Const)
126 rhs := a.pass.TypesInfo.Uses[rhsIdent].(*types.Const) // must be so in a well-typed program
127 con := &goFixInlineConstFact{
128 RHSName: rhs.Name(),
129 RHSPkgName: rhs.Pkg().Name(),
130 RHSPkgPath: rhs.Pkg().Path(),
131 }
132 if rhs.Pkg() == a.pass.Pkg {
133 con.rhsObj = rhs
134 }
135 a.inlinableConsts[lhs] = con
136 // Create a fact only if the LHS is exported and defined at top level.
137 // We create a fact even if the RHS is non-exported,
138 // so we can warn about uses in other packages.
139 if lhs.Exported() && typesinternal.IsPackageLevel(lhs) {
140 a.pass.ExportObjectFact(lhs, con)
141 }
142 }
143
144 // inline inlines each static call to an inlinable function
145 // and each reference to an inlinable constant or type alias.
146 func (a *analyzer) inline() {
147 for cur := range a.root.Preorder((*ast.CallExpr)(nil), (*ast.Ident)(nil)) {
148 switch n := cur.Node().(type) {
149 case *ast.CallExpr:
150 a.inlineCall(n, cur)
151
152 case *ast.Ident:
153 switch obj := a.pass.TypesInfo.Uses[n].(type) {
154 case *types.TypeName:
155 a.inlineAlias(obj, cur)
156 case *types.Const:
157 a.inlineConst(obj, cur)
158 }
159 }
160 }
161 }
162
163 // If call is a call to an inlinable func, suggest inlining its use at cur.
164 func (a *analyzer) inlineCall(call *ast.CallExpr, cur inspector.Cursor) {
165 if fn := typeutil.StaticCallee(a.pass.TypesInfo, call); fn != nil {
166 // Inlinable?
167 callee, ok := a.inlinableFuncs[fn]
168 if !ok {
169 var fact goFixInlineFuncFact
170 if a.pass.ImportObjectFact(fn, &fact) {
171 callee = fact.Callee
172 a.inlinableFuncs[fn] = callee
173 }
174 }
175 if callee == nil {
176 return // nope
177 }
178
179 if a.withinTestOf(cur, fn) {
180 return // don't inline a function from within its own test
181 }
182
183 // Compute the edits.
184 //
185 // Ordinarily the analyzer reports a fix containing
186 // edits. However, the algorithm is somewhat expensive
187 // (unnecessarily so: see go.dev/issue/75773) so
188 // to reduce costs in gopls, we omit the edits,
189 // meaning that gopls must compute them on demand
190 // (based on the Diagnostic.Category) when they are
191 // requested via a code action.
192 //
193 // This does mean that the following categories of
194 // caller-dependent obstacles to inlining will be
195 // reported when the gopls user requests the fix,
196 // rather than by quietly suppressing the diagnostic:
197 // - shadowing problems
198 // - callee imports inaccessible "internal" packages
199 // - callee refers to nonexported symbols
200 // - callee uses too-new Go features
201 // - inlining call from a cgo file
202 var edits []analysis.TextEdit
203 if !lazyEdits {
204 // Inline the call.
205 caller := &inline.Caller{
206 Fset: a.pass.Fset,
207 Types: a.pass.Pkg,
208 Info: a.pass.TypesInfo,
209 File: astutil.EnclosingFile(cur),
210 Call: call,
211 CountUses: func(pkgname *types.PkgName) int {
212 return moreiters.Len(a.index.Uses(pkgname))
213 },
214 }
215 res, err := inline.Inline(caller, callee, &inline.Options{Logf: discard})
216 if err != nil {
217 a.pass.Reportf(call.Lparen, "%v", err)
218 return
219 }
220
221 if res.Literalized {
222 // Users are not fond of inlinings that literalize
223 // f(x) to func() { ... }(), so avoid them.
224 //
225 // (Unfortunately the inliner is very timid,
226 // and often literalizes when it cannot prove that
227 // reducing the call is safe; the user of this tool
228 // has no indication of what the problem is.)
229 return
230 }
231 if res.BindingDecl && !allowBindingDecl {
232 // When applying fix en masse, users are similarly
233 // unenthusiastic about inlinings that cannot
234 // entirely eliminate the parameters and
235 // insert a 'var params = args' declaration.
236 // The flag allows them to decline such fixes.
237 return
238 }
239 edits = res.Edits
240 }
241
242 a.pass.Report(analysis.Diagnostic{
243 Pos: call.Pos(),
244 End: call.End(),
245 Message: fmt.Sprintf("Call of %v should be inlined", callee),
246 Category: "inline_call", // keep consistent with gopls/internal/golang.fixInlineCall
247 SuggestedFixes: []analysis.SuggestedFix{{
248 Message: fmt.Sprintf("Inline call of %v", callee),
249 TextEdits: edits, // within gopls, this is nil => compute fix's edits lazily
250 }},
251 })
252 }
253 }
254
255 // withinTestOf reports whether curUse is within a dedicated test
256 // function for the inlinable target symbol.
257 // A call within its dedicated test should not be inlined.
258 func (a *analyzer) withinTestOf(curUse inspector.Cursor, target types.Object) bool {
259 // x_test.go -> x
260 useFileBase, isTest := strings.CutSuffix(a.pass.Fset.File(curUse.Node().Pos()).Name(), "_test.go")
261 if !isTest {
262 return false // not a test file
263 }
264
265 // Suppress fixes for uses in x_test.go of target symbol defined in x.go (#79272).
266 if useFileBase == strings.TrimSuffix(a.pass.Fset.File(target.Pos()).Name(), ".go") {
267 return true
268 }
269
270 curFuncDecl, ok := moreiters.First(curUse.Enclosing((*ast.FuncDecl)(nil)))
271 if !ok {
272 return false // not in a function
273 }
274 funcDecl := curFuncDecl.Node().(*ast.FuncDecl)
275 if funcDecl.Recv != nil {
276 return false // not a test func
277 }
278 if strings.TrimSuffix(a.pass.Pkg.Path(), "_test") != target.Pkg().Path() {
279 return false // different package
280 }
281
282 // Computed expected SYMBOL portion of "ExampleSYMBOL_comment"
283 // for the target symbol. (Strictly, this convention applies
284 // only to Example functions.)
285 // TODO(adonovan): use a proper Test function parser.
286 symbol := target.Name()
287 if fn, ok := target.(*types.Func); ok {
288 if recv := fn.Signature().Recv(); recv != nil {
289 _, named := typesinternal.ReceiverNamed(recv)
290 symbol = named.Obj().Name() + "_" + symbol
291 }
292 }
293 fname := funcDecl.Name.Name
294 for _, pre := range []string{"Test", "Example", "Bench", "Fuzz"} {
295 if fname == pre+symbol || strings.HasPrefix(fname, pre+symbol+"_") {
296 return true // use of X within TestX
297 }
298 }
299
300 return false
301 }
302
303 // If tn is the TypeName of an inlinable alias, suggest inlining its use at cur.
304 func (a *analyzer) inlineAlias(tn *types.TypeName, curId inspector.Cursor) {
305 inalias, ok := a.inlinableAliases[tn]
306 if !ok {
307 var fact goFixInlineAliasFact
308 if a.pass.ImportObjectFact(tn, &fact) {
309 inalias = &fact
310 a.inlinableAliases[tn] = inalias
311 }
312 }
313 if inalias == nil {
314 return // nope
315 }
316
317 if a.withinTestOf(curId, tn) {
318 return // don't inline a type alias from within its own test
319 }
320
321 alias := tn.Type().(*types.Alias)
322 // Remember the names of the alias's type params. When we check for shadowing
323 // later, we'll ignore these because they won't appear in the replacement text.
324 typeParamNames := map[*types.TypeName]bool{}
325 for tp := range alias.TypeParams().TypeParams() {
326 typeParamNames[tp.Obj()] = true
327 }
328 rhs := alias.Rhs()
329 curPath := a.pass.Pkg.Path()
330 curFile := astutil.EnclosingFile(curId)
331 id := curId.Node().(*ast.Ident)
332
333 // Find the complete identifier, which may take any of these forms:
334 // Id
335 // Id[T]
336 // Id[K, V]
337 // pkg.Id
338 // pkg.Id[T]
339 // pkg.Id[K, V]
340 var expr ast.Expr = id
341 if curId.ParentEdgeKind() == edge.SelectorExpr_Sel {
342 curId = curId.Parent()
343 expr = curId.Node().(ast.Expr)
344 }
345 // If expr is part of an IndexExpr or IndexListExpr, we'll need that node.
346 // Given C[int], TypeOf(C) is generic but TypeOf(C[int]) is instantiated.
347 switch curId.ParentEdgeKind() {
348 case edge.IndexExpr_X:
349 curId = curId.Parent()
350 expr = curId.Node().(*ast.IndexExpr)
351 case edge.IndexListExpr_X:
352 curId = curId.Parent()
353 expr = curId.Node().(*ast.IndexListExpr)
354 }
355
356 // Reject inlining of a type alias used to declare an embedded
357 // struct field if doing so would change the field's name.
358 if v, ok := a.pass.TypesInfo.Defs[id].(*types.Var); ok && v.Embedded() {
359 identicalName := false
360 // TODO(adonovan): should we allow a pointer (type A = *pkg.A)?
361 if rhs, ok := alias.Rhs().(*types.Named); ok {
362 identicalName = alias.Obj().Name() == rhs.Obj().Name()
363 }
364 if !identicalName {
365 // Type is embedded, inlining the alias will cause
366 // the field name to be changed, which might break
367 // programs in terms of backwards compatibility.
368 return
369 }
370 }
371
372 t := a.pass.TypesInfo.TypeOf(expr).(*types.Alias) // type of entire identifier
373 if targs := t.TypeArgs(); targs.Len() > 0 {
374 // Instantiate the alias with the type args from this use.
375 // For example, given type A = M[K, V], compute the type of the use
376 // A[int, Foo] as M[int, Foo].
377 // Don't validate instantiation: it can't panic unless we have a bug,
378 // in which case seeing the stack trace via telemetry would be helpful.
379 instAlias, _ := types.Instantiate(nil, alias, slices.Collect(targs.Types()), false)
380 rhs = instAlias.(*types.Alias).Rhs()
381 }
382
383 // We have an identifier A here (n), possibly qualified by a package
384 // identifier (sel.n), and an inlinable "type A = rhs" elsewhere.
385 //
386 // We can replace A with rhs if no name in rhs is shadowed at n's position,
387 // and every package in rhs is importable by the current package.
388 var (
389 importPrefixes = map[string]string{curPath: ""} // from pkg path to prefix
390 edits []analysis.TextEdit
391 )
392 for _, tn := range typenames(rhs) {
393 // Ignore the type parameters of the alias: they won't appear in the result.
394 if typeParamNames[tn] {
395 continue
396 }
397 var pkgPath, pkgName string
398 if pkg := tn.Pkg(); pkg != nil {
399 pkgPath = pkg.Path()
400 pkgName = pkg.Name()
401 }
402 if pkgPath == "" || pkgPath == curPath {
403 // The name is in the current package or the universe scope, so no import
404 // is required. Check that it is not shadowed (that is, that the type
405 // it refers to in rhs is the same one it refers to at n).
406 scope := a.pass.TypesInfo.Scopes[curFile].Innermost(id.Pos()) // n's scope
407 _, obj := scope.LookupParent(tn.Name(), id.Pos()) // what qn.name means in n's scope
408 if obj != tn {
409 return
410 }
411 } else if !packagepath.CanImport(a.pass.Pkg.Path(), pkgPath) {
412 // If this package can't see the package of this part of rhs, we can't inline.
413 return
414 } else if _, ok := importPrefixes[pkgPath]; !ok {
415 // Use AddImport to add pkgPath if it's not there already. Associate the prefix it assigns
416 // with the prefix it assigns
417 // with the package path for use by the TypeString qualifier below.
418 prefix, eds := refactor.AddImport(
419 a.pass.TypesInfo, curFile, pkgName, pkgPath, tn.Name(), id.Pos())
420 importPrefixes[pkgPath] = strings.TrimSuffix(prefix, ".")
421 edits = append(edits, eds...)
422 }
423 }
424
425 // To get the replacement text, render the alias RHS using the package prefixes
426 // we assigned above.
427 newText := types.TypeString(rhs, func(p *types.Package) string {
428 if p == a.pass.Pkg {
429 return ""
430 }
431 if prefix, ok := importPrefixes[p.Path()]; ok {
432 return prefix
433 }
434 panic(fmt.Sprintf("in %q, package path %q has no import prefix", rhs, p.Path()))
435 })
436 a.reportInline("type alias", "Type alias", expr, edits, newText)
437 }
438
439 // typenames returns the TypeNames for types within t (including t itself) that have
440 // them: basic types, named types and alias types.
441 // The same name may appear more than once.
442 func typenames(t types.Type) []*types.TypeName {
443 var tns []*types.TypeName
444
445 var visit func(types.Type)
446 visit = func(t types.Type) {
447 if hasName, ok := t.(interface{ Obj() *types.TypeName }); ok {
448 tns = append(tns, hasName.Obj())
449 }
450 switch t := t.(type) {
451 case *types.Basic:
452 tns = append(tns, types.Universe.Lookup(t.Name()).(*types.TypeName))
453 case *types.Named:
454 for t := range t.TypeArgs().Types() {
455 visit(t)
456 }
457 case *types.Alias:
458 for t := range t.TypeArgs().Types() {
459 visit(t)
460 }
461 case *types.TypeParam:
462 tns = append(tns, t.Obj())
463 case *types.Pointer:
464 visit(t.Elem())
465 case *types.Slice:
466 visit(t.Elem())
467 case *types.Array:
468 visit(t.Elem())
469 case *types.Chan:
470 visit(t.Elem())
471 case *types.Map:
472 visit(t.Key())
473 visit(t.Elem())
474 case *types.Struct:
475 for field := range t.Fields() {
476 visit(field.Type())
477 }
478 case *types.Signature:
479 // Ignore the receiver: although it may be present, it has no meaning
480 // in a type expression.
481 // Ditto for receiver type params.
482 // Also, function type params cannot appear in a type expression.
483 if t.TypeParams() != nil {
484 panic("Signature.TypeParams in type expression")
485 }
486 visit(t.Params())
487 visit(t.Results())
488 case *types.Interface:
489 for etyp := range t.EmbeddedTypes() {
490 visit(etyp)
491 }
492 for method := range t.ExplicitMethods() {
493 visit(method.Type())
494 }
495 case *types.Tuple:
496 for v := range t.Variables() {
497 visit(v.Type())
498 }
499 case *types.Union:
500 panic("Union in type expression")
501 default:
502 panic(fmt.Sprintf("unknown type %T", t))
503 }
504 }
505
506 visit(t)
507
508 return tns
509 }
510
511 // If con is an inlinable constant, suggest inlining its use at cur.
512 func (a *analyzer) inlineConst(con *types.Const, cur inspector.Cursor) {
513 incon, ok := a.inlinableConsts[con]
514 if !ok {
515 var fact goFixInlineConstFact
516 if a.pass.ImportObjectFact(con, &fact) {
517 incon = &fact
518 a.inlinableConsts[con] = incon
519 }
520 }
521 if incon == nil {
522 return // nope
523 }
524
525 if a.withinTestOf(cur, con) {
526 return // don't inline a type alias from within its own test
527 }
528
529 // If n is qualified by a package identifier, we'll need the full selector expression.
530 curFile := astutil.EnclosingFile(cur)
531 n := cur.Node().(*ast.Ident)
532
533 // We have an identifier A here (n), possibly qualified by a package identifier (sel.X,
534 // where sel is the parent of n), // and an inlinable "const A = B" elsewhere (incon).
535 // Consider replacing A with B.
536
537 // Check that the expression we are inlining (B) means the same thing
538 // (refers to the same object) in n's scope as it does in A's scope.
539 // If the RHS is not in the current package, AddImport will handle
540 // shadowing, so we only need to worry about when both expressions
541 // are in the current package.
542 if a.pass.Pkg.Path() == incon.RHSPkgPath {
543 // incon.rhsObj is the object referred to by B in the definition of A.
544 scope := a.pass.TypesInfo.Scopes[curFile].Innermost(n.Pos()) // n's scope
545 _, obj := scope.LookupParent(incon.RHSName, n.Pos()) // what "B" means in n's scope
546 if obj == nil {
547 // Should be impossible: if code at n can refer to the LHS,
548 // it can refer to the RHS.
549 panic(fmt.Sprintf("no object for inlinable const %s RHS %s", n.Name, incon.RHSName))
550 }
551 if obj != incon.rhsObj {
552 // "B" means something different here than at the inlinable const's scope.
553 return
554 }
555 } else if !packagepath.CanImport(a.pass.Pkg.Path(), incon.RHSPkgPath) {
556 // If this package can't see the RHS's package, we can't inline.
557 return
558 }
559 var (
560 importPrefix string
561 edits []analysis.TextEdit
562 )
563 if incon.RHSPkgPath != a.pass.Pkg.Path() {
564 importPrefix, edits = refactor.AddImport(
565 a.pass.TypesInfo, curFile, incon.RHSPkgName, incon.RHSPkgPath, incon.RHSName, n.Pos())
566 }
567 // If n is qualified by a package identifier, we'll need the full selector expression.
568 var expr ast.Expr = n
569 if cur.ParentEdgeKind() == edge.SelectorExpr_Sel {
570 expr = cur.Parent().Node().(ast.Expr)
571 }
572 a.reportInline("constant", "Constant", expr, edits, importPrefix+incon.RHSName)
573 }
574
575 // reportInline reports a diagnostic for fixing an inlinable name.
576 func (a *analyzer) reportInline(kind, capKind string, ident ast.Expr, edits []analysis.TextEdit, newText string) {
577 edits = append(edits, analysis.TextEdit{
578 Pos: ident.Pos(),
579 End: ident.End(),
580 NewText: []byte(newText),
581 })
582 name := astutil.Format(a.pass.Fset, ident)
583 a.pass.Report(analysis.Diagnostic{
584 Pos: ident.Pos(),
585 End: ident.End(),
586 Message: fmt.Sprintf("%s %s should be inlined", capKind, name),
587 SuggestedFixes: []analysis.SuggestedFix{{
588 Message: fmt.Sprintf("Inline %s %s", kind, name),
589 TextEdits: edits,
590 }},
591 })
592 }
593
594 func (a *analyzer) readFile(node ast.Node) ([]byte, error) {
595 filename := a.pass.Fset.File(node.Pos()).Name()
596 content, ok := a.fileContent[filename]
597 if !ok {
598 var err error
599 content, err = a.pass.ReadFile(filename)
600 if err != nil {
601 return nil, err
602 }
603 a.fileContent[filename] = content
604 }
605 return content, nil
606 }
607
608 // A goFixInlineFuncFact is exported for each function marked "//go:fix inline".
609 // It holds information about the callee to support inlining.
610 type goFixInlineFuncFact struct{ Callee *inline.Callee }
611
612 func (f *goFixInlineFuncFact) String() string { return "goFixInline " + f.Callee.String() }
613 func (*goFixInlineFuncFact) AFact() {}
614
615 // A goFixInlineConstFact is exported for each constant marked "//go:fix inline".
616 // It holds information about an inlinable constant. Gob-serializable.
617 type goFixInlineConstFact struct {
618 // Information about "const LHSName = RHSName".
619 RHSName string
620 RHSPkgPath string
621 RHSPkgName string
622 rhsObj types.Object // for current package
623 }
624
625 func (c *goFixInlineConstFact) String() string {
626 return fmt.Sprintf("goFixInline const %q.%s", c.RHSPkgPath, c.RHSName)
627 }
628
629 func (*goFixInlineConstFact) AFact() {}
630
631 // A goFixInlineAliasFact is exported for each type alias marked "//go:fix inline".
632 // It holds no information; its mere existence demonstrates that an alias is inlinable.
633 type goFixInlineAliasFact struct{}
634
635 func (c *goFixInlineAliasFact) String() string { return "goFixInline alias" }
636 func (*goFixInlineAliasFact) AFact() {}
637
638 func discard(string, ...any) {}