From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from codesynthesis.com (codesynthesis.com [188.40.148.39]) by sourceware.org (Postfix) with ESMTPS id 5C4143858C2C for ; Fri, 22 Apr 2022 14:08:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5C4143858C2C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesynthesis.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=codesynthesis.com Received: from brak.codesynthesis.com (unknown [105.186.193.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by codesynthesis.com (Postfix) with ESMTPSA id E5537603F5; Fri, 22 Apr 2022 14:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codesynthesis.com; s=mail1; t=1650636489; bh=c8hiPhltNolZRquqFehBNgJYqMv7dNPSn9QmiO7BHN4=; h=Date:From:To:Subject:Message-ID:MIME-Version:From; b=dxKsWUX4QUGmAwuSTzYQxhU1GYMsV3MO52DsGTquXSLRSGj735fJqIRgxKazB6dc+ 9f29oLgcR6AaED4At+OMMlHYatIwyPP2BHDO4kt7JHlarx/br9g+Jv9yq03GsPTBsi dmtLFK5WpHlf/Ng+oz4Hk1T54cfnSwO9DFKtquK+z1KcrL1f1GCpiKd84oEbesJyv2 MsQbPr7xeQwkrZS3UR2WJKKHhrp6LMMeIMnYNAUtjdt2OAkbQzWr+4Hy1rWqe9KMYV mIOTea4brUR0sw4bKO0onT38Sd8HAZi3afZzWO/kfWRpEb+/I04G11faXRFJYBRAvy I6FR9m1uwdoWg== Received: by brak.codesynthesis.com (Postfix, from userid 1000) id CB3E21A802AE; Fri, 22 Apr 2022 16:08:00 +0200 (SAST) Date: Fri, 22 Apr 2022 16:08:00 +0200 From: Boris Kolpackov To: Ben Boeckel Cc: gcc@gcc.gnu.org Subject: Re: [modules] Preprocessing requires compiled header unit modules Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Code Synthesis User-Agent: Mutt/1.5.24 (2015-08-30) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Apr 2022 14:08:12 -0000 Ben Boeckel writes: > On Thu, Apr 21, 2022 at 06:05:52 +0200, Boris Kolpackov wrote: > > > I don't think it is. A header unit (unlike a named module) may export > > macros which could affect further dependencies. Consider: > > > > import "header-unit.hpp"; // May or may not export macro FOO. > > > > #ifdef FOO > > import "header-unit2.hpp"; > > #endif > > I agree that the header needs to be *found*, but scanning cannot require > a pre-existing BMI for that header. Well, if scanning cannot require a pre-existing BMI but a pre-existing BMI is required to get accurate dependency information, then something has to give. You hint at a potential solution in your subsequent email: > Can't it just read the header as if it wasn't imported? AFAIU, that's > what GCC did in Jan 2019. I understand that CPP state is probably not > easy, but something to consider. The problem with this approach is that a header import and a header include have subtly different semantics around macros. In particular, the header import does not "see" macros defined by the importer while the header include does. Here is an example: // file: header-unit.hpp // #ifdef BAR #define FOO #endif // file: importer.cpp // #define BAR import "header-unit.hpp"; // Should not "see" BAR. //#include "header-unit.hpp" // Should "see" BAR. #ifdef FOO import "header-unit2.hpp"; #endif In this example, if you treat import of header-unit.hpp as include, you will get incorrect dependency information. So to make this work correctly we will need to re-create the macro isolation semantics of import for include. Even if we manage to do this, there are some implications I am not sure we will like: the isolated macros will contain inclusion guards, which means we will keep re-scanning the same files potentially many many time. Here is an example, assume each header-unitN.hpp includes or imports : // file: importer.cpp // import ; // Defined _GLIBCXX_FUNCTIONAL include import "header-unit1.hpp"; // Ignores _GLIBCXX_FUNCTIONAL import "header-unit2.hpp"; // Ditto. import "header-unit3.hpp"; // Ditto. import "header-unit4.hpp"; // Ditto.