From patchwork Mon Apr 15 15:37:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 63055 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 77B3027BBEB; Mon, 15 Apr 2024 16:39:20 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 6432C27BBE9 for ; Mon, 15 Apr 2024 16:39:19 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rwOQ2-0006I0-SB; Mon, 15 Apr 2024 11:38:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rwOQ1-0006HY-Ee for guix-patches@gnu.org; Mon, 15 Apr 2024 11:38:53 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rwOQ1-0001bY-5v; Mon, 15 Apr 2024 11:38:53 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rwOQB-000805-8b; Mon, 15 Apr 2024 11:39:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70398] [PATCH 3/5] records: Do not inline the constructor. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Mon, 15 Apr 2024 15:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70398 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70398@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 70398-submit@debbugs.gnu.org id=B70398.171319550130407 (code B ref 70398); Mon, 15 Apr 2024 15:39:02 +0000 Received: (at 70398) by debbugs.gnu.org; 15 Apr 2024 15:38:21 +0000 Received: from localhost ([127.0.0.1]:37902 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rwOPU-0007uG-4I for submit@debbugs.gnu.org; Mon, 15 Apr 2024 11:38:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60120) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rwOPG-0007q0-HP for 70398@debbugs.gnu.org; Mon, 15 Apr 2024 11:38:07 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rwOOy-0001UD-Fs; Mon, 15 Apr 2024 11:37:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=1ICemtEEU1CmhNI7sFvE9ToBYNnUj1tEAAedcWXFjdc=; b=a+XL1m1yYrn9FByrq3AK ExBKiCq26aGxG9x/uxLvEA8Zy0/IIE/yWjt5NI+Q9TUix6yXVKvtjqpcQzBlkNh/t1UPkvAkabdLt YbnWn9EbsyzoyMmY28zQwI6GitrKoXTTyK173Se8YR4W47wDU8jpm5MDhz2YSxr/XOwBIHvTWem1r DY2vI8jRqXSSptky1jf9ob335zNy11Y0TAL1uLoVzbC8uhp63r8hfq+WDQC+IMoTYqDgW5OcnEn31 U/daNdBICHrViFAN1WLMGGfA/gLeGhTXWyjbQFQlv2DZt4kbEc9Ttv3UP/t1+W4iwKZOG9aygnNqo fbqwh+QfZ4Ej7Q==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Mon, 15 Apr 2024 17:37:05 +0200 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Struct initialization uses one instruction per field, which contributes to code bloat in the case of package modules. With this change, the ‘.rtl-text’ section of ‘gnu/packages/tex.go’ goes from 7,334,508 B to 6,356,592 B (-13%; -7% on the whole file size), which alone is still larger than the source file (4,2 MB). * guix/records.scm (make-syntactic-constructor)[record-inheritance]: Use CTOR instead of ‘make-struct/no-tail’. Pass ABI-COOKIE as the first argument to CTOR. (define-record-type*): Define CTOR-PROCEDURE and pass it to ‘make-syntactic-constructor’. Change-Id: Ifd7b4e884e9fbf21c43fb4c3ad963126ef5cb476 --- guix/records.scm | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/guix/records.scm b/guix/records.scm index 48637ea0a4..dca1e3c2e7 100644 --- a/guix/records.scm +++ b/guix/records.scm @@ -164,16 +164,16 @@ (define-syntax make-syntactic-constructor (record-error 'name s "extraneous field initializers ~a" unexpected))) - #`(make-struct/no-tail type - #,@(map (lambda (field index) - (or (field-inherited-value field) - (if (innate-field? field) - (wrap-field-value - field (field-default-value field)) - #`(struct-ref #,orig-record - #,index)))) - '(expected ...) - (iota (length '(expected ...)))))) + #`(ctor #,abi-cookie + #,@(map (lambda (field index) + (or (field-inherited-value field) + (if (innate-field? field) + (wrap-field-value + field (field-default-value field)) + #`(struct-ref #,orig-record + #,index)))) + '(expected ...) + (iota (length '(expected ...)))))) (define (thunked-field? f) (memq (syntax->datum f) 'thunked)) @@ -249,8 +249,8 @@ (define-syntax make-syntactic-constructor (cond ((lset= eq? fields '(expected ...)) #`(let* #,(field-bindings #'((field value) (... ...))) - #,(abi-check #'type abi-cookie) - (ctor #,@(map field-value '(expected ...))))) + (ctor #,abi-cookie + #,@(map field-value '(expected ...))))) ((pair? (lset-difference eq? fields '(expected ...))) (record-error 'name s @@ -435,7 +435,13 @@ (define-syntax define-record-type* (sanitizers (filter-map field-sanitizer #'((field properties ...) ...))) (cookie (compute-abi-cookie field-spec))) - (with-syntax (((field-spec* ...) + (with-syntax ((ctor-procedure + (datum->syntax + #'ctor + (symbol-append (string->symbol " %") + (syntax->datum #'ctor) + '-procedure/abi-check))) + ((field-spec* ...) (map field-spec->srfi-9 field-spec)) ((field-type ...) (map (match-lambda @@ -502,7 +508,20 @@ (define-syntax define-record-type* #'id))))))) thunked-field-accessor ... delayed-field-accessor ... - (make-syntactic-constructor type syntactic-ctor ctor + + (define ctor-procedure + ;; This procedure is *not* inlined, to reduce code bloat + ;; (struct initialization takes at least one instruction per + ;; field). + (case-lambda + ((cookie field ...) + (unless (eq? cookie #,cookie) + (record-abi-mismatch-error type)) + (ctor field ...)) + (_ + (record-abi-mismatch-error type)))) + + (make-syntactic-constructor type syntactic-ctor ctor-procedure (field ...) #:abi-cookie #,cookie #:thunked #,thunked