C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Revising #pragma once

From: Jeremy Rifkin <rifkin.jer_at_[hidden]>
Date: Sun, 1 Sep 2024 17:53:38 -0500
> Ah right. fs::equivalent compares whether two files (which must be openable)
are the same. Which in turn means it's unlikely to be what gets used to
implement the functionality in the compiler, because opening every previously-
used file to compare it to the one you're about to open is too expensive: O(n²)
to the number of distinct file paths.

To quickly clarify, I brought up std::filesystem::equivalent only
because of the wording around it, not as a suggestion for how to
actually implement #pragma once. IIUC clang's current implementation
boils down to "same device at the same location" while not being
inefficient as you express concern about here.

On Sun, Sep 1, 2024 at 5:26 PM Thiago Macieira via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> On Sunday 1 September 2024 13:08:51 GMT-7 Andrey Semashev via Std-Proposals
> wrote:
> > > The MS STL implementation uses GetFileInformationByHandleEx(), so it can
> > > compare the 128-bit unique identifier. The libstdc++v3 and libcxx
> > > implementations use GetFileInformationByHandle(), so they suffer from the
> > > same problem as Coverity did.
> >
> > They don't, as long as they keep both files open while obtaining and
> > comparing file ids. Which std::filesystem::equivalent is able to do,
> > unlike Coverity or a C++ compiler, as that would substantially increase
> > system resource consumption during compilation.
>
> Ah right. fs::equivalent compares whether two files (which must be openable)
> are the same. Which in turn means it's unlikely to be what gets used to
> implement the functionality in the compiler, because opening every previously-
> used file to compare it to the one you're about to open is too expensive: O(n²)
> to the number of distinct file paths. Especially on Windows, where opening files
> is slow all by itself, and only gets worse with networked filesystems.
>
> The solution needs to be O(n).
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Principal Engineer - Intel DCAI Platform & System Engineering
>
>
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-09-01 22:53:51