Merge "js/core: expected-gen build rule"
diff --git a/Makefile b/Makefile
index b0fb08b..2aa5a29 100644
--- a/Makefile
+++ b/Makefile
@@ -140,6 +140,22 @@
 gen-vdl-test: JS_VDL_PATH_TO_CORE := "../../src"
 gen-vdl-test: gen-vdl-impl
 
+# This generates the vdl files used by test/vom/test-vdl-arith.js
+# They are placed in test/vdl/expected-gen/v.io/<package-path>.
+# This command is not normally run by the tests. It should only be run when the
+# expected vdl files need to be updated.
+gen-vdl-test-expected: JS_VDL_DIR := "$(V23_ROOT)/release/javascript/core/test/vdl/expected-gen"
+gen-vdl-test-expected: JS_VDL_PATH_TO_CORE := "../../../src"
+gen-vdl-test-expected: gen-vdl-test-expected-impl
+
+gen-vdl-test-expected-impl:
+	rm -rf $(JS_VDL_DIR)
+	echo $(VDLPATH)
+	VDLPATH=$(VDLPATH) v23 go run $(V23_ROOT)/release/go/src/v.io/x/ref/cmd/vdl/main.go generate -lang=javascript \
+		-js-relative-path-to-core=$(JS_VDL_PATH_TO_CORE) \
+		-js-out-dir=$(JS_VDL_DIR) \
+		v.io/x/ref/lib/vdl/testdata/...
+
 gen-vdl-impl:
 ifndef NOVDLGEN
 	rm -rf $(JS_VDL_DIR)
@@ -286,7 +302,7 @@
 .PHONY: test-integration test-integration-node test-integration-browser
 .PHONY: test-unit test-unit-node test-unit-browser
 .PHONY: check-that-npm-is-in-path
-.PHONY: gen-vdl gen-vdl-test gen-vdl-impl
+.PHONY: gen-vdl gen-vdl-test gen-vdl-test-expected gen-vdl-impl gen-vdl-test-expected-impl
 
 # Prevent the tests from running in parallel, which causes problems because it
 # starts multiple instances of the services at once, and also because it
diff --git a/test/vdl/expected-gen/testdata/arith/exp/index.js b/test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/arith/exp/index.js
similarity index 79%
rename from test/vdl/expected-gen/testdata/arith/exp/index.js
rename to test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/arith/exp/index.js
index e2fa41e..87a9092 100644
--- a/test/vdl/expected-gen/testdata/arith/exp/index.js
+++ b/test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/arith/exp/index.js
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// This file was auto-generated by the veyron vdl tool.
-var vdl = require('../../../../../../src/vdl');
+// This file was auto-generated by the vanadium vdl tool.
+var vdl = require('../../../../../../../../../../../src/vdl');
 
 
 
@@ -32,11 +32,11 @@
   
     
 function Exp(){}
-module.exports.Exp = Exp
+module.exports.Exp = Exp;
 
     
       
-Exp.prototype.exp = function(ctx, x) {
+Exp.prototype.exp = function(ctx, serverCall, x) {
   throw new Error('Method Exp not implemented');
 };
      
@@ -75,3 +75,5 @@
 
    
  
+
+
diff --git a/test/vdl/expected-gen/testdata/arith/index.js b/test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/arith/index.js
similarity index 75%
rename from test/vdl/expected-gen/testdata/arith/index.js
rename to test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/arith/index.js
index 1e0441e..7e5ebe8 100644
--- a/test/vdl/expected-gen/testdata/arith/index.js
+++ b/test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/arith/index.js
@@ -2,8 +2,9 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// This file was auto-generated by the veyron vdl tool.
-var vdl = require('../../../../../src/vdl');
+// This file was auto-generated by the vanadium vdl tool.
+var vdl = require('../../../../../../../../../../src/vdl');
+var canonicalize = require('../../../../../../../../../../src/vdl/canonicalize');
 
 
 
@@ -23,19 +24,19 @@
 
 // Consts:
 
-  module.exports.Yes = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.BOOL))(true);
+  module.exports.Yes = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.BOOL))(true, true), vdl.Types.BOOL);
 
-  module.exports.No = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.BOOL))(false);
+  module.exports.No = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.BOOL))(false, true), vdl.Types.BOOL);
 
-  module.exports.Hello = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("hello");
+  module.exports.Hello = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("hello", true), vdl.Types.STRING);
 
-  module.exports.Int32Const = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT32))(123);
+  module.exports.Int32Const = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT32))(123, true), vdl.Types.INT32);
 
-  module.exports.Int64Const = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT64))(new vdl.BigInt(1, new Uint8Array([0x80])));
+  module.exports.Int64Const = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT64))(new vdl.BigInt(1, new Uint8Array([0x80])), true), vdl.Types.INT64);
 
-  module.exports.FloatConst = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.FLOAT64))(2);
+  module.exports.FloatConst = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.FLOAT64))(2, true), vdl.Types.FLOAT64);
 
