From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: catch, throw, prompt, control, fluids, garbage collection Date: Sun, 14 Feb 2010 13:33:42 +0100 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1266150843 5001 80.91.229.12 (14 Feb 2010 12:34:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 14 Feb 2010 12:34:03 +0000 (UTC) To: guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Feb 14 13:33:56 2010 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ngdff-0002ZT-R2 for guile-devel@m.gmane.org; Sun, 14 Feb 2010 13:33:56 +0100 Original-Received: from localhost ([127.0.0.1]:57735 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ngdfe-0002fZ-Ql for guile-devel@m.gmane.org; Sun, 14 Feb 2010 07:33:54 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ngde9-0002Hc-0u for guile-devel@gnu.org; Sun, 14 Feb 2010 07:32:21 -0500 Original-Received: from [140.186.70.92] (port=42933 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ngde8-0002Gr-1O for guile-devel@gnu.org; Sun, 14 Feb 2010 07:32:20 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Ngde6-0000vV-Vm for guile-devel@gnu.org; Sun, 14 Feb 2010 07:32:19 -0500 Original-Received: from a-pb-sasl-quonix.pobox.com ([208.72.237.25]:33082 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Ngde6-0000vC-T0 for guile-devel@gnu.org; Sun, 14 Feb 2010 07:32:18 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 1751699490 for ; Sun, 14 Feb 2010 07:32:16 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to :subject:date:message-id:mime-version:content-type; s=sasl; bh=W PMTdA2IuEyxxkb2DJQ4Reu+aSo=; b=jrFxGrgQtcIymFiIJ8S8FYIzkfFuNGHO3 0sSj5p3wI4HjLHpvgwbqXLdiISsXzZjxw7ydAfXqF0QSGtrU5yvmw1S4Mn3dxM5H RIMwWXHRResIfP3b29GddKmpMczD7vq2LJRsZU11/fzt/honrELFZ7PrSmYPueBC IxzmMfnESc= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:subject :date:message-id:mime-version:content-type; q=dns; s=sasl; b=A3a 55EJnizrzjNF9UDf2bZQP9xtJOIDYsXNm9zdqmA61QK52qgmAxUkEv0xN80L5hBk /ty73BLVvxWyhv/tbkFdXsaeXXeJOPdxC2S5fIy7ggW/JnB1d74z6ehtji9P21q8 0lVrWcZQF9B+X1j3ufXs2Kv7gCuIZ7e79bg0Ud3M= Original-Received: from a-pb-sasl-quonix. (unknown [127.0.0.1]) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTP id 12E949948F for ; Sun, 14 Feb 2010 07:32:16 -0500 (EST) Original-Received: from unquote (unknown [79.151.216.235]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a-pb-sasl-quonix.pobox.com (Postfix) with ESMTPSA id 4BF1F9948E for ; Sun, 14 Feb 2010 07:32:15 -0500 (EST) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (gnu/linux) X-Pobox-Relay-ID: FC0BF8FA-1964-11DF-BED4-6AF7ED7EF46B-02397024!a-pb-sasl-quonix.pobox.com X-detected-operating-system: by eggs.gnu.org: Solaris 10 (beta) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:9976 Archived-At: Hello all, I am currently shaving a yak[0], trying to integrate nonlocal exits into the VM. That's `catch', `throw', and all that. I have also been wanting to integrate delimited continuations into Guile; that's a bigger topic. Anyway it turns out that one can implement catch and throw using delimited continuations. Flatt et al's paper at ICFP 07 [1] shows how. Sitaram 93 shows why you want delimited continuations [2]. Felleisen 88 is the first appearance of delimited continuations that I'm aware of, though I think it's behind a paywall; Sitaram and Felleisen 90 seems to be an adequate substitute [3]. Dybvig et al 07 is a great summary of the relationship between the various delimited continuation operators [4]. [0] http://projects.csail.mit.edu/gsb/old-archive/gsb-archive/gsb2000-02-11.html [1] http://www.cs.utah.edu/plt/publications/icfp07-fyff.pdf [2] http://www.ccs.neu.edu/scheme/pubs/pldi93-sitaram.pdf [3] http://www.ccis.northeastern.edu/scheme/pubs/lasc1990-sf.pdf [4] http://www.cs.indiana.edu/~dyb/pubs/monadicDC.pdf So, the deal. The deal is that Flatt shows very clearly and elegantly how to implement catch and throw using prompt, abort, and dynamic binding. (Actually he uses the % flavor of prompt; and abort is like Sitaram's control afaict. See Sitaram 93.) The dynamic binding is for the current exception handler (corresponding to catch) and for the current "abort handler", which is like a pre-unwind handler. The problem: Well, you might want to set some exception handlers, and then spawn a bunch of threads all with those handlers. But if a pre-unwind handler throws an exception, that exception shouldn't be handled by itself, or you get an infinite loop. Basically you need a bit to say whether a given handler is running in a given thread or not -- a fluid. But you can't / shouldn't make a new fluid every time you enter a `catch', because currently fluids are never garbage collected! We really need to fix this. I think it's a 1.9 regression. To do so effectively, I think you'd need to make fluid objects store their values directly, so that the GC doesn't have to go through hoops to know that they're collectable. Ideally they would get their values via pthread_getspecific; but that would defeat some bits of ours about "dynamic states" (not a very useful concept IMO), and the GC would need help. Actually it would be nice if libgc supported thread-local allocations. (Does it?) Anyway, some disconnected thoughts here. I could have simply implemented catch and throw using what we have now, but I think it's a great opportunity to see if we can do delimited continations. There's some half-complete prompt support in master. I thought I'd get to the rest sooner, but it seems that it will take another couple weeks. I haven't been able to have good hacktime over the last week or two, so things are going slower than they usually do. Also, getting to understand delimited continuations was a bit paralyzing. Regarding the release... I have no thoughts. Perhaps I should prepare the NEWS, and we get a release out the door this week, then the next one will have catch/throw nicely integrated, and at that point I'll be mostly happy for 2.0. Thoughts? Cheers, Andy -- http://wingolog.org/