From patchwork Mon Oct 11 13:39:35 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: 1539333 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=IEuPvgqq; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HSgKl4yp6z9sP7 for ; Tue, 12 Oct 2021 00:55:23 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 75654385803B for ; Mon, 11 Oct 2021 13:55:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75654385803B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633960521; bh=AyJ1XehcHCi2RiqHrlXtGyifRlXGO8gOkPKJexsk3bw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=IEuPvgqq3i+HDeeoU+6nQTH4L/DObrbqj2brV56rAZawMvbyCV6WtNGxZuDev7v8g O+Wqwur6X66Gbl5PB9Hg0zDKGZ6vjY6XrOYVUa7FT8aVwyEF9kNd6EEw/dRlej9gyr B/9x+55vWO5gx2RXAGz/5LUxqt36fmPwj8JO/UaQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id EDD0A3858006 for ; Mon, 11 Oct 2021 13:39:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EDD0A3858006 Received: by mail-lf1-x133.google.com with SMTP id j5so74057078lfg.8 for ; Mon, 11 Oct 2021 06:39:41 -0700 (PDT) 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=AyJ1XehcHCi2RiqHrlXtGyifRlXGO8gOkPKJexsk3bw=; b=AQDoKF3yatUKhsOazmXa+T32+PaujqmuYUrs9Rzzt49UmIVFxLhVjtdF9YQYAA9Wvj qC2V8wHDxqRGFypYvYWinVqjbTGwHuDaXAfUxXjjeuEWQsIvXBs81OVQUdLAvQvAMW1q rX+ESrYEW1Uri2qmtT3WAMcA0n9xGDPD6RomfvV1w2VEgqPgKv6ZipvYlQfvru5xf/tM pt+R+0q0o0xAd08/0AfzkrF/zGNacKA+qbeSuazaeBzOxiUFQQVEB3Wm6KGub7Tjf1eU SnKSVMVL5XvRWaVY6UrxkLediGoXbSppiLI1MSQEdP3xXTCFV8LH+1ENidpOyaeIS0JR ej4Q== X-Gm-Message-State: AOAM5329fKE2wuEysvEva+FjFAqKPUaKbRZj3M46Cu+OvMofeq3LF9+1 FjiIBVNWz7kbrp86/AdRlFyMNSJwT7Lx2g== X-Google-Smtp-Source: ABdhPJy366jpMdbogQpe5UcMjd1DctqMD0aKk07Pdslhlwzj65nh7D05YK4OXD2symCl5vnMDisBrw== X-Received: by 2002:a05:6512:3e27:: with SMTP id i39mr26422980lfv.10.1633959577672; Mon, 11 Oct 2021 06:39:37 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id a18sm713357lfr.105.2021.10.11.06.39.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Oct 2021 06:39:36 -0700 (PDT) Date: Mon, 11 Oct 2021 13:39:35 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Find an interpretation for membership test with a singleton value Message-ID: <20211011133935.GA1518965@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_ASCII_DIVIDERS, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" When resolving type Color is (Blue, Orange); function Get_Color return Color is begin return Blue; end Get_Color; function Get_Color return String is begin return "Blue"; end Get_Color; Test : Boolean := Get_Color in Blue; we did not try all the possible interpretations of Get_Color but only the latest. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_ch4.adb (Analyze_Membership_Op): Finds interpretation for the case of a membership test with a singleton value in case of overloading. diff --git a/gcc/ada/sem_ch4.adb b/gcc/ada/sem_ch4.adb --- a/gcc/ada/sem_ch4.adb +++ b/gcc/ada/sem_ch4.adb @@ -2960,6 +2960,13 @@ package body Sem_Ch4 is -- If a set of alternatives is present, analyze each and find the -- common type to which they must all resolve. + procedure Find_Interpretation; + function Find_Interpretation return Boolean; + -- Routine and wrapper to find a matching interpretation in case + -- of overloading. The wrapper returns True iff a matching + -- interpretation is found. Beware, in absence of overloading, + -- using this function will break gnat's bootstrapping. + procedure Try_One_Interp (T1 : Entity_Id); -- Routine to try one proposed interpretation. Note that the context -- of the operation plays no role in resolving the arguments, so that @@ -3064,6 +3071,26 @@ package body Sem_Ch4 is end if; end Analyze_Set_Membership; + ------------------------- + -- Find_Interpretation -- + ------------------------- + + procedure Find_Interpretation is + begin + Get_First_Interp (L, Index, It); + while Present (It.Typ) loop + Try_One_Interp (It.Typ); + Get_Next_Interp (Index, It); + end loop; + end Find_Interpretation; + + function Find_Interpretation return Boolean is + begin + Find_Interpretation; + + return Found; + end Find_Interpretation; + -------------------- -- Try_One_Interp -- -------------------- @@ -3119,11 +3146,7 @@ package body Sem_Ch4 is Try_One_Interp (Etype (L)); else - Get_First_Interp (L, Index, It); - while Present (It.Typ) loop - Try_One_Interp (It.Typ); - Get_Next_Interp (Index, It); - end loop; + Find_Interpretation; end if; -- If not a range, it can be a subtype mark, or else it is a degenerate @@ -3139,13 +3162,14 @@ package body Sem_Ch4 is Find_Type (R); Check_Fully_Declared (Entity (R), R); - elsif Ada_Version >= Ada_2012 - and then Has_Compatible_Type (R, Etype (L)) + elsif Ada_Version >= Ada_2012 and then + ((Is_Overloaded (L) and then Find_Interpretation) or else + (not Is_Overloaded (L) and then Has_Compatible_Type (R, Etype (L)))) then if Nkind (N) = N_In then - Op := Make_Op_Eq (Loc, Left_Opnd => L, Right_Opnd => R); + Op := Make_Op_Eq (Loc, Left_Opnd => L, Right_Opnd => R); else - Op := Make_Op_Ne (Loc, Left_Opnd => L, Right_Opnd => R); + Op := Make_Op_Ne (Loc, Left_Opnd => L, Right_Opnd => R); end if; if Is_Record_Or_Limited_Type (Etype (L)) then