-  module.exports.Mask = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x1, 0x0])));
+  module.exports.Mask = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x1, 0x0])), true), vdl.Types.UINT64);
 
 
 
@@ -48,16 +49,16 @@
   
     
 function Trigonometry(){}
-module.exports.Trigonometry = Trigonometry
+module.exports.Trigonometry = Trigonometry;
 
     
       
-Trigonometry.prototype.sine = function(ctx, angle) {
+Trigonometry.prototype.sine = function(ctx, serverCall, angle) {
   throw new Error('Method Sine not implemented');
 };
     
       
-Trigonometry.prototype.cosine = function(ctx, angle) {
+Trigonometry.prototype.cosine = function(ctx, serverCall, angle) {
   throw new Error('Method Cosine not implemented');
 };
      
@@ -118,21 +119,21 @@
   
     
 function AdvancedMath(){}
-module.exports.AdvancedMath = AdvancedMath
+module.exports.AdvancedMath = AdvancedMath;
 
     
       
-AdvancedMath.prototype.sine = function(ctx, angle) {
+AdvancedMath.prototype.sine = function(ctx, serverCall, angle) {
   throw new Error('Method Sine not implemented');
 };
     
       
-AdvancedMath.prototype.cosine = function(ctx, angle) {
+AdvancedMath.prototype.cosine = function(ctx, serverCall, angle) {
   throw new Error('Method Cosine not implemented');
 };
     
       
-AdvancedMath.prototype.exp = function(ctx, x) {
+AdvancedMath.prototype.exp = function(ctx, serverCall, x) {
   throw new Error('Method Exp not implemented');
 };
      
@@ -226,46 +227,46 @@
   
     
 function Arith(){}
-module.exports.Arith = Arith
+module.exports.Arith = Arith;
 
     
       
-Arith.prototype.add = function(ctx, a, b) {
+Arith.prototype.add = function(ctx, serverCall, a, b) {
   throw new Error('Method Add not implemented');
 };
     
       
-Arith.prototype.divMod = function(ctx, a, b) {
+Arith.prototype.divMod = function(ctx, serverCall, a, b) {
   throw new Error('Method DivMod not implemented');
 };
     
       
-Arith.prototype.sub = function(ctx, args) {
+Arith.prototype.sub = function(ctx, serverCall, args) {
   throw new Error('Method Sub not implemented');
 };
     
       
-Arith.prototype.mul = function(ctx, nested) {
+Arith.prototype.mul = function(ctx, serverCall, nested) {
   throw new Error('Method Mul not implemented');
 };
     
       
-Arith.prototype.genError = function(ctx) {
+Arith.prototype.genError = function(ctx, serverCall) {
   throw new Error('Method GenError not implemented');
 };
     
       
-Arith.prototype.count = function(ctx, start) {
+Arith.prototype.count = function(ctx, serverCall, start) {
   throw new Error('Method Count not implemented');
 };
     
       
-Arith.prototype.streamingAdd = function(ctx) {
+Arith.prototype.streamingAdd = function(ctx, serverCall) {
   throw new Error('Method StreamingAdd not implemented');
 };
     
       
-Arith.prototype.quoteAny = function(ctx, a) {
+Arith.prototype.quoteAny = function(ctx, serverCall, a) {
   throw new Error('Method QuoteAny not implemented');
 };
      
@@ -385,7 +386,7 @@
     outArgs: [],
     inStream: null,
     outStream: null,
-    tags: [new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("foo"), new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("barz"), new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("hello"), new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT32))(129), new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x24]))), ]
+    tags: [canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("foo", true), vdl.Types.STRING), canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("barz", true), vdl.Types.STRING), canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("hello", true), vdl.Types.STRING), canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT32))(129, true), vdl.Types.INT32), canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x24])), true), vdl.Types.UINT64), ]
   },
     
       
@@ -459,71 +460,71 @@
   
     
 function Calculator(){}
-module.exports.Calculator = Calculator
+module.exports.Calculator = Calculator;
 
     
       
