🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #2122

Re: Oberon vs Modula-2

#2122
From: Andreas Borchert
Date: Thu, 19 Nov 1992 08:14
74 lines
3594 bytes
In article <gpjqq!h+@aix01.rz.fht-mannheim.de>, mw%ki.fht-mannheim.de (Marc Wachowitz) writes:
> Andreas Borchert (borchert@titania.mathematik.uni-ulm.de) wrote
> in reply to Markku Sakkinen <sakkinen@jyu.fi>:
> : Agreed, programmers shouldn't be enforced to use VAR-parameters
> : for reasons of efficiency only. But, even with the semantics of
> : Oberon or Modula-2, it's not to difficult for the compiler to
> : detect that your 1000 x 1000 array isn't modified and, thus,
> : doesn't need to be copied.
> 
> That doesn't work as soon as your procedure is public and (directly or
> indirectly) calls some procedure not fully known to the compiler, since
> the original argument may be accessible and modified behind the back of the
> supposedly innocent routine. According to the current definition it only
> sees a copy made at the entry and therefore would not be influenced by the
> perfectly legal modification, but due to our smart optimizer ... :-(

Probably, you are speaking of a situation like the following:

   TYPE BigArray = ARRAY 1000, 1000 OF REAL;

   VAR
      bigarray: BigArray; (* global accessible *)

   PROCEDURE NastyProcedure;
      (* probably in another module, so we can't see it if
	 we are compiling InnocentProcedure
      *)
   BEGIN
      bigarray[0][0] := 1.0; (* modify bigarray somewhere *)
   END NastyProcedure;

   PROCEDURE InnocentProcedure(bigarray: BigArray);
      (* bigarray is not modified by InnocentProcedure itself *)
   BEGIN
      NastyProcedure;
   END InnocentProcedure;

   PROCEDURE CallingProcedure;
   BEGIN
      InnocentProcedure(bigarray);
   END CallingProcedure;

There may be different viewpoints on this problem: either large
parameters are copied by the calling procedure or by the called
procedure (the latter case reduces code size if the procedure
is at least called at one location which should be usually the case).

Generally, this kind of optimization is only possible if

(1)	we know the code of the called procedure (because it
	is part of the same module), or if
(2)	the code for copying large parameters is part of the
	called procedure.

AND

(3)	the called procedure does not modify the parameter itself
	or calls anything which may modify the parameter.
	This requires all procedures to be known which
	are called by InnocentProcedure or, if InnocentProcedure
	is not exported, we may conclude from the inaccessibility
	of all parameters (i.e. if only local parameters get
	passed to InnocentProcedure).


This, of course, means that there may be cases where we have to
copy the big array without real necessity. But there still remain
enough possibilities to apply this optimization technique.

-- 
_______________________________________________________________________________

Andreas Borchert, University of Ulm, SAI, D-W-7900 Ulm, Germany
Internet: borchert@mathematik.uni-ulm.de
Technical Details
Message-ID: <1992Nov19.081413.26687@informatik.uni-ulm.de>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!news.belwue.de!theorie!titania.mathematik.uni-ulm.de!borchert
References: <1992Nov16.080647.26783@informatik.uni-ulm.de> <gpjqq!h+@aix01.rz.fht-mannheim.de>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.modula2
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!news.belwue.de!theorie!titania.mathematik.uni-ulm.de!borchert
From: borchert@titania.mathematik.uni-ulm.de (Andreas Borchert)
Subject: Re: Oberon vs Modula-2
Message-ID: <1992Nov19.081413.26687@informatik.uni-ulm.de>
Sender: usenet@informatik.uni-ulm.de (Name for nntp-posting)
Nntp-Posting-Host: titania.mathematik.uni-ulm.de
Organization: University of Ulm, SAI
References: <1992Nov16.080647.26783@informatik.uni-ulm.de> <gpjqq!h+@aix01.rz.fht-mannheim.de>
Date: Thu, 19 Nov 92 08:14:13 GMT
Lines: 74