comp.lang.ada
 help / color / mirror / Atom feed
From: Brad Moore <brad.moore@shaw.ca>
Subject: Re: Is this a bug in my code or the compiler?
Date: Sat, 13 Jun 2015 13:42:10 -0600
Date: 2015-06-13T13:42:10-06:00	[thread overview]
Message-ID: <nI%ex.64786$eb2.13161@fx27.iad> (raw)
In-Reply-To: <1g33axhwakrzx.o6t14iz4jruy.dlg@40tude.net>

On 2015-06-12 12:00 PM, Dmitry A. Kazakov wrote:
> On Fri, 12 Jun 2015 19:25:00 +0200, G.B. wrote:
>
>> On 12.06.15 18:15, Dmitry A. Kazakov wrote:
>>> Foo (A) and Foo (A) -- Illegal
>>> Foo (A) and then Foo (A) -- Legal
>>
>> C has similar features...
>
> So?
>
>>> P.P.S. It would become even worse with fine-grained parallelism, as Georg
>>> keep on suggesting.
>>
>> Not sure to what this is referring
>
> Parallel evaluation of arguments.

In the above case with regard to implicit parallelism, the compiler
should be able to determine that the two calls both involve
modifications the same storage, which would be a data race, and then
rule out parallelism and thus generate sequential code. So the issue
here is not about parallelism, but about ordering of evaluation for the
sequential case.

For the sequential case, I would think that a good compiler could also
detect that an expression with multiple calls with in out parameters to
the same storage is likely a problem with evaluation order, and
generate a warning to the programmer, which could be averted by coding
with "and then" for force evaluation order. If your compiler does not
generate such a warning, it might be good to ask your vendor  to
provide such a warning.

Or a programmer could adopt a programming style to use "and then" for
the general case, which I believe could be checked by a tool such as
AdaControl.

This should work for the case Boolean sub expressions, but doesn't help 
in the case of concatenation operations. Hopefully, the compiler could
at least generate warnings for this case, then the programmer can
decide how best to address the warning.

>
>> Query-command separation (on objects) seems far better than
>> functions that make their side effects explicit.
>
> You forgot about indefinite return values, which are not available for
> procedures. The real motivation to have functions with side effects is such
> return values.
>
>> So, in Ada 83, when A is of an access type,
>
> That does not change anything because:
>
>>      Foo (A) and Foo (A)  -- Legal
>
> Only if A is a constant access. Illegal otherwise.
>
> With parallelism atomicity of all immutable operations would additionally
> be required. Which is why that sort of parallelism is a can of worms.
>
>> Moreover, if B and A become pointing to the same object,
>>
>>      Foo (A) and Foo (B)  -- Legal, same effects
>>
>> Can a compiler detect this?


In Ada 2012, we have the attributes 'Has_Same_Storage and 'Overlaps_Storage.

These were introduced to facilitate writing preconditions for a
subprogram.  One would think that if these are available for checking
multiple parameters of a subprogram, the compiler could also do similar
checks for the parameters of subprograms that are part of the same
expression. In some cases, this could be a compile time check, but in
others, it may need to be a run-time check, that possibly could be
enabled/disabled via compiler options.

Brad

>
> Easily. Access is logically a referential type which, if properly designed,
> should be a subtype of the target type. Thus the same rules would apply. If
> access is meant to be a type of its own, like a pointer in C, then the
> language should better have no such types.
>
>> --- So, you'd be asking for pure
>> functions? Or total referential transparency?
>
> Both.
>
> Though purity is not enough for parallelism. A pure function may still get
> broken under parallel access if not atomic.
>

  parent reply	other threads:[~2015-06-13 19:42 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12 15:56 Is this a bug in my code or the compiler? David Botton
2015-06-12 16:15 ` Dmitry A. Kazakov
2015-06-12 17:25   ` G.B.
2015-06-12 18:00     ` Dmitry A. Kazakov
2015-06-13 10:04       ` Georg Bauhaus
2015-06-13 10:32         ` Dmitry A. Kazakov
2015-06-15 10:37           ` G.B.
2015-06-15 12:27             ` Dmitry A. Kazakov
2015-06-15 12:31               ` Simon Wright
2015-06-15 13:16                 ` Dmitry A. Kazakov
2015-06-15 14:56                   ` Simon Wright
2015-06-15 15:03                     ` G.B.
2015-06-13 19:42       ` Brad Moore [this message]
2015-06-12 17:53   ` David Botton
2015-06-12 18:11     ` Dmitry A. Kazakov
2015-06-12 18:43       ` marciant
2015-06-12 19:37     ` Jeffrey R. Carter
2015-06-12 19:55       ` Simon Wright
2015-06-12 20:40         ` Jeffrey R. Carter
2015-06-12 21:40           ` Simon Wright
2015-06-12 19:39     ` jan.de.kruyf
2015-06-12 22:10       ` David Botton
2015-06-13  0:19         ` Dennis Lee Bieber
2015-06-13 14:21         ` jan.de.kruyf
2015-06-14  3:13     ` Randy Brukardt
2015-06-14  3:21     ` Randy Brukardt
2015-06-12 16:48 ` Jeffrey R. Carter
2015-06-13 13:33 ` Jacob Sparre Andersen
2015-06-13 15:15   ` J-P. Rosen
2015-06-13 16:43     ` Jacob Sparre Andersen
2015-06-13 20:50       ` J-P. Rosen
2015-06-14  3:18   ` Randy Brukardt
2015-06-14  3:10 ` Randy Brukardt
2015-06-14  9:02   ` Jacob Sparre Andersen
2015-06-14 12:48     ` brbarkstrom
2015-06-15 22:06     ` 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