-Calculator.prototype.on = function(ctx) {
+Calculator.prototype.on = function(ctx, serverCall) {
   throw new Error('Method On not implemented');
 };
     
       
-Calculator.prototype.off = function(ctx) {
+Calculator.prototype.off = function(ctx, serverCall) {
   throw new Error('Method Off not implemented');
 };
     
       
-Calculator.prototype.add = function(ctx, a, b) {
+Calculator.prototype.add = function(ctx, serverCall, a, b) {
   throw new Error('Method Add not implemented');
 };
     
       
-Calculator.prototype.divMod = function(ctx, a, b) {
+Calculator.prototype.divMod = function(ctx, serverCall, a, b) {
   throw new Error('Method DivMod not implemented');
 };
     
       
-Calculator.prototype.sub = function(ctx, args) {
+Calculator.prototype.sub = function(ctx, serverCall, args) {
   throw new Error('Method Sub not implemented');
 };
     
       
-Calculator.prototype.mul = function(ctx, nested) {
+Calculator.prototype.mul = function(ctx, serverCall, nested) {
   throw new Error('Method Mul not implemented');
 };
     
       
-Calculator.prototype.genError = function(ctx) {
+Calculator.prototype.genError = function(ctx, serverCall) {
   throw new Error('Method GenError not implemented');
 };
     
       
-Calculator.prototype.count = function(ctx, start) {
+Calculator.prototype.count = function(ctx, serverCall, start) {
   throw new Error('Method Count not implemented');
 };
     
       
-Calculator.prototype.streamingAdd = function(ctx) {
+Calculator.prototype.streamingAdd = function(ctx, serverCall) {
   throw new Error('Method StreamingAdd not implemented');
 };
     
       
-Calculator.prototype.quoteAny = function(ctx, a) {
+Calculator.prototype.quoteAny = function(ctx, serverCall, a) {
   throw new Error('Method QuoteAny not implemented');
 };
     
       
-Calculator.prototype.sine = function(ctx, angle) {
+Calculator.prototype.sine = function(ctx, serverCall, angle) {
   throw new Error('Method Sine not implemented');
 };
     
       
-Calculator.prototype.cosine = function(ctx, angle) {
+Calculator.prototype.cosine = function(ctx, serverCall, angle) {
   throw new Error('Method Cosine not implemented');
 };
     
       
-Calculator.prototype.exp = function(ctx, x) {
+Calculator.prototype.exp = function(ctx, serverCall, x) {
   throw new Error('Method Exp not implemented');
 };
      
@@ -565,7 +566,7 @@
     outArgs: [],
     inStream: null,
     outStream: null,
-    tags: [new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("offtag"), ]
+    tags: [canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("offtag", true), vdl.Types.STRING), ]
   },
     
       
@@ -675,7 +676,7 @@
     outArgs: [],
     inStream: null,
     outStream: null,
-    tags: [new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("foo"), new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("barz"), new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("hello"), new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT32))(129), new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x24]))), ]
+    tags: [canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("foo", true), vdl.Types.STRING), canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("barz", true), vdl.Types.STRING), canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("hello", true), vdl.Types.STRING), canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT32))(129, true), vdl.Types.INT32), canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x24])), true), vdl.Types.UINT64), ]
   },
     
       
@@ -811,3 +812,5 @@
 
    
  
+
+
diff --git a/test/vdl/expected-gen/testdata/base/index.js b/test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/base/index.js
similarity index 67%
rename from test/vdl/expected-gen/testdata/base/index.js
rename to test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/base/index.js
index 277b1dd..904d7d6 100644
--- a/test/vdl/expected-gen/testdata/base/index.js
+++ b/test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/base/index.js
@@ -2,10 +2,11 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// This file was auto-generated by the veyron vdl tool.
-var vdl = require('../../../../../src/vdl');
-var makeError = require('../../../../../src/verror/make-errors');
-var actions = require('../../../../../src/verror/actions');
+// This file was auto-generated by the vanadium vdl tool.
+var vdl = require('../../../../../../../../../../src/vdl');
+var makeError = require('../../../../../../../../../../src/verror/make-errors');
+var actions = require('../../../../../../../../../../src/verror/actions');
+var canonicalize = require('../../../../../../../../../../src/vdl/canonicalize');
 
 
 
@@ -26,8 +27,6 @@
 var _type15 = new vdl.Type();
 var _type16 = new vdl.Type();
 var _type17 = new vdl.Type();
-var _type18 = new vdl.Type();
-var _type19 = new vdl.Type();
 var _type2 = new vdl.Type();
 var _type3 = new vdl.Type();
 var _type4 = new vdl.Type();
@@ -64,80 +63,73 @@
 var _typeNestedArgs = new vdl.Type();
 var _typeScalars = new vdl.Type();
 var _typeScalarsArray = new vdl.Type();
-var _typeerror = new vdl.Type();
-_type1.kind = vdl.Kind.ENUM;
+_type1.kind = vdl.Kind.LIST;
 _type1.name = "";
-_type1.labels = ["NoRetry", "RetryConnection", "RetryRefetch", "RetryBackoff"];
-_type10.kind = vdl.Kind.MAP;
+_type1.elem = _typeScalars;
+_type10.kind = vdl.Kind.LIST;
 _type10.name = "";
-_type10.elem = _typeComposites;
-_type10.key = vdl.Types.STRING;
-_type11.kind = vdl.Kind.MAP;
+_type10.elem = _type8;
+_type11.kind = vdl.Kind.LIST;
 _type11.name = "";
-_type11.elem = _type12;
-_type11.key = _typeKeyScalars;
-_type12.kind = vdl.Kind.LIST;
+_type11.elem = vdl.Types.INT32;
+_type12.kind = vdl.Kind.SET;
 _type12.name = "";
-_type12.elem = _type10;
-_type13.kind = vdl.Kind.LIST;
+_type12.key = vdl.Types.INT32;
+_type13.kind = vdl.Kind.MAP;
 _type13.name = "";
