Replies: 6 comments 4 replies
-
My current guess is that both open and include work the same way. During type-checking, we first add the inner items to the outer structure (unconditionally), and then we use the signature of the final construction to build a coercion that fits the expected signature (for the outer module). The difference is that In the case of open, the items are not added to the signature, while with include they are (at least until they get removed by either shadowing or a restricted signature constraint). |
Beta Was this translation helpful? Give feedback.
-
This code looks unfamiliar to me too. It was introduced in 97329f3 "Extend open to arbritrary module expressions in structures and to applicative module paths in signatures" by @objmagic and @trefis. See also #2147. Before that, the code was as I wrote it in 1996, namely no lambda code was generated for |
Beta Was this translation helpful? Give feedback.
-
The code does look similar when |
Beta Was this translation helpful? Give feedback.
-
Note: typemod.ml carries some As noted by @lthls, another hypothesis is that we pretend that the fields are added, but in fact they are ignored in the end because the module expression is wrapped in a coercion that hides them. |
Beta Was this translation helpful? Give feedback.
-
I believe I have a satisfying answer to the question. It involves a lot of different pieces of code, I'll try to summarize everything here.
Maybe at some point I'll try to write some comments, but for now I'm happy with knowing that my code in #12782 is correct (and knowing why). |
Beta Was this translation helpful? Give feedback.
-
@lthls and myself are tearing our hair (that's a lot of hair) over the translmod.ml logic for Tstr_open and its relation to the Tstr_include case above.
ocaml/lambda/translmod.ml
Lines 701 to 750 in 1537083
The two code look extremely similar (where are the differences?), and it looks very much like
Tstr_open
is in fact adding items to the current module, when intuitively -- and in our tests -- that would not happen.Notice in particular that the "bound value identifiers" of the opened modules are added to the
newfields
accumulator, which intuitively should be the fields in the resulting structure. What are we missing? (Could there be a comment that explains what is going on?)Beta Was this translation helpful? Give feedback.
All reactions