Skip to content

Commit 6823dc4

Browse files
committed
go/ssa: tidy the docs
In particular, remove the "EXPERIMENTAL" warning (we couldn't change the API if we wanted---and we do want), and use doc links where appropriate. Change-Id: Ib25e82a936ee79c2f60dc177c55409a76048cf52 Reviewed-on: https://go-review.googlesource.com/c/tools/+/548855 Reviewed-by: Robert Findley <[email protected]> Auto-Submit: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent f580f77 commit 6823dc4

File tree

3 files changed

+37
-36
lines changed

3 files changed

+37
-36
lines changed

go/ssa/doc.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
// static single-assignment (SSA) form intermediate representation
88
// (IR) for the bodies of functions.
99
//
10-
// THIS INTERFACE IS EXPERIMENTAL AND IS LIKELY TO CHANGE.
11-
//
1210
// For an introduction to SSA form, see
1311
// http://en.wikipedia.org/wiki/Static_single_assignment_form.
1412
// This page provides a broader reading list:
@@ -21,15 +19,15 @@
2119
// All looping, branching and switching constructs are replaced with
2220
// unstructured control flow. Higher-level control flow constructs
2321
// such as multi-way branch can be reconstructed as needed; see
24-
// ssautil.Switches() for an example.
22+
// [golang.org/x/tools/go/ssa/ssautil.Switches] for an example.
2523
//
2624
// The simplest way to create the SSA representation of a package is
27-
// to load typed syntax trees using golang.org/x/tools/go/packages, then
28-
// invoke the ssautil.Packages helper function. See Example_loadPackages
29-
// and Example_loadWholeProgram for examples.
30-
// The resulting ssa.Program contains all the packages and their
25+
// to load typed syntax trees using [golang.org/x/tools/go/packages], then
26+
// invoke the [golang.org/x/tools/go/ssa/ssautil.Packages] helper function.
27+
// (See the package-level Examples named LoadPackages and LoadWholeProgram.)
28+
// The resulting [ssa.Program] contains all the packages and their
3129
// members, but SSA code is not created for function bodies until a
32-
// subsequent call to (*Package).Build or (*Program).Build.
30+
// subsequent call to [Package.Build] or [Program.Build].
3331
//
3432
// The builder initially builds a naive SSA form in which all local
3533
// variables are addresses of stack locations with explicit loads and
@@ -41,13 +39,13 @@
4139
//
4240
// The primary interfaces of this package are:
4341
//
44-
// - Member: a named member of a Go package.
45-
// - Value: an expression that yields a value.
46-
// - Instruction: a statement that consumes values and performs computation.
47-
// - Node: a Value or Instruction (emphasizing its membership in the SSA value graph)
42+
// - [Member]: a named member of a Go package.
43+
// - [Value]: an expression that yields a value.
44+
// - [Instruction]: a statement that consumes values and performs computation.
45+
// - [Node]: a [Value] or [Instruction] (emphasizing its membership in the SSA value graph)
4846
//
49-
// A computation that yields a result implements both the Value and
50-
// Instruction interfaces. The following table shows for each
47+
// A computation that yields a result implements both the [Value] and
48+
// [Instruction] interfaces. The following table shows for each
5149
// concrete type which of these interfaces it implements.
5250
//
5351
// Value? Instruction? Member?
@@ -97,24 +95,25 @@
9795
// *TypeAssert ✔ ✔
9896
// *UnOp ✔ ✔
9997
//
100-
// Other key types in this package include: Program, Package, Function
101-
// and BasicBlock.
98+
// Other key types in this package include: [Program], [Package], [Function]
99+
// and [BasicBlock].
102100
//
103101
// The program representation constructed by this package is fully
104102
// resolved internally, i.e. it does not rely on the names of Values,
105103
// Packages, Functions, Types or BasicBlocks for the correct
106104
// interpretation of the program. Only the identities of objects and
107105
// the topology of the SSA and type graphs are semantically
108-
// significant. (There is one exception: Ids, used to identify field
106+
// significant. (There is one exception: [types.Id] values, which identify field
109107
// and method names, contain strings.) Avoidance of name-based
110108
// operations simplifies the implementation of subsequent passes and
111109
// can make them very efficient. Many objects are nonetheless named
112110
// to aid in debugging, but it is not essential that the names be
113111
// either accurate or unambiguous. The public API exposes a number of
114112
// name-based maps for client convenience.
115113
//
116-
// The ssa/ssautil package provides various utilities that depend only
117-
// on the public API of this package.
114+
// The [golang.org/x/tools/go/ssa/ssautil] package provides various
115+
// helper functions, for example to simplify loading a Go program into
116+
// SSA form.
118117
//
119118
// TODO(adonovan): write a how-to document for all the various cases
120119
// of trying to determine corresponding elements across the four

go/ssa/example_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ func main() {
3737
`
3838

3939
// This program demonstrates how to run the SSA builder on a single
40-
// package of one or more already-parsed files. Its dependencies are
41-
// loaded from compiler export data. This is what you'd typically use
42-
// for a compiler; it does not depend on golang.org/x/tools/go/loader.
40+
// package of one or more already-parsed files. Its dependencies are
41+
// loaded from compiler export data. This is what you'd typically use
42+
// for a compiler; it does not depend on the obsolete
43+
// [golang.org/x/tools/go/loader].
4344
//
4445
// It shows the printed representation of packages, functions, and
4546
// instructions. Within the function listing, the name of each
@@ -52,7 +53,7 @@ func main() {
5253
//
5354
// Build and run the ssadump.go program if you want a standalone tool
5455
// with similar functionality. It is located at
55-
// golang.org/x/tools/cmd/ssadump.
56+
// [golang.org/x/tools/cmd/ssadump].
5657
//
5758
// Use ssautil.BuildPackage only if you have parsed--but not
5859
// type-checked--syntax trees. Typically, clients already have typed
@@ -127,7 +128,7 @@ func Example_buildPackage() {
127128
}
128129

129130
// This example builds SSA code for a set of packages using the
130-
// x/tools/go/packages API. This is what you would typically use for a
131+
// [golang.org/x/tools/go/packages] API. This is what you would typically use for a
131132
// analysis capable of operating on a single package.
132133
func Example_loadPackages() {
133134
// Load, parse, and type-check the initial packages.
@@ -157,7 +158,7 @@ func Example_loadPackages() {
157158
}
158159

159160
// This example builds SSA code for a set of packages plus all their dependencies,
160-
// using the x/tools/go/packages API.
161+
// using the [golang.org/x/tools/go/packages] API.
161162
// This is what you'd typically use for a whole-program analysis.
162163
func Example_loadWholeProgram() {
163164
// Load, parse, and type-check the whole program.

go/ssa/ssautil/load.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ import (
2121
// Packages creates an SSA program for a set of packages.
2222
//
2323
// The packages must have been loaded from source syntax using the
24-
// golang.org/x/tools/go/packages.Load function in LoadSyntax or
25-
// LoadAllSyntax mode.
24+
// [packages.Load] function in [packages.LoadSyntax] or
25+
// [packages.LoadAllSyntax] mode.
2626
//
2727
// Packages creates an SSA package for each well-typed package in the
2828
// initial list, plus all their dependencies. The resulting list of
2929
// packages corresponds to the list of initial packages, and may contain
3030
// a nil if SSA code could not be constructed for the corresponding initial
3131
// package due to type errors.
3232
//
33-
// Code for bodies of functions is not built until Build is called on
34-
// the resulting Program. SSA code is constructed only for the initial
35-
// packages with well-typed syntax trees.
33+
// Code for bodies of functions is not built until [Program.Build] is
34+
// called on the resulting Program. SSA code is constructed only for
35+
// the initial packages with well-typed syntax trees.
3636
//
3737
// The mode parameter controls diagnostics and checking during SSA construction.
3838
func Packages(initial []*packages.Package, mode ssa.BuilderMode) (*ssa.Program, []*ssa.Package) {
@@ -61,7 +61,7 @@ func Packages(initial []*packages.Package, mode ssa.BuilderMode) (*ssa.Program,
6161
// their dependencies.
6262
//
6363
// The packages must have been loaded from source syntax using the
64-
// golang.org/x/tools/go/packages.Load function in LoadAllSyntax mode.
64+
// [packages.Load] function in [packages.LoadAllSyntax] mode.
6565
//
6666
// AllPackages creates an SSA package for each well-typed package in the
6767
// initial list, plus all their dependencies. The resulting list of
@@ -121,7 +121,7 @@ func doPackages(initial []*packages.Package, mode ssa.BuilderMode, deps bool) (*
121121
//
122122
// The mode parameter controls diagnostics and checking during SSA construction.
123123
//
124-
// Deprecated: Use golang.org/x/tools/go/packages and the Packages
124+
// Deprecated: Use [golang.org/x/tools/go/packages] and the [Packages]
125125
// function instead; see ssa.Example_loadPackages.
126126
func CreateProgram(lprog *loader.Program, mode ssa.BuilderMode) *ssa.Program {
127127
prog := ssa.NewProgram(lprog.Fset, mode)
@@ -135,16 +135,17 @@ func CreateProgram(lprog *loader.Program, mode ssa.BuilderMode) *ssa.Program {
135135
return prog
136136
}
137137

138-
// BuildPackage builds an SSA program with IR for a single package.
138+
// BuildPackage builds an SSA program with SSA intermediate
139+
// representation (IR) for all functions of a single package.
139140
//
140-
// It populates pkg by type-checking the specified file ASTs. All
141+
// It populates pkg by type-checking the specified file syntax trees. All
141142
// dependencies are loaded using the importer specified by tc, which
142143
// typically loads compiler export data; SSA code cannot be built for
143-
// those packages. BuildPackage then constructs an ssa.Program with all
144+
// those packages. BuildPackage then constructs an [ssa.Program] with all
144145
// dependency packages created, and builds and returns the SSA package
145146
// corresponding to pkg.
146147
//
147-
// The caller must have set pkg.Path() to the import path.
148+
// The caller must have set pkg.Path to the import path.
148149
//
149150
// The operation fails if there were any type-checking or import errors.
150151
//

0 commit comments

Comments
 (0)