-_type13.elem = vdl.Types.INT32;
-_type14.kind = vdl.Kind.SET;
+_type13.elem = vdl.Types.STRING;
+_type13.key = vdl.Types.INT32;
+_type14.kind = vdl.Kind.LIST;
 _type14.name = "";
-_type14.key = vdl.Types.INT32;
-_type15.kind = vdl.Kind.MAP;
+_type14.elem = vdl.Types.BYTE;
+_type15.kind = vdl.Kind.LIST;
 _type15.name = "";
 _type15.elem = vdl.Types.STRING;
-_type15.key = vdl.Types.INT32;
-_type16.kind = vdl.Kind.LIST;
+_type16.kind = vdl.Kind.SET;
 _type16.name = "";
-_type16.elem = vdl.Types.BYTE;
-_type17.kind = vdl.Kind.LIST;
+_type16.key = vdl.Types.STRING;
+_type17.kind = vdl.Kind.MAP;
 _type17.name = "";
-_type17.elem = vdl.Types.STRING;
-_type18.kind = vdl.Kind.SET;
-_type18.name = "";
-_type18.key = vdl.Types.STRING;
-_type19.kind = vdl.Kind.MAP;
-_type19.name = "";
-_type19.elem = vdl.Types.INT64;
-_type19.key = vdl.Types.STRING;
-_type2.kind = vdl.Kind.LIST;
+_type17.elem = vdl.Types.INT64;
+_type17.key = vdl.Types.STRING;
+_type2.kind = vdl.Kind.SET;
 _type2.name = "";
-_type2.elem = vdl.Types.ANY;
-_type3.kind = vdl.Kind.LIST;
+_type2.key = _typeKeyScalars;
+_type3.kind = vdl.Kind.MAP;
 _type3.name = "";
 _type3.elem = _typeScalars;
-_type4.kind = vdl.Kind.SET;
+_type3.key = vdl.Types.STRING;
+_type4.kind = vdl.Kind.MAP;
 _type4.name = "";
+_type4.elem = _type5;
 _type4.key = _typeKeyScalars;
-_type5.kind = vdl.Kind.MAP;
+_type5.kind = vdl.Kind.LIST;
 _type5.name = "";
-_type5.elem = _typeScalars;
-_type5.key = vdl.Types.STRING;
+_type5.elem = _type6;
 _type6.kind = vdl.Kind.MAP;
 _type6.name = "";
-_type6.elem = _type7;
-_type6.key = _typeKeyScalars;
+_type6.elem = vdl.Types.COMPLEX128;
+_type6.key = vdl.Types.STRING;
 _type7.kind = vdl.Kind.LIST;
 _type7.name = "";
-_type7.elem = _type8;
+_type7.elem = _typeComposites;
 _type8.kind = vdl.Kind.MAP;
 _type8.name = "";
-_type8.elem = vdl.Types.COMPLEX128;
+_type8.elem = _typeComposites;
 _type8.key = vdl.Types.STRING;
-_type9.kind = vdl.Kind.LIST;
+_type9.kind = vdl.Kind.MAP;
 _type9.name = "";
-_type9.elem = _typeComposites;
+_type9.elem = _type10;
+_type9.key = _typeKeyScalars;
 _typeArgs.kind = vdl.Kind.STRUCT;
 _typeArgs.name = "v.io/x/ref/lib/vdl/testdata/base.Args";
 _typeArgs.fields = [{name: "A", type: vdl.Types.INT32}, {name: "B", type: vdl.Types.INT32}];
 _typeCompComp.kind = vdl.Kind.STRUCT;
 _typeCompComp.name = "v.io/x/ref/lib/vdl/testdata/base.CompComp";
-_typeCompComp.fields = [{name: "A0", type: _typeComposites}, {name: "A1", type: _typeCompositesArray}, {name: "A2", type: _type9}, {name: "A3", type: _type10}, {name: "A4", type: _type11}];
+_typeCompComp.fields = [{name: "A0", type: _typeComposites}, {name: "A1", type: _typeCompositesArray}, {name: "A2", type: _type7}, {name: "A3", type: _type8}, {name: "A4", type: _type9}];
 _typeComposites.kind = vdl.Kind.STRUCT;
 _typeComposites.name = "v.io/x/ref/lib/vdl/testdata/base.Composites";
-_typeComposites.fields = [{name: "A0", type: _typeScalars}, {name: "A1", type: _typeScalarsArray}, {name: "A2", type: _type3}, {name: "A3", type: _type4}, {name: "A4", type: _type5}, {name: "A5", type: _type6}];
+_typeComposites.fields = [{name: "A0", type: _typeScalars}, {name: "A1", type: _typeScalarsArray}, {name: "A2", type: _type1}, {name: "A3", type: _type2}, {name: "A4", type: _type3}, {name: "A5", type: _type4}];
 _typeCompositesArray.kind = vdl.Kind.ARRAY;
 _typeCompositesArray.name = "v.io/x/ref/lib/vdl/testdata/base.CompositesArray";
 _typeCompositesArray.len = 2;
