| 1 | // Copyright 2026 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 flow implements a monotone flow analysis framework. |
| 6 | package flowscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/ |
| 7 | |
| 8 | import ( |
| 9 | "cmpscip-go gomod github.com/golang/go/src go1.25.0 cmp/" |
| 10 | "slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/" |
| 11 | |
| 12 | "golang.org/x/tools/internal/graphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/" |
| 13 | ) |
| 14 | |
| 15 | const debugscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/debug. = false |
| 16 | |
| 17 | // Analysis is the result of a monotone analysis. Fact is the type of elements |
| 18 | // in the analysis semilattice, and represents the outcome of the analysis at |
| 19 | // every node and edge. |
| 20 | type Analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#[Fact any, NodeID comparable] struct { |
| 21 | nodeMapscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#nodeMap. *graphscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/.Indexscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/Index#[NodeID] |
| 22 | insscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#ins. []Fact // By NodeID |
| 23 | edgesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#edges. []edgeFactscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edgeFact#[Fact] // Sorted by (from, to) |
| 24 | } |
| 25 | |
| 26 | // In returns the analysis fact on entry to nid. This is the merge of the facts |
| 27 | // on all incoming edges. |
| 28 | func (a *Analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#[Fact, NodeID]) Inscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#In().(nid NodeID) Fact { |
| 29 | return a.insscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#ins.[a.nodeMapscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#nodeMap..Indexscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/Index#Index().(nid)] |
| 30 | } |
| 31 | |
| 32 | // Edge returns the analysis fact propagated on edge from ==> to. |
| 33 | func (a *Analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#[Fact, NodeID]) Edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#Edge().(from, to NodeID) Fact { |
| 34 | i, found := slicesscip-go gomod github.com/golang/go/src go1.25.0 slices/.BinarySearchFuncscip-go gomod github.com/golang/go/src go1.25.0 slices/BinarySearchFunc().(a.edgesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#edges., a.edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#edge().(from, to), edgeFactscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edgeFact#[Fact].comparescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edge#compare().) |
| 35 | if !found { |
| 36 | panic("no such edge") |
| 37 | } |
| 38 | return a.edgesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#edges.[i].factscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edgeFact#fact. |
| 39 | } |
| 40 | |
| 41 | func (a *Analysisscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#[Fact, NodeID]) edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#edge().(from, to NodeID) edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edge# { |
| 42 | fromNum, toNum := a.nodeMapscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#nodeMap..Indexscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/Index#Index().(from), a.nodeMapscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/Analysis#nodeMap..Indexscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/graph`/Index#Index().(to) |
| 43 | return edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edge#{fromNum, toNum} |
| 44 | } |
| 45 | |
| 46 | type edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edge# struct { |
| 47 | fromscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edge#from., toscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edge#to. int |
| 48 | } |
| 49 | |
| 50 | func (e edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edge#) comparescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edge#compare().(f edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edge#) int { |
| 51 | if v := cmpscip-go gomod github.com/golang/go/src go1.25.0 cmp/.Comparescip-go gomod github.com/golang/go/src go1.25.0 cmp/Compare().(e.fromscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edge#from., f.fromscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edge#from.); v != 0 { |
| 52 | return v |
| 53 | } |
| 54 | return cmpscip-go gomod github.com/golang/go/src go1.25.0 cmp/.Comparescip-go gomod github.com/golang/go/src go1.25.0 cmp/Compare().(e.toscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edge#to., f.toscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edge#to.) |
| 55 | } |
| 56 | |
| 57 | type edgeFactscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edgeFact#[Fact any] struct { |
| 58 | edgescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edgeFact#edge. |
| 59 | factscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/flow`/edgeFact#fact. Fact |
| 60 | } |