Subject: Re: bug#62537: Error compiling emacs master with native compilation activated

From: Andrea Corallo <[email-masked]>
Date: Fri, 31 Mar 2023 10:26:20 +0000

Andrea Corallo <[email-masked]> writes:

> Mattias Engdegård <[email-masked]> writes:
>
>> 30 mars 2023 kl. 11.28 skrev Andrea Corallo <[email-masked]>:
>>
>>> bisecting this should be due to:
>>> "
>>> 52b67740d10df8ca539fdc2c7d50283997683141
>>
>>> Generalise a LAP optimisation rule
>>
>> That change should be entirely safe. Perhaps it just somehow triggers an unexpected path in nativecomp?
>
> That's entirely possible :)
>
> Will look at and report.
>
>   Andrea

I haven't had time to complete the investigation/fix but as data
point...

This is the most reduced reproducer I could produce:

;;; -*- lexical-binding: t; -*-
(defun test ()
  (when (let
            ((val
              (foo)))
          (cond
           ((eq val 'x)
            t)
           ((eq val 'y)
            'y)))
    (foo))
  t)

This is the old LAP:

(byte-constant foo . 0)
(byte-call . 0)
(byte-dup)
(byte-constant #s(hash-table size 2 test eq rehash-size 1.5 rehash-threshold 0.8125 purecopy t data (x 8 y 12)) . 1)
(byte-switch)
(byte-goto TAG 16 . 1)
(TAG 8 . 1)
(byte-constant t . 2)
(byte-goto TAG 17 . 2)
(TAG 12 . 1)
(byte-constant t . 2)
(byte-goto TAG 17 . 2)
(TAG 16 . 1)
(byte-constant nil . 3)
(TAG 17 . 2)
(byte-stack-set . 1)
(byte-goto-if-nil TAG 25 . 0)
(byte-constant foo . 0)
(byte-call . 0)
(byte-discard)
(TAG 25 . 0)
(byte-constant t . 2)
(byte-return . 0)

This is the new one:

(byte-constant foo . 0)
(byte-call . 0)
(byte-dup)
(byte-constant #s(hash-table size 2 test eq rehash-size 1.5 rehash-threshold 0.8125 purecopy t data (x 9 y 9)) . 1)
(byte-switch)
(byte-discard)
(byte-goto TAG 13 . 0)
(TAG 9 . 1)
(byte-discard)
(byte-constant foo . 0)
(byte-call . 0)
(byte-discard)
(TAG 13 . 0)
(byte-constant t . 2)
(byte-return . 0)

At a very quick look I don't see anything wrong with it so as
anticipated most lickly is just a bug in the native compiler limplify
pass.

Best Regards

  Andrea