comp.lang.ada
 help / color / mirror / Atom feed
From: John Perry <john.perry@usm.edu>
Subject: Re: Performance of records with variant parts
Date: Tue, 23 Mar 2021 16:00:39 -0700 (PDT)	[thread overview]
Message-ID: <b962cd83-c15a-4285-9754-48008e685c49n@googlegroups.com> (raw)
In-Reply-To: <s3ccgm$4j7$1@dont-email.me>

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

  parent reply	other threads:[~2021-03-23 23:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-22 17:02 Performance of records with variant parts John Perry
2021-03-22 17:32 ` Jeffrey R. Carter
2021-03-22 17:49   ` John Perry
2021-03-22 17:54     ` John Perry
2021-03-22 19:31     ` Jeffrey R. Carter
2021-03-22 22:11       ` John Perry
2021-03-23  9:31         ` Jeffrey R. Carter
2021-03-23 14:27           ` Simon Wright
2021-03-23 23:00           ` John Perry [this message]
2021-03-23 23:27             ` Jeffrey R. Carter
2021-03-26 15:38               ` Stephen Leake
2021-03-26 15:44                 ` John Perry
2021-03-30  7:12                   ` Emmanuel Briot
2021-04-01  0:03                     ` John Perry
2021-04-01  6:45                       ` Emmanuel Briot
2021-04-01 13:38                       ` Niklas Holsti
2021-04-02 16:07                         ` John Perry
2021-03-22 17:39 ` Dmitry A. Kazakov
2021-03-22 17:45   ` John Perry
2021-03-22 18:07     ` Dmitry A. Kazakov
2021-03-22 18:23       ` John Perry
2021-03-22 20:30         ` Dmitry A. Kazakov
2021-03-22 18:59 ` Niklas Holsti
2021-03-22 21:54   ` John Perry
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox