Subject: bug#62762: circular dependencies in elisp files and make

From: Max Nikulin <[email-masked]>
Date: Sat, 13 May 2023 18:21:56 +0700

On 13/05/2023 17:58, Eli Zaretskii wrote:
>> Date: Sat, 13 May 2023 17:25:06 +0700 From: Max Nikulin
>>
>> On 13/05/2023 15:46, Eli Zaretskii wrote:
>>>> Date: Sat, 13 May 2023 14:34:06 +0700 From: Max Nikulin
>>>>
>>>> 1. A script reads dependency files (if they exist) created during
----------^^^^^^^^^^^^^^^^^^^^^^^

>>>> previous build and removes stale .elc files.
>>>
>>> This will break if the updated files have different dependencies.  You
>>> need to recreate the dependencies each build.
>>
>> Let's consider a.el that contains (require 'd) or it autoloads some
>> macro from d.el. If a.el changed then a.elc is removed on this stage, so
>> updated a.elc will be created on the next stage. Dependency on d.elc is
>> known from previous build, so if d.el is changed then both a.elc and
>> d.elc are removed. If new (require 'd-new) is added to a.el then it is
>> not a problem as well. a.elc is removed due to changed a.el. d-new.elc
>> is either up to date or it is removed due to changes in its dependencies
>> or in d-new.el.
> 
> I was talking about dependencies, not about stale files.  They will
> need to be refreshed every build, because, unlike C sources, the *.el
> files change in that aspect much more frequently.

Writing "stale" I mean more than comparison timestamps of a.el and 
a.elc. Dependency files may contain

a.elc: a.el d.elc
d.elc: d.el

the script walks through dependency graph, compares timestamps and when 
it d.el is newer than d.elc, *both* "a.elc" and "d.elc" are removed. It 
is unfortunate that a part of "make" should be implemented in the 
script, but I am unsure if some trick is suitable to leverage "make" 
power for removing of files instead of their creation.

Next compile stage updates dependency files as a side effect and new 
dependencies may appear

d.elc: d.el d-transitive.elc

however absence of d-transitive.elc during dependency removing stage 1 
does not lead to any problem.