@@ -204,9 +196,6 @@
 _typeScalarsArray.name = "v.io/x/ref/lib/vdl/testdata/base.ScalarsArray";
 _typeScalarsArray.len = 2;
 _typeScalarsArray.elem = _typeScalars;
-_typeerror.kind = vdl.Kind.STRUCT;
-_typeerror.name = "error";
-_typeerror.fields = [{name: "Id", type: vdl.Types.STRING}, {name: "RetryCode", type: _type1}, {name: "Msg", type: vdl.Types.STRING}, {name: "ParamList", type: _type2}];
 _type1.freeze();
 _type10.freeze();
 _type11.freeze();
@@ -216,8 +205,6 @@
 _type15.freeze();
 _type16.freeze();
 _type17.freeze();
-_type18.freeze();
-_type19.freeze();
 _type2.freeze();
 _type3.freeze();
 _type4.freeze();
@@ -254,7 +241,6 @@
 _typeNestedArgs.freeze();
 _typeScalars.freeze();
 _typeScalarsArray.freeze();
-_typeerror.freeze();
 module.exports.Args = (vdl.Registry.lookupOrCreateConstructor(_typeArgs));
 module.exports.CompComp = (vdl.Registry.lookupOrCreateConstructor(_typeCompComp));
 module.exports.Composites = (vdl.Registry.lookupOrCreateConstructor(_typeComposites));
@@ -265,7 +251,11 @@
 module.exports.NamedByte = (vdl.Registry.lookupOrCreateConstructor(_typeNamedByte));
 module.exports.NamedComplex128 = (vdl.Registry.lookupOrCreateConstructor(_typeNamedComplex128));
 module.exports.NamedComplex64 = (vdl.Registry.lookupOrCreateConstructor(_typeNamedComplex64));
-module.exports.NamedEnum = (vdl.Registry.lookupOrCreateConstructor(_typeNamedEnum));
+module.exports.NamedEnum = {
+  A: canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(_typeNamedEnum))('A', true), _typeNamedEnum),
+  B: canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(_typeNamedEnum))('B', true), _typeNamedEnum),
+  C: canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(_typeNamedEnum))('C', true), _typeNamedEnum),
+};
 module.exports.NamedFloat32 = (vdl.Registry.lookupOrCreateConstructor(_typeNamedFloat32));
 module.exports.NamedFloat64 = (vdl.Registry.lookupOrCreateConstructor(_typeNamedFloat64));
 module.exports.NamedInt16 = (vdl.Registry.lookupOrCreateConstructor(_typeNamedInt16));
@@ -283,74 +273,73 @@
 module.exports.NestedArgs = (vdl.Registry.lookupOrCreateConstructor(_typeNestedArgs));
 module.exports.Scalars = (vdl.Registry.lookupOrCreateConstructor(_typeScalars));
 module.exports.ScalarsArray = (vdl.Registry.lookupOrCreateConstructor(_typeScalarsArray));
-module.exports.error = (vdl.Registry.lookupOrCreateConstructor(_typeerror));
 
 
 
 
 // Consts:
 
-  module.exports.Cbool = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.BOOL))(true);
+  module.exports.Cbool = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.BOOL))(true, true), vdl.Types.BOOL);
 
-  module.exports.Cbyte = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.BYTE))(1);
+  module.exports.Cbyte = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.BYTE))(1, true), vdl.Types.BYTE);
 
-  module.exports.Cint32 = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT32))(2);
+  module.exports.Cint32 = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT32))(2, true), vdl.Types.INT32);
 
-  module.exports.Cint64 = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT64))(new vdl.BigInt(1, new Uint8Array([0x3])));
+  module.exports.Cint64 = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT64))(new vdl.BigInt(1, new Uint8Array([0x3])), true), vdl.Types.INT64);
 
-  module.exports.Cuint32 = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT32))(4);
+  module.exports.Cuint32 = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT32))(4, true), vdl.Types.UINT32);
 
-  module.exports.Cuint64 = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x5])));
+  module.exports.Cuint64 = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x5])), true), vdl.Types.UINT64);
 
-  module.exports.Cfloat32 = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.FLOAT32))(6);
+  module.exports.Cfloat32 = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.FLOAT32))(6, true), vdl.Types.FLOAT32);
 
-  module.exports.Cfloat64 = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.FLOAT64))(7);
+  module.exports.Cfloat64 = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.FLOAT64))(7, true), vdl.Types.FLOAT64);
 
-  module.exports.CNamedBool = new (vdl.Registry.lookupOrCreateConstructor(_typeNamedBool))(true);
+  module.exports.CNamedBool = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(_typeNamedBool))(true, true), _typeNamedBool);
 
