vdl: Add generated vars for TypeOf, for better performance.

Also changed vdl.Decoder.StartValue to take a *vdl.Type argument,
and perform the compatibility check.  This gives up to an
additional 10% improvement, and makes it easier to optimize the
compatibility check in the future, since it's now only performed
by the 3 decoders (vom, vdl.Value and vdl.pipe).

Some numbers.  In general all the generated stuff gets better:
                                 old ns/op  new ns/op   delta
RpcRequestZeroSingleShotEncode     51010      41028    -19.57%
RpcRequestZeroRepeatedEncode         302        194    -35.76%
RpcRequestZeroSingleShotDecode      1962       1636    -16.62%
RpcRequestZeroRepeatedDecode         484        281    -41.94%
RpcRequestFullSingleShotEncode     63755      47481    -25.53%
RpcRequestFullRepeatedEncode        9407       5558    -40.92%
RpcRequestFullSingleShotDecode     58886      58863     -0.04%
RpcRequestFullRepeatedDecode       55303      54106     -2.16%
RpcResponseZeroSingleShotEncode    51700      40604    -21.46%
RpcResponseZeroRepeatedEncode        635        514    -19.06%
RpcResponseZeroSingleShotDecode     2026       1755    -13.38%
RpcResponseZeroRepeatedDecode        524        304    -41.98%
RpcResponseFullSingleShotEncode   106038      91816    -13.41%
RpcResponseFullRepeatedEncode      44273      42005     -5.12%
RpcResponseFullSingleShotDecode    43271      42635     -1.47%
RpcResponseFullRepeatedDecode      38608      37251     -3.51%

For some reason, the reflect version of large-list single-shot
encoding gets much worse.  I'm not sure why.  But I'm going to
ignore that for now, since I think there's plenty of other
optimizations we can explore.
                                  old ns/op  new ns/op   delta
LargeListSingleShotEncodeReflect   19279360   21696617  +12.54%
LargeListRepeatedEncodeReflect     19055693   19550742   +2.60%
LargeListSingleShotDecodeReflect   34161615   32556162   -4.70%
LargeListRepeatedDecodeReflect     33647837   31846309   -5.35%
LargeListSingleShotEncode           3951128    3984021   +0.83%
LargeListRepeatedEncode             3870694    3895734   +0.65%
LargeListSingleShotDecode           5221050    5465362   +4.68%
LargeListRepeatedDecode             5211915    5246888   +0.67%

MultiPart: 5/5
Change-Id: I1dc50e95f037832daf1203456a07ab916b1e0d80
diff --git a/go/src/v.io/x/sensorlog/internal/sbmodel/sbmodel.vdl.go b/go/src/v.io/x/sensorlog/internal/sbmodel/sbmodel.vdl.go
index 3cfd1a7..4bd5979 100644
--- a/go/src/v.io/x/sensorlog/internal/sbmodel/sbmodel.vdl.go
+++ b/go/src/v.io/x/sensorlog/internal/sbmodel/sbmodel.vdl.go
@@ -44,7 +44,7 @@
 }
 
 func (x VDeviceCfg) VDLWrite(enc vdl.Encoder) error {
-	if err := enc.StartValue(vdl.TypeOf((*VDeviceCfg)(nil)).Elem()); err != nil {
+	if err := enc.StartValue(__VDLType_struct_1); err != nil {
 		return err
 	}
 	if x.Desc != "" {
@@ -83,12 +83,9 @@
 
 func (x *VDeviceCfg) VDLRead(dec vdl.Decoder) error {
 	*x = VDeviceCfg{}
-	if err := dec.StartValue(); err != nil {
+	if err := dec.StartValue(__VDLType_struct_1); err != nil {
 		return err
 	}
-	if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
-		return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
-	}
 	for {
 		f, err := dec.NextField()
 		if err != nil {
@@ -98,7 +95,7 @@
 		case "":
 			return dec.FinishValue()
 		case "Desc":
-			if err := dec.StartValue(); err != nil {
+			if err := dec.StartValue(vdl.StringType); err != nil {
 				return err
 			}
 			var err error
@@ -109,7 +106,7 @@
 				return err
 			}
 		case "SgPublishSb":
-			if err := dec.StartValue(); err != nil {
+			if err := dec.StartValue(vdl.StringType); err != nil {
 				return err
 			}
 			var err error
@@ -141,7 +138,7 @@
 }
 
 func (x KDeviceCfg) VDLWrite(enc vdl.Encoder) error {
-	if err := enc.StartValue(vdl.TypeOf((*KDeviceCfg)(nil)).Elem()); err != nil {
+	if err := enc.StartValue(__VDLType_struct_2); err != nil {
 		return err
 	}
 	if x.DevId != "" {
@@ -166,12 +163,9 @@
 
 func (x *KDeviceCfg) VDLRead(dec vdl.Decoder) error {
 	*x = KDeviceCfg{}
-	if err := dec.StartValue(); err != nil {
+	if err := dec.StartValue(__VDLType_struct_2); err != nil {
 		return err
 	}
-	if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
-		return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
-	}
 	for {
 		f, err := dec.NextField()
 		if err != nil {
@@ -181,7 +175,7 @@
 		case "":
 			return dec.FinishValue()
 		case "DevId":
-			if err := dec.StartValue(); err != nil {
+			if err := dec.StartValue(vdl.StringType); err != nil {
 				return err
 			}
 			var err error
@@ -228,7 +222,7 @@
 }
 
 func (x SamplerDef) VDLWrite(enc vdl.Encoder) error {
-	if err := enc.StartValue(vdl.TypeOf((*SamplerDef)(nil)).Elem()); err != nil {
+	if err := enc.StartValue(__VDLType_struct_3); err != nil {
 		return err
 	}
 	if x.Script != "" {
@@ -277,12 +271,9 @@
 
 func (x *SamplerDef) VDLRead(dec vdl.Decoder) error {
 	*x = SamplerDef{}
-	if err := dec.StartValue(); err != nil {
+	if err := dec.StartValue(__VDLType_struct_3); err != nil {
 		return err
 	}
-	if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
-		return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
-	}
 	for {
 		f, err := dec.NextField()
 		if err != nil {
@@ -292,7 +283,7 @@
 		case "":
 			return dec.FinishValue()
 		case "Script":
-			if err := dec.StartValue(); err != nil {
+			if err := dec.StartValue(vdl.StringType); err != nil {
 				return err
 			}
 			var err error
@@ -356,7 +347,7 @@
 }
 
 func (x VStreamDef) VDLWrite(enc vdl.Encoder) error {
-	if err := enc.StartValue(vdl.TypeOf((*VStreamDef)(nil)).Elem()); err != nil {
+	if err := enc.StartValue(__VDLType_struct_6); err != nil {
 		return err
 	}
 	if x.Desc != "" {
@@ -403,12 +394,9 @@
 
 func (x *VStreamDef) VDLRead(dec vdl.Decoder) error {
 	*x = VStreamDef{}
-	if err := dec.StartValue(); err != nil {
+	if err := dec.StartValue(__VDLType_struct_6); err != nil {
 		return err
 	}
-	if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
-		return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
-	}
 	for {
 		f, err := dec.NextField()
 		if err != nil {
@@ -418,7 +406,7 @@
 		case "":
 			return dec.FinishValue()
 		case "Desc":
-			if err := dec.StartValue(); err != nil {
+			if err := dec.StartValue(vdl.StringType); err != nil {
 				return err
 			}
 			var err error
@@ -433,7 +421,7 @@
 				return err
 			}
 		case "Enabled":
-			if err := dec.StartValue(); err != nil {
+			if err := dec.StartValue(vdl.BoolType); err != nil {
 				return err
 			}
 			var err error
@@ -466,7 +454,7 @@
 }
 
 func (x KStreamDef) VDLWrite(enc vdl.Encoder) error {
-	if err := enc.StartValue(vdl.TypeOf((*KStreamDef)(nil)).Elem()); err != nil {
+	if err := enc.StartValue(__VDLType_struct_7); err != nil {
 		return err
 	}
 	if x.DevId != "" {
@@ -505,12 +493,9 @@
 
 func (x *KStreamDef) VDLRead(dec vdl.Decoder) error {
 	*x = KStreamDef{}
-	if err := dec.StartValue(); err != nil {
+	if err := dec.StartValue(__VDLType_struct_7); err != nil {
 		return err
 	}
-	if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
-		return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
-	}
 	for {
 		f, err := dec.NextField()
 		if err != nil {
@@ -520,7 +505,7 @@
 		case "":
 			return dec.FinishValue()
 		case "DevId":
-			if err := dec.StartValue(); err != nil {
+			if err := dec.StartValue(vdl.StringType); err != nil {
 				return err
 			}
 			var err error
@@ -531,7 +516,7 @@
 				return err
 			}
 		case "StreamId":
-			if err := dec.StartValue(); err != nil {
+			if err := dec.StartValue(vdl.StringType); err != nil {
 				return err
 			}
 			var err error
@@ -576,7 +561,7 @@
 }
 
 func (x KDataPoint) VDLWrite(enc vdl.Encoder) error {
-	if err := enc.StartValue(vdl.TypeOf((*KDataPoint)(nil)).Elem()); err != nil {
+	if err := enc.StartValue(__VDLType_struct_8); err != nil {
 		return err
 	}
 	if x.DevId != "" {
@@ -627,12 +612,9 @@
 
 func (x *KDataPoint) VDLRead(dec vdl.Decoder) error {
 	*x = KDataPoint{}
-	if err := dec.StartValue(); err != nil {
+	if err := dec.StartValue(__VDLType_struct_8); err != nil {
 		return err
 	}
-	if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(*x), dec.Type()) {
-		return fmt.Errorf("incompatible struct %T, from %v", *x, dec.Type())
-	}
 	for {
 		f, err := dec.NextField()
 		if err != nil {
@@ -642,7 +624,7 @@
 		case "":
 			return dec.FinishValue()
 		case "DevId":
-			if err := dec.StartValue(); err != nil {
+			if err := dec.StartValue(vdl.StringType); err != nil {
 				return err
 			}
 			var err error
@@ -653,7 +635,7 @@
 				return err
 			}
 		case "StreamId":
-			if err := dec.StartValue(); err != nil {
+			if err := dec.StartValue(vdl.StringType); err != nil {
 				return err
 			}
 			var err error
@@ -727,7 +709,7 @@
 }
 
 func (x VDataPointValue) VDLWrite(enc vdl.Encoder) error {
-	if err := enc.StartValue(vdl.TypeOf((*VDataPoint)(nil))); err != nil {
+	if err := enc.StartValue(__VDLType_union_9); err != nil {
 		return err
 	}
 	if err := enc.NextField("Value"); err != nil {
@@ -749,7 +731,7 @@
 }
 
 func (x VDataPointError) VDLWrite(enc vdl.Encoder) error {
-	if err := enc.StartValue(vdl.TypeOf((*VDataPoint)(nil))); err != nil {
+	if err := enc.StartValue(__VDLType_union_9); err != nil {
 		return err
 	}
 	if err := enc.NextField("Error"); err != nil {
@@ -771,12 +753,9 @@
 }
 
 func VDLReadVDataPoint(dec vdl.Decoder, x *VDataPoint) error {
-	if err := dec.StartValue(); err != nil {
+	if err := dec.StartValue(__VDLType_union_9); err != nil {
 		return err
 	}
-	if (dec.StackDepth() == 1 || dec.IsAny()) && !vdl.Compatible(vdl.TypeOf(x), dec.Type()) {
-		return fmt.Errorf("incompatible union %T, from %v", x, dec.Type())
-	}
 	f, err := dec.NextField()
 	if err != nil {
 		return err
@@ -784,7 +763,7 @@
 	switch f {
 	case "Value":
 		var field VDataPointValue
-		if err := dec.StartValue(); err != nil {
+		if err := dec.StartValue(vdl.Float64Type); err != nil {
 			return err
 		}
 		var err error
@@ -797,7 +776,7 @@
 		*x = field
 	case "Error":
 		var field VDataPointError
-		if err := dec.StartValue(); err != nil {
+		if err := dec.StartValue(vdl.StringType); err != nil {
 			return err
 		}
 		var err error
@@ -822,6 +801,19 @@
 	return dec.FinishValue()
 }
 
+// Hold type definitions in package-level variables, for better performance.
+var (
+	__VDLType_struct_1 *vdl.Type
+	__VDLType_struct_2 *vdl.Type
+	__VDLType_struct_3 *vdl.Type
+	__VDLType_struct_4 *vdl.Type
+	__VDLType_struct_5 *vdl.Type
+	__VDLType_struct_6 *vdl.Type
+	__VDLType_struct_7 *vdl.Type
+	__VDLType_struct_8 *vdl.Type
+	__VDLType_union_9  *vdl.Type
+)
+
 var __VDLInitCalled bool
 
 // __VDLInit performs vdl initialization.  It is safe to call multiple times.
@@ -852,5 +844,16 @@
 	vdl.Register((*KDataPoint)(nil))
 	vdl.Register((*VDataPoint)(nil))
 
+	// Initialize type definitions.
+	__VDLType_struct_1 = vdl.TypeOf((*VDeviceCfg)(nil)).Elem()
+	__VDLType_struct_2 = vdl.TypeOf((*KDeviceCfg)(nil)).Elem()
+	__VDLType_struct_3 = vdl.TypeOf((*SamplerDef)(nil)).Elem()
+	__VDLType_struct_4 = vdl.TypeOf((*vdltime.Time)(nil)).Elem()
+	__VDLType_struct_5 = vdl.TypeOf((*vdltime.Duration)(nil)).Elem()
+	__VDLType_struct_6 = vdl.TypeOf((*VStreamDef)(nil)).Elem()
+	__VDLType_struct_7 = vdl.TypeOf((*KStreamDef)(nil)).Elem()
+	__VDLType_struct_8 = vdl.TypeOf((*KDataPoint)(nil)).Elem()
+	__VDLType_union_9 = vdl.TypeOf((*VDataPoint)(nil))
+
 	return struct{}{}
 }