all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Maxim Cournoyer <maxim.cournoyer@gmail.com>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: "Jakub Kądziołka" <kuba@kadziolka.net>, 42146@debbugs.gnu.org
Subject: [bug#42146] [PATCH core-updates 1/?] build: substitute: Don't fail silently.
Date: Mon, 23 Oct 2023 11:05:31 -0400	[thread overview]
Message-ID: <87ttqh751g.fsf@gmail.com> (raw)
In-Reply-To: <875y2xivbz.fsf_-_@gnu.org> ("Ludovic Courtès"'s message of "Mon, 23 Oct 2023 10:42:08 +0200")

Hi Ludovic,

Ludovic Courtès <ludo@gnu.org> writes:

> Hi Maxim,
>
> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>
>> Ludovic Courtès <ludo@gnu.org> writes:
>
> [...]
>
>>>> +;;; Extend regexp objects with a pattern field.
>>>> +;;;
>>>> +(define-record-type <regexp*>
>>>> +  (%make-regexp* pat flag rx)
>>>> +  regexp*?
>>>> +  (pat regexp*-pattern)                 ;the regexp pattern, a string
>>>> +  (flag regexp*-flag)                   ;regexp flags
>>>> +  (rx regexp*-rx))                      ;the compiled regexp object
>>>> +
>>>> +;;; Work around regexp implementation.
>>>> +;;; This record allows to track the regexp pattern and then display it.
>>>> +(define* (make-regexp* pat #:optional (flag regexp/extended))
>>>
>>> I’m skeptical about the concrete benefits.  I would not include it in
>>> (guix build utils), or at least not in this patch series.
>
> [...]
>
>> The benefit is concrete: it makes it possible to show which regexp
>> pattern failed to match (its textual representation), instead of
>> something much less useful such as a generic placeholder such as
>> "<unknown> (regexp)".
>
> Yes, okay.
>
> Can we keep the <regexp*> interface private, then?  To me it’s an
> implementation detail and perhaps a bit of a hack that I’d rather not
> commit to maintaining.

If you can think of a more elegant way to define it, I'm all ears.
Ideally, as Simon pointed out, that's something that Guile would support
natively (the ability to pull back the raw pattern from a regexp
object).  In Python for example, the re.Pattern object has a 'pattern'
property [0]

[0]  https://docs.python.org/3/library/re.html?highlight=regex#re.Pattern.pattern

Otherwise I don't think "the bit of a hack" is substantiated enough :-).

> The cost might be to duplicate it in teams.scm, but that’s an acceptable
> cost IMO.

I dislike copying bits around just to "hide" them from the "official"
interface, and have no fear maintaining that simple piece of code, so
I'd rather keep it at one place and expose it as a public API.

>> It's in actual use if you look at the definition of substitute:
>>
>>
>>   (let ((rx+proc (map (match-lambda
>>                         (((or (? regexp? pattern) (? regexp*? pattern)) . proc)
>>                          (cons pattern proc))
>>                         ((pattern . proc)
>>                          (cons (make-regexp* pattern regexp/extended) proc)))
>>                       pattern+procs)))
>>
>> The previous version followed a different approach, annotating the
>> rx+proc list with the raw pattern; I think the approach here is a bit
>> cleaner, and it should also enable users to pass pre-computed regexp*
>> objects to substitute* and have useful error messages produced.
>
> Note that ‘substitute*’ only takes string literals as patterns, not
> regexp objects.  The pattern part of clauses has sometimes been abused
> to pass code, typically ‘string-append’ calls, but that’s definitely not
> the spirit.
>

It's true that 'substitute*' only accepts literal patterns, but that's
not the case with 'substitute' itself, which is also exposed in the API
of (guix build utils): it accepts regexp objects as well, and thus
there's value in this change -- users could in theory use make-regexp*
objects and pass that to 'substitute' and benefit from more precises
error messages.

> Another approach would have been, in ‘substitute*’, to capture the
> regexp-as-string as well as other useful debugging info, such as its
> source location.

That'd be a nice solution, but it doesn't take into account
'substitute', as mentioned above.  As it has exactly zero (!) users
outside of substitute*, perhaps it could be yanked from the public API
and then we could consider doing the above for substitute* ?

-- 
Thanks,
Maxim




  reply	other threads:[~2023-10-23 15:07 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-30 22:09 [bug#42146] [PATCH core-updates 1/?] build: substitute: Don't fail silently Jakub Kądziołka
2020-06-30 22:11 ` [bug#42146] [PATCH 2/?] build: bootstrap-configure: Allow lack of matches in substitute Jakub Kądziołka
2020-06-30 22:11 ` [bug#42146] [PATCH 3/?] gnu: commencement: Build fix for %bootstrap-mes-rewired Jakub Kądziołka
     [not found] ` <handler.42146.B.159355497531278.ack@debbugs.gnu.org>
2020-06-30 22:50   ` [bug#42146] [PATCH core-updates 1/?] build: substitute: Don't fail silently Jakub Kądziołka
2023-10-19 13:14     ` Maxim Cournoyer
2020-07-01  0:42 ` [bug#42146] [PATCH 4/?] gnu: mes-boot: Use verbosity settings integrated into buildsystem Jakub Kądziołka
2020-07-01  0:42 ` [bug#42146] [PATCH 5/?] build-system/gnu: Allow lack of matches in substitution phases Jakub Kądziołka
2020-07-01  9:55 ` [bug#42146] [PATCH 6/6] gnu: glibc-mesboot0: Fixup the fixup-configure phase Jakub Kądziołka
2023-10-19 20:33 ` [bug#42146] [PATCH 1/3] build: Relocate <regexp*> record and associated procedures here Maxim Cournoyer
2023-10-19 20:33   ` [bug#42146] [PATCH 2/3] build: substitute: Error when no substitutions were done Maxim Cournoyer
2023-10-19 20:49     ` [bug#42146] [PATCH core-updates 1/?] build: substitute: Don't fail silently Ludovic Courtès
2023-10-20 18:50       ` Bruno Victal
2023-10-20 21:11         ` Maxim Cournoyer
2023-10-19 20:33   ` [bug#42146] [PATCH 3/3] build: bootstrap-configure: Allow lack of matches in substitute Maxim Cournoyer
2023-10-19 20:51     ` [bug#42146] [PATCH core-updates 1/?] build: substitute: Don't fail silently Ludovic Courtès
2023-10-19 20:40   ` Ludovic Courtès
2023-10-19 23:54     ` Maxim Cournoyer
2023-10-23  8:42       ` Ludovic Courtès
2023-10-23 15:05         ` Maxim Cournoyer [this message]
2023-10-20 15:11     ` Simon Tournier
2023-10-20 15:39       ` Maxim Cournoyer
2023-10-20  0:57 ` [bug#42146] [PATCH v3 1/3] build: Relocate <regexp*> record and associated procedures here Maxim Cournoyer
2023-10-20  0:57   ` [bug#42146] [PATCH v3 2/3] build: substitute: Error when no substitutions were done Maxim Cournoyer
2023-10-23  8:48     ` [bug#42146] [PATCH core-updates 1/?] build: substitute: Don't fail silently Ludovic Courtès
2023-10-23 16:25       ` Maxim Cournoyer
2023-10-23  8:51     ` Ludovic Courtès
2023-10-20  0:57   ` [bug#42146] [PATCH v3 3/3] build: bootstrap-configure: Allow lack of matches in substitute Maxim Cournoyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ttqh751g.fsf@gmail.com \
    --to=maxim.cournoyer@gmail.com \
    --cc=42146@debbugs.gnu.org \
    --cc=kuba@kadziolka.net \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.