Nested modules clarification

๏̯͡๏ Jasvir Nagra jas at nagras.com
Fri Jul 20 07:23:00 PDT 2012


On Fri, Jul 20, 2012 at 1:47 AM, Andreas Rossberg <rossberg at google.com>wrote:

> On 20 July 2012 01:36, Erik Arvidsson <erik.arvidsson at gmail.com> wrote:
>
>> On Thu, Jul 19, 2012 at 2:58 PM, ๏̯͡๏ Jasvir Nagra <jas at nagras.com>
>> wrote:
>> > Here's the modified test case from earlier:
>> >
>> > outer.js
>> > ----------
>> > module outer {
>> >   let Object = {};
>> >   export module inner = "http://m/inner.js";
>> > }
>> >
>> > inner.js
>> > ----------
>> > Object.prototype.myMarker = 3;
>> > assert( ({}).myMarker === 3 )
>>
>> A better inlining mechanism is:
>>
>> compiled.js
>> --------------
>> module $temp {
>>   Object.prototype.myMarker = 3;
>>   assert( ({}).myMarker === 3 )
>> }
>> module outer {
>>   let Object = {};
>>   export module inner = $temp;
>> }
>>
>> This way multiple module foo = "http://m/inner.js" only leads to one
>> module and you get less scope issues.
>>
>
> The main problem with this is that it changes the order of effects. Of
> course, it is not recommended for a module body to have observable effects,
> so maybe it's fine if an inliner ignores that issue and does not guarantee
> semantic equivalence for such cases.
>

I quite liked Erik's suggestion (the Arvidsson transform?) - it's clever.
 Is the cleverness made necessary because the lexical scope surrounding a
module is captured by a module.  As a result, the compiler is forced to
compile nested modules to a place where there are no variables to
accidentally capture ie. the "top-level" of a module.  In Sam and Dave's
original module proposal, IIRC modules were a lexical scope cut-point and
thus did not have this issue.

(PS. I suspect it's clear but I'll say it anyways - I don't have a
particular approach I prefer - the modules proposals have a lot of details
and consequences that were non-obvious to me from the wiki writeup. I am
hoping that in asking these questions, I am helping clarify them for
everyone).


>
> /Andreas
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120720/8867a6e2/attachment.html>


More information about the es-discuss mailing list