[MLton-devel] Re: finalization in MLton
Ken Friis Larsen
kfl@it.edu
19 May 2003 10:01:21 +0100
Stephen Weeks <sweeks@sweeks.com> writes:
> Yes. The implementations are somewhat similar, although I used
> closures to hide the type of the value while you used exceptions. One
> problem I see with your withValue implementation is that it doesn't
> ensure the finalizer runs after the function completes.
Hmm, I don't think I understand exactly what your point is. So let me
state what my intentions for withValue are:
(1) I don't want to ensure that the finalizer runs after the
function completes. I fact I think that would be wrong becase
the finalized value might not be dead at that point.
(2) I want to ensure that that the finalizer don't run while in the
"body" of a withValue.
> That is essential -- imagine if the finalizable value were a pointer
> to a C structure that were freed by the finalizer before the
> function could complete.
This corresponds with my intention (2) above. Hence I agree. But I
don't understand *why* my withValue function don't work. Example,
let's say tha v is a finalized value:
withValue (fn x => ...) v
can v be collected in the ... part? I guess that is what you are
saying. Is that because MLton with inline withValue and then realise
that v can be collected? If so, how should I "obfuscate" my code so
that v is protected?
Trying to adobt your code I get:
fun wind(thunk, cleanup) =
let val a = thunk()
in cleanup(); a
end handle exn => (cleanup(); raise exn)
fun touch v =
case v of
Domain => raise Fail "Finalized.touch bug\n"
| _ => ()
fun withValue f (v as {value, getVal}) =
wind (fn () => f(getVal value),
fn () => touch value)
Would this be enough to protect v? Or is MLton smart enough to
eliminate the whole touch call, because can v never be the Domain
exception.
> > The example works with mlton-20030419 but if I try to use yesterdays
> > CVS mlton, then MLton spews tons of SSA SML at me and ends with:
> > unhandled exception: TypeError
>
> I've checked in a fix for that bug.
Thanks. I checked that it works for my code.
> Hmmm. I compiled and ran this with 20030419 without problems.
That is strange.
I just verified that I get the error I reported:
$ /home/kfl/programming/ml/mlton-20030419/install/usr/bin/mlton
MLton 20030419 (built Sun Apr 27 23:00:53 2003 on vips)
$ /home/kfl/programming/ml/mlton-20030419/install/usr/bin/mlton omega-mlton.cm
shrinker raised Prim.apply raised assertion failure: SmallIntInf.fromWord
> So, you must either be using an SML/NJ-compiled version or modified
> sources.
Nope, it was compiled with the MLton from Debian sid. And the only
file I've modified is mlton-20030419/install/usr/bin/mlton where I've
changed what $lib points to.
> I would like to check my guess though, so could you please send more
> details on the configuration of MLton with which you generated the
> error.
OK. What do you want me to send? I usually just compile mlton with
the command:
make clean bootstrap install
and then edit install/usr/bin/mlton by hand. Is this the intended
procedure?
> > If you want it I can send you my implementation together with test
> > program.
>
> Sure, we can take a look. The MLton.FFI structure is under active
> development as we speak.
I'll package it up and send it during the week.
> Excellent. You can alpha test our new stuff. :-)
I shall (and I'm looking forward to do so, expect lots of feedback
next week ;-)
Cheers,
--Ken
-------------------------------------------------------
This SF.net email is sponsored by: If flattening out C++ or Java
code to make your application fit in a relational database is painful,
don't do it! Check out ObjectStore. Now part of Progress Software.
http://www.objectstore.net/sourceforge
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel