Subject: bug#65017: 29.1; Byte compiler interaction with cl-lib function objects, removes symbol-function

From: Stefan Monnier <[email-masked]>
Date: Wed, 09 Aug 2023 23:41:56 -0400

>> > Are you sure?
>> Yes.
> What about two SWPs with the same symbol but different positions?  If
> they aren't considered EQ here, there will never be a match for the
> first arm of the cond form in cl--labels-convert; then
> cl--labels-convert-cache will get written, but never used.

Nope: when it gets written, the `function` macro returns:

    (function <THESYMWITHPOS>)

so the macro is immediately called again with the *exact* same
<THESYMWITHPOS>, so the second time the `function` macro is called, the
cache does hit (and it's the only case where it should hit), making the
second call to the macro return the *exact* `eq`-same

    (function <THESYMWITHPOS>)

list which is the trick that stops the infinite macroexpansion loop.

Next time the `function` macro is invoked with a "similar" sympos the
cache should *not* match because we don't want to accidentally replace

    (function <SOMESYMWITHPOS>)
with
    (function <THESYMWITHPOS>)

> And if, somehow, it does get used (the current code, I think), then (as
> you write below) the argument F will get replaced by an F with the wrong
> position.  Am I right, here?

That's right.

> Why must the F get replaced by a different F?  There must surely be a
> way, a simpler way than the current cl--labels-convert, to retain the
> current F (hence, not corrupting its position)?

There might.  The current hack is the best I could come up with.

>> > If cl--labels-convert-cache is being used
>> > inside the byte compiler, it surely needs to consider #<symbol foo at
>> > 42> and #<symbol foo at 60> as eq?
>> No, it should not treat them equal (when it does, it introduces an
>> incorrect sympos and can thus lead to error messages pointing at the
>> wrong place).
> Then isn't what is wrong here the introduction of the incorrect SWP
> rather than treating the two SWPs as EQ?

I can't see how to separate one from the other here: the introduction of
the incorrect SWP is due to treating the two SWP as `eq`.

> This is obscure, difficult code.  :-(

Agreed.

> We should think about committing a fix to the original bug,
> sometime, too.

I'm not completely sure we agree yet on what is "the original bug", but
obviously I agree with  your sentence :-)

        Stefan