From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Google-Smtp-Source: AGHT+IHUR0rMqc+D0D/ildu5dWsJIsT91FoXz8rIQhUnw2+MNJlTALlUr3sMSro3f393FG+TCRRfuA== 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=20Poulhi=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 Content-Transfer-Encoding: 8bit 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 List-Id: 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 -- 2.42.0