Skip to content

Conversation

@bvisness
Copy link
Collaborator

@bvisness bvisness commented Dec 4, 2025

Per #7, we are adding another compact encoding that deduplicates externtypes as well as module names. This PR updates the formal spec.

The way I'm handling identifiers in the text format seems obviously wrong somehow, but the entire way that the compact encoding is handled in the import section is also wrong, so maybe it's ok for now and we can fix up the fiddly details before phase 4.

@bvisness
Copy link
Collaborator Author

bvisness commented Dec 4, 2025

What in the world do you have to do to pass CI these days? I ran make test and make testpromote repeatedly until make test succeeded, and yet make test is apparently failing.

@rossberg
Copy link
Member

rossberg commented Dec 4, 2025

The dependencies for the test target are rather complicated and unfortunately incomplete somewhere. Before pushing to the repo, I recommend starting the test run from a make clean if you want to make sure it's not missing anything.

Copy link
Member

@rossberg rossberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec is technically fine as is modulo cross-reference nits. However, there are two things I find problematic about the new text format extension:

  • The relative order of externtype and item names is inconsistent with other forms.
  • The bound identifiers are not preceded by a corresponding keyword that declares their namespace. That is completely at odds with the rest of the text format.

For the former, I would suggest changing the order, at least in the text format. For the latter, I would simply remove the ability to bind identifiers in the new short hand. That would be consistent with existing forms like param and local, where you can't use the multi-form if you want to bind names (e.g., (local i32 i32) vs (local $x i32) (local $y i32)).

Abbreviations
.............

Multiple imports with the same ${:nm_1} may be declared together:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Multiple imports with the same ${:nm_1} may be declared together:
Multiple imports with the same :ref:`name <syntax-name>` ${:nm_1} may be declared together:

$${grammar: Timports_/abbrev}
$${grammar: Timports_/abbrev-compact1}

Multiple imports with the same ${:nm_1} and ${:xt} may also be declared together, in which case identifiers may be placed on individual items instead of the ${:externtype}:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Multiple imports with the same ${:nm_1} and ${:xt} may also be declared together, in which case identifiers may be placed on individual items instead of the ${:externtype}:
Multiple imports with the same name ${:nm_1} and :ref:`external type <syntax-externtype>` ${:xt} may also be declared together, in which case identifiers may be placed on individual items instead of the external type:

@bvisness
Copy link
Collaborator Author

bvisness commented Dec 5, 2025

I'm not sure how to reasonably change the order of item name and externtype for the new text format extension. Like, I guess I could do (import "mod" (item "foo") (item "bar") externtype), but that seems quite strange to me given that the point is to declare many items with the same type and a parser would not have any context (until the very end) to distinguish it from (import "mod" (item "foo" externtype1) (item "bar" externtype2)). To me it makes perfect sense to declare the common type up front in some way.

Ideas for your consideration:

;; other existing forms of import for comparison
(import "mod" "foo" externtype)
(import "mod" (item "foo" externtype) (item "bar" externtype))

;; new import form deduplicating externtype
(import "mod" (type externtype (item "foo") (item "bar")) ;; option 1, currently proposed
(import "mod" (type externtype "foo" "bar")) ;; option 2
(import "mod" (type externtype) "foo" "bar") ;; option 3
(import "mod" (type externtype) (item "foo") (item "bar")) ;; option 4

If dropping the ability to add identifiers, then I think I am partial to option 2.

I'm open to suggestions for other text encodings that would possibly swap the order of items and types as you say, but I just can't come up with one that makes sense.

@rossberg
Copy link
Member

rossberg commented Dec 8, 2025

The variations

(import "mod" "foo" externtype)
(import "mod" (item "foo") (item "bar") externtype)
(import "mod" (item "foo" externtype) (item "bar" externtype))

look perfectly consistent to me. I don't think there is a parsing issue between the second and third, it should be LALR(1) just fine, and can easily be transformed to LL(1). The only minor thing is that, in an LL-parser, the list of names has to be buffered before building the list of imports, but that is totally fine for a text parser (less so for the binary format), and there are much worse things of that sort going on elsewhere in the text format.

@bvisness bvisness merged commit 340c725 into main Dec 8, 2025
12 checks passed
@bvisness bvisness deleted the externtype-encoding branch December 8, 2025 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants