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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!reality.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Ada 2012 Constraints (WRT an Ada IR) Date: Wed, 30 Nov 2016 16:12:33 -0600 Organization: JSA Research & Innovation Message-ID: References: <638d0618-f565-47ef-9793-dd05a4b1a662@googlegroups.com> NNTP-Posting-Host: rrsoftware.com X-Trace: franka.jacob-sparre.dk 1480543897 2378 24.196.82.226 (30 Nov 2016 22:11:37 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Wed, 30 Nov 2016 22:11:37 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 Xref: news.eternal-september.org comp.lang.ada:32535 Date: 2016-11-30T16:12:33-06:00 List-Id: "Shark8" wrote in message news:638d0618-f565-47ef-9793-dd05a4b1a662@googlegroups.com... On Tuesday, November 29, 2016 at 4:52:20 PM UTC-7, Randy Brukardt wrote: ... >> P2 is different than the others when used in a membership: >> >> Obj in P2 >> >> would raise Constraint_Error rather than return False (like the others) >> if >> Obj has the value 0. It's not recommended. > >Ah, I didn't realize that... I see the logic of why it does that: it fails >the predicate's > membership-test and then executes the raise-statement. But if that's the > case > whey isn't P3 the same? It is, after all, failing the membership-test and > therefore > failing the predicate, no? Ah, that's why predicate_failure exists. A membership (or 'Valid, which is similar) doesn't "fail", it returns True or False. By definition, the Predicate_Failure aspect isn't used in those cases. That makes it equivalent to P0 and P1. >> P0 and P1 are more likely to be optimized by a compiler (just because of >> the >> many years of history). Perhaps P3 will catch up, but I wouldn't hold my >> breath on that. > >What I'm saying is that P0, P1, and P3 (and perhaps arguably P2) should be > represented as the same thing... that there ought to be some way to > abstract > types and subtypes so that there is a common representation. Very unlikely in existing implementations. And maybe not a good idea in general, as there is a semantic difference in terms of the set of values for a constraint vs. a predicate. (This is one of those cases where I don't know of a way to tell that semantic difference, but I'd probably take a conservative approach and assume that someone will find one someday -- Ada has many amazing ways to do things you'd not expect.) >Just like a function with a single simple return-statement and an >expression-function > should be able to be represented as the same thing because the standard > says the > forms are equivalent. That's different, in that the standard literally says that. But there is no need for IR of any kind for this sort of construct (Janus/Ada only has a symbol table and expression trees; no larger pieces of program code are ever in memory. That then gets turned into a virtual stack machine [instructions which are similar to that of a real machine] which gets optimized and converted into machine code.) For the most part, there is little need for the time waste involved with creating a parse tree of any sort; you have to do that for expressions because of the way Ada resolution works, but it's unnecessary for program units and control flow. (That decision does effectively require implementing shared generics; that fact that we don't have any parse trees in our compiler makes a template implementation essentially impossible.) Randy.