-  module.exports.CNamedStruct = new (vdl.Registry.lookupOrCreateConstructor(_typeNamedStruct))({
+  module.exports.CNamedStruct = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(_typeNamedStruct))({
   'a': true,
   'b': "test",
   'c': 0,
-});
+}, true), _typeNamedStruct);
 
-  module.exports.Ccomplex64 = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.COMPLEX64))(new vdl.Complex(8.000000, 9.000000));
+  module.exports.Ccomplex64 = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.COMPLEX64))(new vdl.Complex(8.000000, 9.000000), true), vdl.Types.COMPLEX64);
 
-  module.exports.Ccomplex128 = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.COMPLEX128))(new vdl.Complex(10.000000, 11.000000));
+  module.exports.Ccomplex128 = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.COMPLEX128))(new vdl.Complex(10.000000, 11.000000), true), vdl.Types.COMPLEX128);
 
-  module.exports.Cstring = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("foo");
+  module.exports.Cstring = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("foo", true), vdl.Types.STRING);
 
-  module.exports.Cenum = new (vdl.Registry.lookupOrCreateConstructor(_typeNamedEnum))('A');
+  module.exports.Cenum = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(_typeNamedEnum))('A', true), _typeNamedEnum);
 
-  module.exports.Cunion = new (vdl.Registry.lookupOrCreateConstructor(_typeNamedUnion))({ "a": true });
+  module.exports.Cunion = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(_typeNamedUnion))({ "a": true }, true), _typeNamedUnion);
 
-  module.exports.Carray = new (vdl.Registry.lookupOrCreateConstructor(_typeNamedArray))([
+  module.exports.Carray = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(_typeNamedArray))([
 true,
 false,
-]);
+], true), _typeNamedArray);
 
-  module.exports.Clist = new (vdl.Registry.lookupOrCreateConstructor(_type13))([
+  module.exports.Clist = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(_type11))([
 1,
 2,
 3,
-]);
+], true), _type11);
 
-  module.exports.Cset = new (vdl.Registry.lookupOrCreateConstructor(_type14))(new Set([
-  1,
-  2,
-  3, ]));
+  module.exports.Cset = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(_type12))(new Set([
+  1, 
+  2, 
+  3, ]), true), _type12);
 
-  module.exports.cmap = new (vdl.Registry.lookupOrCreateConstructor(_type15))(new Map([
+  module.exports.cmap = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(_type13))(new Map([
   [1, "A"],
   [2, "B"],
-  [3, "C"]]));
+  [3, "C"]]), true), _type13);
 
-  module.exports.Cargs = new (vdl.Registry.lookupOrCreateConstructor(_typeArgs))({
+  module.exports.Cargs = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(_typeArgs))({
   'a': 1,
   'b': 2,
-});
+}, true), _typeArgs);
 
-  module.exports.CScalars = new (vdl.Registry.lookupOrCreateConstructor(_typeScalars))({
+  module.exports.CScalars = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(_typeScalars))({
   'a0': true,
   'a1': 1,
   'a2': 2,
@@ -365,7 +354,7 @@
   'a11': new vdl.Complex(11.000000, 0.000000),
   'a12': "abc",
   'a13': null,
-  'a14': new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.BOOL))(false),
+  'a14': canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.BOOL))(false, true), vdl.Types.BOOL),
   'a15': vdl.Types.BOOL,
   'b0': true,
   'b1': 1,
@@ -382,53 +371,53 @@
   'b12': "abc",
   'b13': 'B',
   'b14': { "c": 123 },
-});
+}, true), _typeScalars);
 
-  module.exports.True = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.BOOL))(true);
+  module.exports.True = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.BOOL))(true, true), vdl.Types.BOOL);
 
-  module.exports.Foo = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("foo");
+  module.exports.Foo = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("foo", true), vdl.Types.STRING);
 
-  module.exports.Five = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT32))(5);
+  module.exports.Five = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT32))(5, true), vdl.Types.INT32);
 
-  module.exports.Six = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x6])));
+  module.exports.Six = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x6])), true), vdl.Types.UINT64);
 
-  module.exports.SixSquared = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x24])));
+  module.exports.SixSquared = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x24])), true), vdl.Types.UINT64);
 
-  module.exports.FiveSquared = new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT32))(25);
+  module.exports.FiveSquared = canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.INT32))(25, true), vdl.Types.INT32);
 
-  module.exports.CTObool = vdl.Types.BOOL;
+  module.exports.CTypeObject_bool = vdl.Types.BOOL;
 
-  module.exports.CTOstring = vdl.Types.STRING;
+  module.exports.CTypeObject_string = vdl.Types.STRING;
 
-  module.exports.CTObytes = _type16;
+  module.exports.CTypeObject_bytes = _type14;
 
-  module.exports.CTObyte = vdl.Types.BYTE;
+  module.exports.CTypeObject_byte = vdl.Types.BYTE;
 
-  module.exports.CTOuint16 = vdl.Types.UINT16;
+  module.exports.CTypeObject_uint16 = vdl.Types.UINT16;
 
