vdl: Fix Javascript type generation bugs.

This fixes https://github.com/veyron/release-issues/issues/1202

A few of the issues resolved:
  1) Don't create type definitions for inner-types that aren't
     actually used at the top-level.
  2) Remove special-case for "error", which was causing a type
     definition to be generated for error unnecessarily.
  3) Remove wspr workaround.

Change-Id: I60e60db71605377f7e4f9bdd5c749fe442dac51c
MultiPart: 1/2
diff --git a/lib/vdl/codegen/javascript/pkg_types.go b/lib/vdl/codegen/javascript/pkg_types.go
index c6325c4..f7445d9 100644
--- a/lib/vdl/codegen/javascript/pkg_types.go
+++ b/lib/vdl/codegen/javascript/pkg_types.go
@@ -131,58 +131,47 @@
 	return p.names
 }
 
-// addNameIfNeeded produces a new typeName if:
-// -it is not already generated
-// -it is not from another package
-// -it is not an already a built-in type in vdl.js (primitives, any, etc..)
-func (p *pkgTypeNames) addNameIfNeeded(t *vdl.Type) {
+// addName generates a new name for t if necessary.  Returns true if a new name
+// was generated, and thus names for inner-types should also be generated.
+func (p *pkgTypeNames) addName(t *vdl.Type) bool {
+	// Name has already been generated.
 	if _, ok := p.names[t]; ok {
-		return
+		return false
 	}
 
 	// Do not create name for built-in JS types (primitives, any, etc..)
 	if _, ok := builtinJSType(t); ok {
-		return
+		return false
 	}
 
 	var name string
 	if t.Name() != "" {
 		pp, n := vdl.SplitIdent(t.Name())
 		// Do not create name for types from other packages.
-		// TODO(aghassemi) TODO(bprosnitz): error is special right now, it is not a VDL type
-		// ideally we can handle error similar to other builtin JS types but VDL error is still in flux.
-		// Issue tracked in https://github.com/veyron/release-issues/issues/654
-
-		if pp != p.pkg.Path && n != "error" {
-			return
+		if pp != p.pkg.Path {
+			return false
 		}
 		name = "_type" + n
 	} else {
 		name = fmt.Sprintf("_type%d", p.nextIndex)
 		p.nextIndex++
 	}
-
 	p.names[t] = name
+	return true
 }
 
 func (p *pkgTypeNames) addInnerTypes(t *vdl.Type) {
-	if _, ok := p.names[t]; ok {
+	if !p.addName(t) {
 		return
 	}
-
-	p.addNameIfNeeded(t)
-
 	switch t.Kind() {
-	case vdl.Optional, vdl.Array, vdl.List, vdl.Map:
+	case vdl.Optional, vdl.Array, vdl.List:
 		p.addInnerTypes(t.Elem())
-	}
-
-	switch t.Kind() {
-	case vdl.Set, vdl.Map:
+	case vdl.Set:
 		p.addInnerTypes(t.Key())
-	}
-
-	switch t.Kind() {
+	case vdl.Map:
+		p.addInnerTypes(t.Key())
+		p.addInnerTypes(t.Elem())
 	case vdl.Struct, vdl.Union:
 		for i := 0; i < t.NumField(); i++ {
 			p.addInnerTypes(t.Field(i).Type)
diff --git a/services/wsprd/namespace/namespace.vdl b/services/wsprd/namespace/namespace.vdl
index b2dcf62..2f5a25f 100644
--- a/services/wsprd/namespace/namespace.vdl
+++ b/services/wsprd/namespace/namespace.vdl
@@ -8,17 +8,9 @@
 	"time"
 
 	"v.io/v23/naming"
-	"v.io/v23/security"
 	"v.io/v23/services/security/access"
-
 )
 
-// TODO(nlacasse,bprosnitz): Remove this unused type and the security import
-// once https://github.com/veyron/release-issues/issues/1202 is fixed.
-type Workaround interface {
-	Unused(unused security.BlessingPattern) error
-}
-
 type Namespace interface {
 	// Run a glob query and stream the results.
 	Glob(pattern string) stream<_, naming.VDLGlobReply> error
diff --git a/services/wsprd/namespace/namespace.vdl.go b/services/wsprd/namespace/namespace.vdl.go
index 094aa96..ffc037a 100644
--- a/services/wsprd/namespace/namespace.vdl.go
+++ b/services/wsprd/namespace/namespace.vdl.go
@@ -17,132 +17,10 @@
 	// VDL user imports
 	"time"
 	"v.io/v23/naming"
-	"v.io/v23/security"
 	"v.io/v23/services/security/access"
 	_ "v.io/v23/vdlroot/time"
 )
 
-// WorkaroundClientMethods is the client interface
-// containing Workaround methods.
-//
-// TODO(nlacasse,bprosnitz): Remove this unused type and the security import
-// once https://github.com/veyron/release-issues/issues/1202 is fixed.
-type WorkaroundClientMethods interface {
-	Unused(ctx *context.T, unused security.BlessingPattern, opts ...ipc.CallOpt) error
-}
-
-// WorkaroundClientStub adds universal methods to WorkaroundClientMethods.
-type WorkaroundClientStub interface {
-	WorkaroundClientMethods
-	ipc.UniversalServiceMethods
-}
-
-// WorkaroundClient returns a client stub for Workaround.
-func WorkaroundClient(name string, opts ...ipc.BindOpt) WorkaroundClientStub {
-	var client ipc.Client
-	for _, opt := range opts {
-		if clientOpt, ok := opt.(ipc.Client); ok {
-			client = clientOpt
-		}
-	}
-	return implWorkaroundClientStub{name, client}
-}
-
-type implWorkaroundClientStub struct {
-	name   string
-	client ipc.Client
-}
-
-func (c implWorkaroundClientStub) c(ctx *context.T) ipc.Client {
-	if c.client != nil {
-		return c.client
-	}
-	return v23.GetClient(ctx)
-}
-
-func (c implWorkaroundClientStub) Unused(ctx *context.T, i0 security.BlessingPattern, opts ...ipc.CallOpt) (err error) {
-	var call ipc.ClientCall
-	if call, err = c.c(ctx).StartCall(ctx, c.name, "Unused", []interface{}{i0}, opts...); err != nil {
-		return
-	}
-	err = call.Finish()
-	return
-}
-
-// WorkaroundServerMethods is the interface a server writer
-// implements for Workaround.
-//
-// TODO(nlacasse,bprosnitz): Remove this unused type and the security import
-// once https://github.com/veyron/release-issues/issues/1202 is fixed.
-type WorkaroundServerMethods interface {
-	Unused(call ipc.ServerCall, unused security.BlessingPattern) error
-}
-
-// WorkaroundServerStubMethods is the server interface containing
-// Workaround methods, as expected by ipc.Server.
-// There is no difference between this interface and WorkaroundServerMethods
-// since there are no streaming methods.
-type WorkaroundServerStubMethods WorkaroundServerMethods
-
-// WorkaroundServerStub adds universal methods to WorkaroundServerStubMethods.
-type WorkaroundServerStub interface {
-	WorkaroundServerStubMethods
-	// Describe the Workaround interfaces.
-	Describe__() []ipc.InterfaceDesc
-}
-
-// WorkaroundServer returns a server stub for Workaround.
-// It converts an implementation of WorkaroundServerMethods into
-// an object that may be used by ipc.Server.
-func WorkaroundServer(impl WorkaroundServerMethods) WorkaroundServerStub {
-	stub := implWorkaroundServerStub{
-		impl: impl,
-	}
-	// Initialize GlobState; always check the stub itself first, to handle the
-	// case where the user has the Glob method defined in their VDL source.
-	if gs := ipc.NewGlobState(stub); gs != nil {
-		stub.gs = gs
-	} else if gs := ipc.NewGlobState(impl); gs != nil {
-		stub.gs = gs
-	}
-	return stub
-}
-
-type implWorkaroundServerStub struct {
-	impl WorkaroundServerMethods
-	gs   *ipc.GlobState
-}
-
-func (s implWorkaroundServerStub) Unused(call ipc.ServerCall, i0 security.BlessingPattern) error {
-	return s.impl.Unused(call, i0)
-}
-
-func (s implWorkaroundServerStub) Globber() *ipc.GlobState {
-	return s.gs
-}
-
-func (s implWorkaroundServerStub) Describe__() []ipc.InterfaceDesc {
-	return []ipc.InterfaceDesc{WorkaroundDesc}
-}
-
-// WorkaroundDesc describes the Workaround interface.
-var WorkaroundDesc ipc.InterfaceDesc = descWorkaround
-
-// descWorkaround hides the desc to keep godoc clean.
-var descWorkaround = ipc.InterfaceDesc{
-	Name:    "Workaround",
-	PkgPath: "v.io/x/ref/services/wsprd/namespace",
-	Doc:     "// TODO(nlacasse,bprosnitz): Remove this unused type and the security import\n// once https://github.com/veyron/release-issues/issues/1202 is fixed.",
-	Methods: []ipc.MethodDesc{
-		{
-			Name: "Unused",
-			InArgs: []ipc.ArgDesc{
-				{"unused", ``}, // security.BlessingPattern
-			},
-		},
-	},
-}
-
 // NamespaceClientMethods is the client interface
 // containing Namespace methods.
 type NamespaceClientMethods interface {