From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 X-Received: by 2002:a05:620a:1369:: with SMTP id d9mr422877qkl.378.1616540439749; Tue, 23 Mar 2021 16:00:39 -0700 (PDT) X-Received: by 2002:a25:6610:: with SMTP id a16mr645971ybc.339.1616540439498; Tue, 23 Mar 2021 16:00:39 -0700 (PDT) Path: eternal-september.org!reader02.eternal-september.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 23 Mar 2021 16:00:39 -0700 (PDT) In-Reply-To: Injection-Info: google-groups.googlegroups.com; posting-host=2601:3c3:401:f550:bc9a:b3cb:29f3:e32c; posting-account=JSxOkAoAAADa00TJoz2WZ_46XrZCdXeS NNTP-Posting-Host: 2601:3c3:401:f550:bc9a:b3cb:29f3:e32c References: <07a56dcc-9e17-49b2-a980-3a5a2d265cedn@googlegroups.com> <23dcce3e-0db1-4417-a5d1-a05f03f74464n@googlegroups.com> <302c2e86-2379-46e0-b1f7-d69e7e14f9cfn@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Performance of records with variant parts From: John Perry Injection-Date: Tue, 23 Mar 2021 23:00:39 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader02.eternal-september.org comp.lang.ada:61652 List-Id: On Tuesday, March 23, 2021 at 4:31:05 AM UTC-5, Jeffrey R. Carter wrote: > On 3/22/21 11:11 PM, John Perry wrote: > Interesting. With that optimization I would not expect this to differ noticeably > from a record without discriminants. > > I note that all your nested declarations could be declared constant. > > Use of Long_Float is completely non-portable. Thank you for these tips. > If you want to look into this further, IIRC, there is an option that will output > a low-level, Ada-like description of the IR that the front end produces. You'll > have to look in the top-secret GNAT documentation to find it. Yep, that shows the problem. For the declaration that immediately follows "when Sphere =>" we get | B_2 : declare | [constraint_error when | objects__thing_typeD2 (obj.kind) | "discriminant check failed"] | eo : vectors__vector := vectors__Osubtract (obj.center, and that function translates as | function objects__thing_typeD2 (kind : objects__object_type) | return boolean is | begin | if kind = objects__sphere then | return false; | else | return true; | end if; | end objects__thing_typeD2; So I'm getting a completely useless warning. It's even worse for "case Plane =>"; it checks the same thing twice! | if denom <= 0.0 then | [constraint_error when | objects__thing_typeD3 (obj.kind) | "discriminant check failed"] | [constraint_error when | objects__thing_typeD3 (obj.kind) | "discriminant check failed"] | return (vectors__vector_dot (obj.norm, ray.start) + | obj.offset) / (-denom); Am I right in thinking this is a bug? It shouldn't even check it, let alone check it twice. regards john perry