You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: container.go
    path of file: ./repos/cosmos-sdk/depinject
    
    the code of the file until where you have to start completion: package depinject

import (
	"bytes"
	stderrors "errors"
	"fmt"
	"reflect"

	"github.com/cockroachdb/errors"

	"cosmossdk.io/depinject/internal/graphviz"
)

type container struct {
	*debugConfig

	resolvers         map[string]resolver
	interfaceBindings map[string]interfaceBinding
	invokers          []invoker

	moduleKeyContext *ModuleKeyContext

	resolveStack []resolveFrame
	callerStack  []Location
	callerMap    map[Location]bool
}

type invoker struct {
	fn     *providerDescriptor
	modKey *moduleKey
}

type resolveFrame struct {
	loc Location
	typ reflect.Type
}

// interfaceBinding defines a type binding for interfaceName to type implTypeName when being provided as a
// dependency to the module identified by moduleKey.  If moduleKey is nil then the type binding is applied globally,
// not module-scoped.
type interfaceBinding struct {
	interfaceName string
	implTypeName  string
	moduleKey     *moduleKey
	resolver      resolver
}

func newContainer(cfg *debugConfig) *container {
	return &container{
		debugConfig:       cfg,
		resolvers:         map[string]resolver{},
		moduleKeyContext:  &ModuleKeyContext{},
		interfaceBindings: map[string]interfaceBinding{},
		callerStack:       nil,
		callerMap:         map[Location]bool{},
	}
}

func (c *container) call(provider *providerDescriptor, moduleKey *moduleKey) ([]reflect.Value, error) {
	loc := provider.Location
	graphNode := c.locationGraphNode(loc, moduleKey)

	markGraphNodeAsFailed(graphNode)

	if c.callerMap[loc] {
		return nil, errors.Errorf("cyclic dependency: %s -> %s", loc.Name(), loc.Name())
	}

	c.callerMap[loc] = true
	c.callerStack = append(c.callerStack, loc)

	c.logf("Resolving dependencies for %s", loc)
	c.indentLogger()
	inVals := make([]reflect.Value, len(provider.Inputs))
	for i, in := range provider.Inputs {
		val, err := c.resolve(in, moduleKey, loc)
		if err != nil {
			return nil, err
		}
		inVals[i] = val
	}
	c.dedentLogger()
	c.logf("Calling %s", loc)

	delete(c.callerMap, loc)
	c.callerStack = c.callerStack[0 : len(c.callerStack)-1]

	out, err := provider.Fn(inVals)
	if err != nil {
		return nil, errors.Wrapf(err, "error calling provider %s", loc)
	}

	markGraphNodeAsUsed(graphNode)

	return out, nil
}

func (c *container) getResolver(typ reflect.Type, key *moduleKey) (resolver, error) {
	pr, err := c.getExplicitResolver(typ, key)
	if err != nil {
		return nil, err
	}
	if pr != nil {
		return pr, nil
	}

	if vr, ok := c.resolverByType(typ); ok {
		return vr, nil
	}

	elemType := typ
	if isManyPerContainerSliceType(elemType) || isOnePerModuleMapType(elemType) {
		elemType = elemType.Elem()
	}

	var typeGraphNode *graphviz.Node

	if isManyPerContainerType(elemType) {
		c.logf("Registering resolver for many-per-container type %v", elemType)
		sliceType := reflect.SliceOf(elemT
    
func (c *container) addNode(provider *providerDescriptor, key *moduleKey) (interface{}, error) {
	providerGraphNode := c.locationGraphNode(provider.Location, key)
	hasModuleKeyParam := false
	hasOwnModuleKeyParam := false
	for _, in := range provider.Inputs {
		typ := in.Type
		if typ == moduleKeyType {
			hasModuleKeyParam = true
		}

		if typ == ownModuleKeyType {
			hasOwnModuleKeyParam = true
		}

		if isManyPerContainerType(typ) {
			return nil, fmt.Errorf("many-per-container type %v can't be used as an input parameter", typ)
		} else if isOnePerModuleType(typ) {
			return nil, fmt.Errorf("one-per-module type %v can't be used as an input parameter", typ)
		}

		vr, err := c.getResolver(typ, key)
		if err != nil {
			return nil, err
		}

		var typeGraphNode *graphviz.Node
		if vr != nil {
			typeGraphNode = vr.typeGraphNode()
		} else {
			typeGraphNode = c.typeGraphNode(typ)
			if err != nil {
				return nil, err
			}
		}

		c.addGraphEdge(typeGraphNode, providerGraphNode)
	}

	if !hasModuleKeyParam {
		c.logf("Registering %s", provider.Location.String())
		c.indentLogger()
		defer c.dedentLogger()

		sp := &simpleProvider{
			provider:  provider,
			moduleKey: key,
		}

		for i, out := range provider.Outputs {
			typ := out.Type

			// one-per-module maps can't be used as a return type
			if isOnePerModuleMapType(typ) {
				return nil, fmt.Errorf("%v cannot be used as a return type because %v is a one-per-module type",
					typ, typ.Elem())
			}

			// many-per-container slices of many-per-container types
			if isManyPerContainerSliceType(typ) {
				typ = typ.Elem()
			}

			vr, err := c.getResolver(typ, key)
			if err != nil {
				return nil, err
			}

			if vr != nil {
				c.logf("Found resolver for %v: %T", typ, vr)
				err := vr.addNode(sp, i)
				if err != nil {
					return nil, err
				}
			} else {
				c.logf("Registering resolver for simple type %v", typ)

				typeGraphNode := c.typeGraphNode(typ)
				vr = &simpleResolver{
					node:        sp,
					typ:         typ,
					graphNode:   typeGraphNode,
					idxInValues: i,
				}
				c.addResolver(typ, vr)
			}

			c.addGraphEdge(providerGraphNode, vr.typeGraphNode())
		}

		return sp, nil
	}

	if hasOwnModuleKeyParam {
		return nil, errors.Errorf("%T and %T must not be declared as dependencies on the same provided",
			ModuleKey{}, OwnModuleKey{})
	}

	c.logf("Registering module-scoped provider: %s", provider.Location.String())
	c.indentLogger()
	defer c.dedentLogger()

	node := &moduleDepProvider{
		provider:        provider,
		calledForModule: map[*moduleKey]bool{},
		valueMap:        map[*moduleKey][]reflect.Value{},
	}

	for i, out := range provider.Outputs {
		typ := out.Type

		c.logf("Registering resolver for module-scoped type %v", typ)

		existing, ok := c.resolverByType(typ)
		if ok {
			return nil, errors.Errorf("duplicate provision of type %v by module-scoped provider %s\n\talready provided by %s",
				typ, provider.Location, existing.describeLocation())
		}

		typeGraphNode := c.typeGraphNode(typ)
		c.addResolver(typ, &moduleDepResolver{
			typ:         typ,
			idxInValues: i,
			node:        node,
			valueMap:    map[*moduleKey]reflect.Value{},
			graphNode:   typeGraphNode,
		})

		c.addGraphEdge(providerGraphNode, typeGraphNode)
	}

	return node, nil
}