From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id YHiIKz9eRGILLgAAgWs5BA (envelope-from ) for ; Wed, 30 Mar 2022 15:42:23 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id CM4ZKT9eRGK5RQEA9RJhRA (envelope-from ) for ; Wed, 30 Mar 2022 15:42:23 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 089D212655 for ; Wed, 30 Mar 2022 15:42:23 +0200 (CEST) Received: from localhost ([::1]:47582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nZYac-0002QY-5g for larch@yhetil.org; Wed, 30 Mar 2022 09:42:22 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZYNQ-0004nD-OV for guix-devel@gnu.org; Wed, 30 Mar 2022 09:28:44 -0400 Received: from fanzine.igalia.com ([178.60.130.6]:58558 helo=fanzine2.igalia.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZYNO-0006ie-8D; Wed, 30 Mar 2022 09:28:44 -0400 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: Date:References:In-Reply-To:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Gx+7okrZAT06xwEvCJYWcHcoMC1uAx+SuIaNK1ODgKE=; b=f9Nhn6V7DWwBgkPrJcENLSfjqm iK5dKMiBnr4COSvzAd9lNouGJfaUkb5y0OuZvqVE2lOPX2NDiKiq/dPbqFtPVQiMBlXaz/zHduQdA kL8GlDJETRM9n5ITAy5Th2wtyFaDmOH7zslnCzJF3fibG53aBHb3uc7pdDVSeZVVrprpzkwwKq5r7 qfL9prCV6hVBbTGldg5SuvFaprky5RZdDhLCNvl/9UT/MwNXFo7+6hh8Utnl8LXaBcwl3USgdyXoS LR51JXnbPfeWt2K8RspaOorfiegn2YzY0dwbb9NuQVw5hltsTeHUX8OJq5InanRUHiqrLGxsjWced iSup2ZSQ==; Received: from 162.156.15.93.rev.sfr.net ([93.15.156.162] helo=milano) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1nZYMx-0001U6-57; Wed, 30 Mar 2022 15:28:15 +0200 From: Andy Wingo To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: better error messages through assertions In-Reply-To: <87lewrwzll.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Wed, 30 Mar 2022 11:37:10 +0200") References: <87ilthoxvu.fsf@elephly.net> <87k0dv6ahq.fsf@elephly.net> <87mtibdu5l.fsf@gnu.org> <2205364.8dmU9V6fpu@bastet> <87cziy2hq0.fsf@gnu.org> <87lewrwzll.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Date: Wed, 30 Mar 2022 15:28:03 +0200 Message-ID: <87bkxny3h8.fsf@igalia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=178.60.130.6; envelope-from=wingo@igalia.com; helo=fanzine2.igalia.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ricardo Wurmus , guix-devel@gnu.org Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1648647743; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=Gx+7okrZAT06xwEvCJYWcHcoMC1uAx+SuIaNK1ODgKE=; b=Vi27k6mP34TECUUOBlqZ1q0NdYryW6cQ9/GUg43G34s8F9pF2LgiDZsfWI3nW2D4gABMRj fP6MK51r0FAI5qgwJxuejPKThqhVAwUHo+4fUsKUPN1DIaoVXYwpw300ikwIWV1MGxzwP+ m7k9zsoMZVJM16BZ660igQbMiP6aYuHWCBrHhEu+AErjdrj+Xw+31tXMCHx+Ce0ESSJcY3 i/Ni4+A3KNLNy9iSFOK2jYp3z3qnozkcyrlABTTE/L7EUvPWfusulOdHUAQBxxJh30lb4K GQdpjYADF9Kw11FkQVZ8F7O7HnOHcbAsGE+vKCAfE+nKc8OvsW4ay+yZMkzUcQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1648647743; a=rsa-sha256; cv=none; b=PJSv/KbpzHQavZh79yNWs1psFpaQp0vOoMuj5uG6P238Fa2ZEQAU5BuRAWOFINB1BCyNes n6ob4j8bTclBNO1IkYDhr6dB1HSK7baJnULQWuH0Xa8dcyFqjt5PPKGwNVPqig+0F5/B/F CNevkJwvcSX7/6FiH0KCp+yuWJI8m+2CgZVWUeGOuvnQuXQa4WrxH5mjOqvuH0lDgc3NAq kxk3scTL9KSrAvpD2MMpUHQhwc9ilZgWytkISLmkB+Zyu00CMQm9tdXNx5BBzkhW3tU+OW cGfjiz4+S3Q64l8wtkWepxGLsWvKd50unLwrqxiypkhfOWFXZEpoorwNqzd1hw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=igalia.com header.s=20170329 header.b=f9Nhn6V7; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 0.63 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=igalia.com header.s=20170329 header.b=f9Nhn6V7; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 089D212655 X-Spam-Score: 0.63 X-Migadu-Scanner: scn0.migadu.com X-TUID: tmSAhrv1hEMy On Wed 30 Mar 2022 11:37, Ludovic Court=C3=A8s writes: >> scheme@(guile-user)> (container-contents '()) >> ice-9/boot-9.scm:1685:16: In procedure raise-exception: >> In procedure struct-vtable: Wrong type argument in position 1 > scheme@(guile-user)> ,use(srfi srfi-9) > scheme@(guile-user)> (define-record-type > (make-foo x) > foo? > (x foo-x)) > scheme@(guile-user)> ,optimize (foo-x '()) > $9 =3D (if (eq? (struct-vtable '()) ) > (struct-ref '() 0) > (throw 'wrong-type-arg > 'foo-x > "Wrong type argument: ~S" > (list '()) > (list '()))) > > With Guile 3, it might be that adding an extra =E2=80=98struct?=E2=80=99 = test would have > little effect on performance; we=E2=80=99d need to check. Would have no effect. Incidentally, you might want to use ,optimize-cps; scheme@(guile-user)> ,optimize (foo-x '()) $9 =3D (if (eq? (struct-vtable '()) ) (struct-ref '() 0) (throw 'wrong-type-arg 'foo-x "Wrong type argument: ~S" (list '()) (list '()))) scheme@(guile-user)> ,optimize-cps (foo-x '()) L0: ; at :15:14 v0 :=3D self L1(...) L1: receive() v1 :=3D const () ; arg at :15:21 throw throw/value+data[#(wrong-type-arg "struct-vtable" "Wrong type arg= ument in position 1 (expecting struct): ~S")](v1) ; at :15:14 L1(...) means, pass all values to L1. In this case because there are varargs on the stack from the procedure call. L1 parses them with the receive(). Anyway, here we see that with respect to the immediate '(), that all the tests folded. If we instead lift to a procedure: scheme@(guile-user)> ,optimize-cps (lambda (x) (foo-x x)) L0: ; at :16:14 v0 :=3D self L1(...) L1: receive() v1 :=3D current-module() ; module at :16:14 cache-set![0](v1) ; at :16:14 v2 :=3D const-fun L7 ; _=20 return v2 ; at :16:14 L7: ; at :16:14 v3 :=3D self L8(...) L8: v4 :=3D receive(x) ; x=20 heap-object?(v4) ? L10() : L38() ; at :16:26 L10(): struct?(v4) ? L11() : L38() ; at :16:26 L38(): throw throw/value+data[#(wrong-type-arg "struct-vtable" "Wrong type arg= ument in position 1 (expecting struct): ~S")](v4) ; at :16:26 L11(): v5 :=3D scm-ref/tag[struct](v4) ; vtable at :16:26 v6 :=3D cache-ref[(0 . )]() ; cached at :10:20 heap-object?(v6) ? L19() : L14() ; at :10:20 L19(): L20(v6) ; at :10:20 L14(): v7 :=3D cache-ref[0]() ; mod at :10:20 v8 :=3D const ; name at :10:20 v9 :=3D lookup-bound(v7, v8) ; var at :10:20 cache-set![(0 . )](v9) ; at :10:20 L20(v9) ; at :10:20 L20(v10): ; box=20 v11 :=3D scm-ref/immediate[(box . 1)](v10) ; arg at :10:20 eq?(v5, v11) ? L22() : L37() ; at :16:26 L37(): throw throw/value+data[#(wrong-type-arg foo-x "Wrong type argument: ~S"= )](v4) ; at :16:26 L22(): v12 :=3D word-ref/immediate[(struct . 6)](v5) ; rfields at :16:26 v13 :=3D v12 ; nfields at :16:26 imm-u64-<[0](v13) ? L25() : L35() ; at :16:26 L35(): v21 :=3D const 0 ; _ at :16:26 throw throw/value+data[#(out-of-range "struct-ref/immediate" "Argument = 2 out of range: ~S")](v21) ; at :16:26 L25(): v14 :=3D pointer-ref/immediate[(struct . 7)](v5) ; ptr at :16:26 v15 :=3D load-u64[0]() ; word at :16:26 v16 :=3D u32-ref[bitmask](v5, v14, v15) ; bits at :16:26 v17 :=3D load-u64[1]() ; mask at :16:26 v18 :=3D ulogand(v17, v16) ; res at :16:26 u64-imm-=3D[0](v18) ? L31() : L33() ; at :16:26 L33(): v20 :=3D const 0 ; _ at :16:26 throw throw/value+data[#(wrong-type-arg "struct-ref/immediate" "Wrong t= ype argument in position 2 (expecting boxed field): ~S")](v20) ; at :16:26 L31(): v19 :=3D scm-ref/immediate[(struct . 1)](v4) ; val at :16:26 return v19 ; at :16:26 Here we see the first procedure which is the thunk that wraps the expression. Then in the beginning of the procedure at L7 you can see there is a check for struct?, which has to be dominated by a true heap-object? check. Duplicate checks are elided. So if SRFI-9 added a `struct?` check it wouldn't be more code; rather it would be less, actually, because instead of branching to L38, you'd branch to L37. Too bad about all that other crap about checking whether the index is in range and the field is boxed or not, though :-/ Probably there is a better design... Andy