default constructors and implicit super() insertion

Peter Hall peter.hall at
Wed Jun 27 12:00:34 PDT 2007

> For JS, this means
> having a straightforward compiler that performs the minimum amount of
> analysis, incroporating quick-and-dirty code generation, and so on.
> (Strict mode may be beyond such an implementation.)

I was under the impression that this discussion would not apply in
non-strict mode. Would it be an error to not initialize a non-nullable
variable in non-strict mode?

> Definite
> assignment analysis is probably only slightly superlinear (I'm not
> co-located with my compiler books, but I seem to remember that
> definite assignment analysis requires the computation of dominators
> and dominator computation is O(n log n) in the size of the flow
> graph), but it's another pass added to the compiler.  Some compilers
> do on-the-fly code generation and only have one pass anyway and no
> notion of "flow graph" to speak of... so the cost *might* be
> significant.   If we can find a compromise between usability and
> processability then so much the better.

I think you misunderstood my intent. I am suggesting that you could
enforce that, for each non-nullable instance variable, a constructor
must contain an assignment with the variable on the LHS. I believe
that this is functionally the same as the proposed new syntax (and I'm
pretty sure you can incorporate the test into a single pass). There
are plenty of cases where assignment is guaranteed at runtime, but
cannot be guaranteed at compile-time so I don't think there would even
be value in any more "difficult" analysis to prove valid assignments.

Also, could you clarify the scoping of the RHS of the initializer
assignments? Is the scope hoisted or a completely different scope?
e.g. would the following work as expected:

class C {
  var delegate:D!;
  function C(d:D=null) : delegate = d || new D(this)

class D {
    function D(host:Object) { }

Further, what happens when the initialization could take several lines
to create and parametrize the object? Would you be allowed to invoke
other instance or static methods in that code block?


More information about the Es4-discuss mailing list