WebAssembly / annotations

Proposal for Custom Annotation Syntax in the Text Format
https://WebAssembly.github.io/annotations/
Other
19 stars 10 forks source link

Specify where the annotation anchors to #2

Closed yurydelendik closed 2 years ago

yurydelendik commented 6 years ago

We probably need to specify exact location where annotation attached to, e.g. is there a difference between these two constructs: (local $var1 i32 (@name "i")) and (local $var1 (@name "i") i32). Does the (@name ...) annotation attached to the (local... ) in both cases?

The same applicable to operators in functions and init expressions, e.g.:

(func $func1 (result i32)
  nop
  (@location "foo.c" 10 12) (; does it annotate nop or unreachable? ;)
  unreachable
  i32.const (@symbol "static_array.ptr")1024 (; can we annotate operands? ;)
)
carlsmith commented 3 years ago

It would read most naturally if annotations that are on their own line were prefixes, while inline annotations (including those on the end of a line) were suffixes. That's basically how we read comments. It would also introduce significant whitespace, so it will have to be one or the other in practice.

Prefix

If the annotation was a prefix, there'd be this case, where anchoring to the i64.instruction would be counter-intuitive, so prefix-based annotations would ideally never appear on the end of a line:

i32.instruction (@a "anchor to the i64.instruction")
i64.instruction

However, in these cases, it looks fine:

(@a "anchor to the i32.instruction") i32.instruction
(@b "anchor to the i64.instruction")
i64.instruction

Suffix

If annotations were suffixes, this would make perfect sense:

i32.instruction (@a "anchor to the i32.instruction")
i64.instruction

However, the following example would be counter-intuitive (as it anchors to the i32.instruction still), but avoiding doing this would be less of a loss for readability than not being able to annotate at the end of the line:

i32.instruction
(@a "anchor to the i32.instruction") i64.instruction

This is now a problem though:

i32.instruction
(@a "anchor to the i32.instruction")
i64.instruction

Summary

If the way we read comments applies to annotations too, you have to pick between, this:

i32.instruction (@a "anchor to the i64.instruction")
i64.instruction

Or this:

i32.instruction
(@a "anchor to the i32.instruction")
i64.instruction
rossberg commented 3 years ago

As far as the Wasm spec itself is concerned, annotations are not "attached" anywhere. This is intentional. It is completely up to a custom interpretation/definition of a specific annotation to define their individual meaning, including the meaning of their placement. We can't predict all possible use cases, so it would be counter-productive to prescribe any form of interpretation, in the same way we don't do that for custom sections in the binary format.

carlsmith commented 3 years ago

@rossberg - Ah. That makes sense.