From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id IPKVLx/Z3GCSZQEAgWs5BA (envelope-from ) for ; Wed, 30 Jun 2021 22:50:39 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id KMZFKx/Z3GAYRAAAB5/wlQ (envelope-from ) for ; Wed, 30 Jun 2021 20:50:39 +0000 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 7F62C1D9AC for ; Wed, 30 Jun 2021 22:50:39 +0200 (CEST) Received: from localhost ([::1]:54634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyhAM-0001w2-I3 for larch@yhetil.org; Wed, 30 Jun 2021 16:50:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lyh9r-0000zw-KE for guix-patches@gnu.org; Wed, 30 Jun 2021 16:50:07 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:47416) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lyh9r-0001l2-6E for guix-patches@gnu.org; Wed, 30 Jun 2021 16:50:07 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lyh9r-0005Cx-5J for guix-patches@gnu.org; Wed, 30 Jun 2021 16:50:07 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49169] [PATCH v2 10/16] utils: 'edit-expression' copies part of the original source map. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 30 Jun 2021 20:50:07 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49169 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49169@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 49169-submit@debbugs.gnu.org id=B49169.162508615619851 (code B ref 49169); Wed, 30 Jun 2021 20:50:07 +0000 Received: (at 49169) by debbugs.gnu.org; 30 Jun 2021 20:49:16 +0000 Received: from localhost ([127.0.0.1]:58942 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lyh91-0005A1-KP for submit@debbugs.gnu.org; Wed, 30 Jun 2021 16:49:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47902) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lyh8o-000562-Dt for 49169@debbugs.gnu.org; Wed, 30 Jun 2021 16:49:02 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:53138) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lyh8i-0000zt-Tf; Wed, 30 Jun 2021 16:48:57 -0400 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=42586 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lyh8i-0001jQ-Hn; Wed, 30 Jun 2021 16:48:56 -0400 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Wed, 30 Jun 2021 22:48:26 +0200 Message-Id: <20210630204832.25753-11-ludo@gnu.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210630204832.25753-1-ludo@gnu.org> References: <20210622090221.15182-1-ludo@gnu.org> <20210630204832.25753-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1625086239; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=EjfjJ2tM6/U2Nc9yo8mZ+d4Du77LJ3c2VzS78xDBOnw=; b=bguzCAi6UHkHIzHloKh7rnMectidpfaGyCrTbMiOj/pUhZVLZsLhxahdIy4niJJ6cI4ZAi kRQf1RRVSSDCpTVQEj1fKhBykLT78cSou7lZQkMKRUbiWcXkmt4F1h2DhPMg9Rtc+B18yU b1Izd6i65xEJoZVZtcEIXm1SaMSZZ1YYPA4/jkJVOJSIwKwGqadd4epmsaz2n6avmCE0YQ krX99zVmae1zIhigUZN1pgzi6kkuwh+HlICXMr+9Yj9A66qQ/GJhqslduT5dme5E8JkBGE u5QKheH2tDc2U3nL874c4q0dMHB9TM2ZSyA5fG1ZXwPJ1MISw8s835uzwQWEWg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1625086239; a=rsa-sha256; cv=none; b=oD+sdkPG1ue4uYPNozVaPWOhjs5rCaO0cqqGiP0oALBsvGB19AqTE5Zb1ALccwQIDLbwNr xOmn77yY7RubipeLbpT98xcm4ih9LzNkiJ1M2/bUgwDgZi45y9JULeZtMcwBSfIHQLdwmK FkBaVUtqyNkSwqub3ZUoqN0fxxM5viCnnC6rQqEJFltsmStcv/N+6QjfnnANv7AEsAg647 N9+tHoPCZ5vxF4+vYasqKifrsX8PkNrrl6ot0xqMU1APnnYxzW3maXpCL9mNaNIE6RZmQ/ ABzGb9rk1SILhkKtzj2ReE5sVdTLPxf7G0jmA210cppCsUHprafS4ghf1eizPQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 3.58 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 7F62C1D9AC X-Spam-Score: 3.58 X-Migadu-Scanner: scn1.migadu.com X-TUID: TafvGXA+I3GX * guix/utils.scm (source-location-key/stamp): New procedure. (go-to-location): Use it. (move-source-location-map!): New procedure. (edit-expression): Call it. --- guix/utils.scm | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/guix/utils.scm b/guix/utils.scm index e6d0761679..65d709a01f 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -34,6 +34,7 @@ #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) #:use-module (srfi srfi-39) + #:use-module (srfi srfi-71) #:use-module (ice-9 ftw) #:use-module (rnrs io ports) ;need 'port-position' etc. #:use-module ((rnrs bytevectors) #:select (bytevector-u8-set!)) @@ -344,14 +345,20 @@ a list of command-line arguments passed to the compression program." ;; 'go-to-location'. (make-hash-table)) -(define (go-to-location port line column) +(define (source-location-key/stamp stat) + "Return two values: the key for STAT in %SOURCE-LOCATION-MAP, and a stamp +used to invalidate corresponding entries." + (let ((key (list (stat:ino stat) (stat:dev stat))) + (stamp (list (stat:mtime stat) (stat:mtimensec stat) + (stat:size stat)))) + (values key stamp))) + +(define* (go-to-location port line column) "Jump to LINE and COLUMN (both one-indexed) in PORT. Maintain a source location map such that this can boil down to seek(2) and a few read(2) calls, which can drastically speed up repetitive operations on large files." (let* ((stat (stat port)) - (key (list (stat:ino stat) (stat:dev stat))) - (stamp (list (stat:mtime stat) (stat:mtimensec stat) - (stat:size stat))) + (key stamp (source-location-key/stamp stat)) ;; Look for an up-to-date source map for KEY. The map is a vlist ;; where each entry gives the byte offset of the beginning of a line: @@ -398,6 +405,20 @@ which can drastically speed up repetitive operations on large files." (set-port-line! port (- line 1)) (set-port-column! port (- column 1)))) +(define (move-source-location-map! source target line) + "Move the source location map from SOURCE up to LINE to TARGET. SOURCE and +TARGET must be stat buffers as returned by 'stat'." + (let* ((source-key (source-location-key/stamp source)) + (target-key target-stamp (source-location-key/stamp target))) + (match (hash-ref %source-location-map source-key) + (#f #t) + ((_ ... source-map) + ;; Strip the source map and update the associated stamp. + (let ((source-map (vlist-take source-map (max line 1)))) + (hash-remove! %source-location-map source-key) + (hash-set! %source-location-map target-key + `(,@target-stamp ,source-map))))))) + (define* (edit-expression source-properties proc #:key (encoding "UTF-8")) "Edit the expression specified by SOURCE-PROPERTIES using PROC, which should be a procedure that takes the original expression in string and returns a new @@ -435,7 +456,13 @@ This procedure returns #t on success." ;; post-bv maybe the end-of-file object. (when (not (eof-object? post-bv)) (put-bytevector out post-bv)) - #t))))))))) + #t)) + + ;; Due to 'with-atomic-file-output', IN and FILE no longer share + ;; the same inode, but we can reassign the source map up to LINE + ;; to the new file. + (move-source-location-map! (stat in) (stat file) + (+ 1 line))))))))) ;;; -- 2.32.0