From patchwork Sun Jul 2 16:32:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Boeckel X-Patchwork-Id: 11527 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp46495vqx; Sun, 2 Jul 2023 09:35:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5oYDOY1zmMT4HqpiuFiej94Y8u/RzZKnir6vsmRwl4pqZdHvWAOdYkHr7edfGdnD0ZP46L X-Received: by 2002:a17:907:3e07:b0:985:259f:6f50 with SMTP id hp7-20020a1709073e0700b00985259f6f50mr12527449ejc.34.1688315700970; Sun, 02 Jul 2023 09:35:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688315700; cv=none; d=google.com; s=arc-20160816; b=Cr6PscYzuUsj7pAsL2MxteU9Y0nk+UFSeMgE35UJ8/ybsgz88zkeWsG2BYKuznc5c6 KC7Hk6ht50G16hytZVM3XMx2lB+4pCfWyaLOoHMXCTvw9wimg7/VFpM5o9Z35io6V0WJ hM14P6/4TUXypn0QTLlo7rgwGHVX3wyJz/y1qdAg4P7Tw9QwmXFOwu/Z5JphN4uTYZfn MVkQYXf/FH5Hv0Jw7RauGW70n68LqN5Jml18bhcv/pdRzQnngVE8KqqujvUVBISlvc/T gZUFRapE+0kWfMmuWDZ5MYRQx8j3cm2R7hOJg3EBs/nX8XISNjXN1blouuQE+yCVB2db GZIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=s+jofIzcmw62J8CidtpUpKrarSuEPf9dTO0lJgV/C3A=; fh=WmOQlEQshjW1IyckmJV5Nh43dgdMAM2UcuXDxiXBGYo=; b=QnYXK2EaB0w1DfAR+Z9xQ2HlNO/YY2M1gx3Q9Q8Vv5yIf6qpjGGoQiXYsEonSA2ZXH iw92tMB5E2YTFEdxp9Uc7D9rcOd3uEh6g4CMA0dRAoitOqDnzeds2RghNMfc4nDqqaE1 JTbhUdsxzN3sF2qMBBzGWHFjiSbHstFYTGxqw54QLIMofnKV0rXvTiBtJHbNR9ubu56e vxI9QfR2skwpzrYlnNDic+Umwh+xg+EwH8U1ZNdHATQa1AOnsHRYosNXIf/nfAiX+Szd sP+XnjfQwUV1c7r9FM2YH7ul7+dDJrPoVnHB3d4wMHvLD4Sler8tQMXeVqzDwn++NmT4 u0uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=J0AlHri1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id jj15-20020a170907984f00b00992e2779596si2822828ejc.827.2023.07.02.09.35.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 09:35:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=J0AlHri1; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AB62038708CA for ; Sun, 2 Jul 2023 16:33:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AB62038708CA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688315611; bh=s+jofIzcmw62J8CidtpUpKrarSuEPf9dTO0lJgV/C3A=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=J0AlHri1UeGFMZQcKOAjySNUy0r7/UJbGtdfF4lvVEUmElgsRXbZieA84TD3p7idh pS3Dk84j6OIr0eDi0GDLcN8J4peBJhehqT/evmMWP6giPDFwhIASrjScsLNwdbXe58 pABwUjc3WQw15bTYrJ0zV6jnHHZCJwgYg5szrZZM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by sourceware.org (Postfix) with ESMTPS id 11B603858417 for ; Sun, 2 Jul 2023 16:32:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 11B603858417 Received: by mail-qt1-x82d.google.com with SMTP id d75a77b69052e-40355e76338so6901631cf.3 for ; Sun, 02 Jul 2023 09:32:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688315538; x=1690907538; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=s+jofIzcmw62J8CidtpUpKrarSuEPf9dTO0lJgV/C3A=; b=K2utiRJE8rXGDVz5KvIV6ixmWYS++Qy2Og8IIbDu0mWaQeZgwERhuvP1EONkoz3eH8 cfOmVrN6hPfK990FfxUKKuCP+y774EbKvS8BkfI+YRdLJwNYblg9Q9O+qebPQ3vYpUwf FJvimOrnX9nuzuYK5l6Oo04RKeQ0/1vx7E8bbbDPq4akKVhc8F2YGYwW43fzbOmNdSZK nwWUYXf6jopHuIzKjXZVca+0eL/ctVB0HKguDt9RD4CvMA00kqPvpHSLfheiXH8sDwps 2S6xLLKB86suY+IistO5jupEgXcEKZkX9hBJ4WjHN87NTi3GDDbUwiklM1DeeGWEnSek dTBg== X-Gm-Message-State: AC+VfDxMq+NEegWajL8PE3/vbvIDDXgkAgD2/yGZ3eDzj7SJAPux+ppm ThWoZrPdHgomGLX/zxN8JCFgE3gX7HspFzK5zIGNdQ== X-Received: by 2002:ac8:7d46:0:b0:3f0:a426:5f29 with SMTP id h6-20020ac87d46000000b003f0a4265f29mr11796796qtb.11.1688315538325; Sun, 02 Jul 2023 09:32:18 -0700 (PDT) Received: from localhost (cpe-142-105-146-128.nycap.res.rr.com. [142.105.146.128]) by smtp.gmail.com with ESMTPSA id f12-20020ac8134c000000b00400a1ecddf2sm7384152qtj.55.2023.07.02.09.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jul 2023 09:32:17 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Ben Boeckel , jason@redhat.com, nathan@acm.org, fortran@gcc.gnu.org, gcc@gcc.gnu.org, brad.king@kitware.com Subject: [PATCH v7 0/4] P1689R5 support Date: Sun, 2 Jul 2023 12:32:07 -0400 Message-Id: <20230702163211.3396210-1-ben.boeckel@kitware.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ben Boeckel via Gcc-patches From: Ben Boeckel Reply-To: Ben Boeckel Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770327324288310294?= X-GMAIL-MSGID: =?utf-8?q?1770327324288310294?= Hi, This patch series adds initial support for ISO C++'s [P1689R5][], a format for describing C++ module requirements and provisions based on the source code. This is required because compiling C++ with modules is not embarrassingly parallel and need to be ordered to ensure that `import some_module;` can be satisfied in time by making sure that any TU with `export import some_module;` is compiled first. [P1689R5]: https://isocpp.org/files/papers/P1689R5.html I've also added patches to include imported module CMI files and the module mapper file as dependencies of the compilation. I briefly looked into adding dependencies on response files as well, but that appeared to need some code contortions to have a `class mkdeps` available before parsing the command line or to keep the information around until one was made. I'd like feedback on the approach taken here with respect to the user-visible flags. I'll also note that header units are not supported at this time because the current `-E` behavior with respect to `import ;` is to search for an appropriate `.gcm` file which is not something such a "scan" can support. A new mode will likely need to be created (e.g., replacing `-E` with `-fc++-module-scanning` or something) where headers are looked up "normally" and processed only as much as scanning requires. FWIW, Clang as taken an alternate approach with its `clang-scan-deps` tool rather than using the compiler directly. Thanks, --Ben --- v6 -> v7: - rebase onto `master` (80ae426a195 (d: Fix core.volatile.volatileLoad discarded if result is unused, 2023-07-02)) - add test cases for patches 3 and 4 (new dependency reporting in `-MF`) - add a Python script to test aspects of generated dependency files - a new `join` spec function to support `-fdeps-*` defaults based on the `-o` flag (needed to strip the leading space that appears otherwise) - note that JSON writing support should be factored out for use by `libcpp` and `gcc` (libiberty?) - use `.ddi` for the extension of `-fdeps-*` output files by default - support defaults for `-fdeps-file=` and `-fdeps-target=` when only `-fdeps-format=` is provided (with tests) - error if `-MF` and `-fdeps-file=` are both the same (non-`stdout`) file as their formats are incompatible - expand the documentation on how the `-fdeps-*` flags should be used v5 -> v6: - rebase onto `master` (585c660f041 (reload1: Change return type of predicate function from int to bool, 2023-06-06)) - fix crash related to reporting imported CMI files as dependencies - rework utf-8 validity to patch the new `cpp_valid_utf8_p` function instead of the core utf-8 decoding routine to reject invalid codepoints (preserves higher-level error detection of invalid utf-8) - harmonize of `fdeps` spelling in flags, variables, comments, etc. - rename `-fdeps-output=` to `-fdeps-target=` v4 -> v5: - add dependency tracking for imported modules to `-MF` - add dependency tracking for static module mapper files given to `-fmodule-mapper=` v3 -> v4: - add missing spaces between function names and arguments v2 -> v3: - changelog entries moved to commit messages - documentation updated/added in the UTF-8 routine editing v1 -> v2: - removal of the `deps_write(extra)` parameter to option-checking where ndeeded - default parameter of `cpp_finish(fdeps_stream = NULL)` - unification of libcpp UTF-8 validity functions from v1 - test cases for flag parsing states (depflags-*) and p1689 output (p1689-*) Ben Boeckel (4): spec: add a spec function to join arguments p1689r5: initial support c++modules: report imported CMI files as dependencies c++modules: report module mapper files as a dependency gcc/c-family/c-opts.cc | 44 +++- gcc/c-family/c.opt | 12 + gcc/cp/mapper-client.cc | 5 + gcc/cp/mapper-client.h | 1 + gcc/cp/module.cc | 24 +- gcc/doc/invoke.texi | 27 +++ gcc/gcc.cc | 19 +- gcc/json.h | 3 + gcc/testsuite/g++.dg/modules/depflags-f-MD.C | 2 + gcc/testsuite/g++.dg/modules/depflags-f.C | 3 + gcc/testsuite/g++.dg/modules/depflags-fi.C | 4 + gcc/testsuite/g++.dg/modules/depflags-fj-MD.C | 3 + .../g++.dg/modules/depflags-fj-MF-share.C | 6 + gcc/testsuite/g++.dg/modules/depflags-fj.C | 4 + .../g++.dg/modules/depflags-fjo-MD.C | 4 + gcc/testsuite/g++.dg/modules/depflags-fjo.C | 5 + gcc/testsuite/g++.dg/modules/depflags-fo-MD.C | 3 + gcc/testsuite/g++.dg/modules/depflags-fo.C | 4 + gcc/testsuite/g++.dg/modules/depflags-j-MD.C | 2 + gcc/testsuite/g++.dg/modules/depflags-j.C | 3 + gcc/testsuite/g++.dg/modules/depflags-jo-MD.C | 3 + gcc/testsuite/g++.dg/modules/depflags-jo.C | 4 + gcc/testsuite/g++.dg/modules/depflags-o-MD.C | 2 + gcc/testsuite/g++.dg/modules/depflags-o.C | 3 + gcc/testsuite/g++.dg/modules/depreport-1_a.C | 10 + gcc/testsuite/g++.dg/modules/depreport-1_b.C | 12 + .../g++.dg/modules/depreport-2.modmap | 2 + gcc/testsuite/g++.dg/modules/depreport-2_a.C | 15 ++ gcc/testsuite/g++.dg/modules/depreport-2_b.C | 14 ++ gcc/testsuite/g++.dg/modules/modules.exp | 1 + gcc/testsuite/g++.dg/modules/p1689-1.C | 17 ++ gcc/testsuite/g++.dg/modules/p1689-1.exp.ddi | 27 +++ gcc/testsuite/g++.dg/modules/p1689-2.C | 15 ++ gcc/testsuite/g++.dg/modules/p1689-2.exp.ddi | 16 ++ gcc/testsuite/g++.dg/modules/p1689-3.C | 13 + gcc/testsuite/g++.dg/modules/p1689-3.exp.ddi | 16 ++ gcc/testsuite/g++.dg/modules/p1689-4.C | 13 + gcc/testsuite/g++.dg/modules/p1689-4.exp.ddi | 14 ++ gcc/testsuite/g++.dg/modules/p1689-5.C | 13 + gcc/testsuite/g++.dg/modules/p1689-5.exp.ddi | 14 ++ .../g++.dg/modules/p1689-file-default.C | 16 ++ .../g++.dg/modules/p1689-file-default.exp.ddi | 27 +++ .../g++.dg/modules/p1689-target-default.C | 16 ++ .../modules/p1689-target-default.exp.ddi | 27 +++ gcc/testsuite/g++.dg/modules/test-depfile.py | 207 ++++++++++++++++ gcc/testsuite/g++.dg/modules/test-p1689.py | 222 ++++++++++++++++++ gcc/testsuite/lib/modules.exp | 100 ++++++++ libcpp/include/cpplib.h | 12 +- libcpp/include/mkdeps.h | 9 +- libcpp/init.cc | 13 +- libcpp/mkdeps.cc | 153 +++++++++++- 51 files changed, 1181 insertions(+), 23 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/depflags-f-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-f.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fi.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fj-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fj-MF-share.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fj.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fjo-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fjo.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fo-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-fo.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-j-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-j.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-jo-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-jo.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-o-MD.C create mode 100644 gcc/testsuite/g++.dg/modules/depflags-o.C create mode 100644 gcc/testsuite/g++.dg/modules/depreport-1_a.C create mode 100644 gcc/testsuite/g++.dg/modules/depreport-1_b.C create mode 100644 gcc/testsuite/g++.dg/modules/depreport-2.modmap create mode 100644 gcc/testsuite/g++.dg/modules/depreport-2_a.C create mode 100644 gcc/testsuite/g++.dg/modules/depreport-2_b.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-1.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-1.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/p1689-2.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-2.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/p1689-3.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-3.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/p1689-4.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-4.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/p1689-5.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-5.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/p1689-file-default.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-file-default.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/p1689-target-default.C create mode 100644 gcc/testsuite/g++.dg/modules/p1689-target-default.exp.ddi create mode 100644 gcc/testsuite/g++.dg/modules/test-depfile.py create mode 100644 gcc/testsuite/g++.dg/modules/test-p1689.py create mode 100644 gcc/testsuite/lib/modules.exp base-commit: 80ae426a195a0d035640a6301da833564deade52