From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <010d01781cddc00d-906dcffc-0b6b-456d-b0b6-05a4c86931b8-000000@ca-central-1.amazonses.com> Received: from d208-14.smtp-out.ca-central-1.amazonses.com (d208-14.smtp-out.ca-central-1.amazonses.com [23.249.208.14]) by sourceware.org (Postfix) with ESMTPS id C4FF5384A018 for ; Wed, 10 Mar 2021 15:59:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C4FF5384A018 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=annexi-strayline.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=010d01781cddc00d-906dcffc-0b6b-456d-b0b6-05a4c86931b8-000000@ca-central-1.amazonses.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=k5b76xhpalcgrb3af3ji3mgpa4ove7c7; d=annexi-strayline.com; t=1615391998; h=From:To:Cc:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=z55hA27Q5P33n+PjHciA9fAwM+QaxCd+0rY3Lj9os+E=; b=JgVDcOEkyreELbo8qJnzDqfaHHpf0yt6Mr/46XE8Clqv+e2TasAGOyNidpKKVZhT yeFxxjz4asWsXzi7pRISub0yDCfl5j9vbrKsTiktCF8HFEzU01ZTlr636imXuVE6wvy J6ooh8rKRWR3bwn77zaGyzma/2V0ZtqmZ4j/mCX4= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=3alvvvbel33b2fx6aci3gonjgwxev6s4; d=amazonses.com; t=1615391998; h=From:To:Cc:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Feedback-ID; bh=z55hA27Q5P33n+PjHciA9fAwM+QaxCd+0rY3Lj9os+E=; b=A/ykuN77zejZgX7yfHV4QaWdFbm6P2qMIuy0Hk+tuxIIUsKZmY5EiDs9RE0bGD6v qsPAp6PBJSWRAB49YuPVZzht5SCN8H/kr1kOgvQkX5SEPCXuHuit/qwg37QIGSs4LIC q1ireGbi7NDuds9Dt+rUqpzOvxSxH3LUzlU5DjgM= From: "Richard Wai" To: "'Arnaud Charlet'" Cc: , "'Bob Duff'" References: <010d017802c7c419-a01a5c04-4e82-4ad0-922b-ac0f6b13592f-000000@ca-central-1.amazonses.com> <20210309081151.GB21507@adacore.com> <010d017817a35ab9-73d753e9-cfa4-4a41-af77-dc8b7168bc73-000000@ca-central-1.amazonses.com> <20210309155106.GA17162@adacore.com> <010d01781cafee3c-7c2ea77f-785c-4642-a145-a5b56f2de1f0-000000@ca-central-1.amazonses.com> <20210310152319.GA6734@adacore.com> In-Reply-To: <20210310152319.GA6734@adacore.com> Subject: RE: [PATCH] Ada: hashed container Cursor type predefined equality non-conformance Date: Wed, 10 Mar 2021 15:59:57 +0000 Message-ID: <010d01781cddc00d-906dcffc-0b6b-456d-b0b6-05a4c86931b8-000000@ca-central-1.amazonses.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_00AB_01D7159C.826F4250" X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQLtL7pizF+mMrbwQKV3/4XjyV2k/AH6kvYWAzGfoYECTYaABQG1hT+KAguOyDin91OeUA== Content-Language: en-ca X-SES-Outgoing: 2021.03.10-23.249.208.14 Feedback-ID: 1.ca-central-1.KKZpW0DP3lOi0JgzUh4V+obZyxLGOx2dpGS8+RWwiDg=:AmazonSES X-Spam-Status: No, score=1.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, DOS_OUTLOOK_TO_MX, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Wed, 10 Mar 2021 16:00:00 -0000 This is a multipart message in MIME format. ------=_NextPart_000_00AB_01D7159C.826F4250 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit > -----Original Message----- > From: Arnaud Charlet > Sent: March 10, 2021 10:23 AM > To: Richard Wai > Cc: gcc-patches@gcc.gnu.org; 'Bob Duff' ; Arnaud > Charlet > Subject: Re: [PATCH] Ada: hashed container Cursor type predefined equality > non-conformance > > > I appologise for making a mess of this final step. I have leared the > > errors of my ways. > > > By the way, ChangeLog are automatically generated these days, so we're > really talking about commit logs and diffs against ChangeLog (as you did in > your previous email) are no longer appropriate (and almost never apply > anyway). > I'm not sure I correctly understand you here, but my interpretation is that I should no longer submit Changelog entries, rather just the patch, and then a commit message (a-la git), and then presumably the Changelong entries will be generated automatically. From what I can see, gcc' website does not talk about that, so I'm guessing this format based on what I see from git-log, generally. So assuming that, attached is the "correct" patch, and here is the commit message: --- Author: Richard Wai Ada: Ensure correct Cursor predefined equality behavior for hashed containers. -- And for the record, the change log entries I've come up with as per the previous email: -- gcc/ada/Changelog: 2021-03-09 Richard Wai * libgnat/a-cohase.ads (Cursor): Synchronize comments for the Cursor type definition to be consistent with identical definitions in other container packages. Add additional comments regarding the importance of maintaining the "Position" component for predefined equality. * libgnat/a-cohama.ads (Cursor): Likewise. * libgnat/a-cihama.ads (Cursor): Likewise. * libgnat/a-cohase.adb (Find, Insert): Ensure that Cursor objects always have their "Position" component set to ensure predefined equality works as required. * libgnat/a-cohama.adb (Find, Insert): Likewise. * libgnat/a-cihama.adb (Find, Insert): Likewise. gcc/testsuite/Changelog: 2021-03-09 Richard Wai * gnat.dg/containers2.adb: New test. -- I've learned a lot, and appreciate your time. Richard ------=_NextPart_000_00AB_01D7159C.826F4250 Content-Type: application/octet-stream; name="container_cursor_equality_20210304.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="container_cursor_equality_20210304.patch" diff --git a/gcc/ada/libgnat/a-cihama.adb b/gcc/ada/libgnat/a-cihama.adb=0A= index 7a490d545cd..50adea1b46a 100644=0A= --- a/gcc/ada/libgnat/a-cihama.adb=0A= +++ b/gcc/ada/libgnat/a-cihama.adb=0A= @@ -522,7 +522,8 @@ is=0A= return No_Element;=0A= end if;=0A= =0A= - return Cursor'(Container'Unrestricted_Access, Node, = Hash_Type'Last);=0A= + return Cursor'=0A= + (Container'Unrestricted_Access, Node, HT_Ops.Index (HT, Node));=0A= end Find;=0A= =0A= --------------------=0A= @@ -748,6 +749,7 @@ is=0A= end if;=0A= =0A= Position.Container :=3D Container'Unchecked_Access;=0A= + Position.Position :=3D HT_Ops.Index (HT, Position.Node);=0A= end Insert;=0A= =0A= procedure Insert=0A= diff --git a/gcc/ada/libgnat/a-cihama.ads b/gcc/ada/libgnat/a-cihama.ads=0A= index ccf5f4e58ec..f8961671b37 100644=0A= --- a/gcc/ada/libgnat/a-cihama.ads=0A= +++ b/gcc/ada/libgnat/a-cihama.ads=0A= @@ -363,8 +363,22 @@ private=0A= =0A= type Cursor is record=0A= Container : Map_Access;=0A= + -- Access to this cursor's container=0A= +=0A= Node : Node_Access;=0A= + -- Access to the node pointed to by this cursor=0A= +=0A= Position : Hash_Type :=3D Hash_Type'Last;=0A= + -- Position of the node in the buckets of the container. If this = is=0A= + -- equal to Hash_Type'Last, then it will not be used. Position is=0A= + -- not requried by the implementation, but improves the = efficiency=0A= + -- of various operations.=0A= + --=0A= + -- However, this value must be maintained so that the predefined=0A= + -- equality operation acts as required by RM A.18.4-18/2, which=0A= + -- states: "The predefined "=3D" operator for type Cursor = returns True=0A= + -- if both cursors are No_Element, or designate the same element=0A= + -- in the same container."=0A= end record;=0A= =0A= procedure Write=0A= diff --git a/gcc/ada/libgnat/a-cohama.adb b/gcc/ada/libgnat/a-cohama.adb=0A= index 9c4e51a6392..fb46e074261 100644=0A= --- a/gcc/ada/libgnat/a-cohama.adb=0A= +++ b/gcc/ada/libgnat/a-cohama.adb=0A= @@ -478,7 +478,8 @@ is=0A= return No_Element;=0A= end if;=0A= =0A= - return Cursor'(Container'Unrestricted_Access, Node, = Hash_Type'Last);=0A= + return Cursor'=0A= + (Container'Unrestricted_Access, Node, HT_Ops.Index (HT, Node));=0A= end Find;=0A= =0A= --------------------=0A= @@ -635,6 +636,7 @@ is=0A= end if;=0A= =0A= Position.Container :=3D Container'Unrestricted_Access;=0A= + Position.Position :=3D HT_Ops.Index (HT, Position.Node);=0A= end Insert;=0A= =0A= procedure Insert=0A= @@ -677,6 +679,7 @@ is=0A= end if;=0A= =0A= Position.Container :=3D Container'Unrestricted_Access;=0A= + Position.Position :=3D HT_Ops.Index (HT, Position.Node);=0A= end Insert;=0A= =0A= procedure Insert=0A= diff --git a/gcc/ada/libgnat/a-cohama.ads b/gcc/ada/libgnat/a-cohama.ads=0A= index 21b69354db0..c6e377c6bb1 100644=0A= --- a/gcc/ada/libgnat/a-cohama.ads=0A= +++ b/gcc/ada/libgnat/a-cohama.ads=0A= @@ -465,7 +465,15 @@ private=0A= =0A= Position : Hash_Type :=3D Hash_Type'Last;=0A= -- Position of the node in the buckets of the container. If this = is=0A= - -- equal to Hash_Type'Last, then it will not be used.=0A= + -- equal to Hash_Type'Last, then it will not be used. Position is=0A= + -- not requried by the implementation, but improves the = efficiency=0A= + -- of various operations.=0A= + --=0A= + -- However, this value must be maintained so that the predefined=0A= + -- equality operation acts as required by RM A.18.4-18/2, which=0A= + -- states: "The predefined "=3D" operator for type Cursor = returns True=0A= + -- if both cursors are No_Element, or designate the same element=0A= + -- in the same container."=0A= end record;=0A= =0A= procedure Read=0A= diff --git a/gcc/ada/libgnat/a-cohase.adb b/gcc/ada/libgnat/a-cohase.adb=0A= index 0131f73eb7a..aac5b1b3cf2 100644=0A= --- a/gcc/ada/libgnat/a-cohase.adb=0A= +++ b/gcc/ada/libgnat/a-cohase.adb=0A= @@ -605,13 +605,13 @@ is=0A= is=0A= HT : Hash_Table_Type renames Container'Unrestricted_Access.HT;=0A= Node : constant Node_Access :=3D Element_Keys.Find (HT, Item);=0A= -=0A= begin=0A= if Node =3D null then=0A= return No_Element;=0A= end if;=0A= =0A= - return Cursor'(Container'Unrestricted_Access, Node, = Hash_Type'Last);=0A= + return Cursor'=0A= + (Container'Unrestricted_Access, Node, HT_Ops.Index (HT, Node));=0A= end Find;=0A= =0A= --------------------=0A= @@ -763,9 +763,11 @@ is=0A= Position : out Cursor;=0A= Inserted : out Boolean)=0A= is=0A= + HT : Hash_Table_Type renames Container'Unrestricted_Access.HT;=0A= begin=0A= Insert (Container.HT, New_Item, Position.Node, Inserted);=0A= Position.Container :=3D Container'Unchecked_Access;=0A= + Position.Position :=3D HT_Ops.Index (HT, Position.Node);=0A= end Insert;=0A= =0A= procedure Insert=0A= @@ -1998,7 +2000,7 @@ is=0A= return No_Element;=0A= else=0A= return Cursor'=0A= - (Container'Unrestricted_Access, Node, Hash_Type'Last);=0A= + (Container'Unrestricted_Access, Node, HT_Ops.Index (HT, = Node));=0A= end if;=0A= end Find;=0A= =0A= diff --git a/gcc/ada/libgnat/a-cohase.ads b/gcc/ada/libgnat/a-cohase.ads=0A= index a0aca526db9..c1415b57ff8 100644=0A= --- a/gcc/ada/libgnat/a-cohase.ads=0A= +++ b/gcc/ada/libgnat/a-cohase.ads=0A= @@ -537,8 +537,22 @@ private=0A= =0A= type Cursor is record=0A= Container : Set_Access;=0A= + -- Access to this cursor's container=0A= +=0A= Node : Node_Access;=0A= + -- Access to the node pointed to by this cursor=0A= +=0A= Position : Hash_Type :=3D Hash_Type'Last;=0A= + -- Position of the node in the buckets of the container. If this = is=0A= + -- equal to Hash_Type'Last, then it will not be used. Position is=0A= + -- not requried by the implementation, but improves the = efficiency=0A= + -- of various operations.=0A= + --=0A= + -- However, this value must be maintained so that the predefined=0A= + -- equality operation acts as required by RM A.18.7-17/2, which=0A= + -- states: "The predefined "=3D" operator for type Cursor = returns True=0A= + -- if both cursors are No_Element, or designate the same element=0A= + -- in the same container."=0A= end record;=0A= =0A= procedure Write=0A= diff --git a/gcc/testsuite/gnat.dg/containers2.adb = b/gcc/testsuite/gnat.dg/containers2.adb=0A= new file mode 100644=0A= index 00000000000..68c1824ca03=0A= --- /dev/null=0A= +++ b/gcc/testsuite/gnat.dg/containers2.adb=0A= @@ -0,0 +1,158 @@=0A= +-- { dg-do run }=0A= +-- { dg-options "-gnata" }=0A= +=0A= +with Ada.Strings.Hash;=0A= +with Ada.Containers.Hashed_Sets;=0A= +with Ada.Containers.Hashed_Maps;=0A= +with Ada.Containers.Indefinite_Hashed_Sets;=0A= +with Ada.Containers.Indefinite_Hashed_Maps;=0A= +=0A= +procedure Containers2 is=0A= + -- Check that Cursors of the hashed containers follow the correct=0A= + -- predefined equality rules - that two Cursors to the same element=0A= + -- are equal, one one is obtained through, for example, iteration,=0A= + -- and the other is obtained through a search=0A= + =0A= + subtype Definite_Name is String (1 .. 5);=0A= + =0A= + type Named_Item is=0A= + record=0A= + Name : Definite_Name;=0A= + Item : Integer :=3D 0;=0A= + end record;=0A= + =0A= + =0A= + function Equivalent_Item (Left, Right: Named_Item) return Boolean =0A= + is (Left.Name =3D Right.Name);=0A= + =0A= + function DI_Hash (Item: Named_Item) return Ada.Containers.Hash_Type=0A= + is (Ada.Strings.Hash (Item.Name));=0A= + =0A= + package HS is new Ada.Containers.Hashed_Sets=0A= + (Element_Type =3D> Named_Item,=0A= + Hash =3D> DI_Hash,=0A= + Equivalent_Elements =3D> Equivalent_Item);=0A= + =0A= + package IHS is new Ada.Containers.Indefinite_Hashed_Sets=0A= + (Element_Type =3D> Named_Item,=0A= + Hash =3D> DI_Hash,=0A= + Equivalent_Elements =3D> Equivalent_Item);=0A= + =0A= + package HM is new Ada.Containers.Hashed_Maps=0A= + (Key_Type =3D> Definite_Name,=0A= + Element_Type =3D> Integer,=0A= + Hash =3D> Ada.Strings.Hash,=0A= + Equivalent_Keys =3D> "=3D");=0A= + =0A= + package IHM is new Ada.Containers.Indefinite_Hashed_Maps=0A= + (Key_Type =3D> Definite_Name,=0A= + Element_Type =3D> Integer,=0A= + Hash =3D> Ada.Strings.Hash,=0A= + Equivalent_Keys =3D> "=3D");=0A= + =0A= + Item_Data : constant array (1 .. 5) of Named_Item=0A= + :=3D ((Name =3D> "ABCDE", others =3D> <>),=0A= + (Name =3D> "FGHIJ", others =3D> <>),=0A= + (Name =3D> "KLMNO", others =3D> <>),=0A= + (Name =3D> "PQRST", others =3D> <>),=0A= + (Name =3D> "UVWXY", others =3D> <>));=0A= + =0A= + use type HS.Cursor;=0A= + use type IHS.Cursor;=0A= + use type HM.Cursor;=0A= + use type IHM.Cursor;=0A= + =0A= + type HS_Cursor_Vec is array (Item_Data'Range) of HS.Cursor;=0A= + type IHS_Cursor_Vec is array (Item_Data'Range) of IHS.Cursor;=0A= + type HM_Cursor_Vec is array (Item_Data'Range) of HM.Cursor;=0A= + type IHM_Cursor_Vec is array (Item_Data'Range) of IHM.Cursor;=0A= + =0A= + HSC : HS.Set;=0A= + IHSC : IHS.Set;=0A= + HMC : HM.Map;=0A= + IHMC : IHM.Map;=0A= + =0A= + HS_Create_Cursors : HS_Cursor_Vec;=0A= + IHS_Create_Cursors : IHS_Cursor_Vec;=0A= + HM_Create_Cursors : HM_Cursor_Vec;=0A= + IHM_Create_Cursors : IHM_Cursor_Vec;=0A= + =0A= + HS_Index : HS.Cursor;=0A= + IHS_Index : IHS.Cursor;=0A= + HM_Index : HM.Cursor;=0A= + IHM_Index : IHM.Cursor;=0A= + =0A= + HS_Find : HS.Cursor;=0A= + IHS_Find : IHS.Cursor;=0A= + HM_Find : HM.Cursor;=0A= + IHM_Find : IHM.Cursor;=0A= + =0A= + =0A= + Inserted : Boolean;=0A= + =0A= +begin=0A= + =0A= + for I in Item_Data'Range loop=0A= + HSC.Insert (New_Item =3D> Item_Data(I),=0A= + Position =3D> HS_Create_Cursors(I),=0A= + Inserted =3D> Inserted);=0A= + =0A= + pragma Assert (Inserted);=0A= + =0A= + =0A= + IHSC.Insert (New_Item =3D> Item_Data(I),=0A= + Position =3D> IHS_Create_Cursors(I),=0A= + Inserted =3D> Inserted);=0A= + =0A= + pragma Assert (Inserted);=0A= + =0A= + HMC.Insert (New_Item =3D> Item_Data(I).Item,=0A= + Key =3D> Item_Data(I).Name,=0A= + Position =3D> HM_Create_Cursors(I),=0A= + Inserted =3D> Inserted);=0A= + =0A= + pragma Assert (Inserted);=0A= + =0A= + IHMC.Insert (New_Item =3D> Item_Data(I).Item,=0A= + Key =3D> Item_Data(I).Name,=0A= + Position =3D> IHM_Create_Cursors(I),=0A= + Inserted =3D> Inserted);=0A= + =0A= + pragma Assert (Inserted);=0A= + =0A= + end loop;=0A= + =0A= + HS_Index :=3D HSC.First;=0A= + IHS_Index :=3D IHSC.First;=0A= + HM_Index :=3D HMC.First;=0A= + IHM_Index :=3D IHMC.First;=0A= + =0A= + for I in Item_Data'Range loop=0A= + pragma Assert (HS.Has_Element (HS_Index));=0A= + pragma Assert (IHS.Has_Element (IHS_Index));=0A= + pragma Assert (HM.Has_Element (HM_Index));=0A= + pragma Assert (IHM.Has_Element (IHM_Index));=0A= + =0A= + HS_Find :=3D HSC.Find (Item_Data(I));=0A= + pragma Assert (HS_Create_Cursors(I) =3D HS_Index);=0A= + pragma Assert (HS_Find =3D HS_Index);=0A= + =0A= + IHS_Find :=3D IHSC.Find (Item_Data(I));=0A= + pragma Assert (IHS_Create_Cursors(I) =3D IHS_Index);=0A= + pragma Assert (IHS_Find =3D IHS_Index);=0A= + =0A= + HM_Find :=3D HMC.Find (Item_Data(I).Name);=0A= + pragma Assert (HM_Create_Cursors(I) =3D HM_Index);=0A= + pragma Assert (HM_Find =3D HM_Index);=0A= + =0A= + IHM_Find :=3D IHMC.Find (Item_Data(I).Name);=0A= + pragma Assert (IHM_Create_Cursors(I) =3D IHM_Index);=0A= + pragma Assert (IHM_Find =3D IHM_Index);=0A= + =0A= + HS.Next (HS_Index);=0A= + IHS.Next (IHS_Index);=0A= + HM.Next (HM_Index);=0A= + IHM.Next (IHM_Index);=0A= + end loop;=0A= + =0A= +end;=0A= ------=_NextPart_000_00AB_01D7159C.826F4250--