From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.bugs Subject: bug#20938: make-dynamic-state, with-dynamic-state & exceptions Date: Wed, 01 Mar 2017 18:30:09 +0100 Message-ID: <87wpc8dhwe.fsf@pobox.com> References: <55929EA6.6090404@primfilat.com> <87tw7emmbq.fsf@pobox.com> <1b66634b-9e69-da86-116a-088eafb383e7@primfilat.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1488389480 12139 195.159.176.226 (1 Mar 2017 17:31:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 1 Mar 2017 17:31:20 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: 20938@debbugs.gnu.org To: Josep Portella Florit Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Wed Mar 01 18:31:13 2017 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cj85o-0002J4-5M for guile-bugs@m.gmane.org; Wed, 01 Mar 2017 18:31:12 +0100 Original-Received: from localhost ([::1]:47899 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj85s-0002lI-Mt for guile-bugs@m.gmane.org; Wed, 01 Mar 2017 12:31:16 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cj85j-0002js-Mb for bug-guile@gnu.org; Wed, 01 Mar 2017 12:31:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cj85f-0003En-45 for bug-guile@gnu.org; Wed, 01 Mar 2017 12:31:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36518) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cj85f-0003E0-18 for bug-guile@gnu.org; Wed, 01 Mar 2017 12:31:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1cj85e-0005Nd-K3 for bug-guile@gnu.org; Wed, 01 Mar 2017 12:31:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Andy Wingo Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 01 Mar 2017 17:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20938 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 20938-submit@debbugs.gnu.org id=B20938.148838942120633 (code B ref 20938); Wed, 01 Mar 2017 17:31:02 +0000 Original-Received: (at 20938) by debbugs.gnu.org; 1 Mar 2017 17:30:21 +0000 Original-Received: from localhost ([127.0.0.1]:34717 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cj84z-0005Mj-16 for submit@debbugs.gnu.org; Wed, 01 Mar 2017 12:30:21 -0500 Original-Received: from pb-sasl1.pobox.com ([64.147.108.66]:51923 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cj84w-0005Mb-UZ for 20938@debbugs.gnu.org; Wed, 01 Mar 2017 12:30:19 -0500 Original-Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id ABC16603E1; Wed, 1 Mar 2017 12:30:17 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=sasl; bh=GzJ3VLI58ZOGRucNuLM+cbR6F3I=; b=J+Z6YA bjuXI3JAGKVdJPHYYXsQluwEYbz7FObU9f+ks8+aPSWbpbOgUXDZ0+mgp9HpUaj9 DrgI7KYhw9YxDeC0qNAivK1bixcJUrI2yyxRDnfanCMotzciyxSaTAWXuQ71CpJU ykitSigHc8Bb2evFB8AlD5tARp/a0OnkOZhAY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; q=dns; s=sasl; b=sqZC4iHzQ7PALQ0BmyHss2iJONMmyDvJ jNoty0t7w25dvpob0htcQBNpfwPc1J2FsvoRlzMKX0yLZeQMX9Fqbc9Lu54Pry8c KZMcz6B1W4ba6Vw+FXXv4GM6yolHi+WqgjBkqaraDhlt+svAmVsA3oZwFXxi2XX6 3pJD7DprKU4= Original-Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id A3441603E0; Wed, 1 Mar 2017 12:30:17 -0500 (EST) Original-Received: from clucks (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl1.pobox.com (Postfix) with ESMTPSA id 97DBD603DF; Wed, 1 Mar 2017 12:30:16 -0500 (EST) In-Reply-To: <1b66634b-9e69-da86-116a-088eafb383e7@primfilat.com> (Josep Portella Florit's message of "Wed, 1 Mar 2017 16:11:03 +0100") X-Pobox-Relay-ID: BC3BEFA0-FEA4-11E6-8224-B667064AB293-02397024!pb-sasl1.pobox.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8638 Archived-At: On Wed 01 Mar 2017 16:11, Josep Portella Florit writes: > Hi Andy, > > On 02/28/2017 03:17 PM, Andy Wingo wrote: >> On Tue 30 Jun 2015 15:50, Josep Portella Florit writes: >> >>> This code crashes Guile 2.0.11: >>> >>> (define x (make-dynamic-state)) >>> (with-dynamic-state x (lambda () (/ 1 0))) >> >> Sad :/ Fixed in 2.2 though, finally. I don't really know how to fix it >> in 2.0 though. Marking as closed given that we will have a shiny new >> 2.2.0 soon. > > Good work! Do I have to wait until you release 2.2.0 to test it? > (Today I've tested it with 2.1.7.22-fcebf and it still crashed.) Ack, I didn't actually test it! I thought a related fix in 2.1.7 would have caught it. I will have a look. > BTW, did you change your mind on deprecating dynamic states? > Yes, with a caveat. Having captured dynamic states also be mutable places was untenable, as you could have multiple threads mutating the same place at one time. However dynamic states work well as a way to transport a parameterization from one part of the code to another. I rely on them in Fibers for this purpose. What do you think? :) See NEWS: ** Fix too-broad capture of dynamic stack by delimited continuations Guile was using explicit stacks to represent, for example, the chain of current exception handlers. This means that a delimited continuation that captured a "catch" expression would capture the whole stack of exception handlers, not just the exception handler added by the "catch". This led to strangeness when resuming the continuation in some other context like other threads; "throw" could see an invalid stack of exception handlers. This has been fixed by the addition of the new "fluid-ref*" procedure that can access older values of fluids; in this way the exception handler stack is now implicit. See "Fluids and Dynamic States" in the manual, for more on fluid-ref*. And: ** Dynamic states capture values, not locations Dynamic states used to capture the locations of fluid-value associations. Capturing the current dynamic state then setting a fluid would result in a mutation of that captured state. Now capturing a dynamic state simply captures the current values, and calling `with-dynamic-state' copies those values into the Guile virtual machine instead of aliasing them in a way that could allow them to be mutated in place. This change allows Guile's fluid variables to be thread-safe. To capture the locations of a dynamic state, capture a `with-dynamic-state' invocation using partial continuations instead. Andy