comp.lang.ada
 help / color / mirror / Atom feed
From: Shark8 <onewingedshark@gmail.com>
Subject: Re: Ada 2012 Constraints (WRT an Ada IR)
Date: Wed, 30 Nov 2016 10:28:57 -0800 (PST)
Date: 2016-11-30T10:28:57-08:00	[thread overview]
Message-ID: <03847fd7-5699-48de-bb3c-ef5512398f26@googlegroups.com> (raw)
In-Reply-To: <o1m2oi$g8l$1@gioia.aioe.org>

On Wednesday, November 30, 2016 at 1:31:17 AM UTC-7, Dmitry A. Kazakov wrote:
> 
> BTW, "representing" is certainly irrelevant because Ada is a statically 
> typed language, hence, no types are ever represented in an Ada program 
> [they are in the compiler and then the representations are thrown away].

Insofar as you can think of the Ada translator as a function of the form "Function Translate( Input : Source ) Return Executable_or_Library_Object;" that's absolutely true... it is untrue if you are considering an IR (intermediate representation).

Now we could decompose Translate along the phases of compilation as something perhaps like:

    Function Translate( Input : Source ) Return Executable_or_Library_Object is
    ( Code_Generator(Optimizer(Semantic_Analyzer((Parser((Lexer(Source))))))) );

and, further, if we were to instead do something like this:

    Function Translate( Input : Source ) Return Executable_or_Library_Object is
    Begin
      declare
        Semantic_Tree : constant Semantic_Analysis_Result := 
            Semantic_Analyzer(Parser(Lexer(Source)));
      begin
        Semantic_Analysis_Result'Write( IR_Stream, Semantic_Tree );
        Return Code_Generator(Optimizer(Semantic_Tree));
      end;
    End Translate;

The result would be that the compiler phases 'Lexer' through 'Semantic_Analyzer' have been "captured" into the stream IR_Stream, and it's guaranteed to be valid Ada (insofar as the correctness of the implementation of those phases are concerned) and, moreover, consistent w/ itself. We could then at a later date read that stream into a Semantic_Analysis_Result object and continue the compilation process (optimizing and code-gen). -- So, with that in mind it makes sense to consider the usefulness of making Semantic_Analysis_Result its own formal language: the Intermediate Representation.

Because of the properties listed above, every instance of Semantic_Analysis_Result is valid, consistent Ada -- by uniformly representing the underlying construct/concepts of the Ada-source we can severely cut down the complexity needed by the later stages of the compiler^1  (like, say, the DER encodings vs the BER encodings of ASN.1).

These properties are ideal for many applications -- one of the most practical to addressing some of the complaints/difficulties leveled at Ada (like a poor ecosystem) would be implementation of a CPAN-style repository... but far better -- for if we can, say, make this IR amiable to storage in a DB (with attendant consistency-checks) we can eliminate the storage of invalid Ada in said repository; furthermore, because we have all the semantic-information already we could build-in tools to allow correct dependency-storage, like Gnoga using Simple Components, but with proper versioning so that a breaking change in a new version's API could be detected and the older one with the required properties could be retrieved.

> On 29/11/2016 23:59, Shark8 wrote:
> > On Tuesday, November 29, 2016 at 2:06:21 PM UTC-7, Dmitry A. Kazakov wrote:
> >> On 2016-11-29 21:51, Shark8 wrote:
> >>> On Tuesday, November 29, 2016 at 1:44:43 PM UTC-7, Dmitry A. Kazakov wrote:
> >>>> On 2016-11-29 21:32, Shark8 wrote:
> >>>>
> >>>>> The above has a constraint -- that of only holding digits -- but
> >>>>> still  is unconstrained. If we were doing a formal CS class we'd say something
> >>>>> like "The type Serial_Number contains all strings that have only the
> >>>>> decimal digits therein."
> >>>>
> >>>> You want convariance, that is a completely different beast.
> >>>
> >>> No, I really don't.
> >>> I'm not talking about Ada-syntax,
> >>
> >> Yes you do, covariance vs. contravariance is semantics, not syntax.
> >
> > Maybe I'm misunderstanding.
> > I simply don't see how covariance vs. contravariance is at all
> > germane  to representing the definition of a type.
> 
> It is relevant to the difference between Ada 83 style constrained types 
> and constrained types introduced by predicates. Ada 83 constraints are 
> more consistent because they took into account operations that must be 
> covariant. E.g. adding to the list of examples:
> 
>     subtype Text is String (1..80);
> 
> That overrides 'First, 'Last, 'Range, 'Length and propagates the 
> constraint to other types by promoting Text definite. None of this 
> happens if you add a predicate because all operations are inherited 
> as-is = contravariant.

