Repository navigation
wasmprinter: fix outer aliases that print unparsable or shadowed identifiers - #2795
Conversation
Outer aliases now print the same identifier as the header of the component they refer to, or its count when a scope in between has the same identifier. They printed the target's name with its `(@name ...)` annotation, which only parses where the component is defined; they used a nested component's own name from its `component-name` section, while its header uses the name its parent gives it; and they printed identifiers that an inner scope shadows, such as the synthetic `$"#component0 "` of both a component and its first nested component, so the printed text didn't parse or referred to the wrong scope. (component (@name "") (type u8) (alias outer 0 0 (type))) printed `(alias outer $"#component0 " (@name "") 0 (type))`.
6f556a1 to
a949791
Compare
alexcrichton
left a comment
There was a problem hiding this comment.
I'm a bit confused by this PR - the title says that this prints the identifier outer aliases refer to, but it looks like that was already done since outer.name.as_ref() was already inspected. Is the change in this PR primarily to handle the shadowing problem? Or handle the case that outer.name wasn't set by looking at the component name sections?
| // Outer aliases refer to a nested component by the name | ||
| // printed above, which its parent gives it. | ||
| #[cfg(feature = "component-model")] | ||
| if let [.., parent, state] = &mut states[..] { | ||
| if state.encoding == Encoding::Component { | ||
| state.name = parent | ||
| .component | ||
| .component_names | ||
| .index_to_name | ||
| .get(&parent.component.components) | ||
| .cloned(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Could this be part of read_names since that seems most readily applicable to what's going on here.
For example this'd go well inside register_component_names perhaps
There was a problem hiding this comment.
I've moved this into read_names. It can't go in register_component_names, because that only runs when the nested component has its own component-name section, and the parent's name needs to apply either way.
|
Oh, also, this should likely have some tests one way or another. |
Sets a nested component's name from its parent's name for it in read_names, and adds a test for each case where an outer alias printed text that didn't parse or referred to the wrong component.
|
This fixes three separate problems, not only the shadowing. The old code did print
I've added |
Outer aliases now print the same identifier as the header of the component they refer to, or the alias's count when a scope in between has the same identifier. In three cases, the printed text of a valid component didn't parse or referred to the wrong scope:
(@name ...)annotation, which only parses where the component is defined.(component (@name "") (type u8) (alias outer 0 0 (type)))printed(alias outer $"#component0 " (@name "") 0 (type)).component-namesection, so it could refer to an identifier that nothing defines.$"#component0 ", for example.These were found by the grammar-based component fuzzer in #2796.