2015-08-13 19:05:37 -07:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
// Binary package export.
|
|
|
|
|
|
|
|
|
|
/*
|
2016-05-25 11:23:56 -07:00
|
|
|
1) Export data encoding principles:
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
The export data is a serialized description of the graph of exported
|
2016-10-25 14:09:18 -07:00
|
|
|
"objects": constants, types, variables, and functions. Aliases may be
|
|
|
|
|
directly reexported, and unaliased types may be indirectly reexported
|
2016-10-27 11:20:20 -07:00
|
|
|
(as part of the type of a directly exported object). More generally,
|
2016-10-25 14:09:18 -07:00
|
|
|
objects referred to from inlined function bodies can be reexported.
|
|
|
|
|
We need to know which package declares these reexported objects, and
|
|
|
|
|
therefore packages are also part of the export graph.
|
2015-08-13 19:05:37 -07:00
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
The roots of the graph are two lists of objects. The 1st list (phase 1,
|
|
|
|
|
see Export) contains all objects that are exported at the package level.
|
|
|
|
|
These objects are the full representation of the package's API, and they
|
|
|
|
|
are the only information a platform-independent tool (e.g., go/types)
|
|
|
|
|
needs to know to type-check against a package.
|
|
|
|
|
|
|
|
|
|
The 2nd list of objects contains all objects referred to from exported
|
|
|
|
|
inlined function bodies. These objects are needed by the compiler to
|
|
|
|
|
make sense of the function bodies; the exact list contents are compiler-
|
|
|
|
|
specific.
|
|
|
|
|
|
|
|
|
|
Finally, the export data contains a list of representations for inlined
|
|
|
|
|
function bodies. The format of this representation is compiler specific.
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
The graph is serialized in in-order fashion, starting with the roots.
|
|
|
|
|
Each object in the graph is serialized by writing its fields sequentially.
|
2016-10-25 14:09:18 -07:00
|
|
|
If the field is a pointer to another object, that object is serialized in
|
|
|
|
|
place, recursively. Otherwise the field is written in place. Non-pointer
|
|
|
|
|
fields are all encoded as integer or string values.
|
2015-08-13 19:05:37 -07:00
|
|
|
|
2016-04-13 17:53:03 -07:00
|
|
|
Some objects (packages, types) may be referred to more than once. When
|
|
|
|
|
reaching an object that was not serialized before, an integer _index_
|
2015-10-22 18:56:45 -07:00
|
|
|
is assigned to it, starting at 0. In this case, the encoding starts
|
|
|
|
|
with an integer _tag_ < 0. The tag value indicates the kind of object
|
2016-04-13 17:53:03 -07:00
|
|
|
that follows and that this is the first time that we see this object.
|
|
|
|
|
If the object was already serialized, the encoding is simply the object
|
|
|
|
|
index >= 0. An importer can trivially determine if an object needs to
|
|
|
|
|
be read in for the first time (tag < 0) and entered into the respective
|
|
|
|
|
object table, or if the object was seen already (index >= 0), in which
|
2016-10-25 14:09:18 -07:00
|
|
|
case the index is used to look up the object in the respective table.
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
Before exporting or importing, the type tables are populated with the
|
|
|
|
|
predeclared types (int, string, error, unsafe.Pointer, etc.). This way
|
|
|
|
|
they are automatically encoded with a known and fixed type index.
|
|
|
|
|
|
2016-05-25 11:23:56 -07:00
|
|
|
2) Encoding format:
|
2015-08-13 19:05:37 -07:00
|
|
|
|
2016-08-19 18:10:00 -07:00
|
|
|
The export data starts with two newline-terminated strings: a version
|
|
|
|
|
string and either an empty string, or "debug", when emitting the debug
|
|
|
|
|
format. These strings are followed by version-specific encoding options.
|
2015-08-13 19:05:37 -07:00
|
|
|
|
2016-08-19 18:10:00 -07:00
|
|
|
(The Go1.7 version starts with a couple of bytes specifying the format.
|
|
|
|
|
That format encoding is no longer used but is supported to avoid spurious
|
|
|
|
|
errors when importing old installed package files.)
|
|
|
|
|
|
2016-10-25 14:09:18 -07:00
|
|
|
This header is followed by the package object for the exported package,
|
2016-08-19 18:10:00 -07:00
|
|
|
two lists of objects, and the list of inlined function bodies.
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
The encoding of objects is straight-forward: Constants, variables, and
|
|
|
|
|
functions start with their name, type, and possibly a value. Named types
|
|
|
|
|
record their name and package so that they can be canonicalized: If the
|
|
|
|
|
same type was imported before via another import, the importer must use
|
|
|
|
|
the previously imported type pointer so that we have exactly one version
|
|
|
|
|
(i.e., one pointer) for each named type (and read but discard the current
|
|
|
|
|
type encoding). Unnamed types simply encode their respective fields.
|
2016-11-02 20:34:29 -07:00
|
|
|
Aliases are encoded starting with their name followed by the qualified
|
|
|
|
|
identifier denoting the original (aliased) object, which was exported
|
|
|
|
|
earlier.
|
2015-08-13 19:05:37 -07:00
|
|
|
|
2016-04-13 17:53:03 -07:00
|
|
|
In the encoding, some lists start with the list length. Some lists are
|
|
|
|
|
terminated with an end marker (usually for lists where we may not know
|
|
|
|
|
the length a priori).
|
|
|
|
|
|
|
|
|
|
Integers use variable-length encoding for compact representation.
|
2015-08-13 19:05:37 -07:00
|
|
|
|
2016-04-13 17:53:03 -07:00
|
|
|
Strings are canonicalized similar to objects that may occur multiple times:
|
|
|
|
|
If the string was exported already, it is represented by its index only.
|
|
|
|
|
Otherwise, the export data starts with the negative string length (negative,
|
|
|
|
|
so we can distinguish from string index), followed by the string bytes.
|
2016-08-19 18:10:00 -07:00
|
|
|
The empty string is mapped to index 0. (The initial format string is an
|
|
|
|
|
exception; it is encoded as the string bytes followed by a newline).
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
The exporter and importer are completely symmetric in implementation: For
|
2015-10-22 18:56:45 -07:00
|
|
|
each encoding routine there is a matching and symmetric decoding routine.
|
2015-08-13 19:05:37 -07:00
|
|
|
This symmetry makes it very easy to change or extend the format: If a new
|
|
|
|
|
field needs to be encoded, a symmetric change can be made to exporter and
|
|
|
|
|
importer.
|
2016-05-25 11:23:56 -07:00
|
|
|
|
|
|
|
|
3) Making changes to the encoding format:
|
|
|
|
|
|
|
|
|
|
Any change to the encoding format requires a respective change in the
|
|
|
|
|
exporter below and a corresponding symmetric change to the importer in
|
|
|
|
|
bimport.go.
|
|
|
|
|
|
|
|
|
|
Furthermore, it requires a corresponding change to go/internal/gcimporter
|
|
|
|
|
and golang.org/x/tools/go/gcimporter15. Changes to the latter must preserve
|
|
|
|
|
compatibility with both the last release of the compiler, and with the
|
|
|
|
|
corresponding compiler at tip. That change is necessarily more involved,
|
|
|
|
|
as it must switch based on the version number in the export data file.
|
|
|
|
|
|
2016-10-25 14:09:18 -07:00
|
|
|
It is recommended to turn on debugFormat temporarily when working on format
|
|
|
|
|
changes as it will help finding encoding/decoding inconsistencies quickly.
|
2015-08-13 19:05:37 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package gc
|
|
|
|
|
|
|
|
|
|
import (
|
2016-04-08 19:30:41 +10:00
|
|
|
"bufio"
|
2015-08-13 19:05:37 -07:00
|
|
|
"bytes"
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
"cmd/compile/internal/types"
|
2015-08-13 19:05:37 -07:00
|
|
|
"encoding/binary"
|
|
|
|
|
"fmt"
|
2016-10-19 12:58:16 -07:00
|
|
|
"math/big"
|
2015-08-13 19:05:37 -07:00
|
|
|
"sort"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// If debugFormat is set, each integer and string value is preceded by a marker
|
|
|
|
|
// and position information in the encoding. This mechanism permits an importer
|
|
|
|
|
// to recognize immediately when it is out of sync. The importer recognizes this
|
|
|
|
|
// mode automatically (i.e., it can import export data produced with debugging
|
|
|
|
|
// support even if debugFormat is not set at the time of import). This mode will
|
|
|
|
|
// lead to massively larger export data (by a factor of 2 to 3) and should only
|
|
|
|
|
// be enabled during development and debugging.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: This flag is the first flag to enable if importing dies because of
|
|
|
|
|
// (suspected) format errors, and whenever a change is made to the format.
|
|
|
|
|
const debugFormat = false // default: false
|
2015-08-13 19:05:37 -07:00
|
|
|
|
2016-08-25 16:53:10 -07:00
|
|
|
// Current export format version. Increase with each format change.
|
2017-04-24 06:06:14 -07:00
|
|
|
// 5: improved position encoding efficiency (issue 20080, CL 41619)
|
2016-12-22 13:04:04 -08:00
|
|
|
// 4: type name objects support type aliases, uses aliasTag
|
|
|
|
|
// 3: Go1.8 encoding (same as version 2, aliasTag defined but never used)
|
|
|
|
|
// 2: removed unused bool in ODCL export (compiler only)
|
2016-10-25 14:09:18 -07:00
|
|
|
// 1: header format change (more regular), export package for _ struct fields
|
|
|
|
|
// 0: Go1.7 encoding
|
2017-04-24 06:06:14 -07:00
|
|
|
const exportVersion = 5
|
2015-08-13 19:05:37 -07:00
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// exportInlined enables the export of inlined function bodies and related
|
|
|
|
|
// dependencies. The compiler should work w/o any loss of functionality with
|
|
|
|
|
// the flag disabled, but the generated code will lose access to inlined
|
|
|
|
|
// function bodies across packages, leading to performance bugs.
|
|
|
|
|
// Leave for debugging.
|
|
|
|
|
const exportInlined = true // default: true
|
|
|
|
|
|
2016-05-05 18:03:59 -07:00
|
|
|
// trackAllTypes enables cycle tracking for all types, not just named
|
|
|
|
|
// types. The existing compiler invariants assume that unnamed types
|
|
|
|
|
// that are not completely set up are not used, or else there are spurious
|
|
|
|
|
// errors.
|
|
|
|
|
// If disabled, only named types are tracked, possibly leading to slightly
|
|
|
|
|
// less efficient encoding in rare cases. It also prevents the export of
|
2016-08-16 12:55:17 -07:00
|
|
|
// some corner-case type declarations (but those were not handled correctly
|
|
|
|
|
// with the former textual export format either).
|
2017-05-01 08:06:48 -07:00
|
|
|
// Note that when a type is only seen once, as many unnamed types are,
|
|
|
|
|
// it is less efficient to track it, since we then also record an index for it.
|
|
|
|
|
// See CLs 41622 and 41623 for some data and discussion.
|
|
|
|
|
// TODO(gri) enable selectively and remove once issues caused by it are fixed
|
2016-05-05 18:03:59 -07:00
|
|
|
const trackAllTypes = false
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
type exporter struct {
|
2016-04-12 18:00:04 -07:00
|
|
|
out *bufio.Writer
|
|
|
|
|
|
2016-04-13 17:53:03 -07:00
|
|
|
// object -> index maps, indexed in order of serialization
|
2017-04-24 06:06:14 -07:00
|
|
|
strIndex map[string]int
|
|
|
|
|
pathIndex map[string]int
|
|
|
|
|
pkgIndex map[*types.Pkg]int
|
|
|
|
|
typIndex map[*types.Type]int
|
|
|
|
|
funcList []*Func
|
2016-04-13 17:53:03 -07:00
|
|
|
|
cmd/compile: don't export unreachable inline method bodies
Previously, anytime we exported a function or method declaration
(which includes methods for every type transitively exported), we
included the inline function bodies, if any. However, in many cases,
it's impossible (or at least very unlikely) for the importing package
to call the method.
For example:
package p
type T int
func (t T) M() { t.u() }
func (t T) u() {}
func (t T) v() {}
T.M and T.u are inlineable, and they're both reachable through calls
to T.M, which is exported. However, t.v is also inlineable, but cannot
be reached.
Exception: if p.T is embedded in another type q.U, p.T.v will be
promoted to q.U.v, and the generated wrapper function could have
inlined the call to p.T.v. However, in practice, this doesn't happen,
and a missed inlining opportunity doesn't affect correctness.
To implement this, this CL introduces an extra flood fill pass before
exporting to mark inline bodies that are actually reachable, so the
exporter can skip over methods like t.v.
This reduces Kubernetes build time (as measured by "time go build -a
k8s.io/kubernetes/cmd/...") on an HP Z620 measurably:
== before ==
real 0m44.658s
user 11m19.136s
sys 0m53.844s
== after ==
real 0m41.702s
user 10m29.732s
sys 0m50.908s
It also significantly cuts down the cost of enabling mid-stack
inlining (-l=4):
== before (-l=4) ==
real 1m19.236s
user 20m6.528s
sys 1m17.328s
== after (-l=4) ==
real 0m59.100s
user 13m12.808s
sys 0m58.776s
Updates #19348.
Change-Id: Iade58233ca42af823a1630517a53848b5d3c7a7e
Reviewed-on: https://go-review.googlesource.com/74110
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2017-10-27 15:36:59 -07:00
|
|
|
marked map[*types.Type]bool // types already seen by markType
|
|
|
|
|
|
2016-04-13 17:53:03 -07:00
|
|
|
// position encoding
|
2016-04-26 22:31:02 -07:00
|
|
|
posInfoFormat bool
|
|
|
|
|
prevFile string
|
|
|
|
|
prevLine int
|
2016-03-18 17:21:32 -07:00
|
|
|
|
|
|
|
|
// debugging support
|
|
|
|
|
written int // bytes written
|
|
|
|
|
indent int // for p.trace
|
|
|
|
|
trace bool
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-08 20:09:10 +10:00
|
|
|
// export writes the exportlist for localpkg to out and returns the number of bytes written.
|
2016-04-08 19:30:41 +10:00
|
|
|
func export(out *bufio.Writer, trace bool) int {
|
2015-08-13 19:05:37 -07:00
|
|
|
p := exporter{
|
2016-10-19 12:58:16 -07:00
|
|
|
out: out,
|
|
|
|
|
strIndex: map[string]int{"": 0}, // empty string is mapped to 0
|
2017-04-24 06:06:14 -07:00
|
|
|
pathIndex: map[string]int{"": 0}, // empty path is mapped to 0
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
pkgIndex: make(map[*types.Pkg]int),
|
|
|
|
|
typIndex: make(map[*types.Type]int),
|
2016-10-19 12:58:16 -07:00
|
|
|
posInfoFormat: true,
|
2016-04-26 22:31:02 -07:00
|
|
|
trace: trace,
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-08-19 18:10:00 -07:00
|
|
|
// write version info
|
2016-08-25 16:53:10 -07:00
|
|
|
// The version string must start with "version %d" where %d is the version
|
|
|
|
|
// number. Additional debugging information may follow after a blank; that
|
|
|
|
|
// text is ignored by the importer.
|
|
|
|
|
p.rawStringln(fmt.Sprintf("version %d", exportVersion))
|
2016-08-19 18:10:00 -07:00
|
|
|
var debug string
|
2015-08-13 19:05:37 -07:00
|
|
|
if debugFormat {
|
2016-08-19 18:10:00 -07:00
|
|
|
debug = "debug"
|
2016-05-05 18:03:59 -07:00
|
|
|
}
|
2016-08-19 18:10:00 -07:00
|
|
|
p.rawStringln(debug) // cannot use p.bool since it's affected by debugFormat; also want to see this clearly
|
|
|
|
|
p.bool(trackAllTypes)
|
2016-04-26 22:31:02 -07:00
|
|
|
p.bool(p.posInfoFormat)
|
2016-04-22 14:50:20 -07:00
|
|
|
|
2015-08-13 19:05:37 -07:00
|
|
|
// --- generic export data ---
|
|
|
|
|
|
|
|
|
|
// populate type map with predeclared "known" types
|
|
|
|
|
predecl := predeclared()
|
|
|
|
|
for index, typ := range predecl {
|
|
|
|
|
p.typIndex[typ] = index
|
|
|
|
|
}
|
|
|
|
|
if len(p.typIndex) != len(predecl) {
|
2015-10-22 18:56:45 -07:00
|
|
|
Fatalf("exporter: duplicate entries in type map?")
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// write package data
|
|
|
|
|
if localpkg.Path != "" {
|
2015-10-22 18:56:45 -07:00
|
|
|
Fatalf("exporter: local package path not empty: %q", localpkg.Path)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
p.pkg(localpkg)
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// export objects
|
2016-04-12 11:31:16 -07:00
|
|
|
//
|
cmd/compile: simplify reexport logic
Currently, we reexport any package-scope constant, function, type, or
variable declarations needed by an inlineable function body. However,
now that we have an early pass to walk inlineable function bodies
(golang.org/cl/74110), we can simplify the logic for finding these
declarations.
The binary export format supports writing out type declarations
in-place at their first use. Also, it always writes out constants by
value, so their declarations never need to be reexported.
Notably, we attempted this before (golang.org/cl/36170) and had to
revert it (golang.org/cl/45911). However, this was because while
writing out inline bodies, we could discover variable/function
dependencies. By collecting variable/function dependencies during
inlineable function discovery, we avoid this problem.
While here, get rid of isInlineable. We already typecheck inlineable
function bodies during inlFlood, so it's become a no-op. Just move the
comment explaining parameter numbering to its caller.
Change-Id: Ibbfaafce793733675d3a2ad98791758583055666
Reviewed-on: https://go-review.googlesource.com/103864
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-30 18:58:03 -07:00
|
|
|
// We've already added all exported (package-level) objects to
|
|
|
|
|
// exportlist. These objects represent all information
|
|
|
|
|
// required to import this package and type-check against it;
|
|
|
|
|
// i.e., this is the platform-independent export data. The
|
|
|
|
|
// format is generic in the sense that different compilers can
|
|
|
|
|
// use the same representation.
|
2016-03-18 17:21:32 -07:00
|
|
|
//
|
cmd/compile: simplify reexport logic
Currently, we reexport any package-scope constant, function, type, or
variable declarations needed by an inlineable function body. However,
now that we have an early pass to walk inlineable function bodies
(golang.org/cl/74110), we can simplify the logic for finding these
declarations.
The binary export format supports writing out type declarations
in-place at their first use. Also, it always writes out constants by
value, so their declarations never need to be reexported.
Notably, we attempted this before (golang.org/cl/36170) and had to
revert it (golang.org/cl/45911). However, this was because while
writing out inline bodies, we could discover variable/function
dependencies. By collecting variable/function dependencies during
inlineable function discovery, we avoid this problem.
While here, get rid of isInlineable. We already typecheck inlineable
function bodies during inlFlood, so it's become a no-op. Just move the
comment explaining parameter numbering to its caller.
Change-Id: Ibbfaafce793733675d3a2ad98791758583055666
Reviewed-on: https://go-review.googlesource.com/103864
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-30 18:58:03 -07:00
|
|
|
// However, due to inlineable function and their dependencies,
|
|
|
|
|
// we may need to export (or possibly reexport) additional
|
|
|
|
|
// objects. We handle these objects separately. This data is
|
|
|
|
|
// platform-specific as it depends on the inlining decisions
|
|
|
|
|
// of the compiler and the representation of the inlined
|
|
|
|
|
// function bodies.
|
|
|
|
|
|
|
|
|
|
// Remember initial exportlist length.
|
|
|
|
|
numglobals := len(exportlist)
|
|
|
|
|
|
|
|
|
|
// Phase 0: Mark all inlineable functions that an importing
|
|
|
|
|
// package could call. This is done by tracking down all
|
|
|
|
|
// inlineable methods reachable from exported declarations.
|
|
|
|
|
//
|
|
|
|
|
// Along the way, we add to exportlist any function and
|
|
|
|
|
// variable declarations needed by the inline bodies.
|
|
|
|
|
if exportInlined {
|
|
|
|
|
p.marked = make(map[*types.Type]bool)
|
|
|
|
|
for _, n := range exportlist {
|
|
|
|
|
sym := n.Sym
|
|
|
|
|
p.markType(asNode(sym.Def).Type)
|
|
|
|
|
}
|
|
|
|
|
p.marked = nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Phase 1: Export package-level objects.
|
2016-03-18 17:21:32 -07:00
|
|
|
objcount := 0
|
cmd/compile: simplify reexport logic
Currently, we reexport any package-scope constant, function, type, or
variable declarations needed by an inlineable function body. However,
now that we have an early pass to walk inlineable function bodies
(golang.org/cl/74110), we can simplify the logic for finding these
declarations.
The binary export format supports writing out type declarations
in-place at their first use. Also, it always writes out constants by
value, so their declarations never need to be reexported.
Notably, we attempted this before (golang.org/cl/36170) and had to
revert it (golang.org/cl/45911). However, this was because while
writing out inline bodies, we could discover variable/function
dependencies. By collecting variable/function dependencies during
inlineable function discovery, we avoid this problem.
While here, get rid of isInlineable. We already typecheck inlineable
function bodies during inlFlood, so it's become a no-op. Just move the
comment explaining parameter numbering to its caller.
Change-Id: Ibbfaafce793733675d3a2ad98791758583055666
Reviewed-on: https://go-review.googlesource.com/103864
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-30 18:58:03 -07:00
|
|
|
for _, n := range exportlist[:numglobals] {
|
2015-08-13 19:05:37 -07:00
|
|
|
sym := n.Sym
|
2016-03-18 17:21:32 -07:00
|
|
|
|
2015-08-13 19:05:37 -07:00
|
|
|
// TODO(gri) Closures have dots in their names;
|
|
|
|
|
// e.g., TestFloatZeroValue.func1 in math/big tests.
|
|
|
|
|
if strings.Contains(sym.Name, ".") {
|
2015-10-22 18:56:45 -07:00
|
|
|
Fatalf("exporter: unexpected symbol: %v", sym)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
if sym.Def == nil {
|
|
|
|
|
Fatalf("exporter: unknown export symbol: %v", sym)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// TODO(gri) Optimization: Probably worthwhile collecting
|
|
|
|
|
// long runs of constants and export them "in bulk" (saving
|
|
|
|
|
// tags and types, and making import faster).
|
2015-08-13 19:05:37 -07:00
|
|
|
|
2015-10-22 18:56:45 -07:00
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
2016-03-18 17:21:32 -07:00
|
|
|
p.obj(sym)
|
|
|
|
|
objcount++
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// indicate end of list
|
2015-10-22 18:56:45 -07:00
|
|
|
if p.trace {
|
2016-03-18 17:21:32 -07:00
|
|
|
p.tracef("\n")
|
2015-10-22 18:56:45 -07:00
|
|
|
}
|
2016-03-18 17:21:32 -07:00
|
|
|
p.tag(endTag)
|
|
|
|
|
|
|
|
|
|
// for self-verification only (redundant)
|
|
|
|
|
p.int(objcount)
|
|
|
|
|
|
|
|
|
|
// --- compiler-specific export data ---
|
|
|
|
|
|
2015-10-22 18:56:45 -07:00
|
|
|
if p.trace {
|
2016-03-18 17:21:32 -07:00
|
|
|
p.tracef("\n--- compiler-specific export data ---\n[ ")
|
|
|
|
|
if p.indent != 0 {
|
|
|
|
|
Fatalf("exporter: incorrect indentation")
|
2015-10-22 18:56:45 -07:00
|
|
|
}
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-04-12 11:31:16 -07:00
|
|
|
// write compiler-specific flags
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: simplify reexport logic
Currently, we reexport any package-scope constant, function, type, or
variable declarations needed by an inlineable function body. However,
now that we have an early pass to walk inlineable function bodies
(golang.org/cl/74110), we can simplify the logic for finding these
declarations.
The binary export format supports writing out type declarations
in-place at their first use. Also, it always writes out constants by
value, so their declarations never need to be reexported.
Notably, we attempted this before (golang.org/cl/36170) and had to
revert it (golang.org/cl/45911). However, this was because while
writing out inline bodies, we could discover variable/function
dependencies. By collecting variable/function dependencies during
inlineable function discovery, we avoid this problem.
While here, get rid of isInlineable. We already typecheck inlineable
function bodies during inlFlood, so it's become a no-op. Just move the
comment explaining parameter numbering to its caller.
Change-Id: Ibbfaafce793733675d3a2ad98791758583055666
Reviewed-on: https://go-review.googlesource.com/103864
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-30 18:58:03 -07:00
|
|
|
// Phase 2: Export objects added to exportlist during phase 0.
|
2016-03-18 17:21:32 -07:00
|
|
|
objcount = 0
|
cmd/compile: simplify reexport logic
Currently, we reexport any package-scope constant, function, type, or
variable declarations needed by an inlineable function body. However,
now that we have an early pass to walk inlineable function bodies
(golang.org/cl/74110), we can simplify the logic for finding these
declarations.
The binary export format supports writing out type declarations
in-place at their first use. Also, it always writes out constants by
value, so their declarations never need to be reexported.
Notably, we attempted this before (golang.org/cl/36170) and had to
revert it (golang.org/cl/45911). However, this was because while
writing out inline bodies, we could discover variable/function
dependencies. By collecting variable/function dependencies during
inlineable function discovery, we avoid this problem.
While here, get rid of isInlineable. We already typecheck inlineable
function bodies during inlFlood, so it's become a no-op. Just move the
comment explaining parameter numbering to its caller.
Change-Id: Ibbfaafce793733675d3a2ad98791758583055666
Reviewed-on: https://go-review.googlesource.com/103864
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-30 18:58:03 -07:00
|
|
|
for _, n := range exportlist[numglobals:] {
|
2016-03-18 17:21:32 -07:00
|
|
|
sym := n.Sym
|
|
|
|
|
|
|
|
|
|
// TODO(gri) The rest of this loop body is identical with
|
|
|
|
|
// the loop body above. Leave alone for now since there
|
|
|
|
|
// are different optimization opportunities, but factor
|
|
|
|
|
// eventually.
|
|
|
|
|
|
|
|
|
|
// TODO(gri) Closures have dots in their names;
|
|
|
|
|
// e.g., TestFloatZeroValue.func1 in math/big tests.
|
|
|
|
|
if strings.Contains(sym.Name, ".") {
|
|
|
|
|
Fatalf("exporter: unexpected symbol: %v", sym)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if sym.Def == nil {
|
|
|
|
|
Fatalf("exporter: unknown export symbol: %v", sym)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// TODO(gri) Optimization: Probably worthwhile collecting
|
|
|
|
|
// long runs of constants and export them "in bulk" (saving
|
|
|
|
|
// tags and types, and making import faster).
|
|
|
|
|
|
2015-10-22 18:56:45 -07:00
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
2016-10-25 14:09:18 -07:00
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if IsAlias(sym) {
|
2017-01-11 11:24:35 -08:00
|
|
|
Fatalf("exporter: unexpected type alias %v in inlined function body", sym)
|
2016-10-25 14:09:18 -07:00
|
|
|
}
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
p.obj(sym)
|
|
|
|
|
objcount++
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// indicate end of list
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
|
|
|
|
p.tag(endTag)
|
|
|
|
|
|
|
|
|
|
// for self-verification only (redundant)
|
|
|
|
|
p.int(objcount)
|
|
|
|
|
|
|
|
|
|
// --- inlined function bodies ---
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
if p.trace {
|
2016-04-12 18:00:04 -07:00
|
|
|
p.tracef("\n--- inlined function bodies ---\n")
|
2015-08-13 19:05:37 -07:00
|
|
|
if p.indent != 0 {
|
2015-10-22 18:56:45 -07:00
|
|
|
Fatalf("exporter: incorrect indentation")
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-12 18:00:04 -07:00
|
|
|
// write inlineable function bodies
|
2017-06-14 19:57:11 -07:00
|
|
|
// Don't use range since funcList may grow.
|
2016-04-12 18:00:04 -07:00
|
|
|
objcount = 0
|
2017-06-14 19:57:11 -07:00
|
|
|
for i := 0; i < len(p.funcList); i++ {
|
cmd/compile: simplify reexport logic
Currently, we reexport any package-scope constant, function, type, or
variable declarations needed by an inlineable function body. However,
now that we have an early pass to walk inlineable function bodies
(golang.org/cl/74110), we can simplify the logic for finding these
declarations.
The binary export format supports writing out type declarations
in-place at their first use. Also, it always writes out constants by
value, so their declarations never need to be reexported.
Notably, we attempted this before (golang.org/cl/36170) and had to
revert it (golang.org/cl/45911). However, this was because while
writing out inline bodies, we could discover variable/function
dependencies. By collecting variable/function dependencies during
inlineable function discovery, we avoid this problem.
While here, get rid of isInlineable. We already typecheck inlineable
function bodies during inlFlood, so it's become a no-op. Just move the
comment explaining parameter numbering to its caller.
Change-Id: Ibbfaafce793733675d3a2ad98791758583055666
Reviewed-on: https://go-review.googlesource.com/103864
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-30 18:58:03 -07:00
|
|
|
if f := p.funcList[i]; f.ExportInline() {
|
2016-04-12 18:00:04 -07:00
|
|
|
// function has inlineable body:
|
|
|
|
|
// write index and body
|
|
|
|
|
if p.trace {
|
2018-04-04 15:53:27 -07:00
|
|
|
p.tracef("\n----\nfunc { %#v }\n", asNodes(f.Inl.Body))
|
2016-04-12 18:00:04 -07:00
|
|
|
}
|
|
|
|
|
p.int(i)
|
2018-04-04 15:53:27 -07:00
|
|
|
p.int(int(f.Inl.Cost))
|
|
|
|
|
p.stmtList(asNodes(f.Inl.Body))
|
2016-04-12 18:00:04 -07:00
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
|
|
|
|
objcount++
|
2015-10-22 18:56:45 -07:00
|
|
|
}
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-04-12 18:00:04 -07:00
|
|
|
// indicate end of list
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
2016-04-13 16:57:23 -07:00
|
|
|
p.int(-1) // invalid index terminates list
|
2016-04-12 18:00:04 -07:00
|
|
|
|
|
|
|
|
// for self-verification only (redundant)
|
|
|
|
|
p.int(objcount)
|
|
|
|
|
|
2015-08-13 19:05:37 -07:00
|
|
|
if p.trace {
|
2015-10-22 18:56:45 -07:00
|
|
|
p.tracef("\n--- end ---\n")
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- end of export data ---
|
|
|
|
|
|
|
|
|
|
return p.written
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *exporter) pkg(pkg *types.Pkg) {
|
2015-08-13 19:05:37 -07:00
|
|
|
if pkg == nil {
|
2015-10-22 18:56:45 -07:00
|
|
|
Fatalf("exporter: unexpected nil pkg")
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if we saw the package before, write its index (>= 0)
|
|
|
|
|
if i, ok := p.pkgIndex[pkg]; ok {
|
|
|
|
|
p.index('P', i)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// otherwise, remember the package, write the package tag (< 0) and package data
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("P%d = { ", len(p.pkgIndex))
|
|
|
|
|
defer p.tracef("} ")
|
|
|
|
|
}
|
|
|
|
|
p.pkgIndex[pkg] = len(p.pkgIndex)
|
|
|
|
|
|
|
|
|
|
p.tag(packageTag)
|
|
|
|
|
p.string(pkg.Name)
|
2017-04-24 06:06:14 -07:00
|
|
|
p.path(pkg.Path)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func unidealType(typ *types.Type, val Val) *types.Type {
|
2016-03-18 17:21:32 -07:00
|
|
|
// Untyped (ideal) constants get their own type. This decouples
|
|
|
|
|
// the constant type from the encoding of the constant value.
|
|
|
|
|
if typ == nil || typ.IsUntyped() {
|
|
|
|
|
typ = untype(val.Ctype())
|
|
|
|
|
}
|
|
|
|
|
return typ
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: don't export unreachable inline method bodies
Previously, anytime we exported a function or method declaration
(which includes methods for every type transitively exported), we
included the inline function bodies, if any. However, in many cases,
it's impossible (or at least very unlikely) for the importing package
to call the method.
For example:
package p
type T int
func (t T) M() { t.u() }
func (t T) u() {}
func (t T) v() {}
T.M and T.u are inlineable, and they're both reachable through calls
to T.M, which is exported. However, t.v is also inlineable, but cannot
be reached.
Exception: if p.T is embedded in another type q.U, p.T.v will be
promoted to q.U.v, and the generated wrapper function could have
inlined the call to p.T.v. However, in practice, this doesn't happen,
and a missed inlining opportunity doesn't affect correctness.
To implement this, this CL introduces an extra flood fill pass before
exporting to mark inline bodies that are actually reachable, so the
exporter can skip over methods like t.v.
This reduces Kubernetes build time (as measured by "time go build -a
k8s.io/kubernetes/cmd/...") on an HP Z620 measurably:
== before ==
real 0m44.658s
user 11m19.136s
sys 0m53.844s
== after ==
real 0m41.702s
user 10m29.732s
sys 0m50.908s
It also significantly cuts down the cost of enabling mid-stack
inlining (-l=4):
== before (-l=4) ==
real 1m19.236s
user 20m6.528s
sys 1m17.328s
== after (-l=4) ==
real 0m59.100s
user 13m12.808s
sys 0m58.776s
Updates #19348.
Change-Id: Iade58233ca42af823a1630517a53848b5d3c7a7e
Reviewed-on: https://go-review.googlesource.com/74110
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2017-10-27 15:36:59 -07:00
|
|
|
// markType recursively visits types reachable from t to identify
|
|
|
|
|
// functions whose inline bodies may be needed.
|
|
|
|
|
func (p *exporter) markType(t *types.Type) {
|
|
|
|
|
if p.marked[t] {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
p.marked[t] = true
|
|
|
|
|
|
|
|
|
|
// If this is a named type, mark all of its associated
|
|
|
|
|
// methods. Skip interface types because t.Methods contains
|
|
|
|
|
// only their unexpanded method set (i.e., exclusive of
|
|
|
|
|
// interface embeddings), and the switch statement below
|
|
|
|
|
// handles their full method set.
|
|
|
|
|
if t.Sym != nil && t.Etype != TINTER {
|
|
|
|
|
for _, m := range t.Methods().Slice() {
|
|
|
|
|
if exportname(m.Sym.Name) {
|
|
|
|
|
p.markType(m.Type)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Recursively mark any types that can be produced given a
|
|
|
|
|
// value of type t: dereferencing a pointer; indexing an
|
|
|
|
|
// array, slice, or map; receiving from a channel; accessing a
|
|
|
|
|
// struct field or interface method; or calling a function.
|
|
|
|
|
//
|
|
|
|
|
// Notably, we don't mark map key or function parameter types,
|
|
|
|
|
// because the user already needs some way to construct values
|
|
|
|
|
// of those types.
|
|
|
|
|
//
|
|
|
|
|
// It's not critical for correctness that this algorithm is
|
|
|
|
|
// perfect. Worst case, we might miss opportunities to inline
|
|
|
|
|
// some function calls in downstream packages.
|
|
|
|
|
switch t.Etype {
|
|
|
|
|
case TPTR32, TPTR64, TARRAY, TSLICE, TCHAN:
|
|
|
|
|
p.markType(t.Elem())
|
|
|
|
|
|
|
|
|
|
case TMAP:
|
|
|
|
|
p.markType(t.Val())
|
|
|
|
|
|
|
|
|
|
case TSTRUCT:
|
|
|
|
|
for _, f := range t.FieldSlice() {
|
|
|
|
|
if exportname(f.Sym.Name) || f.Embedded != 0 {
|
|
|
|
|
p.markType(f.Type)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TFUNC:
|
|
|
|
|
// If t is the type of a function or method, then
|
|
|
|
|
// t.Nname() is its ONAME. Mark its inline body and
|
|
|
|
|
// any recursively called functions for export.
|
|
|
|
|
inlFlood(asNode(t.Nname()))
|
|
|
|
|
|
|
|
|
|
for _, f := range t.Results().FieldSlice() {
|
|
|
|
|
p.markType(f.Type)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case TINTER:
|
|
|
|
|
for _, f := range t.FieldSlice() {
|
|
|
|
|
if exportname(f.Sym.Name) {
|
|
|
|
|
p.markType(f.Type)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *exporter) obj(sym *types.Sym) {
|
2016-03-18 17:21:32 -07:00
|
|
|
// Exported objects may be from different packages because they
|
2016-10-25 14:09:18 -07:00
|
|
|
// may be re-exported via an exported alias or as dependencies in
|
|
|
|
|
// exported inlined function bodies. Thus, exported object names
|
|
|
|
|
// must be fully qualified.
|
2016-03-18 17:21:32 -07:00
|
|
|
//
|
2016-10-25 14:09:18 -07:00
|
|
|
// (This can only happen for aliased objects or during phase 2
|
|
|
|
|
// (exportInlined enabled) of object export. Unaliased Objects
|
|
|
|
|
// exported in phase 1 (compiler-indendepent objects) are by
|
|
|
|
|
// definition only the objects from the current package and not
|
|
|
|
|
// pulled in via inlined function bodies. In that case the package
|
|
|
|
|
// qualifier is not needed. Possible space optimization.)
|
2016-03-18 17:21:32 -07:00
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
n := asNode(sym.Def)
|
2016-03-18 17:21:32 -07:00
|
|
|
switch n.Op {
|
|
|
|
|
case OLITERAL:
|
|
|
|
|
// constant
|
|
|
|
|
// TODO(gri) determine if we need the typecheck call here
|
|
|
|
|
n = typecheck(n, Erv)
|
|
|
|
|
if n == nil || n.Op != OLITERAL {
|
|
|
|
|
Fatalf("exporter: dumpexportconst: oconst nil: %v", sym)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.tag(constTag)
|
2016-04-13 17:53:03 -07:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
// TODO(gri) In inlined functions, constants are used directly
|
|
|
|
|
// so they should never occur as re-exported objects. We may
|
|
|
|
|
// not need the qualified name here. See also comment above.
|
|
|
|
|
// Possible space optimization.
|
|
|
|
|
p.qualifiedName(sym)
|
|
|
|
|
p.typ(unidealType(n.Type, n.Val()))
|
|
|
|
|
p.value(n.Val())
|
|
|
|
|
|
|
|
|
|
case OTYPE:
|
|
|
|
|
// named type
|
|
|
|
|
t := n.Type
|
|
|
|
|
if t.Etype == TFORW {
|
|
|
|
|
Fatalf("exporter: export of incomplete type %v", sym)
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if IsAlias(sym) {
|
2016-12-22 13:04:04 -08:00
|
|
|
p.tag(aliasTag)
|
|
|
|
|
p.pos(n)
|
|
|
|
|
p.qualifiedName(sym)
|
|
|
|
|
} else {
|
|
|
|
|
p.tag(typeTag)
|
|
|
|
|
}
|
2016-03-18 17:21:32 -07:00
|
|
|
p.typ(t)
|
|
|
|
|
|
|
|
|
|
case ONAME:
|
|
|
|
|
// variable or function
|
|
|
|
|
n = typecheck(n, Erv|Ecall)
|
|
|
|
|
if n == nil || n.Type == nil {
|
|
|
|
|
Fatalf("exporter: variable/function exported but not defined: %v", sym)
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-25 18:14:12 -07:00
|
|
|
if n.Type.Etype == TFUNC && n.Class() == PFUNC {
|
2016-03-18 17:21:32 -07:00
|
|
|
// function
|
|
|
|
|
p.tag(funcTag)
|
2016-04-13 17:53:03 -07:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.qualifiedName(sym)
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
sig := asNode(sym.Def).Type
|
cmd/compile: simplify reexport logic
Currently, we reexport any package-scope constant, function, type, or
variable declarations needed by an inlineable function body. However,
now that we have an early pass to walk inlineable function bodies
(golang.org/cl/74110), we can simplify the logic for finding these
declarations.
The binary export format supports writing out type declarations
in-place at their first use. Also, it always writes out constants by
value, so their declarations never need to be reexported.
Notably, we attempted this before (golang.org/cl/36170) and had to
revert it (golang.org/cl/45911). However, this was because while
writing out inline bodies, we could discover variable/function
dependencies. By collecting variable/function dependencies during
inlineable function discovery, we avoid this problem.
While here, get rid of isInlineable. We already typecheck inlineable
function bodies during inlFlood, so it's become a no-op. Just move the
comment explaining parameter numbering to its caller.
Change-Id: Ibbfaafce793733675d3a2ad98791758583055666
Reviewed-on: https://go-review.googlesource.com/103864
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-30 18:58:03 -07:00
|
|
|
|
|
|
|
|
// Theoretically, we only need numbered
|
|
|
|
|
// parameters if we're supplying an inline
|
|
|
|
|
// function body. However, it's possible to
|
|
|
|
|
// import a function from a package that
|
|
|
|
|
// didn't supply the inline body, and then
|
|
|
|
|
// another that did. In this case, we would
|
|
|
|
|
// need to rename the parameters during
|
|
|
|
|
// import, which is a little sketchy.
|
|
|
|
|
//
|
|
|
|
|
// For simplicity, just always number
|
|
|
|
|
// parameters.
|
|
|
|
|
p.paramList(sig.Params(), true)
|
|
|
|
|
p.paramList(sig.Results(), true)
|
|
|
|
|
|
|
|
|
|
p.funcList = append(p.funcList, asNode(sym.Def).Func)
|
2016-03-18 17:21:32 -07:00
|
|
|
} else {
|
|
|
|
|
// variable
|
|
|
|
|
p.tag(varTag)
|
2016-04-13 17:53:03 -07:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.qualifiedName(sym)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
p.typ(asNode(sym.Def).Type)
|
2016-03-18 17:21:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
2016-04-27 15:10:10 +10:00
|
|
|
Fatalf("exporter: unexpected export symbol: %v %v", n.Op, sym)
|
2016-03-18 17:21:32 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-24 06:06:14 -07:00
|
|
|
// deltaNewFile is a magic line delta offset indicating a new file.
|
|
|
|
|
// We use -64 because it is rare; see issue 20080 and CL 41619.
|
|
|
|
|
// -64 is the smallest int that fits in a single byte as a varint.
|
|
|
|
|
const deltaNewFile = -64
|
|
|
|
|
|
2016-04-13 17:53:03 -07:00
|
|
|
func (p *exporter) pos(n *Node) {
|
2016-04-26 22:31:02 -07:00
|
|
|
if !p.posInfoFormat {
|
2016-04-22 14:50:20 -07:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-28 12:43:12 -07:00
|
|
|
file, line := fileLine(n)
|
|
|
|
|
if file == p.prevFile {
|
|
|
|
|
// common case: write line delta
|
2017-04-24 06:06:14 -07:00
|
|
|
// delta == deltaNewFile means different file
|
|
|
|
|
// if the actual line delta is deltaNewFile,
|
|
|
|
|
// follow up with a negative int to indicate that.
|
|
|
|
|
// only non-negative ints can follow deltaNewFile
|
|
|
|
|
// when writing a new file.
|
2016-04-28 12:43:12 -07:00
|
|
|
delta := line - p.prevLine
|
|
|
|
|
p.int(delta)
|
2017-04-24 06:06:14 -07:00
|
|
|
if delta == deltaNewFile {
|
2016-04-28 12:43:12 -07:00
|
|
|
p.int(-1) // -1 means no file change
|
|
|
|
|
}
|
2016-04-13 17:53:03 -07:00
|
|
|
} else {
|
2016-04-28 12:43:12 -07:00
|
|
|
// different file
|
2017-04-24 06:06:14 -07:00
|
|
|
p.int(deltaNewFile)
|
|
|
|
|
p.int(line) // line >= 0
|
|
|
|
|
p.path(file)
|
2016-04-13 17:53:03 -07:00
|
|
|
p.prevFile = file
|
|
|
|
|
}
|
|
|
|
|
p.prevLine = line
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-24 06:06:14 -07:00
|
|
|
func (p *exporter) path(s string) {
|
|
|
|
|
if i, ok := p.pathIndex[s]; ok {
|
2017-06-15 15:05:03 -07:00
|
|
|
// Note: Using p.index(i) here requires the use of p.tag(-len(c)) below
|
|
|
|
|
// to get matching debug markers ('t'). But in trace mode p.tag
|
|
|
|
|
// assumes that the tag argument is a valid tag that can be looked
|
|
|
|
|
// up in the tagString list, rather then some arbitrary slice length.
|
|
|
|
|
// Use p.int instead.
|
|
|
|
|
p.int(i) // i >= 0
|
2017-04-24 06:06:14 -07:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
p.pathIndex[s] = len(p.pathIndex)
|
|
|
|
|
c := strings.Split(s, "/")
|
|
|
|
|
p.int(-len(c)) // -len(c) < 0
|
|
|
|
|
for _, x := range c {
|
|
|
|
|
p.string(x)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-28 12:43:12 -07:00
|
|
|
func fileLine(n *Node) (file string, line int) {
|
|
|
|
|
if n != nil {
|
2016-12-15 17:17:01 -08:00
|
|
|
pos := Ctxt.PosTable.Pos(n.Pos)
|
2017-03-07 15:58:28 -08:00
|
|
|
file = pos.Base().AbsFilename()
|
|
|
|
|
line = int(pos.RelLine())
|
2016-04-28 12:43:12 -07:00
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *exporter) typ(t *types.Type) {
|
2015-08-13 19:05:37 -07:00
|
|
|
if t == nil {
|
2015-10-22 18:56:45 -07:00
|
|
|
Fatalf("exporter: nil type")
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Possible optimization: Anonymous pointer types *T where
|
|
|
|
|
// T is a named type are common. We could canonicalize all
|
|
|
|
|
// such types *T to a single type PT = *T. This would lead
|
|
|
|
|
// to at most one *T entry in typIndex, and all future *T's
|
|
|
|
|
// would be encoded as the respective index directly. Would
|
|
|
|
|
// save 1 byte (pointerTag) per *T and reduce the typIndex
|
|
|
|
|
// size (at the cost of a canonicalization map). We can do
|
|
|
|
|
// this later, without encoding format change.
|
|
|
|
|
|
|
|
|
|
// if we saw the type before, write its index (>= 0)
|
|
|
|
|
if i, ok := p.typIndex[t]; ok {
|
|
|
|
|
p.index('T', i)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// otherwise, remember the type, write the type tag (< 0) and type data
|
2016-05-05 18:03:59 -07:00
|
|
|
if trackAllTypes {
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("T%d = {>\n", len(p.typIndex))
|
|
|
|
|
defer p.tracef("<\n} ")
|
|
|
|
|
}
|
|
|
|
|
p.typIndex[t] = len(p.typIndex)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// pick off named types
|
2016-04-06 15:27:30 -07:00
|
|
|
if tsym := t.Sym; tsym != nil {
|
2016-05-05 18:03:59 -07:00
|
|
|
if !trackAllTypes {
|
|
|
|
|
// if we don't track all types, track named types now
|
|
|
|
|
p.typIndex[t] = len(p.typIndex)
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 19:05:37 -07:00
|
|
|
// Predeclared types should have been found in the type map.
|
|
|
|
|
if t.Orig == t {
|
2015-10-22 18:56:45 -07:00
|
|
|
Fatalf("exporter: predeclared type missing from type map?")
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
2016-04-13 17:53:03 -07:00
|
|
|
|
2016-04-18 13:55:40 -07:00
|
|
|
n := typenod(t)
|
|
|
|
|
if n.Type != t {
|
|
|
|
|
Fatalf("exporter: named type definition incorrectly set up")
|
|
|
|
|
}
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
p.tag(namedTag)
|
2016-04-18 13:55:40 -07:00
|
|
|
p.pos(n)
|
2016-04-06 15:27:30 -07:00
|
|
|
p.qualifiedName(tsym)
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
// write underlying type
|
2017-09-05 18:49:36 -07:00
|
|
|
p.typ(t.Orig)
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
// interfaces don't have associated methods
|
2016-03-30 14:56:08 -07:00
|
|
|
if t.Orig.IsInterface() {
|
2015-08-13 19:05:37 -07:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// sort methods for reproducible export format
|
|
|
|
|
// TODO(gri) Determine if they are already sorted
|
|
|
|
|
// in which case we can drop this step.
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
var methods []*types.Field
|
2017-09-28 20:17:59 +01:00
|
|
|
methods = append(methods, t.Methods().Slice()...)
|
2015-08-13 19:05:37 -07:00
|
|
|
sort.Sort(methodbyname(methods))
|
|
|
|
|
p.int(len(methods))
|
|
|
|
|
|
2016-03-11 03:25:00 -08:00
|
|
|
if p.trace && len(methods) > 0 {
|
|
|
|
|
p.tracef("associated methods {>")
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, m := range methods {
|
2016-03-11 03:25:00 -08:00
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
2016-03-18 17:21:32 -07:00
|
|
|
if strings.Contains(m.Sym.Name, ".") {
|
|
|
|
|
Fatalf("invalid symbol name: %s (%v)", m.Sym.Name, m.Sym)
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
p.pos(asNode(m.Nname))
|
2016-03-18 17:21:32 -07:00
|
|
|
p.fieldSym(m.Sym, false)
|
|
|
|
|
|
2016-03-11 13:40:01 -08:00
|
|
|
sig := m.Type
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
mfn := asNode(sig.FuncType().Nname)
|
2016-03-18 17:21:32 -07:00
|
|
|
|
cmd/compile: simplify reexport logic
Currently, we reexport any package-scope constant, function, type, or
variable declarations needed by an inlineable function body. However,
now that we have an early pass to walk inlineable function bodies
(golang.org/cl/74110), we can simplify the logic for finding these
declarations.
The binary export format supports writing out type declarations
in-place at their first use. Also, it always writes out constants by
value, so their declarations never need to be reexported.
Notably, we attempted this before (golang.org/cl/36170) and had to
revert it (golang.org/cl/45911). However, this was because while
writing out inline bodies, we could discover variable/function
dependencies. By collecting variable/function dependencies during
inlineable function discovery, we avoid this problem.
While here, get rid of isInlineable. We already typecheck inlineable
function bodies during inlFlood, so it's become a no-op. Just move the
comment explaining parameter numbering to its caller.
Change-Id: Ibbfaafce793733675d3a2ad98791758583055666
Reviewed-on: https://go-review.googlesource.com/103864
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-30 18:58:03 -07:00
|
|
|
// See comment in (*exporter).obj about
|
|
|
|
|
// numbered parameters.
|
|
|
|
|
p.paramList(sig.Recvs(), true)
|
|
|
|
|
p.paramList(sig.Params(), true)
|
|
|
|
|
p.paramList(sig.Results(), true)
|
2017-02-27 19:56:38 +02:00
|
|
|
p.bool(m.Nointerface()) // record go:nointerface pragma value (see also #16243)
|
2016-07-01 10:51:59 -07:00
|
|
|
|
cmd/compile: simplify reexport logic
Currently, we reexport any package-scope constant, function, type, or
variable declarations needed by an inlineable function body. However,
now that we have an early pass to walk inlineable function bodies
(golang.org/cl/74110), we can simplify the logic for finding these
declarations.
The binary export format supports writing out type declarations
in-place at their first use. Also, it always writes out constants by
value, so their declarations never need to be reexported.
Notably, we attempted this before (golang.org/cl/36170) and had to
revert it (golang.org/cl/45911). However, this was because while
writing out inline bodies, we could discover variable/function
dependencies. By collecting variable/function dependencies during
inlineable function discovery, we avoid this problem.
While here, get rid of isInlineable. We already typecheck inlineable
function bodies during inlFlood, so it's become a no-op. Just move the
comment explaining parameter numbering to its caller.
Change-Id: Ibbfaafce793733675d3a2ad98791758583055666
Reviewed-on: https://go-review.googlesource.com/103864
Reviewed-by: Robert Griesemer <gri@golang.org>
2018-03-30 18:58:03 -07:00
|
|
|
p.funcList = append(p.funcList, mfn.Func)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-03-11 03:25:00 -08:00
|
|
|
if p.trace && len(methods) > 0 {
|
2015-08-13 19:05:37 -07:00
|
|
|
p.tracef("<\n} ")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// otherwise we have a type literal
|
|
|
|
|
switch t.Etype {
|
|
|
|
|
case TARRAY:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if t.IsDDDArray() {
|
2016-03-27 17:57:42 -07:00
|
|
|
Fatalf("array bounds should be known at export time: %v", t)
|
|
|
|
|
}
|
2016-04-18 14:02:08 -07:00
|
|
|
p.tag(arrayTag)
|
|
|
|
|
p.int64(t.NumElem())
|
|
|
|
|
p.typ(t.Elem())
|
|
|
|
|
|
|
|
|
|
case TSLICE:
|
|
|
|
|
p.tag(sliceTag)
|
2016-03-30 10:57:47 -07:00
|
|
|
p.typ(t.Elem())
|
2015-08-13 19:05:37 -07:00
|
|
|
|
2016-03-27 12:30:16 -07:00
|
|
|
case TDDDFIELD:
|
|
|
|
|
// see p.param use of TDDDFIELD
|
2015-08-13 19:05:37 -07:00
|
|
|
p.tag(dddTag)
|
2016-04-01 20:11:30 -07:00
|
|
|
p.typ(t.DDDField())
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
case TSTRUCT:
|
|
|
|
|
p.tag(structTag)
|
|
|
|
|
p.fieldList(t)
|
|
|
|
|
|
|
|
|
|
case TPTR32, TPTR64: // could use Tptr but these are constants
|
|
|
|
|
p.tag(pointerTag)
|
2016-03-30 10:57:47 -07:00
|
|
|
p.typ(t.Elem())
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
case TFUNC:
|
|
|
|
|
p.tag(signatureTag)
|
2016-03-11 13:40:01 -08:00
|
|
|
p.paramList(t.Params(), false)
|
|
|
|
|
p.paramList(t.Results(), false)
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
case TINTER:
|
|
|
|
|
p.tag(interfaceTag)
|
|
|
|
|
p.methodList(t)
|
|
|
|
|
|
|
|
|
|
case TMAP:
|
|
|
|
|
p.tag(mapTag)
|
2016-03-28 21:48:47 -07:00
|
|
|
p.typ(t.Key())
|
|
|
|
|
p.typ(t.Val())
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
case TCHAN:
|
|
|
|
|
p.tag(chanTag)
|
2016-04-02 16:26:30 -07:00
|
|
|
p.int(int(t.ChanDir()))
|
2016-03-30 10:57:47 -07:00
|
|
|
p.typ(t.Elem())
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
default:
|
2016-09-09 21:08:46 -07:00
|
|
|
Fatalf("exporter: unexpected type: %v (Etype = %d)", t, t.Etype)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *exporter) qualifiedName(sym *types.Sym) {
|
2015-08-13 19:05:37 -07:00
|
|
|
p.string(sym.Name)
|
|
|
|
|
p.pkg(sym.Pkg)
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *exporter) fieldList(t *types.Type) {
|
2016-03-17 13:26:08 -07:00
|
|
|
if p.trace && t.NumFields() > 0 {
|
2016-03-11 03:25:00 -08:00
|
|
|
p.tracef("fields {>")
|
2015-08-13 19:05:37 -07:00
|
|
|
defer p.tracef("<\n} ")
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-17 13:26:08 -07:00
|
|
|
p.int(t.NumFields())
|
2016-03-17 01:32:18 -07:00
|
|
|
for _, f := range t.Fields().Slice() {
|
2016-03-11 03:25:00 -08:00
|
|
|
if p.trace {
|
2015-08-13 19:05:37 -07:00
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
2016-03-11 03:25:00 -08:00
|
|
|
p.field(f)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *exporter) field(f *types.Field) {
|
|
|
|
|
p.pos(asNode(f.Nname))
|
2016-08-23 15:18:09 -07:00
|
|
|
p.fieldName(f)
|
2015-08-13 19:05:37 -07:00
|
|
|
p.typ(f.Type)
|
2016-04-25 13:24:48 -07:00
|
|
|
p.string(f.Note)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *exporter) methodList(t *types.Type) {
|
|
|
|
|
var embeddeds, methods []*types.Field
|
2017-03-20 12:14:16 -07:00
|
|
|
|
|
|
|
|
for _, m := range t.Methods().Slice() {
|
|
|
|
|
if m.Sym != nil {
|
|
|
|
|
methods = append(methods, m)
|
|
|
|
|
} else {
|
|
|
|
|
embeddeds = append(embeddeds, m)
|
|
|
|
|
}
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
2017-03-20 12:14:16 -07:00
|
|
|
if p.trace && len(embeddeds) > 0 {
|
|
|
|
|
p.tracef("embeddeds {>")
|
|
|
|
|
}
|
|
|
|
|
p.int(len(embeddeds))
|
|
|
|
|
for _, m := range embeddeds {
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
p.pos(asNode(m.Nname))
|
2017-03-20 12:14:16 -07:00
|
|
|
p.typ(m.Type)
|
|
|
|
|
}
|
|
|
|
|
if p.trace && len(embeddeds) > 0 {
|
|
|
|
|
p.tracef("<\n} ")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if p.trace && len(methods) > 0 {
|
|
|
|
|
p.tracef("methods {>")
|
|
|
|
|
}
|
|
|
|
|
p.int(len(methods))
|
|
|
|
|
for _, m := range methods {
|
2016-03-11 03:25:00 -08:00
|
|
|
if p.trace {
|
2015-08-13 19:05:37 -07:00
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
2016-03-11 03:25:00 -08:00
|
|
|
p.method(m)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
2017-03-20 12:14:16 -07:00
|
|
|
if p.trace && len(methods) > 0 {
|
|
|
|
|
p.tracef("<\n} ")
|
|
|
|
|
}
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *exporter) method(m *types.Field) {
|
|
|
|
|
p.pos(asNode(m.Nname))
|
2016-12-22 13:04:04 -08:00
|
|
|
p.methodName(m.Sym)
|
2016-03-11 13:40:01 -08:00
|
|
|
p.paramList(m.Type.Params(), false)
|
|
|
|
|
p.paramList(m.Type.Results(), false)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *exporter) fieldName(t *types.Field) {
|
2016-08-23 15:18:09 -07:00
|
|
|
name := t.Sym.Name
|
|
|
|
|
if t.Embedded != 0 {
|
2016-12-22 13:04:04 -08:00
|
|
|
// anonymous field - we distinguish between 3 cases:
|
2016-12-27 16:53:33 -08:00
|
|
|
// 1) field name matches base type name and is exported
|
|
|
|
|
// 2) field name matches base type name and is not exported
|
|
|
|
|
// 3) field name doesn't match base type name (alias name)
|
2016-12-22 13:04:04 -08:00
|
|
|
bname := basetypeName(t.Type)
|
|
|
|
|
if name == bname {
|
|
|
|
|
if exportname(name) {
|
2016-12-27 16:53:33 -08:00
|
|
|
name = "" // 1) we don't need to know the field name or package
|
2016-12-22 13:04:04 -08:00
|
|
|
} else {
|
2016-12-27 16:53:33 -08:00
|
|
|
name = "?" // 2) use unexported name "?" to force package export
|
2016-12-22 13:04:04 -08:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 3) indicate alias and export name as is
|
|
|
|
|
// (this requires an extra "@" but this is a rare case)
|
|
|
|
|
p.string("@")
|
2016-08-23 15:18:09 -07:00
|
|
|
}
|
2016-03-18 17:21:32 -07:00
|
|
|
}
|
2015-08-13 19:05:37 -07:00
|
|
|
p.string(name)
|
2016-08-23 16:02:19 -07:00
|
|
|
if name != "" && !exportname(name) {
|
2016-08-23 15:18:09 -07:00
|
|
|
p.pkg(t.Sym.Pkg)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-22 13:04:04 -08:00
|
|
|
// methodName is like qualifiedName but it doesn't record the package for exported names.
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *exporter) methodName(sym *types.Sym) {
|
2016-12-22 13:04:04 -08:00
|
|
|
p.string(sym.Name)
|
|
|
|
|
if !exportname(sym.Name) {
|
|
|
|
|
p.pkg(sym.Pkg)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func basetypeName(t *types.Type) string {
|
2015-08-13 19:05:37 -07:00
|
|
|
s := t.Sym
|
2016-03-30 15:09:25 -07:00
|
|
|
if s == nil && t.IsPtr() {
|
2016-03-30 10:57:47 -07:00
|
|
|
s = t.Elem().Sym // deref
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
if s != nil {
|
|
|
|
|
return s.Name
|
|
|
|
|
}
|
2016-12-27 16:53:33 -08:00
|
|
|
return "" // unnamed type
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *exporter) paramList(params *types.Type, numbered bool) {
|
2016-04-05 16:44:07 -07:00
|
|
|
if !params.IsFuncArgStruct() {
|
2015-10-22 18:56:45 -07:00
|
|
|
Fatalf("exporter: parameter list expected")
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// use negative length to indicate unnamed parameters
|
|
|
|
|
// (look at the first parameter only since either all
|
|
|
|
|
// names are present or all are absent)
|
2016-03-18 17:21:32 -07:00
|
|
|
//
|
|
|
|
|
// TODO(gri) If we don't have an exported function
|
|
|
|
|
// body, the parameter names are irrelevant for the
|
|
|
|
|
// compiler (though they may be of use for other tools).
|
|
|
|
|
// Possible space optimization.
|
2016-03-17 13:26:08 -07:00
|
|
|
n := params.NumFields()
|
2016-03-11 13:40:01 -08:00
|
|
|
if n > 0 && parName(params.Field(0), numbered) == "" {
|
2015-08-13 19:05:37 -07:00
|
|
|
n = -n
|
|
|
|
|
}
|
|
|
|
|
p.int(n)
|
2016-03-17 01:32:18 -07:00
|
|
|
for _, q := range params.Fields().Slice() {
|
2016-03-11 13:40:01 -08:00
|
|
|
p.param(q, n, numbered)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *exporter) param(q *types.Field, n int, numbered bool) {
|
2015-08-13 19:05:37 -07:00
|
|
|
t := q.Type
|
2017-02-27 19:56:38 +02:00
|
|
|
if q.Isddd() {
|
2015-08-13 19:05:37 -07:00
|
|
|
// create a fake type to encode ... just for the p.typ call
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
t = types.NewDDDField(t.Elem())
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
p.typ(t)
|
|
|
|
|
if n > 0 {
|
2016-05-02 17:03:36 -07:00
|
|
|
name := parName(q, numbered)
|
|
|
|
|
if name == "" {
|
|
|
|
|
// Sometimes we see an empty name even for n > 0.
|
|
|
|
|
// This appears to happen for interface methods
|
|
|
|
|
// with _ (blank) parameter names. Make sure we
|
|
|
|
|
// have a proper name and package so we don't crash
|
|
|
|
|
// during import (see also issue #15470).
|
|
|
|
|
// (parName uses "" instead of "?" as in fmt.go)
|
|
|
|
|
// TODO(gri) review parameter name encoding
|
|
|
|
|
name = "_"
|
|
|
|
|
}
|
|
|
|
|
p.string(name)
|
|
|
|
|
if name != "_" {
|
2016-04-27 22:04:49 -07:00
|
|
|
// Because of (re-)exported inlined functions
|
|
|
|
|
// the importpkg may not be the package to which this
|
|
|
|
|
// function (and thus its parameter) belongs. We need to
|
|
|
|
|
// supply the parameter package here. We need the package
|
|
|
|
|
// when the function is inlined so we can properly resolve
|
2016-05-02 17:03:36 -07:00
|
|
|
// the name. The _ (blank) parameter cannot be accessed, so
|
|
|
|
|
// we don't need to export a package.
|
|
|
|
|
//
|
2016-04-27 22:04:49 -07:00
|
|
|
// TODO(gri) This is compiler-specific. Try using importpkg
|
|
|
|
|
// here and then update the symbols if we find an inlined
|
|
|
|
|
// body only. Otherwise, the parameter name is ignored and
|
|
|
|
|
// the package doesn't matter. This would remove an int
|
|
|
|
|
// (likely 1 byte) for each named parameter.
|
|
|
|
|
p.pkg(q.Sym.Pkg)
|
|
|
|
|
}
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
// TODO(gri) This is compiler-specific (escape info).
|
|
|
|
|
// Move into compiler-specific section eventually?
|
|
|
|
|
// (Not having escape info causes tests to fail, e.g. runtime GCInfoTest)
|
2016-04-25 13:24:48 -07:00
|
|
|
p.string(q.Note)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func parName(f *types.Field, numbered bool) string {
|
2016-03-18 17:21:32 -07:00
|
|
|
s := f.Sym
|
|
|
|
|
if s == nil {
|
2015-08-13 19:05:37 -07:00
|
|
|
return ""
|
|
|
|
|
}
|
2016-03-18 17:21:32 -07:00
|
|
|
|
|
|
|
|
// Take the name from the original, lest we substituted it with ~r%d or ~b%d.
|
|
|
|
|
// ~r%d is a (formerly) unnamed result.
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if asNode(f.Nname) != nil {
|
2017-10-28 17:35:27 +01:00
|
|
|
if asNode(f.Nname).Orig == nil {
|
2016-03-18 17:21:32 -07:00
|
|
|
return "" // s = nil
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
2017-10-28 17:35:27 +01:00
|
|
|
s = asNode(f.Nname).Orig.Sym
|
|
|
|
|
if s != nil && s.Name[0] == '~' {
|
|
|
|
|
if s.Name[1] == 'r' { // originally an unnamed result
|
|
|
|
|
return "" // s = nil
|
|
|
|
|
} else if s.Name[1] == 'b' { // originally the blank identifier _
|
|
|
|
|
return "_" // belongs to localpkg
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
2016-03-18 17:21:32 -07:00
|
|
|
|
|
|
|
|
if s == nil {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// print symbol with Vargen number or not as desired
|
|
|
|
|
name := s.Name
|
|
|
|
|
if strings.Contains(name, ".") {
|
2016-05-08 20:59:53 -07:00
|
|
|
Fatalf("invalid symbol name: %s", name)
|
2016-03-18 17:21:32 -07:00
|
|
|
}
|
|
|
|
|
|
2017-01-07 08:23:11 -08:00
|
|
|
// Functions that can be inlined use numbered parameters so we can distinguish them
|
2016-03-18 17:21:32 -07:00
|
|
|
// from other names in their context after inlining (i.e., the parameter numbering
|
|
|
|
|
// is a form of parameter rewriting). See issue 4326 for an example and test case.
|
2017-04-06 15:14:08 -07:00
|
|
|
if numbered {
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
if !strings.Contains(name, "·") && asNode(f.Nname) != nil && asNode(f.Nname).Name != nil && asNode(f.Nname).Name.Vargen > 0 {
|
|
|
|
|
name = fmt.Sprintf("%s·%d", name, asNode(f.Nname).Name.Vargen) // append Vargen
|
2016-03-18 17:21:32 -07:00
|
|
|
}
|
|
|
|
|
} else {
|
2016-03-11 13:40:01 -08:00
|
|
|
if i := strings.Index(name, "·"); i > 0 {
|
2016-03-18 17:21:32 -07:00
|
|
|
name = name[:i] // cut off Vargen
|
2016-03-11 13:40:01 -08:00
|
|
|
}
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
return name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exporter) value(x Val) {
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("= ")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch x := x.U.(type) {
|
|
|
|
|
case bool:
|
|
|
|
|
tag := falseTag
|
|
|
|
|
if x {
|
|
|
|
|
tag = trueTag
|
|
|
|
|
}
|
|
|
|
|
p.tag(tag)
|
|
|
|
|
|
|
|
|
|
case *Mpint:
|
2016-09-16 00:33:29 +10:00
|
|
|
if minintval[TINT64].Cmp(x) <= 0 && x.Cmp(maxintval[TINT64]) <= 0 {
|
2015-08-13 19:05:37 -07:00
|
|
|
// common case: x fits into an int64 - use compact encoding
|
|
|
|
|
p.tag(int64Tag)
|
2016-03-20 13:55:42 -07:00
|
|
|
p.int64(x.Int64())
|
2015-08-13 19:05:37 -07:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// uncommon case: large x - use float encoding
|
|
|
|
|
// (powers of 2 will be encoded efficiently with exponent)
|
|
|
|
|
f := newMpflt()
|
2016-03-20 13:55:42 -07:00
|
|
|
f.SetInt(x)
|
2015-10-22 18:56:45 -07:00
|
|
|
p.tag(floatTag)
|
2015-08-13 19:05:37 -07:00
|
|
|
p.float(f)
|
|
|
|
|
|
|
|
|
|
case *Mpflt:
|
|
|
|
|
p.tag(floatTag)
|
|
|
|
|
p.float(x)
|
|
|
|
|
|
|
|
|
|
case *Mpcplx:
|
|
|
|
|
p.tag(complexTag)
|
|
|
|
|
p.float(&x.Real)
|
|
|
|
|
p.float(&x.Imag)
|
|
|
|
|
|
|
|
|
|
case string:
|
|
|
|
|
p.tag(stringTag)
|
|
|
|
|
p.string(x)
|
|
|
|
|
|
2015-10-22 18:56:45 -07:00
|
|
|
case *NilVal:
|
|
|
|
|
// not a constant but used in exported function bodies
|
|
|
|
|
p.tag(nilTag)
|
|
|
|
|
|
2015-08-13 19:05:37 -07:00
|
|
|
default:
|
2015-10-22 18:56:45 -07:00
|
|
|
Fatalf("exporter: unexpected value %v (%T)", x, x)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exporter) float(x *Mpflt) {
|
2015-10-22 14:14:41 -07:00
|
|
|
// extract sign (there is no -0)
|
2015-08-13 19:05:37 -07:00
|
|
|
f := &x.Val
|
|
|
|
|
sign := f.Sign()
|
|
|
|
|
if sign == 0 {
|
2015-10-22 14:14:41 -07:00
|
|
|
// x == 0
|
2015-08-13 19:05:37 -07:00
|
|
|
p.int(0)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// x != 0
|
|
|
|
|
|
|
|
|
|
// extract exponent such that 0.5 <= m < 1.0
|
|
|
|
|
var m big.Float
|
|
|
|
|
exp := f.MantExp(&m)
|
|
|
|
|
|
|
|
|
|
// extract mantissa as *big.Int
|
|
|
|
|
// - set exponent large enough so mant satisfies mant.IsInt()
|
|
|
|
|
// - get *big.Int from mant
|
|
|
|
|
m.SetMantExp(&m, int(m.MinPrec()))
|
|
|
|
|
mant, acc := m.Int(nil)
|
|
|
|
|
if acc != big.Exact {
|
2015-10-22 18:56:45 -07:00
|
|
|
Fatalf("exporter: internal error")
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.int(sign)
|
|
|
|
|
p.int(exp)
|
|
|
|
|
p.string(string(mant.Bytes()))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// Inlined function bodies
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// Approach: More or less closely follow what fmt.go is doing for FExp mode
|
|
|
|
|
// but instead of emitting the information textually, emit the node tree in
|
|
|
|
|
// binary form.
|
|
|
|
|
|
2016-05-08 20:59:53 -07:00
|
|
|
// TODO(gri) Improve tracing output. The current format is difficult to read.
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// stmtList may emit more (or fewer) than len(list) nodes.
|
|
|
|
|
func (p *exporter) stmtList(list Nodes) {
|
|
|
|
|
if p.trace {
|
|
|
|
|
if list.Len() == 0 {
|
|
|
|
|
p.tracef("{}")
|
|
|
|
|
} else {
|
|
|
|
|
p.tracef("{>")
|
|
|
|
|
defer p.tracef("<\n}")
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
2016-03-18 17:21:32 -07:00
|
|
|
|
|
|
|
|
for _, n := range list.Slice() {
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
|
|
|
|
// TODO inlining produces expressions with ninits. we can't export these yet.
|
|
|
|
|
// (from fmt.go:1461ff)
|
|
|
|
|
if opprec[n.Op] < 0 {
|
|
|
|
|
p.stmt(n)
|
|
|
|
|
} else {
|
|
|
|
|
p.expr(n)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.op(OEND)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exporter) exprList(list Nodes) {
|
|
|
|
|
if p.trace {
|
|
|
|
|
if list.Len() == 0 {
|
|
|
|
|
p.tracef("{}")
|
|
|
|
|
} else {
|
|
|
|
|
p.tracef("{>")
|
|
|
|
|
defer p.tracef("<\n}")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, n := range list.Slice() {
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
|
|
|
|
p.expr(n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.op(OEND)
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
func (p *exporter) elemList(list Nodes) {
|
2015-10-22 18:56:45 -07:00
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("[ ")
|
|
|
|
|
}
|
2016-03-09 12:39:36 -08:00
|
|
|
p.int(list.Len())
|
2015-10-22 18:56:45 -07:00
|
|
|
if p.trace {
|
2016-03-09 12:39:36 -08:00
|
|
|
if list.Len() == 0 {
|
2015-10-22 18:56:45 -07:00
|
|
|
p.tracef("] {}")
|
|
|
|
|
} else {
|
|
|
|
|
p.tracef("] {>")
|
|
|
|
|
defer p.tracef("<\n}")
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-18 17:21:32 -07:00
|
|
|
|
2016-03-09 12:39:36 -08:00
|
|
|
for _, n := range list.Slice() {
|
2015-10-22 18:56:45 -07:00
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("\n")
|
|
|
|
|
}
|
2016-10-12 15:48:18 -07:00
|
|
|
p.fieldSym(n.Sym, false)
|
|
|
|
|
p.expr(n.Left)
|
2015-10-22 18:56:45 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
func (p *exporter) expr(n *Node) {
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("( ")
|
|
|
|
|
defer p.tracef(") ")
|
|
|
|
|
}
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2016-05-08 20:59:53 -07:00
|
|
|
// from nodefmt (fmt.go)
|
|
|
|
|
//
|
|
|
|
|
// nodefmt reverts nodes back to their original - we don't need to do
|
|
|
|
|
// it because we are not bound to produce valid Go syntax when exporting
|
|
|
|
|
//
|
|
|
|
|
// if (fmtmode != FExp || n.Op != OLITERAL) && n.Orig != nil {
|
|
|
|
|
// n = n.Orig
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// from exprfmt (fmt.go)
|
2017-02-27 19:56:38 +02:00
|
|
|
for n != nil && n.Implicit() && (n.Op == OIND || n.Op == OADDR) {
|
2016-03-18 17:21:32 -07:00
|
|
|
n = n.Left
|
|
|
|
|
}
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
switch op := n.Op; op {
|
|
|
|
|
// expressions
|
|
|
|
|
// (somewhat closely following the structure of exprfmt in fmt.go)
|
|
|
|
|
case OPAREN:
|
|
|
|
|
p.expr(n.Left) // unparen
|
|
|
|
|
|
|
|
|
|
// case ODDDARG:
|
|
|
|
|
// unimplemented - handled by default case
|
|
|
|
|
|
2015-10-22 18:56:45 -07:00
|
|
|
case OLITERAL:
|
2016-03-18 17:21:32 -07:00
|
|
|
if n.Val().Ctype() == CTNIL && n.Orig != nil && n.Orig != n {
|
|
|
|
|
p.expr(n.Orig)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
p.op(OLITERAL)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2015-10-22 18:56:45 -07:00
|
|
|
p.typ(unidealType(n.Type, n.Val()))
|
|
|
|
|
p.value(n.Val())
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
case ONAME:
|
|
|
|
|
// Special case: explicit name of func (*T) method(...) is turned into pkg.(*T).method,
|
|
|
|
|
// but for export, this should be rendered as (*pkg.T).meth.
|
|
|
|
|
// These nodes have the special property that they are names with a left OTYPE and a right ONAME.
|
2017-10-24 14:45:41 -07:00
|
|
|
if n.isMethodExpression() {
|
2016-05-11 11:28:36 -07:00
|
|
|
p.op(OXDOT)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-05-11 11:28:36 -07:00
|
|
|
p.expr(n.Left) // n.Left.Op == OTYPE
|
2016-03-18 17:21:32 -07:00
|
|
|
p.fieldSym(n.Right.Sym, true)
|
|
|
|
|
break
|
|
|
|
|
}
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2016-05-11 12:40:17 -07:00
|
|
|
p.op(ONAME)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.sym(n)
|
|
|
|
|
|
2016-05-11 12:40:17 -07:00
|
|
|
// case OPACK, ONONAME:
|
|
|
|
|
// should have been resolved by typechecking - handled by default case
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
case OTYPE:
|
|
|
|
|
p.op(OTYPE)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2017-09-12 13:42:10 -07:00
|
|
|
p.typ(n.Type)
|
2016-03-18 17:21:32 -07:00
|
|
|
|
2016-05-08 20:59:53 -07:00
|
|
|
// case OTARRAY, OTMAP, OTCHAN, OTSTRUCT, OTINTER, OTFUNC:
|
|
|
|
|
// should have been resolved by typechecking - handled by default case
|
2016-03-18 17:21:32 -07:00
|
|
|
|
|
|
|
|
// case OCLOSURE:
|
|
|
|
|
// unimplemented - handled by default case
|
|
|
|
|
|
|
|
|
|
// case OCOMPLIT:
|
2016-05-08 20:59:53 -07:00
|
|
|
// should have been resolved by typechecking - handled by default case
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
case OPTRLIT:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(OPTRLIT)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
2017-02-27 19:56:38 +02:00
|
|
|
p.bool(n.Implicit())
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
case OSTRUCTLIT:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(OSTRUCTLIT)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-05-08 20:59:53 -07:00
|
|
|
p.typ(n.Type)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.elemList(n.List) // special handling of field names
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2016-06-19 07:20:28 -07:00
|
|
|
case OARRAYLIT, OSLICELIT, OMAPLIT:
|
2016-05-08 20:59:53 -07:00
|
|
|
p.op(OCOMPLIT)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-05-08 20:59:53 -07:00
|
|
|
p.typ(n.Type)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.exprList(n.List)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
case OKEY:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(OKEY)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.exprsOrNil(n.Left, n.Right)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2016-10-12 15:48:18 -07:00
|
|
|
// case OSTRUCTKEY:
|
|
|
|
|
// unreachable - handled in case OSTRUCTLIT by elemList
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// case OCALLPART:
|
|
|
|
|
// unimplemented - handled by default case
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
case OXDOT, ODOT, ODOTPTR, ODOTINTER, ODOTMETH:
|
|
|
|
|
p.op(OXDOT)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
|
|
|
|
p.fieldSym(n.Sym, true)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
case ODOTTYPE, ODOTTYPE2:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(ODOTTYPE)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
2017-04-05 18:52:33 -07:00
|
|
|
p.typ(n.Type)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
case OINDEX, OINDEXMAP:
|
|
|
|
|
p.op(OINDEX)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
|
|
|
|
p.expr(n.Right)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
case OSLICE, OSLICESTR, OSLICEARR:
|
|
|
|
|
p.op(OSLICE)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
2016-04-21 11:55:33 -07:00
|
|
|
low, high, _ := n.SliceBounds()
|
|
|
|
|
p.exprsOrNil(low, high)
|
2016-03-18 17:21:32 -07:00
|
|
|
|
|
|
|
|
case OSLICE3, OSLICE3ARR:
|
|
|
|
|
p.op(OSLICE3)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
2016-04-21 11:55:33 -07:00
|
|
|
low, high, max := n.SliceBounds()
|
|
|
|
|
p.exprsOrNil(low, high)
|
|
|
|
|
p.expr(max)
|
2016-03-18 17:21:32 -07:00
|
|
|
|
|
|
|
|
case OCOPY, OCOMPLEX:
|
2016-05-11 13:39:36 -07:00
|
|
|
// treated like other builtin calls (see e.g., OREAL)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(op)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
|
|
|
|
p.expr(n.Right)
|
2016-05-11 13:39:36 -07:00
|
|
|
p.op(OEND)
|
2016-03-18 17:21:32 -07:00
|
|
|
|
|
|
|
|
case OCONV, OCONVIFACE, OCONVNOP, OARRAYBYTESTR, OARRAYRUNESTR, OSTRARRAYBYTE, OSTRARRAYRUNE, ORUNESTR:
|
|
|
|
|
p.op(OCONV)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2017-04-06 13:04:34 -07:00
|
|
|
p.expr(n.Left)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.typ(n.Type)
|
|
|
|
|
|
|
|
|
|
case OREAL, OIMAG, OAPPEND, OCAP, OCLOSE, ODELETE, OLEN, OMAKE, ONEW, OPANIC, ORECOVER, OPRINT, OPRINTN:
|
|
|
|
|
p.op(op)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-05-11 13:39:36 -07:00
|
|
|
if n.Left != nil {
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
2016-05-11 13:39:36 -07:00
|
|
|
p.op(OEND)
|
2016-03-18 17:21:32 -07:00
|
|
|
} else {
|
2016-05-11 13:39:36 -07:00
|
|
|
p.exprList(n.List) // emits terminating OEND
|
|
|
|
|
}
|
|
|
|
|
// only append() calls may contain '...' arguments
|
|
|
|
|
if op == OAPPEND {
|
2017-02-27 19:56:38 +02:00
|
|
|
p.bool(n.Isddd())
|
|
|
|
|
} else if n.Isddd() {
|
2017-11-09 23:10:43 +00:00
|
|
|
Fatalf("exporter: unexpected '...' with %v call", op)
|
2016-03-18 17:21:32 -07:00
|
|
|
}
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
case OCALL, OCALLFUNC, OCALLMETH, OCALLINTER, OGETG:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(OCALL)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
|
|
|
|
p.exprList(n.List)
|
2017-02-27 19:56:38 +02:00
|
|
|
p.bool(n.Isddd())
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
case OMAKEMAP, OMAKECHAN, OMAKESLICE:
|
|
|
|
|
p.op(op) // must keep separate from OMAKE for importer
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.typ(n.Type)
|
|
|
|
|
switch {
|
|
|
|
|
default:
|
|
|
|
|
// empty list
|
|
|
|
|
p.op(OEND)
|
|
|
|
|
case n.List.Len() != 0: // pre-typecheck
|
|
|
|
|
p.exprList(n.List) // emits terminating OEND
|
|
|
|
|
case n.Right != nil:
|
|
|
|
|
p.expr(n.Left)
|
|
|
|
|
p.expr(n.Right)
|
|
|
|
|
p.op(OEND)
|
|
|
|
|
case n.Left != nil && (n.Op == OMAKESLICE || !n.Left.Type.IsUntyped()):
|
|
|
|
|
p.expr(n.Left)
|
|
|
|
|
p.op(OEND)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// unary expressions
|
|
|
|
|
case OPLUS, OMINUS, OADDR, OCOM, OIND, ONOT, ORECV:
|
|
|
|
|
p.op(op)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
|
|
|
|
|
|
|
|
|
// binary expressions
|
|
|
|
|
case OADD, OAND, OANDAND, OANDNOT, ODIV, OEQ, OGE, OGT, OLE, OLT,
|
|
|
|
|
OLSH, OMOD, OMUL, ONE, OOR, OOROR, ORSH, OSEND, OSUB, OXOR:
|
|
|
|
|
p.op(op)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
|
|
|
|
p.expr(n.Right)
|
|
|
|
|
|
|
|
|
|
case OADDSTR:
|
|
|
|
|
p.op(OADDSTR)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.exprList(n.List)
|
|
|
|
|
|
2015-10-22 18:56:45 -07:00
|
|
|
case OCMPSTR, OCMPIFACE:
|
2018-03-08 04:18:18 -08:00
|
|
|
p.op(n.SubOp())
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
|
|
|
|
p.expr(n.Right)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
case ODCLCONST:
|
|
|
|
|
// if exporting, DCLCONST should just be removed as its usage
|
|
|
|
|
// has already been replaced with literals
|
|
|
|
|
// TODO(gri) these should not be exported in the first place
|
|
|
|
|
// TODO(gri) why is this considered an expression in fmt.go?
|
|
|
|
|
p.op(ODCLCONST)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
|
|
|
|
|
default:
|
2016-09-09 21:08:46 -07:00
|
|
|
Fatalf("cannot export %v (%d) node\n"+
|
|
|
|
|
"==> please file an issue and assign to gri@\n", n.Op, int(n.Op))
|
2016-03-18 17:21:32 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Caution: stmt will emit more than one node for statement nodes n that have a non-empty
|
|
|
|
|
// n.Ninit and where n cannot have a natural init section (such as in "if", "for", etc.).
|
|
|
|
|
func (p *exporter) stmt(n *Node) {
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("( ")
|
|
|
|
|
defer p.tracef(") ")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if n.Ninit.Len() > 0 && !stmtwithinit(n.Op) {
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("( /* Ninits */ ")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// can't use stmtList here since we don't want the final OEND
|
|
|
|
|
for _, n := range n.Ninit.Slice() {
|
|
|
|
|
p.stmt(n)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef(") ")
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
switch op := n.Op; op {
|
2015-10-22 18:56:45 -07:00
|
|
|
case ODCL:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(ODCL)
|
2018-04-02 17:33:38 -07:00
|
|
|
p.pos(n.Left) // use declared variable's pos
|
2016-08-29 10:37:13 -07:00
|
|
|
p.sym(n.Left)
|
2015-10-22 18:56:45 -07:00
|
|
|
p.typ(n.Left.Type)
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// case ODCLFIELD:
|
|
|
|
|
// unimplemented - handled by default case
|
|
|
|
|
|
2016-12-19 10:30:44 -08:00
|
|
|
case OAS:
|
2016-03-18 17:21:32 -07:00
|
|
|
// Don't export "v = <N>" initializing statements, hope they're always
|
|
|
|
|
// preceded by the DCL which will be re-parsed and typecheck to reproduce
|
|
|
|
|
// the "v = <N>" again.
|
2016-04-13 13:17:30 -07:00
|
|
|
if n.Right != nil {
|
|
|
|
|
p.op(OAS)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
|
|
|
|
p.expr(n.Right)
|
|
|
|
|
}
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
case OASOP:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(OASOP)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2018-03-08 04:18:18 -08:00
|
|
|
p.op(n.SubOp())
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
2017-02-27 19:56:38 +02:00
|
|
|
if p.bool(!n.Implicit()) {
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Right)
|
|
|
|
|
}
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2016-05-11 12:40:17 -07:00
|
|
|
case OAS2, OAS2DOTTYPE, OAS2FUNC, OAS2MAPR, OAS2RECV:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(OAS2)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.exprList(n.List)
|
|
|
|
|
p.exprList(n.Rlist)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
case ORETURN:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(ORETURN)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.exprList(n.List)
|
|
|
|
|
|
2016-05-08 20:59:53 -07:00
|
|
|
// case ORETJMP:
|
|
|
|
|
// unreachable - generated by compiler for trampolin routines
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
case OPROC, ODEFER:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(op)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
case OIF:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(OIF)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.stmtList(n.Ninit)
|
|
|
|
|
p.expr(n.Left)
|
2017-03-27 11:38:20 -07:00
|
|
|
p.stmtList(n.Nbody)
|
|
|
|
|
p.stmtList(n.Rlist)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
case OFOR:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(OFOR)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.stmtList(n.Ninit)
|
|
|
|
|
p.exprsOrNil(n.Left, n.Right)
|
|
|
|
|
p.stmtList(n.Nbody)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
case ORANGE:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(ORANGE)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.stmtList(n.List)
|
|
|
|
|
p.expr(n.Right)
|
|
|
|
|
p.stmtList(n.Nbody)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
case OSELECT, OSWITCH:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(op)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.stmtList(n.Ninit)
|
|
|
|
|
p.exprsOrNil(n.Left, nil)
|
|
|
|
|
p.stmtList(n.List)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
case OCASE, OXCASE:
|
2016-04-13 13:17:30 -07:00
|
|
|
p.op(OXCASE)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.stmtList(n.List)
|
|
|
|
|
p.stmtList(n.Nbody)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2017-09-01 14:55:15 -07:00
|
|
|
case OFALL:
|
|
|
|
|
p.op(OFALL)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-04-13 13:17:30 -07:00
|
|
|
|
cmd/compile: correctly import labels, gotos, and fallthroughs
The importer had several bugs with respect to labels and gotos:
- it didn't create a new ONAME node for label names (label dcl,
goto, continue, and break)
- it overwrote the symbol for gotos with the dclstack
- it didn't set the dclstack for labels
In the process changed export format slightly to always assume
a label name for labels and gotos, and never assume a label for
fallthroughs.
For fallthroughs and switch cases, now also set Xoffset like in
the parser. (Not setting it, i.e., using 0 was ok since this is
only used for verifying correct use of fallthroughs, which was
checked already. But it's an extra level of verification of the
import.)
Fixes #15838.
Change-Id: I3637f6314b8651c918df0c8cd70cd858c92bd483
Reviewed-on: https://go-review.googlesource.com/23445
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-05-25 16:38:02 -07:00
|
|
|
case OBREAK, OCONTINUE:
|
2016-03-18 17:21:32 -07:00
|
|
|
p.op(op)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.exprsOrNil(n.Left, nil)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
case OEMPTY:
|
2016-05-08 20:59:53 -07:00
|
|
|
// nothing to emit
|
2015-10-22 18:56:45 -07:00
|
|
|
|
cmd/compile: correctly import labels, gotos, and fallthroughs
The importer had several bugs with respect to labels and gotos:
- it didn't create a new ONAME node for label names (label dcl,
goto, continue, and break)
- it overwrote the symbol for gotos with the dclstack
- it didn't set the dclstack for labels
In the process changed export format slightly to always assume
a label name for labels and gotos, and never assume a label for
fallthroughs.
For fallthroughs and switch cases, now also set Xoffset like in
the parser. (Not setting it, i.e., using 0 was ok since this is
only used for verifying correct use of fallthroughs, which was
checked already. But it's an extra level of verification of the
import.)
Fixes #15838.
Change-Id: I3637f6314b8651c918df0c8cd70cd858c92bd483
Reviewed-on: https://go-review.googlesource.com/23445
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-05-25 16:38:02 -07:00
|
|
|
case OGOTO, OLABEL:
|
|
|
|
|
p.op(op)
|
2017-02-20 09:55:54 -05:00
|
|
|
p.pos(n)
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(n.Left)
|
2015-10-22 18:56:45 -07:00
|
|
|
|
|
|
|
|
default:
|
2016-09-09 21:08:46 -07:00
|
|
|
Fatalf("exporter: CANNOT EXPORT: %v\nPlease notify gri@\n", n.Op)
|
2015-10-22 18:56:45 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
func (p *exporter) exprsOrNil(a, b *Node) {
|
2015-10-22 18:56:45 -07:00
|
|
|
ab := 0
|
|
|
|
|
if a != nil {
|
|
|
|
|
ab |= 1
|
|
|
|
|
}
|
|
|
|
|
if b != nil {
|
|
|
|
|
ab |= 2
|
|
|
|
|
}
|
|
|
|
|
p.int(ab)
|
|
|
|
|
if ab&1 != 0 {
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(a)
|
2015-10-22 18:56:45 -07:00
|
|
|
}
|
|
|
|
|
if ab&2 != 0 {
|
2016-03-18 17:21:32 -07:00
|
|
|
p.expr(b)
|
2015-10-22 18:56:45 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func (p *exporter) fieldSym(s *types.Sym, short bool) {
|
2015-10-22 18:56:45 -07:00
|
|
|
name := s.Name
|
2016-03-18 17:21:32 -07:00
|
|
|
|
|
|
|
|
// remove leading "type." in method names ("(T).m" -> "m")
|
|
|
|
|
if short {
|
|
|
|
|
if i := strings.LastIndex(name, "."); i >= 0 {
|
|
|
|
|
name = name[i+1:]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-02 17:03:36 -07:00
|
|
|
// we should never see a _ (blank) here - these are accessible ("read") fields
|
|
|
|
|
// TODO(gri) can we assert this with an explicit check?
|
2015-10-22 18:56:45 -07:00
|
|
|
p.string(name)
|
2016-03-18 17:21:32 -07:00
|
|
|
if !exportname(name) {
|
|
|
|
|
p.pkg(s.Pkg)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-11 11:28:36 -07:00
|
|
|
// sym must encode the _ (blank) identifier as a single string "_" since
|
|
|
|
|
// encoding for some nodes is based on this assumption (e.g. ONAME nodes).
|
2016-03-18 17:21:32 -07:00
|
|
|
func (p *exporter) sym(n *Node) {
|
|
|
|
|
s := n.Sym
|
|
|
|
|
if s.Pkg != nil {
|
|
|
|
|
if len(s.Name) > 0 && s.Name[0] == '.' {
|
|
|
|
|
Fatalf("exporter: exporting synthetic symbol %s", s.Name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("{ SYM ")
|
|
|
|
|
defer p.tracef("} ")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
name := s.Name
|
|
|
|
|
|
|
|
|
|
// remove leading "type." in method names ("(T).m" -> "m")
|
|
|
|
|
if i := strings.LastIndex(name, "."); i >= 0 {
|
|
|
|
|
name = name[i+1:]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if strings.Contains(name, "·") && n.Name.Vargen > 0 {
|
|
|
|
|
Fatalf("exporter: unexpected · in symbol name")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if i := n.Name.Vargen; i > 0 {
|
|
|
|
|
name = fmt.Sprintf("%s·%d", name, i)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.string(name)
|
|
|
|
|
if name != "_" {
|
2015-10-22 18:56:45 -07:00
|
|
|
p.pkg(s.Pkg)
|
|
|
|
|
}
|
2016-12-02 13:55:25 -05:00
|
|
|
// Fixes issue #18167.
|
|
|
|
|
p.string(s.Linkname)
|
2015-10-22 18:56:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exporter) bool(b bool) bool {
|
2016-03-18 17:21:32 -07:00
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("[")
|
|
|
|
|
defer p.tracef("= %v] ", b)
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-22 18:56:45 -07:00
|
|
|
x := 0
|
|
|
|
|
if b {
|
|
|
|
|
x = 1
|
|
|
|
|
}
|
|
|
|
|
p.int(x)
|
|
|
|
|
return b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exporter) op(op Op) {
|
|
|
|
|
if p.trace {
|
2016-03-18 17:21:32 -07:00
|
|
|
p.tracef("[")
|
2016-09-09 21:08:46 -07:00
|
|
|
defer p.tracef("= %v] ", op)
|
2015-10-22 18:56:45 -07:00
|
|
|
}
|
2016-03-18 17:21:32 -07:00
|
|
|
|
|
|
|
|
p.int(int(op))
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// Low-level encoders
|
|
|
|
|
|
|
|
|
|
func (p *exporter) index(marker byte, index int) {
|
|
|
|
|
if index < 0 {
|
2015-10-22 18:56:45 -07:00
|
|
|
Fatalf("exporter: invalid index < 0")
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
if debugFormat {
|
|
|
|
|
p.marker('t')
|
|
|
|
|
}
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("%c%d ", marker, index)
|
|
|
|
|
}
|
|
|
|
|
p.rawInt64(int64(index))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exporter) tag(tag int) {
|
|
|
|
|
if tag >= 0 {
|
2015-10-22 18:56:45 -07:00
|
|
|
Fatalf("exporter: invalid tag >= 0")
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
if debugFormat {
|
|
|
|
|
p.marker('t')
|
|
|
|
|
}
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("%s ", tagString[-tag])
|
|
|
|
|
}
|
|
|
|
|
p.rawInt64(int64(tag))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exporter) int(x int) {
|
|
|
|
|
p.int64(int64(x))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exporter) int64(x int64) {
|
|
|
|
|
if debugFormat {
|
|
|
|
|
p.marker('i')
|
|
|
|
|
}
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("%d ", x)
|
|
|
|
|
}
|
|
|
|
|
p.rawInt64(x)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *exporter) string(s string) {
|
|
|
|
|
if debugFormat {
|
|
|
|
|
p.marker('s')
|
|
|
|
|
}
|
|
|
|
|
if p.trace {
|
|
|
|
|
p.tracef("%q ", s)
|
|
|
|
|
}
|
2016-04-13 17:53:03 -07:00
|
|
|
// if we saw the string before, write its index (>= 0)
|
|
|
|
|
// (the empty string is mapped to 0)
|
|
|
|
|
if i, ok := p.strIndex[s]; ok {
|
|
|
|
|
p.rawInt64(int64(i))
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// otherwise, remember string and write its negative length and bytes
|
|
|
|
|
p.strIndex[s] = len(p.strIndex)
|
|
|
|
|
p.rawInt64(-int64(len(s)))
|
2015-10-23 16:01:09 -07:00
|
|
|
for i := 0; i < len(s); i++ {
|
2016-04-13 17:53:03 -07:00
|
|
|
p.rawByte(s[i])
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// marker emits a marker byte and position information which makes
|
2016-03-18 17:21:32 -07:00
|
|
|
// it easy for a reader to detect if it is "out of sync". Used only
|
|
|
|
|
// if debugFormat is set.
|
2015-08-13 19:05:37 -07:00
|
|
|
func (p *exporter) marker(m byte) {
|
2016-04-13 17:53:03 -07:00
|
|
|
p.rawByte(m)
|
2016-03-18 17:21:32 -07:00
|
|
|
// Uncomment this for help tracking down the location
|
|
|
|
|
// of an incorrect marker when running in debugFormat.
|
|
|
|
|
// if p.trace {
|
|
|
|
|
// p.tracef("#%d ", p.written)
|
|
|
|
|
// }
|
2015-08-13 19:05:37 -07:00
|
|
|
p.rawInt64(int64(p.written))
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-19 18:10:00 -07:00
|
|
|
// rawInt64 should only be used by low-level encoders.
|
2015-08-13 19:05:37 -07:00
|
|
|
func (p *exporter) rawInt64(x int64) {
|
|
|
|
|
var tmp [binary.MaxVarintLen64]byte
|
|
|
|
|
n := binary.PutVarint(tmp[:], x)
|
2015-10-23 16:01:09 -07:00
|
|
|
for i := 0; i < n; i++ {
|
2016-04-13 17:53:03 -07:00
|
|
|
p.rawByte(tmp[i])
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-19 18:10:00 -07:00
|
|
|
// rawStringln should only be used to emit the initial version string.
|
|
|
|
|
func (p *exporter) rawStringln(s string) {
|
|
|
|
|
for i := 0; i < len(s); i++ {
|
|
|
|
|
p.rawByte(s[i])
|
|
|
|
|
}
|
|
|
|
|
p.rawByte('\n')
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-13 17:53:03 -07:00
|
|
|
// rawByte is the bottleneck interface to write to p.out.
|
|
|
|
|
// rawByte escapes b as follows (any encoding does that
|
2015-10-23 16:01:09 -07:00
|
|
|
// hides '$'):
|
|
|
|
|
//
|
|
|
|
|
// '$' => '|' 'S'
|
|
|
|
|
// '|' => '|' '|'
|
|
|
|
|
//
|
|
|
|
|
// Necessary so other tools can find the end of the
|
|
|
|
|
// export data by searching for "$$".
|
2016-04-13 17:53:03 -07:00
|
|
|
// rawByte should only be used by low-level encoders.
|
|
|
|
|
func (p *exporter) rawByte(b byte) {
|
2015-10-23 16:01:09 -07:00
|
|
|
switch b {
|
|
|
|
|
case '$':
|
|
|
|
|
// write '$' as '|' 'S'
|
|
|
|
|
b = 'S'
|
|
|
|
|
fallthrough
|
|
|
|
|
case '|':
|
|
|
|
|
// write '|' as '|' '|'
|
2016-04-06 21:45:29 -07:00
|
|
|
p.out.WriteByte('|')
|
2015-10-23 16:01:09 -07:00
|
|
|
p.written++
|
|
|
|
|
}
|
2016-04-06 21:45:29 -07:00
|
|
|
p.out.WriteByte(b)
|
2015-10-23 16:01:09 -07:00
|
|
|
p.written++
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-13 19:05:37 -07:00
|
|
|
// tracef is like fmt.Printf but it rewrites the format string
|
|
|
|
|
// to take care of indentation.
|
|
|
|
|
func (p *exporter) tracef(format string, args ...interface{}) {
|
2015-12-22 02:40:47 -05:00
|
|
|
if strings.ContainsAny(format, "<>\n") {
|
2015-08-13 19:05:37 -07:00
|
|
|
var buf bytes.Buffer
|
|
|
|
|
for i := 0; i < len(format); i++ {
|
|
|
|
|
// no need to deal with runes
|
|
|
|
|
ch := format[i]
|
|
|
|
|
switch ch {
|
|
|
|
|
case '>':
|
|
|
|
|
p.indent++
|
|
|
|
|
continue
|
|
|
|
|
case '<':
|
|
|
|
|
p.indent--
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
buf.WriteByte(ch)
|
|
|
|
|
if ch == '\n' {
|
|
|
|
|
for j := p.indent; j > 0; j-- {
|
|
|
|
|
buf.WriteString(". ")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
format = buf.String()
|
|
|
|
|
}
|
|
|
|
|
fmt.Printf(format, args...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// Export format
|
|
|
|
|
|
|
|
|
|
// Tags. Must be < 0.
|
|
|
|
|
const (
|
2016-03-18 17:21:32 -07:00
|
|
|
// Objects
|
2015-08-13 19:05:37 -07:00
|
|
|
packageTag = -(iota + 1)
|
2016-03-18 17:21:32 -07:00
|
|
|
constTag
|
|
|
|
|
typeTag
|
|
|
|
|
varTag
|
|
|
|
|
funcTag
|
|
|
|
|
endTag
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
// Types
|
|
|
|
|
namedTag
|
|
|
|
|
arrayTag
|
|
|
|
|
sliceTag
|
|
|
|
|
dddTag
|
|
|
|
|
structTag
|
|
|
|
|
pointerTag
|
|
|
|
|
signatureTag
|
|
|
|
|
interfaceTag
|
|
|
|
|
mapTag
|
|
|
|
|
chanTag
|
|
|
|
|
|
|
|
|
|
// Values
|
|
|
|
|
falseTag
|
|
|
|
|
trueTag
|
|
|
|
|
int64Tag
|
|
|
|
|
floatTag
|
|
|
|
|
fractionTag // not used by gc
|
|
|
|
|
complexTag
|
|
|
|
|
stringTag
|
2015-10-22 18:56:45 -07:00
|
|
|
nilTag
|
2016-03-18 11:13:24 -04:00
|
|
|
unknownTag // not used by gc (only appears in packages with errors)
|
2016-10-25 14:09:18 -07:00
|
|
|
|
2016-12-22 13:04:04 -08:00
|
|
|
// Type aliases
|
2016-10-25 14:09:18 -07:00
|
|
|
aliasTag
|
2015-08-13 19:05:37 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Debugging support.
|
|
|
|
|
// (tagString is only used when tracing is enabled)
|
|
|
|
|
var tagString = [...]string{
|
2016-03-18 17:21:32 -07:00
|
|
|
// Objects
|
2015-08-13 19:05:37 -07:00
|
|
|
-packageTag: "package",
|
2016-03-18 17:21:32 -07:00
|
|
|
-constTag: "const",
|
|
|
|
|
-typeTag: "type",
|
|
|
|
|
-varTag: "var",
|
|
|
|
|
-funcTag: "func",
|
|
|
|
|
-endTag: "end",
|
2015-08-13 19:05:37 -07:00
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// Types
|
2015-08-13 19:05:37 -07:00
|
|
|
-namedTag: "named type",
|
|
|
|
|
-arrayTag: "array",
|
|
|
|
|
-sliceTag: "slice",
|
|
|
|
|
-dddTag: "ddd",
|
|
|
|
|
-structTag: "struct",
|
|
|
|
|
-pointerTag: "pointer",
|
|
|
|
|
-signatureTag: "signature",
|
|
|
|
|
-interfaceTag: "interface",
|
|
|
|
|
-mapTag: "map",
|
|
|
|
|
-chanTag: "chan",
|
|
|
|
|
|
2016-03-18 17:21:32 -07:00
|
|
|
// Values
|
2015-08-13 19:05:37 -07:00
|
|
|
-falseTag: "false",
|
|
|
|
|
-trueTag: "true",
|
|
|
|
|
-int64Tag: "int64",
|
|
|
|
|
-floatTag: "float",
|
|
|
|
|
-fractionTag: "fraction",
|
|
|
|
|
-complexTag: "complex",
|
|
|
|
|
-stringTag: "string",
|
2016-03-18 11:13:24 -04:00
|
|
|
-nilTag: "nil",
|
|
|
|
|
-unknownTag: "unknown",
|
2016-10-25 14:09:18 -07:00
|
|
|
|
2016-12-22 13:04:04 -08:00
|
|
|
// Type aliases
|
2016-10-25 14:09:18 -07:00
|
|
|
-aliasTag: "alias",
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// untype returns the "pseudo" untyped type for a Ctype (import/export use only).
|
|
|
|
|
// (we can't use an pre-initialized array because we must be sure all types are
|
|
|
|
|
// set up)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func untype(ctype Ctype) *types.Type {
|
2015-08-13 19:05:37 -07:00
|
|
|
switch ctype {
|
|
|
|
|
case CTINT:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
return types.Idealint
|
2015-08-13 19:05:37 -07:00
|
|
|
case CTRUNE:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
return types.Idealrune
|
2015-08-13 19:05:37 -07:00
|
|
|
case CTFLT:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
return types.Idealfloat
|
2015-08-13 19:05:37 -07:00
|
|
|
case CTCPLX:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
return types.Idealcomplex
|
2015-08-13 19:05:37 -07:00
|
|
|
case CTSTR:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
return types.Idealstring
|
2015-08-13 19:05:37 -07:00
|
|
|
case CTBOOL:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
return types.Idealbool
|
2015-08-13 19:05:37 -07:00
|
|
|
case CTNIL:
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
return types.Types[TNIL]
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
2015-10-22 18:56:45 -07:00
|
|
|
Fatalf("exporter: unknown Ctype")
|
2015-08-13 19:05:37 -07:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
var predecl []*types.Type // initialized lazily
|
2015-08-13 19:05:37 -07:00
|
|
|
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
func predeclared() []*types.Type {
|
2015-08-13 19:05:37 -07:00
|
|
|
if predecl == nil {
|
|
|
|
|
// initialize lazily to be sure that all
|
|
|
|
|
// elements have been initialized before
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
predecl = []*types.Type{
|
2015-08-13 19:05:37 -07:00
|
|
|
// basic types
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
types.Types[TBOOL],
|
|
|
|
|
types.Types[TINT],
|
|
|
|
|
types.Types[TINT8],
|
|
|
|
|
types.Types[TINT16],
|
|
|
|
|
types.Types[TINT32],
|
|
|
|
|
types.Types[TINT64],
|
|
|
|
|
types.Types[TUINT],
|
|
|
|
|
types.Types[TUINT8],
|
|
|
|
|
types.Types[TUINT16],
|
|
|
|
|
types.Types[TUINT32],
|
|
|
|
|
types.Types[TUINT64],
|
|
|
|
|
types.Types[TUINTPTR],
|
|
|
|
|
types.Types[TFLOAT32],
|
|
|
|
|
types.Types[TFLOAT64],
|
|
|
|
|
types.Types[TCOMPLEX64],
|
|
|
|
|
types.Types[TCOMPLEX128],
|
|
|
|
|
types.Types[TSTRING],
|
2015-08-13 19:05:37 -07:00
|
|
|
|
2016-12-22 13:04:04 -08:00
|
|
|
// basic type aliases
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
types.Bytetype,
|
|
|
|
|
types.Runetype,
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
// error
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
types.Errortype,
|
2015-08-13 19:05:37 -07:00
|
|
|
|
|
|
|
|
// untyped types
|
|
|
|
|
untype(CTBOOL),
|
|
|
|
|
untype(CTINT),
|
|
|
|
|
untype(CTRUNE),
|
|
|
|
|
untype(CTFLT),
|
|
|
|
|
untype(CTCPLX),
|
|
|
|
|
untype(CTSTR),
|
|
|
|
|
untype(CTNIL),
|
|
|
|
|
|
|
|
|
|
// package unsafe
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
types.Types[TUNSAFEPTR],
|
2015-12-01 12:05:30 -08:00
|
|
|
|
2016-03-18 11:13:24 -04:00
|
|
|
// invalid type (package contains errors)
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
types.Types[Txxx],
|
2016-03-18 11:13:24 -04:00
|
|
|
|
2015-12-01 12:05:30 -08:00
|
|
|
// any type, for builtin export data
|
cmd/compile: factor out Pkg, Sym, and Type into package types
- created new package cmd/compile/internal/types
- moved Pkg, Sym, Type to new package
- to break cycles, for now we need the (ugly) types/utils.go
file which contains a handful of functions that must be installed
early by the gc frontend
- to break cycles, for now we need two functions to convert between
*gc.Node and *types.Node (the latter is a dummy type)
- adjusted the gc's code to use the new package and the conversion
functions as needed
- made several Pkg, Sym, and Type methods functions as needed
- renamed constructors typ, typPtr, typArray, etc. to types.New,
types.NewPtr, types.NewArray, etc.
Passes toolstash-check -all.
Change-Id: I8adfa5e85c731645d0a7fd2030375ed6ebf54b72
Reviewed-on: https://go-review.googlesource.com/39855
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2017-04-04 17:54:02 -07:00
|
|
|
types.Types[TANY],
|
2015-08-13 19:05:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return predecl
|
|
|
|
|
}
|