Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1583825pxb; Thu, 4 Mar 2021 15:28:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJxqE72pbjtGz3dyCIo4eYphpWCuRCv0z0iPuG8mo9ooWM06f71R9EPZ4EG9ZDLESQqJnMQT X-Received: by 2002:a17:906:a3d1:: with SMTP id ca17mr6750985ejb.92.1614900535731; Thu, 04 Mar 2021 15:28:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614900535; cv=none; d=google.com; s=arc-20160816; b=yBNTDJfeaeYo1njAmo0QOg/ALR78ZJB27f1jTuC/O+/yDjGLWKf178AWd5krg3qieM Lkh/GJfTc/vBx5xtSiINS5Vi12Vz2Ty/Si8lB5ra0bN8dAcFqNvfxDXRDr6F0ibmlD49 zoD4Nb/o6Eg5lovuZw9N90h+d2WJG2mJujRo2lyEP4CXFTraMSCAwyRm66H5lZrV2Nr7 FYAFsu4y4HrmjxzkUr+8/czB7ua6RDUwMdKwIetRbXMQWi6y/af5tzvZHypUKmgfVUs4 CBdknjKLql8sVNlfudp+XNKh0aJXnUu1oy8t0gLeL+Q5YScPOzdD1cs6L50RdsyKxqSO 06Hw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=WJU47HfLr24C5iHZ6QnN66/JheJ0eDT25q9fy/MswAI=; b=UImK3NnAaGZYMvI53qPK92QIZ2klTCre6ZwS4+sVJ1aA7B313u1Lpen2+b+fS4xUES n2YgZ21CBaNRHDL8kkNcGg1yTTdyov5wXhCApPf7I47gH5RPe2B2aGccMuBkqiyI84Dw INg0BTk8Vh9ee9oe6AbNuosehqgSmVWaBmyQ3lHs367J/OscMs1MWLJQC5G3/csAaGFg rA40kHvTnJ+JgpOHitDixhd3wb87cKLhDI/MfwcxZyDYMmHD9kUSB1V96nfQ8mufij9z /w42dhiBEcrVOoHDyTHLOZG+wBc5LpMyxkCiVb13iI+8vrlR78wx4Z2TN2p6lDERBuC+ K8wA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=QLA9Vfft; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c11si574939edy.117.2021.03.04.15.28.33; Thu, 04 Mar 2021 15:28:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=QLA9Vfft; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349283AbhCDACs (ORCPT + 99 others); Wed, 3 Mar 2021 19:02:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1387998AbhCCUSG (ORCPT ); Wed, 3 Mar 2021 15:18:06 -0500 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EE68C06175F for ; Wed, 3 Mar 2021 12:17:26 -0800 (PST) Received: by mail-lf1-x130.google.com with SMTP id 18so30649930lff.6 for ; Wed, 03 Mar 2021 12:17:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WJU47HfLr24C5iHZ6QnN66/JheJ0eDT25q9fy/MswAI=; b=QLA9VfftBNrxhMy11KY7iYzpDwYXuC99/HWIBxltPnMI5ztG9/vW21kc1NVhBQ/G5m kKYXenXZCPFpBe/SQLVhcB/mrEA88dF0aV5ReqvCDpu3eopgJZPnBvojk7pBjyjLHpHb aIaG3jG6p0K8uMEl9uNHlxdJPHLRoguFi63uw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WJU47HfLr24C5iHZ6QnN66/JheJ0eDT25q9fy/MswAI=; b=C7odhaCF34ZiIq/J/WdFRfmYelKp3ukero04Qkv3vEMqx2kDCzCTL13mMFk3IdQO3L ZUTL4HlSRho/f0EPGPuowyhIpYeuiBNvu1WkcjxEGFKT3YaSJafCiHA4+bo0UW1fboly 5mT7fYmJqBcmcwTCH+4P93pG21R93UBYKIFuSI/zsSVHFN5zW8dwFk3dCProjeN+fW3J e5y9hOsh+P/emLXaKTVT620E+EPB3scFi7hGnWs9sx5tDhJNrqs12I6eCqGellSwkKAD HFHSuTtASpQvkl0rbqafuPkxLHj4e04S04e2QSq6kdFvbGVcwZlx+JDqgnrXsKNGtYSC zTpg== X-Gm-Message-State: AOAM533J3CVrqS++Y3GZ3P8Vxf2gZgvbidTJMcqrTtJtPmWHMwWQNqH+ 98ZoER1MXzVFxrVIi7jBM2DRb/uIHZy3Mg== X-Received: by 2002:ac2:51ac:: with SMTP id f12mr176601lfk.605.1614802643975; Wed, 03 Mar 2021 12:17:23 -0800 (PST) Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com. [209.85.167.47]) by smtp.gmail.com with ESMTPSA id j1sm711414lfb.18.2021.03.03.12.17.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Mar 2021 12:17:23 -0800 (PST) Received: by mail-lf1-f47.google.com with SMTP id q25so18989593lfc.8 for ; Wed, 03 Mar 2021 12:17:23 -0800 (PST) X-Received: by 2002:a19:ed03:: with SMTP id y3mr226039lfy.377.1614802642636; Wed, 03 Mar 2021 12:17:22 -0800 (PST) MIME-Version: 1.0 References: <877dmo10m3.fsf@tromey.com> In-Reply-To: <877dmo10m3.fsf@tromey.com> From: Linus Torvalds Date: Wed, 3 Mar 2021 12:17:06 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 00/11] pragma once: treewide conversion To: Tom Tromey Cc: Alexey Dobriyan , Luc Van Oostenryck , Linux Kernel Mailing List , Andrew Morton , Sparse Mailing-list Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 3, 2021 at 11:46 AM Tom Tromey wrote: > > It's also worth noting that in GCC it is slower than include guards. > See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58770 > > It's just a bug, probably easy to fix. On the other hand, nobody has > ever bothered to do so. That bugzilla is actually worth reading, if only to explain how the include guard is more robust technology compared to #pragma once. The traditional include guarding with #ifndef/#define/#endif around the contents has the advantage that a compiler _can_ generate the obvious trivial optimizations of just memoizing that "oh, I've seen this filename already, and it had that include guard pattern, so I don't need to include it again". But, I hear you say "that's exactly what '#pragma once' does too!". No, it's not. There's actually two huge and very fundamental differences between '#pragma once' and the traditional include guard optimization: (a) the traditional include guard optimization HAS NO HIDDEN SEMANTIC MEANING. It's a pure optimization that doesn't actually change anything else. If you don't do the optimization, absolutely nothing changes. (b) the traditional include guard model allows for overriding and is simply more flexible And the GCC bugzilla talks about some of the issues with (a), and I already mentioned one similar issue with (a) wrt sparse: exactly what is it that "#pragma once" really protects? Is it the filename? Is it the _canonical_ filename? What about symbolic links or hardlinks? Is it the inode number? What about filesystems that don't really have those concepts? The above questions aren't some made-up example. They are literally FUNDAMENTAL DESIGN MISTAKES in "#pragma once". In contrast, include guards just work. You give the guard an explicit name, and that solves all the problems above, and allows for extra flexibility (ie the (b) issue: you can override things and include things twice if you know you're playing games, but you can also use the guard name to see "have I already included this file" for when you have possible nasty circular include file issues etc). So the traditional include guard model is simply technically the superior model. This is why I'm NAK'ing "#pragma once". It was never a good idea, and the alleged advantage ("faster builds by avoiding double includes") was always pure garbage because preprocessors could do the same optimization using the traditional include guards. In fact, because the traditional include guards have well-defined meaning and doesn't have any of the questions about what makes a file unique, and a missed optimization doesn't cause any semantic differences, a compiler has a much _easier_ time with that optimization than with the ostensibly simpler "#pragma once". Most #pragma things are not wonderful. But '#pragma once' is actively bad. Linus