diff --git a/.circleci/config.yml b/.circleci/config.yml index 3372e9c5bb..29a246f88e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,6 +49,7 @@ jobs: test-race: docker: - image: quay.io/influxdb/flux-build:latest + resource_class: large environment: GOPATH: /tmp/go GOFLAGS: -p=8 diff --git a/runtime/runtime.go b/runtime/runtime.go index 03c37e7a56..49b897bb24 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -21,6 +21,7 @@ var Default = &runtime{} // runtime contains the flux runtime for interpreting and // executing queries. type runtime struct { + astPkgs map[string]*ast.Package pkgs map[string]*semantic.Package builtins map[string]map[string]values.Value finalized bool @@ -56,11 +57,11 @@ func (r *runtime) RegisterPackage(pkg *ast.Package) error { return errors.New(codes.Internal, "already finalized, cannot register builtin package") } - if r.pkgs == nil { - r.pkgs = make(map[string]*semantic.Package) + if r.astPkgs == nil { + r.astPkgs = make(map[string]*ast.Package) } - if _, ok := r.pkgs[pkg.Path]; ok { + if _, ok := r.astPkgs[pkg.Path]; ok { return errors.Newf(codes.Internal, "duplicate builtin package %q", pkg.Path) } @@ -68,20 +69,7 @@ func (r *runtime) RegisterPackage(pkg *ast.Package) error { err := ast.GetError(pkg) return errors.Wrapf(err, codes.Inherit, "failed to parse builtin package %q", pkg.Path) } - - bs, err := json.Marshal(pkg) - if err != nil { - return err - } - hdl, err := r.JSONToHandle(bs) - if err != nil { - return err - } - root, err := AnalyzePackage(hdl) - if err != nil { - return err - } - r.pkgs[pkg.Path] = root + r.astPkgs[pkg.Path] = pkg return nil } @@ -192,11 +180,38 @@ func (r *runtime) Stdlib() interpreter.Importer { return &importer{r: r} } +func (r *runtime) compilePackages() error { + pkgs := make(map[string]*semantic.Package) + for _, pkg := range r.astPkgs { + bs, err := json.Marshal(pkg) + if err != nil { + return err + } + hdl, err := r.JSONToHandle(bs) + if err != nil { + return err + } + root, err := AnalyzePackage(hdl) + if err != nil { + return err + } + pkgs[pkg.Path] = root + } + r.pkgs = pkgs + r.astPkgs = nil + return nil +} + func (r *runtime) Finalize() error { if r.finalized { return errors.New(codes.Internal, "already finalized") } r.finalized = true + + if err := r.compilePackages(); err != nil { + return err + } + for path, pkg := range r.builtins { semPkg, ok := r.pkgs[path] if !ok {