From 23caab4774864b54b78a99e422f767a526947899 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 12 Oct 2022 08:05:13 -0700 Subject: [PATCH] Remove some trailing whitespace in printed components Currently (component (type (instance)) (type (component)) (core instance) ) prints the `(type` and `(core instance` declarations with a trailing space, so this commit removes the trailing whitespace there with a minor refactor. --- .../tests/compositions/complex-import/composed.wat | 10 +++++----- crates/wasm-compose/tests/compositions/complex/b.wat | 6 +++--- .../tests/compositions/complex/composed.wat | 8 ++++---- .../tests/compositions/merged-import/composed.wat | 8 ++++---- crates/wasmprinter/src/lib.rs | 5 +++-- 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/crates/wasm-compose/tests/compositions/complex-import/composed.wat b/crates/wasm-compose/tests/compositions/complex-import/composed.wat index ef0bb42544..fb9c8cdb9c 100644 --- a/crates/wasm-compose/tests/compositions/complex-import/composed.wat +++ b/crates/wasm-compose/tests/compositions/complex-import/composed.wat @@ -1,5 +1,5 @@ (component - (type (;0;) + (type (;0;) (component (type (;0;) (record (field "a" s8) (field "b" u8) (field "c" s16) (field "d" u16) (field "e" s32) (field "f" u32) (field "g" s64) (field "h" u64) (field "i" float32) (field "j" float64) (field "k" bool) (field "l" string))) (export "record1" (type (eq 0))) @@ -61,9 +61,9 @@ ) (import "a" (component (;0;) (type 0))) (instance (;0;) (instantiate 0)) - (type (;1;) + (type (;1;) (component - (type (;0;) + (type (;0;) (instance (type (;0;) (func)) (export "a" (func (type 0))) @@ -124,7 +124,7 @@ ) ) (import "a" (instance (type 0))) - (type (;1;) + (type (;1;) (instance (type (;0;) (func (param "x" string) (result string))) (export "m" (func (type 0))) @@ -143,7 +143,7 @@ ) ) (component (;2;) - (type (;0;) + (type (;0;) (instance (type (;0;) (func (param "x" string) (result string))) (export "m" (func (type 0))) diff --git a/crates/wasm-compose/tests/compositions/complex/b.wat b/crates/wasm-compose/tests/compositions/complex/b.wat index 9c69e8fae1..0dcc823e04 100644 --- a/crates/wasm-compose/tests/compositions/complex/b.wat +++ b/crates/wasm-compose/tests/compositions/complex/b.wat @@ -29,7 +29,7 @@ (type (func (param "x" 26))) (type (result 13 (error string))) (type (func (result 28))) - (type + (type (instance (alias outer 1 0 (type)) (export "a" (func (type 0))) @@ -256,7 +256,7 @@ (core func (canon lower (func 11))) (core func (canon lower (func 12))) (core func (canon lower (func 13))) - (core instance + (core instance (export "m" (func 0)) (export "n" (func 1)) (export "o" (func 2)) @@ -300,7 +300,7 @@ (core func (canon lower (func 18) (memory 0) (realloc 21) string-encoding=utf8)) (core func (canon lower (func 19) (memory 0) (realloc 21) string-encoding=utf8)) (core func (canon lower (func 20) (memory 0) (realloc 21) string-encoding=utf8)) - (core instance + (core instance (export "$imports" (table 0)) (export "0" (func 22)) (export "1" (func 23)) diff --git a/crates/wasm-compose/tests/compositions/complex/composed.wat b/crates/wasm-compose/tests/compositions/complex/composed.wat index d5eec4189e..df0a885b0a 100644 --- a/crates/wasm-compose/tests/compositions/complex/composed.wat +++ b/crates/wasm-compose/tests/compositions/complex/composed.wat @@ -238,7 +238,7 @@ (type (;27;) (func (param "x" 26))) (type (;28;) (result 13 (error string))) (type (;29;) (func (result 28))) - (type (;30;) + (type (;30;) (instance (alias outer 1 0 (type (;0;))) (export "a" (func (type 0))) @@ -472,7 +472,7 @@ (core func (;18;) (canon lower (func 11))) (core func (;19;) (canon lower (func 12))) (core func (;20;) (canon lower (func 13))) - (core instance (;1;) + (core instance (;1;) (export "m" (func 0)) (export "n" (func 1)) (export "o" (func 2)) @@ -516,7 +516,7 @@ (core func (;26;) (canon lower (func 18) (memory 0) (realloc 21) string-encoding=utf8)) (core func (;27;) (canon lower (func 19) (memory 0) (realloc 21) string-encoding=utf8)) (core func (;28;) (canon lower (func 20) (memory 0) (realloc 21) string-encoding=utf8)) - (core instance (;3;) + (core instance (;3;) (export "$imports" (table 0)) (export "0" (func 22)) (export "1" (func 23)) @@ -546,7 +546,7 @@ ) ) (component (;2;) - (type (;0;) + (type (;0;) (instance (type (;0;) (func (param "x" string) (result string))) (export "m" (func (type 0))) diff --git a/crates/wasm-compose/tests/compositions/merged-import/composed.wat b/crates/wasm-compose/tests/compositions/merged-import/composed.wat index 52c5a8310d..4a274b3e32 100644 --- a/crates/wasm-compose/tests/compositions/merged-import/composed.wat +++ b/crates/wasm-compose/tests/compositions/merged-import/composed.wat @@ -1,5 +1,5 @@ (component - (type (;0;) + (type (;0;) (instance (type (;0;) (func)) (export "b" (func (type 0))) @@ -11,7 +11,7 @@ ) (import "a" (instance (;0;) (type 0))) (component (;0;) - (type (;0;) + (type (;0;) (instance (type (;0;) (func (param "x" string))) (export "a" (func (type 0))) @@ -26,7 +26,7 @@ ) ) (component (;1;) - (type (;0;) + (type (;0;) (instance (type (;0;) (func)) (export "b" (func (type 0))) @@ -35,7 +35,7 @@ ) ) (import "a" (instance (;0;) (type 0))) - (type (;1;) + (type (;1;) (instance) ) (import "b" (instance (;1;) (type 1))) diff --git a/crates/wasmprinter/src/lib.rs b/crates/wasmprinter/src/lib.rs index 1860f7141b..d774c2f2b7 100644 --- a/crates/wasmprinter/src/lib.rs +++ b/crates/wasmprinter/src/lib.rs @@ -1660,12 +1660,13 @@ impl Printer { let state = states.last_mut().unwrap(); self.print_name(&state.component.type_names, state.component.types)?; } - self.result.push(' '); match ty { ComponentType::Defined(ty) => { + self.result.push(' '); self.print_defined_type(states.last_mut().unwrap(), &ty)?; } ComponentType::Func(ty) => { + self.result.push(' '); self.print_component_func_type(states.last_mut().unwrap(), &ty)?; } ComponentType::Component(decls) => { @@ -1961,9 +1962,9 @@ impl Printer { self.newline(offset); self.start_group("core instance "); self.print_name(&state.core.instance_names, state.core.instances)?; - self.result.push(' '); match instance { Instance::Instantiate { module_index, args } => { + self.result.push(' '); self.start_group("instantiate "); self.print_idx(&state.core.module_names, module_index)?; for arg in args.iter() {