Skip to content

Commit

Permalink
cue: remove build.Context reference
Browse files Browse the repository at this point in the history
This is really unused,but would cause memory leaks
when used.

Change-Id: I9dc637324d16eb4290cba9a56c96a64287083d14
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/8223
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
  • Loading branch information
mpvl committed Feb 16, 2021
1 parent e1e7031 commit 830cfbc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
13 changes: 2 additions & 11 deletions cue/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
//
// The zero value of a Runtime is ready to use.
type Runtime struct {
ctx *build.Context // TODO: remove
idx *index
}

Expand Down Expand Up @@ -75,14 +74,6 @@ func (r *Runtime) index() *index {
return r.idx
}

func (r *Runtime) buildContext() *build.Context {
ctx := r.ctx
if r.ctx == nil {
ctx = build.NewContext()
}
return ctx
}

func (r *Runtime) complete(p *build.Instance) (*Instance, error) {
idx := r.index()
if err := p.Complete(); err != nil {
Expand All @@ -101,7 +92,7 @@ func (r *Runtime) complete(p *build.Instance) (*Instance, error) {
// name in position information. The source may import builtin packages. Use
// Build to allow importing non-builtin packages.
func (r *Runtime) Compile(filename string, source interface{}) (*Instance, error) {
ctx := r.buildContext()
ctx := build.NewContext()
p := ctx.NewInstance(filename, dummyLoad)
if err := p.AddFile(filename, source); err != nil {
return nil, p.Err
Expand All @@ -112,7 +103,7 @@ func (r *Runtime) Compile(filename string, source interface{}) (*Instance, error
// CompileFile compiles the given source file into an Instance. The source may
// import builtin packages. Use Build to allow importing non-builtin packages.
func (r *Runtime) CompileFile(file *ast.File) (*Instance, error) {
ctx := r.buildContext()
ctx := build.NewContext()
p := ctx.NewInstance(file.Filename, dummyLoad)
err := p.AddSyntax(file)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cue/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (b *unmarshaller) build(bi *instanceData) *build.Instance {

func compileInstances(r *Runtime, data []*instanceData) (instances []*Instance, err error) {
b := unmarshaller{
ctxt: r.buildContext(),
ctxt: build.NewContext(),
imports: map[string]*instanceData{},
}
for _, i := range data {
Expand Down

0 comments on commit 830cfbc

Please sign in to comment.