And shouldn't that (eg Predicated_Subtype'Pred or 'Last, etc) be caught by the semantic-analysis phase? If so, then it's entirely a moot point, isn't it?

But it certainly doesn't invalidate the concept of considering a type [and subtype] as the collection of a set of values and a set of operations on those values; for example:

    Type Nybble is range 0..15 with Size => 4;
    Subtype Prime_Nybble is Nybble with
      Static_Predicate => Prime_Nybble in 2|3|5|7|11|13;

could be represented as something which visualized-as-text would be:

   Nybble is
    Size            : Bits(4)
    Internal_Values : Set(0..15)
    Offset          : 0          -- So we could represent 1..16 w/ 4-bits
    Operations      : Arithmetic_ops & Scalar_Attributes

   
   Prime_Nybble modifying Nybble is
    Operations      : Operations without Scalar_Attributes

or somesuch.

> >>>> It is a new
> >>>> type with some operations overridden, e.g. the operation that yields a
> >>>> value of a discrete type for case statement. It is an implicit operation
> >>>> in Ada, yet it is an operation. It must be covariant, i.e. returning the
> >>>> new type rather than the old one for the case be satisfied with the new
> >>>> set of values. Same with already mentioned 'First, 'Last, 'Range. Or,
> >>>> for that matter, 'Succ and 'Pred if the new type has a non-contiguous
> >>>> values set, e.g. Odd_Number. You cannot get there by merely putting some
> >>>> predicate on the assignment operation (which Ada's predicates do). That
> >>>> model is too weak to express such things.
> >>>
> >>> This is not about defining a type in Ada, it's about abstracting the
> >>> making of a type [in Ada] and how best to represent _that_.
> >>
> >> What is abstracting making the type?
> >
> > Perhaps I should have used the word "defining" or "representing" instead of "making".
> 
> So it *is* about "defining" now?
> 
> [I still do not understand what you meant.]

In some sense, yes. -- By making the IR a mapping of Ada's concepts (such as defining a new type, or adding constraints thereon, [ie] the particular subject of this thread) in a general manner we can simplify some complexity of the Ada language insofar as [implementations of] tools and the back-end of compilers are concerned.

But as a whole, no -- the IR is about (a) abstracting the concepts that underlay Ada, and (b) storing/transforming an Ada text-source in terms of those concepts.

Does that clear things up?

--------------------------------------

^1 -- As an example the Standard says that a renaming of a function-call and a constant-object initialized to that function-call are equivalent; it is therefore quite sensible to have a single IR-construct to represent both... if exact source-text recovery is important then simply adding a discriminant/field of "Is_Renaming : Boolean" would be enough to track source recovery for that construct.


  reply	other threads:[~2016-11-30 18:28 UTC|newest]

Thread overview: 195+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-28 23:49 Ada 2012 Constraints (WRT an Ada IR) Shark8
2016-11-29  8:17 ` G.B.
2016-11-29 20:32   ` Shark8
2016-11-29 20:44     ` Dmitry A. Kazakov
2016-11-29 20:51       ` Shark8
2016-11-29 21:06         ` Dmitry A. Kazakov
2016-11-29 22:59           ` Shark8
2016-11-30  8:31             ` Dmitry A. Kazakov
2016-11-30 18:28               ` Shark8 [this message]
2016-11-30 20:26                 ` Niklas Holsti
2016-12-01  0:16                   ` Shark8
2016-12-01 22:15                     ` Randy Brukardt
2016-11-30 20:45                 ` Dmitry A. Kazakov
2016-12-01  0:58                   ` Shark8
2016-12-01  8:55                     ` Dmitry A. Kazakov
2016-12-01 22:26                       ` Randy Brukardt
2016-12-02 16:21                         ` Dmitry A. Kazakov
2016-12-02 19:15                           ` Randy Brukardt
2016-12-03 10:21                             ` Dmitry A. Kazakov
2016-12-02 19:50                           ` G.B.
2016-12-03 10:23                             ` Dmitry A. Kazakov
2016-12-03 14:02                               ` G.B.
2016-12-03 16:26                                 ` Dmitry A. Kazakov
2016-12-04 15:28                                   ` Robert Eachus
2016-12-05  8:41                                     ` Stefan.Lucks
2016-12-05  8:58                                       ` Dmitry A. Kazakov
2016-12-05 11:09                                         ` Simon Wright
2016-12-05 18:42                                           ` Shark8
2016-12-05 22:13                                             ` Dmitry A. Kazakov
2016-12-06 20:51                                               ` Shark8
2016-12-06 21:07                                                 ` Dmitry A. Kazakov
2016-12-06 21:44                                                   ` Shark8
2016-12-06 23:23                                                     ` Randy Brukardt
2016-12-07 22:42                                                       ` Shark8
2016-12-07  1:08                                                     ` Dennis Lee Bieber
2016-12-07  6:36                                                       ` Niklas Holsti
2016-12-07 13:10                                                         ` Dennis Lee Bieber
2016-12-07 22:55                                                           ` Brian Drummond
2016-12-08  2:44                                                         ` Shark8
2016-12-07 10:04                                                       ` G.B.
2016-12-07 10:14                                                         ` G.B.
2016-12-07 10:51                                                         ` J-P. Rosen
2016-12-08 18:33                                                           ` G.B.
2016-12-09  8:26                                                             ` J-P. Rosen
2016-12-09  8:56                                                               ` G.B.
2016-12-10 15:13                                                                 ` Jacob Sparre Andersen
2016-12-11 19:50                                                                   ` Shark8
2016-12-05 22:07                                           ` Dmitry A. Kazakov
2016-12-06 23:09                                             ` Randy Brukardt
2016-12-07 10:03                                               ` Dmitry A. Kazakov
2016-12-07 22:37                                                 ` Randy Brukardt
2016-12-08  8:46                                                   ` Dmitry A. Kazakov
2016-12-10 15:24                                               ` Jacob Sparre Andersen
2016-12-09  9:12                                           ` Robert Eachus
2016-12-05 19:22                                         ` G.B.
2016-12-05 22:18                                           ` Dmitry A. Kazakov
2016-12-05 22:12                                         ` Randy Brukardt
2016-12-05 22:26                                           ` Dmitry A. Kazakov
2016-12-06  9:29                                             ` Simon Wright
2016-12-06 10:01                                               ` Dmitry A. Kazakov
2016-12-06 23:15                                             ` Randy Brukardt
2016-12-07 10:20                                               ` Dmitry A. Kazakov
2016-12-07 22:26                                                 ` Randy Brukardt
2016-12-08  8:57                                                   ` Dmitry A. Kazakov
2016-12-08  9:42                                                     ` G.B.
2016-12-08 10:03                                                       ` Dmitry A. Kazakov
2016-12-08 18:35                                                         ` G.B.
2016-12-09  9:38                                                           ` Dmitry A. Kazakov
2016-12-11 11:21                                                             ` G.B.
2016-12-11 12:28                                                               ` Dmitry A. Kazakov
2016-12-11 13:31                                                                 ` G.B.
2016-12-11 15:40                                                                   ` Dmitry A. Kazakov
2016-12-11 20:51                                                                     ` G.B.
2016-12-12  8:27                                                                       ` Dmitry A. Kazakov
2016-12-12 15:31                                                                         ` G.B.
2016-12-12 17:39                                                                           ` Dmitry A. Kazakov
2016-12-12 18:55                                                                             ` G.B.
2016-12-12 20:53                                                                               ` Dmitry A. Kazakov
2016-12-13  7:15                                                                                 ` G.B.
2016-12-13  8:27                                                                                   ` Dmitry A. Kazakov
2016-12-13 10:39                                                                                     ` G.B.
2016-12-13 11:19                                                                                       ` Dmitry A. Kazakov
2016-12-13 16:59                                                                                         ` G.B.
2016-12-13 21:11                                                                                           ` Dmitry A. Kazakov
2016-12-13 22:13                                                                                             ` Shark8
2016-12-14  8:42                                                                                               ` Dmitry A. Kazakov
2016-12-14 11:04                                                                                                 ` G.B.
2016-12-14 11:25                                                                                                   ` Dmitry A. Kazakov
2016-12-14 12:44                                                                                                     ` G.B.
2016-12-14 12:52                                                                                                       ` Dmitry A. Kazakov
2016-12-14 16:31                                                                                                         ` G.B.
2016-12-14 16:52                                                                                                           ` Dmitry A. Kazakov
2016-12-14 18:14                                                                                                             ` G.B.
2016-12-14 12:05                                                                                                 ` G.B.
2016-12-14 19:23                                                                                                 ` Shark8
2016-12-14 20:04                                                                                                   ` Dmitry A. Kazakov
2016-12-14 21:46                                                                                                     ` Shark8
2016-12-15  8:41                                                                                                       ` Dmitry A. Kazakov
2016-12-15 10:31                                                                                                         ` G.B.
2016-12-15 13:17                                                                                                           ` Dmitry A. Kazakov
2016-12-15 13:27                                                                                                             ` Dmitry A. Kazakov
2016-12-15 19:50                                                                                                             ` G.B.
2016-12-16 10:04                                                                                                               ` Dmitry A. Kazakov
2016-12-16 11:48                                                                                                                 ` G.B.
2016-12-16 12:56                                                                                                                   ` Stefan.Lucks
2016-12-16 19:59                                                                                                                     ` Randy Brukardt
2016-12-16 20:35                                                                                                                     ` G.B.
2016-12-17  9:33                                                                                                                       ` Stefan.Lucks
2016-12-19 22:57                                                                                                                         ` Randy Brukardt
2016-12-16 13:24                                                                                                                   ` Dmitry A. Kazakov
2016-12-15 14:34                                                                                                         ` Shark8
2016-12-15 14:53                                                                                                           ` Dmitry A. Kazakov
2016-12-15 22:34                                                                                                             ` Shark8
2016-12-16  8:28                                                                                                               ` Dmitry A. Kazakov
2016-12-17  3:46                                                                                                                 ` Shark8
2016-12-14 12:21                                                                                             ` G.B.
2016-12-14 12:55                                                                                               ` Dmitry A. Kazakov
2016-12-14 16:21                                                                                                 ` G.B.
2016-12-14 16:55                                                                                                   ` Dmitry A. Kazakov
2016-12-14 18:55                                                                                                     ` G.B.
2016-12-13 18:25                                                                                         ` Shark8
2016-12-13 21:11                                                                                           ` Dmitry A. Kazakov
2016-12-13 22:32                                                                                             ` Shark8
2016-12-14  8:54                                                                                               ` Dmitry A. Kazakov
2016-12-14 22:53                                                                                                 ` Randy Brukardt
2016-12-15  8:44                                                                                                   ` Dmitry A. Kazakov
2016-12-15 22:19                                                                                                     ` Randy Brukardt
2016-12-16  8:38                                                                                                       ` Dmitry A. Kazakov
2016-12-16 19:51                                                                                                         ` Randy Brukardt
2016-12-17  9:13                                                                                                           ` Dmitry A. Kazakov
2016-12-19 22:33                                                                                                             ` Randy Brukardt
2016-12-20 11:00                                                                                                               ` Dmitry A. Kazakov
2016-12-21  0:54                                                                                                                 ` Shark8
2016-12-21  0:59                                                                                                                 ` Randy Brukardt
2016-12-21 15:56                                                                                                                   ` Dmitry A. Kazakov
2016-12-21 18:26                                                                                                                     ` G.B.
2016-12-21 21:15                                                                                                                       ` Dmitry A. Kazakov
2016-12-22  9:54                                                                                                                         ` G.B.
2016-12-22 10:16                                                                                                                           ` Dmitry A. Kazakov
2016-12-14 11:46                                                                                             ` G.B.
2016-12-12 19:48                                                                             ` Shark8
2016-12-12 20:46                                                                               ` Dmitry A. Kazakov
2016-12-12 21:33                                                                                 ` Shark8
2016-12-13  8:28                                                                                   ` Dmitry A. Kazakov
2016-12-13 18:53                                                                                     ` Shark8
2016-12-13 21:11                                                                                       ` Dmitry A. Kazakov
2016-12-13 22:16                                                                                         ` Shark8
2016-12-14  9:00                                                                                           ` Dmitry A. Kazakov
2016-12-11 23:58                                                                   ` Paul Rubin
2016-12-12  8:33                                                                     ` Dmitry A. Kazakov
2016-12-12 15:23                                                                       ` G.B.
2016-12-12 15:51                                                                         ` G.B.
2016-12-09 21:46                                                     ` Randy Brukardt
2016-12-13 11:56                                         ` Alejandro R. Mosteo
2016-12-13 15:02                                           ` Dmitry A. Kazakov
2016-12-13 17:38                                             ` Alejandro R. Mosteo
2016-12-05 22:06                                       ` Randy Brukardt
2016-11-29 17:53 ` Niklas Holsti
2016-11-29 18:21   ` Dmitry A. Kazakov
2016-11-29 20:45   ` Shark8
2016-11-30  0:03     ` Randy Brukardt
2016-11-30  0:59       ` Shark8
2016-12-01 10:33   ` AdaMagica
2016-11-29 23:52 ` Randy Brukardt
2016-11-30  1:24   ` Shark8
2016-11-30 22:12     ` Randy Brukardt
2016-11-30  1:29   ` Shark8
2016-11-30 22:17     ` Randy Brukardt
2016-12-01  1:21       ` Shark8
2016-12-01 22:07         ` Randy Brukardt
2016-12-01 10:06   ` AdaMagica
  -- strict thread matches above, loose matches on Subject: below --
2016-12-09 21:41 Randy Brukardt
2016-12-09 22:32 ` Niklas Holsti
2016-12-13  0:41   ` Randy Brukardt
2016-12-13  2:34     ` Shark8
2016-12-13 22:35       ` Randy Brukardt
2016-12-14  0:38         ` Shark8
2016-12-13 20:45     ` Niklas Holsti
2016-12-13 23:19       ` Randy Brukardt
2016-12-14  0:53         ` Shark8
2016-12-14 22:22           ` Randy Brukardt
2016-12-13 22:45 Randy Brukardt
2016-12-14 22:40 Randy Brukardt
2016-12-15  8:48 ` Dmitry A. Kazakov
2016-12-15 22:24   ` Randy Brukardt
2016-12-16  8:40     ` Dmitry A. Kazakov
2016-12-16 19:46       ` Randy Brukardt
2016-12-16 20:14         ` Dmitry A. Kazakov
2016-12-19 22:52           ` Randy Brukardt
2016-12-20 10:59             ` Dmitry A. Kazakov
2016-12-21  0:50               ` Randy Brukardt
2016-12-21 15:56                 ` Dmitry A. Kazakov
2016-12-21 22:03 Randy Brukardt
2016-12-21 23:02 ` Shark8
2016-12-21 22:12 Randy Brukardt
replies disabled

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