Skip to content

Where to place the externtype in the text format? #11

@bvisness

Description

@bvisness

Currently (as of #10) the text format for the compact import encoding looks like the following:

(import "foo" "bar" (global i32))
(import "foo" (item "bar" (global i32)) (item "baz" (global i32))
(import "foo" (item "bar") (item "baz") (global i32))

This seems nice and consistent, with a consistent order of module name, item name, externtype. However, the ergonomics of the latter are disastrous when looking at an actual module:

  (import "'"
    (item "null")
    (item ", ")
    (item "}")
    (item "{")
    (item "true")
    (item "")
    (item "false")
    (item ")")
    (item "ATOMIC")
    (item ",")
    (item "]")
    (item "\u{22}")
    (item ":")
    ;; ... 12,900 lines later...
    (global (ref extern))
  )

A human reader will have no idea what type each import item is until they find the very bottom of the import declaration, which can be extremely far away from the module name. This is very annoying. It really seems to me that both the name and type ought to be declared up front, so that the reader does not have to jump around.

Furthermore, the current syntax makes parsing quite cumbersome, since parsers must buffer up all the item names that appear before the end of the declaration, where hopefully we will find a type. It would be far more natural to declare the type up front so that each import item can be processed as it is parsed.

Other formats we could use that would be easier to read:

(import "mod" (global i32) (item "foo") (item "bar"))
(import "mod" (type (global i32) (item "foo") (item "bar")))
(import "mod" (type (global i32)) (item "foo") (item "bar"))

Would one of these be preferable to what we currently have?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions