From patchwork Wed Nov 10 08:58:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 47366 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2B805385801F for ; Wed, 10 Nov 2021 09:01:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B805385801F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636534864; bh=c7V2Z8pI99v3UI0Bl2Twh78rd1Yl2tnLdIIXwywvu1E=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=jPzlMVhvrU1TN0jstv6h9tn3u/5B9bt5VHdJEpaz+a4ssywLFeEDNQWt2IkBFZU7z DDWHbrc4fPIoxcJAdJ7fpVslSbfaKkJTe1yFsupjhA3D9kMNFj5B3T018Timq1KNF+ 2M9MI6o0M68KLgRG4pv4m+ChfcrelmnTJqyjcMT4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id 68D7F3857C51 for ; Wed, 10 Nov 2021 08:58:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 68D7F3857C51 Received: by mail-lf1-x131.google.com with SMTP id l22so4305424lfg.7 for ; Wed, 10 Nov 2021 00:58:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=c7V2Z8pI99v3UI0Bl2Twh78rd1Yl2tnLdIIXwywvu1E=; b=8GLwnu/5V8yh+sztrr82TtFtAGBVIbnq+ocfUFq/Qmg4GmDZQI7tP/NroDwjJZz7mv sjYPJmwvZKCfQAREz8+Q/KbDl0vP2yLfPYdfXyMsSvnd3gSpT6Z/Y4Mz43OEqPqYSt5n GOcXmyxd8IXv20DSbZ4IwkmME1oFqmMJoYelU3H0QPo+VhvmPEd5OuxdHJbwdtIqLXPz E7NdAzelxgsIts7BHXLHq7PbiXVBDqRyJvzjrGZ7tpxtS088g360ubW8e+T7tV42g5et JbiIEOewSeddHb0WtaKU7MQDaXdnXH0CZko6o9PxLIptvJzmO6wIhbW09dNW+lqIA5Oi k/Nw== X-Gm-Message-State: AOAM53189lxDY62Nx9OX4iBdxeiThTj3mTEpXCsAQ1Vwls4/Eh1lPSIh dp0XqzsKCQ8kETX09xFV3Le62jcXv8Y27g== X-Google-Smtp-Source: ABdhPJw6vf86FSJJ9M5yQ4IfLV3A14N4OrVD89Jcoht3YQYfQWV5rPzhZJJMde7ph9WJStQ3MnLh+g== X-Received: by 2002:ac2:53ae:: with SMTP id j14mr12902336lfh.323.1636534708176; Wed, 10 Nov 2021 00:58:28 -0800 (PST) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id s5sm761444ljg.3.2021.11.10.00.58.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Nov 2021 00:58:27 -0800 (PST) Date: Wed, 10 Nov 2021 08:58:26 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Warn when interfaces swapped between full and partial view Message-ID: <20211110085826.GA2811006@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.0 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Etienne Servais Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The following package declaration is legal but the declaration of D leads to performing a tree transformation. Defining D as `type D is new B and A with null record` would be consistent with the partial view and thus does not require any transformation. This is helpful in the case of generic packages where we fail to correctly transform the tree. package E is type A is interface; type B is interface and A; type D is new B with private; private type D is new A and B with null record; end; Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch3.adb (Derived_Type_Declaration): Introduce a subprogram for tree transformation. If a tree transformation is performed, then warn that it would be better to reorder the interfaces. diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -17258,10 +17258,46 @@ package body Sem_Ch3 is and then Is_Interface (Parent_Type) then declare - Iface : Node_Id; Partial_View : Entity_Id; Partial_View_Parent : Entity_Id; - New_Iface : Node_Id; + + function Reorder_Interfaces return Boolean; + -- Look for an interface in the full view's interface list that + -- matches the parent type of the partial view, and when found, + -- rewrite the full view's parent with the partial view's parent, + -- append the full view's original parent to the interface list, + -- recursively call Derived_Type_Definition on the full type, and + -- return True. If a match is not found, return False. + -- ??? This seems broken in the case of generic packages. + + ------------------------ + -- Reorder_Interfaces -- + ------------------------ + + function Reorder_Interfaces return Boolean is + Iface : Node_Id; + New_Iface : Node_Id; + begin + Iface := First (Interface_List (Def)); + while Present (Iface) loop + if Etype (Iface) = Etype (Partial_View) then + Rewrite (Subtype_Indication (Def), + New_Copy (Subtype_Indication (Parent (Partial_View)))); + + New_Iface := + Make_Identifier (Sloc (N), Chars (Parent_Type)); + Append (New_Iface, Interface_List (Def)); + + -- Analyze the transformed code + + Derived_Type_Declaration (T, N, Is_Completion); + return True; + end if; + + Next (Iface); + end loop; + return False; + end Reorder_Interfaces; begin -- Look for the associated private type declaration @@ -17282,30 +17318,26 @@ package body Sem_Ch3 is then null; - -- Traverse the list of interfaces of the full-view to look - -- for the parent of the partial-view and perform the tree - -- transformation. + -- Traverse the list of interfaces of the full view to look + -- for the parent of the partial view and reorder the + -- interfaces to match the order in the partial view, + -- if needed. else - Iface := First (Interface_List (Def)); - while Present (Iface) loop - if Etype (Iface) = Etype (Partial_View) then - Rewrite (Subtype_Indication (Def), - New_Copy (Subtype_Indication - (Parent (Partial_View)))); - - New_Iface := - Make_Identifier (Sloc (N), Chars (Parent_Type)); - Append (New_Iface, Interface_List (Def)); - -- Analyze the transformed code + if Reorder_Interfaces then + -- Having the interfaces listed in any order is legal. + -- However, the compiler does not properly handle + -- different orders between partial and full views in + -- generic units. We give a warning about the order + -- mismatch, so the user can work around this problem. - Derived_Type_Declaration (T, N, Is_Completion); - return; - end if; + Error_Msg_N ("??full declaration does not respect " & + "partial declaration order", T); + Error_Msg_N ("\??consider reordering", T); - Next (Iface); - end loop; + return; + end if; end if; end if; end;