From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.devel Subject: Re: Mutating public bindings of a declarative module Date: Mon, 25 Nov 2019 09:33:16 +0100 Message-ID: <87h82s1hkj.fsf@igalia.com> References: <87a78lyxbi.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="150204"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) Cc: Guile Devel To: Ludovic =?utf-8?Q?Court=C3=A8s?= Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Nov 25 09:33:55 2019 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iZ9og-000cw6-Jw for guile-devel@m.gmane.org; Mon, 25 Nov 2019 09:33:54 +0100 Original-Received: from localhost ([::1]:41322 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iZ9of-0001c9-Bu for guile-devel@m.gmane.org; Mon, 25 Nov 2019 03:33:53 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51401) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iZ9oa-0001ad-F3 for guile-devel@gnu.org; Mon, 25 Nov 2019 03:33:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iZ9oX-0007sB-B2 for guile-devel@gnu.org; Mon, 25 Nov 2019 03:33:48 -0500 Original-Received: from fanzine.igalia.com ([178.60.130.6]:33624) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iZ9oW-0007o2-OU; Mon, 25 Nov 2019 03:33:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References:Subject:Cc:To:From; bh=Zi0dsRc3HDjcHzBXsTMwsqjXSSxN4ITV+BcMEdCaki4=; b=TP70oTWywjbHFwHcJJGwh+B4K6NsD9i8+Es70S7aWldY+/d8kT7O+ZvHPqjCUm2Au51YWL97Yo/dFPgfcW53smkRp68Enl742VCzyitlrScv4BWtdnuF6PTxhdG1wHeONEgxyBuodw/lrFyxJfBM9qy0wb6Bbv2RyVdo4kK1XVjfB7V0nlSiipLgMJFxWfu6QFjL2LA/4d+lI4IomPKvu4/XyLoT7Wfr5Qq0j7EMykFKIGgwtbg0B3zuY+wfNwur9CBTgGtJJymcRDSKbTSCy1CjNvH3GZJLFxQqDj1mBkdeyd2Z+VhRfJ15OFJmYLQvUkl7B8/JPEylhgYGdvq1oQ==; Original-Received: from lfbn-ann-1-376-195.w86-200.abo.wanadoo.fr ([86.200.91.195] helo=milano) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1iZ9oF-0008E3-6l; Mon, 25 Nov 2019 09:33:27 +0100 In-Reply-To: <87a78lyxbi.fsf@gnu.org> ("Ludovic \=\?utf-8\?Q\?Court\=C3\=A8s\=22'\?\= \=\?utf-8\?Q\?s\?\= message of "Sun, 24 Nov 2019 18:54:25 +0100") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 178.60.130.6 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:20162 Archived-At: Hi :) On Sun 24 Nov 2019 18:54, Ludovic Court=C3=A8s writes: > It seems that if you =E2=80=98set!=E2=80=99 a public variable of a declar= ative module, > the change is visible to all the module users, but it=E2=80=99s not neces= sarily > visible to procedures within that module, presumably because they use an > inlined or specialized variant of that thing. > > I would have imagined that public bindings are considered mutable and > thus not subject to inlining; OTOH, that would obviously be a loss, so > the current approach makes sense. Right, I understand the frustration. For what it is worth, I think we have the right default for what it means to be a declarative module, but I'm definitely open to having that conversation. > Anyway, it complicates a use case for me. In Guix, we =E2=80=9Cmock=E2= =80=9D bindings > like so: > > (define-syntax-rule (mock (module proc replacement) body ...) > "Within BODY, replace the definition of PROC from MODULE with the def= inition > given by REPLACEMENT." > (let* ((m (resolve-interface 'module)) > (original (module-ref m 'proc))) > (dynamic-wind > (lambda () (module-set! m 'proc replacement)) > (lambda () body ...) > (lambda () (module-set! m 'proc original))))) > > and that allows us to write tests that temporarily modify public (or > private!) bindings. > > It seems like this could be addressed by compiling selected modules with > =E2=80=98user-modules-declarative?=E2=80=99 set to #false, or by avoiding= the above hack > altogether when possible, but I thought I=E2=80=99d share my impressions = and > listen to what people think. :-) This works. (Actually the way I would do it is to pass #:declarative? #f in the define-module for the modules in question.) Marking some bindings as not declarative also works (e.g. (set! foo foo)). For me the most robust solution would be to have `mock' verify that the module it's funging isn't declarative. We don't currently have a way to know if an individual module binding is declarative or not (though we could add this). Cheers, Andy