From owner-sc22wg5+sc22wg5-dom8=www.open-std.org@open-std.org  Fri Dec  5 02:40:44 2014
Return-Path: <owner-sc22wg5+sc22wg5-dom8=www.open-std.org@open-std.org>
X-Original-To: sc22wg5-dom8
Delivered-To: sc22wg5-dom8@www.open-std.org
Received: by www.open-std.org (Postfix, from userid 521)
	id 8EC92358761; Fri,  5 Dec 2014 02:40:44 +0100 (CET)
Delivered-To: sc22wg5@open-std.org
Received: from nag-j.co.jp (nag-j.co.jp [111.68.142.10])
	by www.open-std.org (Postfix) with ESMTP id 8616B358538
	for <sc22wg5@open-std.org>; Fri,  5 Dec 2014 02:40:43 +0100 (CET)
Received: from Maru6 (218-42-159-105.cust.bit-drive.ne.jp [218.42.159.105])
	(authenticated bits=0)
	by nag-j.co.jp (8.14.5/8.14.5) with ESMTP id sB51TS8A001884
	for <sc22wg5@open-std.org>; Fri, 5 Dec 2014 10:29:30 +0900 (JST)
	(envelope-from malcolm@nag-j.co.jp)
Message-ID: <D646458047A04F8686A8BCCCA6ACB99B@Maru6>
From: "Malcolm Cohen" <malcolm@nag-j.co.jp>
To: "WG5" <sc22wg5@open-std.org>
References: <20141204170247.9A28E35837D@www.open-std.org>
In-Reply-To: <20141204170247.9A28E35837D@www.open-std.org>
Subject: Re: [ukfortran] (SC22WG5.5369) Question on PURE subroutines
Date: Fri, 5 Dec 2014 10:29:22 +0900
Organization: =?utf-8?B?5pel5pysTkFH?=
MIME-Version: 1.0
Content-Type: text/plain;
	format=flowed;
	charset="utf-8";
	reply-type=original
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Mailer: Microsoft Windows Live Mail 15.4.3555.308
X-MimeOLE: Produced By Microsoft MimeOLE V15.4.3555.308
Sender: owner-sc22wg5@open-std.org
Precedence: bulk

Furthermore, you don't need a pointer to cause a global side-effect in a PURE 
subroutine, and all the proposed fixes do not even approach preventing 
side-effects in PURE subroutines (luckily, since that would make them completely 
useless).

Consider

Module junk
  Type t
    Real :: c
  End Type
  Type(t) x(10)
  Interface Assignment(=)
    Module Procedure ugh
  End Interface
Contains
  Pure Elemental Subroutine ugh(a,b)
    Type(t),Intent(InOut) :: a
    Integer,Intent(In) :: b
    a%c = a%c + x(3)%c + b
  End Subroutine
End Module
Program bad
  Use junk
  x%c = 1
  Forall (i=1:10) x(i) = 0
  Print *,x
End Program

If this is evaluated "in parallel", it might print 2 for all values.  If it is 
evaluated sequentially, it will print some 2's and some 3's.

This is not conforming merely because no interpretation is established.  It 
might behoove us to make this into a more explicit non-constraint requirement, 
e.g. something like
   "An invocation of a pure subroutine shall not cause a variable to become 
defined or undefined if that variable is referenced, directly or indirectly, by 
that pure subroutine."

I see no point whatsoever in playing with pointer restrictions - it's like 
closing the doors of a stable that doesn't even have any walls!

Cheers,
-- 
................................Malcolm Cohen, Nihon NAG, Tokyo. 

