From patchwork Tue Sep 26 11:46:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 144836 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1849271vqu; Tue, 26 Sep 2023 04:50:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE0M56zSAI4uATLCA6LpJgPu7NgSUSEAfpnQalSxy7AScxcYXGqIvxQ1PIY2Ar3CTkKUhGr X-Received: by 2002:a17:906:7955:b0:9ae:705a:8451 with SMTP id l21-20020a170906795500b009ae705a8451mr3919927ejo.25.1695729033254; Tue, 26 Sep 2023 04:50:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695729033; cv=none; d=google.com; s=arc-20160816; b=x51nZqz/ORwtu2qMOKCvo3I0MgJ/biRF2JI2IbcTzpbYDuTvSQZsI/cFKg4JcWb7/C II8moeuIqtSvmyKQytnKSL1Xhbv6m+xyegEsqTU7VFobNtSRcB0vn3PoBD+yQHBamY/1 4aDrKDTvq6Vg9LO5w+sByvdGUiCQb/XBVgjjsi5oZfnK7G3otU8TQIEgALBOizXy3TiY bNhPOG4qFMYBkhBvxiQvM972IKkZ/Uc+XZjvniev/TywrydsQiw9cB3h/rdVTYfg3k+S 6CmjsTTIwwR85j3je4j67L3lcb7K0+BhENOP+ERyvWk+j5Ziuou1ctcbjmpEnY9+FwA6 nJfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=bDQS18R7yiH0J0/bVFik/P99Dnu9UPCzIHCZ5H/214k=; fh=95w09Yw9RsEmXXrZWzamEBA8qYTe5GusNFVa8juhsy8=; b=GuOy35p0LjQJgvnuqZQELduO5ooXRlU8wdfbTPe6eQk2CSIVSb9E3OoYXFcWVt2BMQ kxFN3y4CJRNYJtr54buiuhWnCJBJRK/hLrDnEDooenoQWPvPUbu3gYg16Dzw3sSrVg3/ Ig9mpLbMCeZ9sputb8HhdpKJZb1/Xt84gK4qZ3vRBUO2QWWcZh0/qcQ8lkWdmzSWC8vL Eglq81JgJh5/D5abgAmvqfStkG8wRk3P9/RGHiQ366cZb1JcKa3OnnJMmN5C+MdywzE1 SdXLG8k9Ot79LeSEmKBUjAEyz0IaHdT5IH5h/caC+iS48VH1VnnCj6+6f5HwsEwdI/3n nwcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@adacore.com header.s=google header.b=GqN7N5R4; 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=adacore.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ss15-20020a170907038f00b0099327749bddsi10242225ejb.125.2023.09.26.04.50.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 04:50:33 -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=@adacore.com header.s=google header.b=GqN7N5R4; 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=adacore.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CF00138754BF for ; Tue, 26 Sep 2023 11:47:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 2021F385C6E8 for ; Tue, 26 Sep 2023 11:46:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2021F385C6E8 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-401d6f6b2e0so64860655e9.1 for ; Tue, 26 Sep 2023 04:46:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1695728780; x=1696333580; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=bDQS18R7yiH0J0/bVFik/P99Dnu9UPCzIHCZ5H/214k=; b=GqN7N5R4edFR+rdlo8KJuZekS4Z42G2h6kvgLFOm06dlbZf1pqn/8iN90U5RSpFoAK n2kjxDrSmn/E+xk4PzAYph4N0wC5tz7OKRMC2bMxZ3lgwdsaM/jEFJTJo1JdJSZKMlOd W5f0hK2nGu6p5byk/UAMKgUYhnsoYnVRk5VlGfhVDkcVxUMDtbG57dHvQrRVPfdapOIV kyolKwf7kNl6TFLn1wID0GEAwl+ah3lhWW2ABCjAtGj8Hug3m9f7zP7QuES+MyrOyIcP MwjEcBqV/WFKs4TFdeQqNHApQWeLETLoVVL+qF9t2UYk1u+7WQRqUsdzh+PsVwSxmL4Q K7Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695728780; x=1696333580; 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=bDQS18R7yiH0J0/bVFik/P99Dnu9UPCzIHCZ5H/214k=; b=cNpnxkE61pt/Zv16RuBtsBA1B+Hw6OR4A2zFIuh4OPU/33rH3y7z04gQgjhXhPc4Qo Zih2KoHglc12xhDYeQVBXkBd/3X3ECBShKWHfj5Hxr2QjnHY9/uFTTqLLypNu+/25kMx nuXa3ArFVb7I4GRT/laTnzvA7E0nC+zjVzNS1HhffBjVyhXAnLLIcFuINLuJ23TrcpHU HD0xh50IRb30VQzYV9OqixO9NyhMGRnDpaN5V87IsaKrPRtJNBJ117/AkKtSFnScC7F/ jXIVHEsVNf9inY48g+BvdsHdk1NkrhVv8V3W+Yc+m5GE4SKfXVydlqQQwBsd8xhwlqyL RIwg== X-Gm-Message-State: AOJu0Yy0yZyhH9n+FjaAZ4+fYhMa6NzqIyOnU/tiUrvhdhfE/n7PfkhQ QTpOfqR0WUD20Dm6lOBZ5Is3VHJqfRUd1y8tWtMlzQ== X-Received: by 2002:a05:600c:2044:b0:405:3941:ce2c with SMTP id p4-20020a05600c204400b004053941ce2cmr1912515wmg.6.1695728779680; Tue, 26 Sep 2023 04:46:19 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:27f0:a2f3:f97:f30e]) by smtp.gmail.com with ESMTPSA id n3-20020a05600c3b8300b004053a6b8c41sm13316440wms.12.2023.09.26.04.46.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 04:46:19 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Derek Schacht Subject: [COMMITTED] ada: Dimensional analysis when used with elementary functions Date: Tue, 26 Sep 2023 13:46:18 +0200 Message-ID: <20230926114618.3272422-1-poulhies@adacore.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778100766980740412 X-GMAIL-MSGID: 1778100766980740412 From: Derek Schacht gcc/ada/ * doc/gnat_ugn/gnat_and_program_execution.rst: Add more details on using Generic Elementary Functions with dimensional analysis. * gnat_ugn.texi: Regenerate. Tested on x86_64-pc-linux-gnu, committed on master. --- .../gnat_ugn/gnat_and_program_execution.rst | 12 ++++++++++++ gcc/ada/gnat_ugn.texi | 19 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/gcc/ada/doc/gnat_ugn/gnat_and_program_execution.rst b/gcc/ada/doc/gnat_ugn/gnat_and_program_execution.rst index 62abca24f41..35e34772658 100644 --- a/gcc/ada/doc/gnat_ugn/gnat_and_program_execution.rst +++ b/gcc/ada/doc/gnat_ugn/gnat_and_program_execution.rst @@ -3294,6 +3294,18 @@ requires ``DV(Source)`` = ``DV(Target)``, and analogously for parameter passing (the dimension vector for the actual parameter must be equal to the dimension vector for the formal parameter). +When using dimensioned types with elementary functions it is necessary to +instantiate the ``Ada.Numerics.Generic_Elementary_Functions`` package using +the ``Mks_Type`` and not any of the derived subtypes such as ``Distance``. +For functions such as ``Sqrt`` the dimensional analysis will fail when using +the subtypes because both the parameter and return are of the same type. + +An example instantiation + + .. code-block:: ada + + package Mks_Numerics is new + Ada.Numerics.Generic_Elementary_Functions (System.Dim.Mks.Mks_Type); .. _Stack_Related_Facilities: diff --git a/gcc/ada/gnat_ugn.texi b/gcc/ada/gnat_ugn.texi index 7c5926eba64..1562bee1f64 100644 --- a/gcc/ada/gnat_ugn.texi +++ b/gcc/ada/gnat_ugn.texi @@ -19,7 +19,7 @@ @copying @quotation -GNAT User's Guide for Native Platforms , Aug 31, 2023 +GNAT User's Guide for Native Platforms , Sep 26, 2023 AdaCore @@ -15510,7 +15510,6 @@ Linker to be used. The default is @code{bfd} for @code{ld.bfd}; @code{gold} (for @code{ld.gold}) and @code{mold} (for @code{ld.mold}) are more recent and faster alternatives, but only available on GNU/Linux platforms. - @end table @node Binding with gnatbind,Linking with gnatlink,Linker Switches,Building Executable Programs with GNAT @@ -22093,6 +22092,22 @@ requires @code{DV(Source)} = @code{DV(Target)}, and analogously for parameter passing (the dimension vector for the actual parameter must be equal to the dimension vector for the formal parameter). +When using dimensioned types with elementary functions it is necessary to +instantiate the @code{Ada.Numerics.Generic_Elementary_Functions} package using +the @code{Mks_Type} and not any of the derived subtypes such as @code{Distance}. +For functions such as @code{Sqrt} the dimensional analysis will fail when using +the subtypes because both the parameter and return are of the same type. + +An example instantiation + +@quotation + +@example +package Mks_Numerics is new + Ada.Numerics.Generic_Elementary_Functions (System.Dim.Mks.Mks_Type); +@end example +@end quotation + @node Stack Related Facilities,Memory Management Issues,Performing Dimensionality Analysis in GNAT,GNAT and Program Execution @anchor{gnat_ugn/gnat_and_program_execution id52}@anchor{14d}@anchor{gnat_ugn/gnat_and_program_execution stack-related-facilities}@anchor{1aa} @section Stack Related Facilities