[MLton] MinGW hosted MLton

Matthew Fluet fluet@cs.cornell.edu
Tue, 3 May 2005 16:04:14 -0400 (EDT)


> I've committed your patch with a few tweaks.  I liked the idea of
> moving wait from OS.Process into Posix.Process.

===================================================================
RCS file: /cvsroot/mlton/mlton/basis-library/posix/process.sml,v
retrieving revision 1.29
retrieving revision 1.30
diff -c -r1.29 -r1.30
*** mlton/mlton/basis-library/posix/process.sml	2004/12/02 21:07:43	1.29
--- mlton/mlton/basis-library/posix/process.sml	2005/05/02 19:20:27	1.30
***************
*** 92,97 ****
--- 92,100 ----
  	 val status: Status.t ref = ref (Status.fromInt 0)
  	 fun wait (wa, status, flags) =
  	    let
+ 	       val useCwait = 
+ 	          Primitive.MLton.Platform.OS.useWindowsProcess
+ 	          andalso case wa of W_CHILD _ => true | _ => false
  	       val p =
  		  case wa of
  		     W_ANY_CHILD => ~1
***************
*** 103,110 ****
  	       SysCall.syscallRestart
  	       (fn () =>
  		let
! 		   val pid = Prim.waitpid (Pid.fromInt p, status,
! 					   SysWord.toInt flags)
  		in
  		   (Pid.toInt pid, fn () => pid)
  		end)
--- 106,116 ----
  	       SysCall.syscallRestart
  	       (fn () =>
  		let
! 		   val pid = 
! 		      if useCwait 
! 			 then Prim.cwait (Pid.fromInt p, status)
! 		      else Prim.waitpid (Pid.fromInt p, status,
! 					 SysWord.toInt flags)
  		in
  		   (Pid.toInt pid, fn () => pid)
  		end)


This patch breaks a self-compile on Linux (and presumably on every 
non-Windows platform).  Although it is clear that 
Primitive.MLton.Platform.OS.useWindowsProcess  must be false on a 
non-Windows platform (and, hence,  usCwait  must be false), it is 
insufficiently optimized, leaving a reference to MLton_Process_cwait in 
the final object files, which are left unsresolved by libmlton.a on 
non-Windows platforms.

I suspect that the issue arises from the fact that the computation of  
useCwait  is caught up in the closure of the  wait  function above and 
constant propagation isn't able to push the constant value of  
Primitive.MLton.Platform.OS.useWindowsProcess  though to its use.  While 
it would be nice to improve constant propagation (or some other 
optimization) to eliminate this situation, it would also be desirable to 
have a dummy MLton_Process_cwait  on non-Windows platforms in the 
situations when the optimizer isn't sufficiently powerful.