[MLton] behavior of forceUsed

Matthew Fluet fluet@cs.cornell.edu
Thu, 5 Aug 2004 19:21:34 -0400 (EDT)


What do people intuitively believe (or want) the forceUsed annotation to
do in the following situation:

xy.sml:
  structure X = struct val x = () end
  structure Y = struct val y = () end

z.sml:
  structure Z : sig val z : unit end
              = struct val z = X.x val zz = ()end

a.mlb:
  local
    ann warnUnused true in
      local
        xy.sml
      in
        ann forceUsed in
          z.sml
        end
      end
    end
  in

  end

Each of X,X.x,Y,Y.y,Z,Z.z,Z.zz were introduced in the scope of warnUnused
true, so might appear in an unused warning.
There are no bindings in scope at the end of the program.
The only thing that is actually used is X.x, so we certainly should not
get warnings for X or X.x.

I see three choices for what to do in the scope of forceUsed :

1) everything that is introduced in the scope of forceUsed is forced;
   Under this scenario, Z, Z.z, and Z.zz will be forced.
   Hence, Y and Y.y will be warned as unused.

   However, this is really a non-option, as it exactly corresponds to
   warnUnused false, so we have a mechanism for acheiving this.

2) everything in the environment scope at the end of the forceUsed scope
   is forced to be used.  Under this scenario, because Y and Y.y are in
   scope for the forceUsed annotation, then they will be forced and
   will not be warned.  Likewise, Z and Z.z will be forced.
   Hence, Z.zz will be warned as unused.

3) everything that was introduced in the scope of the forceUsed and
   is in the environment scope at the end of the forceUsed scope
   is forced to be used.  Under this scenario, only Z and Z.z will be
   forced.  Hence, Y, Y.y, and Z.zz will be warned as unused.

The current behavior is 2, although I think it would be more natural to
have the behavior be 3.  Although, I don't quite know how to implement it.