return true
case ir.OCLOSURE:
- // TODO(danscales) - fix some bugs when budget is lowered below 30
+ // TODO(danscales,mdempsky): Get working with -G.
+ // Probably after #43818 is fixed.
+ if base.Flag.G > 0 {
+ v.reason = "inlining closures not yet working with -G"
+ return true
+ }
+
+ // TODO(danscales) - fix some bugs when budget is lowered below 15
// Maybe make budget proportional to number of closure variables, e.g.:
//v.budget -= int32(len(n.(*ir.ClosureExpr).Func.ClosureVars) * 3)
- v.budget -= 30
+ v.budget -= 15
+ // Scan body of closure (which DoChildren doesn't automatically
+ // do) to check for disallowed ops in the body and include the
+ // body in the budget.
+ if doList(n.(*ir.ClosureExpr).Func.Body, v.do) {
+ return true
+ }
case ir.ORANGE,
ir.OSELECT,
import (
"errors"
"fmt"
+ "io"
"os"
pathpkg "path"
"runtime"
"unicode/utf8"
"cmd/compile/internal/base"
+ "cmd/compile/internal/importer"
"cmd/compile/internal/ir"
"cmd/compile/internal/syntax"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
+ "cmd/compile/internal/types2"
"cmd/internal/archive"
"cmd/internal/bio"
"cmd/internal/goobj"
"cmd/internal/src"
)
+// Temporary import helper to get type2-based type-checking going.
+type gcimports struct {
+ packages map[string]*types2.Package
+}
+
+func (m *gcimports) Import(path string) (*types2.Package, error) {
+ return m.ImportFrom(path, "" /* no vendoring */, 0)
+}
+
+func (m *gcimports) ImportFrom(path, srcDir string, mode types2.ImportMode) (*types2.Package, error) {
+ if mode != 0 {
+ panic("mode must be 0")
+ }
+
+ path, err := resolveImportPath(path)
+ if err != nil {
+ return nil, err
+ }
+
+ lookup := func(path string) (io.ReadCloser, error) { return openPackage(path) }
+ return importer.Import(m.packages, path, srcDir, lookup)
+}
+
func isDriveLetter(b byte) bool {
return 'a' <= b && b <= 'z' || 'A' <= b && b <= 'Z'
}
// TODO(mdempsky): Return an error instead.
func importfile(decl *syntax.ImportDecl) *types.Pkg {
+ if decl.Path.Kind != syntax.StringLit {
+ base.Errorf("import path must be a string")
+ return nil
+ }
+
path, err := strconv.Unquote(decl.Path.Value)
if err != nil {
base.Errorf("import path must be a string")