From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8bf89a9bbd99a65e X-Google-Attributes: gid103376,public From: Geert Bosch Subject: Re: array conversion - how to do? Date: 1997/07/04 Message-ID: <5pjkpi$mvk$1@gonzo.sun3.iaf.nl>#1/1 X-Deja-AN: 254656913 References: <5opej8$rv5$1@gonzo.sun3.iaf.nl> <33B3DE95.41EF@does.not.exist.com> <5p3qk2$8mk$1@gonzo.sun3.iaf.nl> Organization: La Calandre Infortunee Newsgroups: comp.lang.ada Date: 1997-07-04T00:00:00+00:00 List-Id: Geert says ``Now I think about it, it is possible to rather closely model typecasting for arrays by implementing array conversion as showed below. It is a pity that this generates lots of code with GNAT although all code could be eliminated. Are there any compilers that correctly compile this into a null function?'' Robert Dewar replies: ``If the body of Error is not available, this is not a valid optimization, and indeed is typical of the kind of invalid optimizations that optimizing compilers are sometimes known to do.'' I think you placed my remark about optimization in the wrong context. Your reply seems to target the loop approach which makes a copy that cannot trivially be eliminated. The code for Array_Conversion that I showed uses Unchecked_Conversion from one constrained array to another. All checks can be eliminated, so Unchecked_Conversion can just provide a different view of the array which is the goal I want to achieve. I'll quote some references to support my claim that the code can be optimized to null. Regards, Geert RM95 13.9 /Implementation permissions/ (12) An implementation may return the result of an unchecked conversion by reference, if the Source type is not a by-copy type. In this case, the result of the unchecked conversion represents simply a different (read-only) view of the operand of the conversion. RM95 13.9 /Implementation Advice/ (14) The Size of an array object should not include its bounds; hence, the bounds should not be part of the converted data. (15) The implementation should not generate unnecessary run-time checks to ensure that the representation of S is a representation of the target type. It should take advantage of the permission to return by reference when possible. Restrictions on unchecked conversions should be avoided unless required by the target environment.