-  module.exports.CTOint16 = vdl.Types.INT16;
+  module.exports.CTypeObject_int16 = vdl.Types.INT16;
 
-  module.exports.CTOfloat32 = vdl.Types.FLOAT32;
+  module.exports.CTypeObject_float32 = vdl.Types.FLOAT32;
 
-  module.exports.CTOcomplex64 = vdl.Types.COMPLEX64;
+  module.exports.CTypeObject_complex64 = vdl.Types.COMPLEX64;
 
-  module.exports.CTOenum = _typeNamedEnum;
+  module.exports.CTypeObject_enum = _typeNamedEnum;
 
-  module.exports.CTOArray = _typeNamedArray;
+  module.exports.CTypeObject_Array = _typeNamedArray;
 
-  module.exports.CTOList = _type17;
+  module.exports.CTypeObject_List = _type15;
 
-  module.exports.CTOSet = _type18;
+  module.exports.CTypeObject_Set = _type16;
 
-  module.exports.CTOMap = _type19;
+  module.exports.CTypeObject_Map = _type17;
 
-  module.exports.CTOStruct = _typeScalars;
+  module.exports.CTypeObject_Struct = _typeScalars;
 
-  module.exports.CTOUnion = _typeNamedUnion;
+  module.exports.CTypeObject_Union = _typeNamedUnion;
 
-  module.exports.CTOTypeObject = vdl.Types.TYPEOBJECT;
+  module.exports.CTypeObject_TypeObject = vdl.Types.TYPEOBJECT;
 
-  module.exports.CTOAny = vdl.Types.ANY;
+  module.exports.CTypeObject_Any = vdl.Types.ANY;
 
 
 
@@ -476,42 +465,42 @@
 
 // Services:
 
-
-
+  
+    
 function ServiceA(){}
-module.exports.ServiceA = ServiceA
+module.exports.ServiceA = ServiceA;
 
-
-
-ServiceA.prototype.methodA1 = function(ctx) {
+    
+      
+ServiceA.prototype.methodA1 = function(ctx, serverCall) {
   throw new Error('Method MethodA1 not implemented');
 };
-
-
-ServiceA.prototype.methodA2 = function(ctx, a, b) {
+    
+      
+ServiceA.prototype.methodA2 = function(ctx, serverCall, a, b) {
   throw new Error('Method MethodA2 not implemented');
 };
-
-
-ServiceA.prototype.methodA3 = function(ctx, a) {
+    
+      
+ServiceA.prototype.methodA3 = function(ctx, serverCall, a) {
   throw new Error('Method MethodA3 not implemented');
 };
-
-
-ServiceA.prototype.methodA4 = function(ctx, a) {
+    
+      
+ServiceA.prototype.methodA4 = function(ctx, serverCall, a) {
   throw new Error('Method MethodA4 not implemented');
 };
+     
 
-
-
+    
 ServiceA.prototype._serviceDescription = {
   name: 'ServiceA',
   pkgPath: 'v.io/x/ref/lib/vdl/testdata/base',
   doc: "",
   embeds: [],
   methods: [
-
-
+    
+      
     {
     name: 'MethodA1',
     doc: "",
@@ -521,8 +510,8 @@
     outStream: null,
     tags: []
   },
-
-
+    
+      
     {
     name: 'MethodA2',
     doc: "",
@@ -547,8 +536,8 @@
     outStream: null,
     tags: []
   },
-
-
+    
+      
     {
     name: 'MethodA3',
     doc: "",
@@ -570,10 +559,10 @@
       doc: '',
       type: _typeScalars
     },
-    tags: [new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("tag"), new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x6]))), ]
+    tags: [canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("tag", true), vdl.Types.STRING), canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x6])), true), vdl.Types.UINT64), ]
   },
-
-
+    
+      
     {
     name: 'MethodA4',
     doc: "",
@@ -596,43 +585,43 @@
     },
     tags: []
   },
-
+     
   ]
 };
 
-
-
+  
+    
 function ServiceB(){}
-module.exports.ServiceB = ServiceB
+module.exports.ServiceB = ServiceB;
 
-
-
-ServiceB.prototype.methodB1 = function(ctx, a, b) {
+    
+      
+ServiceB.prototype.methodB1 = function(ctx, serverCall, a, b) {
   throw new Error('Method MethodB1 not implemented');
 };
-
-
-ServiceB.prototype.methodA1 = function(ctx) {
+    
+      
+ServiceB.prototype.methodA1 = function(ctx, serverCall) {
   throw new Error('Method MethodA1 not implemented');
 };
-
-
-ServiceB.prototype.methodA2 = function(ctx, a, b) {
+    
+      
+ServiceB.prototype.methodA2 = function(ctx, serverCall, a, b) {
   throw new Error('Method MethodA2 not implemented');
 };
-
-
-ServiceB.prototype.methodA3 = function(ctx, a) {
+    
+      
+ServiceB.prototype.methodA3 = function(ctx, serverCall, a) {
   throw new Error('Method MethodA3 not implemented');
 };
-
-
-ServiceB.prototype.methodA4 = function(ctx, a) {
+    
+      
+ServiceB.prototype.methodA4 = function(ctx, serverCall, a) {
   throw new Error('Method MethodA4 not implemented');
 };
+     
 
-
-
+    
 ServiceB.prototype._serviceDescription = {
   name: 'ServiceB',
   pkgPath: 'v.io/x/ref/lib/vdl/testdata/base',
@@ -644,8 +633,8 @@
     },
     ],
   methods: [
-
-
+    
+      
     {
     name: 'MethodB1',
     doc: "",
@@ -670,8 +659,8 @@
     outStream: null,
     tags: []
   },
-
-
+    
+      
     {
     name: 'MethodA1',
     doc: "",
@@ -681,8 +670,8 @@
     outStream: null,
     tags: []
   },
-
-
+    
+      
     {
     name: 'MethodA2',
     doc: "",
@@ -707,8 +696,8 @@
     outStream: null,
     tags: []
   },
-
-
+    
+      
     {
     name: 'MethodA3',
     doc: "",
@@ -730,10 +719,10 @@
       doc: '',
       type: _typeScalars
     },
-    tags: [new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("tag"), new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x6]))), ]
+    tags: [canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.STRING))("tag", true), vdl.Types.STRING), canonicalize.reduce(new (vdl.Registry.lookupOrCreateConstructor(vdl.Types.UINT64))(new vdl.BigInt(1, new Uint8Array([0x6])), true), vdl.Types.UINT64), ]
   },
-
-
+    
+      
     {
     name: 'MethodA4',
     doc: "",
@@ -756,9 +745,11 @@
     },
     tags: []
   },
-
+     
   ]
 };
 
+   
+ 
 
 
diff --git a/test/vdl/expected-gen/testdata/nativedep/index.js b/test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/nativedep/index.js
similarity index 87%
rename from test/vdl/expected-gen/testdata/nativedep/index.js
rename to test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/nativedep/index.js
index 701cc05..0776af4 100644
--- a/test/vdl/expected-gen/testdata/nativedep/index.js
+++ b/test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/nativedep/index.js
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// This file was auto-generated by the veyron vdl tool.
-var vdl = require('../../../../../src/vdl');
+// This file was auto-generated by the vanadium vdl tool.
+var vdl = require('../../../../../../../../../../src/vdl');
 
 
 
@@ -38,3 +38,5 @@
 
    
  
+
+
diff --git a/test/vdl/expected-gen/testdata/nativedep2/index.js b/test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/nativedep2/index.js
similarity index 80%
rename from test/vdl/expected-gen/testdata/nativedep2/index.js
rename to test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/nativedep2/index.js
index d7960a7..95ac328 100644
--- a/test/vdl/expected-gen/testdata/nativedep2/index.js
+++ b/test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/nativedep2/index.js
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// This file was auto-generated by the veyron vdl tool.
-var vdl = require('../../../../../src/vdl');
+// This file was auto-generated by the vanadium vdl tool.
+var vdl = require('../../../../../../../../../../src/vdl');
 
 
 
@@ -36,3 +36,5 @@
 
    
  
+
+
diff --git a/test/vdl/expected-gen/testdata/nativetest/index.js b/test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/nativetest/index.js
similarity index 94%
rename from test/vdl/expected-gen/testdata/nativetest/index.js
rename to test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/nativetest/index.js
index d01134b..796ae37 100644
--- a/test/vdl/expected-gen/testdata/nativetest/index.js
+++ b/test/vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/nativetest/index.js
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// This file was auto-generated by the veyron vdl tool.
-var vdl = require('../../../../../src/vdl');
+// This file was auto-generated by the vanadium vdl tool.
+var vdl = require('../../../../../../../../../../src/vdl');
 
 
 
@@ -69,3 +69,5 @@
 
    
  
+
+
diff --git a/test/vom/test-vdl-arith.js b/test/vom/test-vdl-arith.js
index 394b34f..0f22713 100644
--- a/test/vom/test-vdl-arith.js
+++ b/test/vom/test-vdl-arith.js
@@ -75,13 +75,14 @@
 });
 
 var expectedAdvancedMathDescription =
-  require('../vdl/expected-gen/testdata/arith').AdvancedMath.
+  require('../vdl/expected-gen/v.io/x/ref/lib/vdl/testdata/arith').AdvancedMath.
   prototype._serviceDescription;
 
 test('correct service description', function(assert) {
   var arith = require('../vdl-out/v.io/x/ref/lib/vdl/testdata/arith');
   var description = (new arith.AdvancedMath())._serviceDescription;
   assert.deepEqual(description, expectedAdvancedMathDescription,
-    'service description matches expectation');
+    'service description matches expectation. (To update the expected ' +
+    'service description, run `make gen-vdl-test-expected`.)');
   assert.end();
 });