-
Notifications
You must be signed in to change notification settings - Fork 13
Module types need their own index spaces #21
Comments
Ah, good point. So then to handle bullets 1 and 2, is the idea to treat module types analogous to nested module definitions? viz.:
|
Yes, that's the idea. There would be other ways of doing it, but this seems the most consistent. |
Fixed with #26 |
Thinking about this issue again from the fresh perspective of rebasing this proposal as a new layered spec, I wonder if the rules above are unnecessarily restrictive and verbose. In particular, what if index space validation rules worked like this:
This seems equivalent to what you could express by eagerly outer-aliasing everything with the net effect being less outer-alias annotation burden in the text format (which I experienced reworking all the examples) and binary format. What I don't know is if this is harder to implement for some reason. I wondered if it might even be easier or more efficient if it allows simply reusing the module environment instead of having to set up a whole new one for each module/instance type)? Any thoughts here @alexcrichton? |
Oh, and the other benefit is that, until we do add type imports or aliases-in-module-types, we don't have to do anything special; so this would just be a future plan-of-record. |
From a decoding point of view I think that seems easy enough and won't be hard to implement. I think from a text format perspective it won't be too too hard as well, although it may require a two-pass sort of indexing where indexes within a module type are determined relative to wherever the module type is declared and then after the outer modules' type indices are all determined the inner module could get fully numbered. Either way though I don't expect it to be too hard, the issues with repeated sections in the text format are probably trickier. |
Hm, I would advice against this. When dealing with syntax that has nested binding structure, you really want the property that local bindings are not affected by outer bindings. That's why you typically have shadowing rules for named bindings, and it is what de Bruijn indexing (relative indexing from inside to outside, like Wasm labels) achieves for numeric bindings, and why that is universally preferred as a name-free representation. Without that composition property, constructing and transforming terms/types becomes more complicated and error-prone. Moreover, it prevents canonicalisation, because even a completely closed type will differ (from itself) depending on where it occurs. |
Ah, that's an interesting point; I hadn't thought of this in terms of de Bruijn indexing, but I suppose the "outer alias" is really just factoring out the de Bruijn index pair from what would otherwise be every use site of the alias. Then my next question is: in the text format, could we allow outer aliases to be implicitly created (in the same manner as |
At least for implementation-complexity I think auto-inserting |
Some sugar for symbolic aliases should certainly be feasible. I admit that I don't remember what complexity existed before. :) |
Ok, sounds like a plan; I'll add a note to the explainer about automatic insertion of outer-aliases when used in nested modules and types. |
The proposal currently assumes that all type indices used inside a module or instance type refer to the enclosing module's index space. However, that is incompatible with the addition of type imports, which introduce a way of binding types local to a module type: if every type index in the inner module's type is interpreted as indexing into the enclosing module, then there is no way of actually referring to such local types.
This has various consequences:
Obviously, this also has non-trivial effects on the definition of subtyping.
The latter two items are extensions that we can introduce once type imports are actually added. But the former two are necessary to change/add now in order to be forward-compatible with such an extension.
The text was updated successfully, but these errors were encountered: