home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / modula2 / 1415 < prev    next >
Encoding:
Text File  |  1992-11-18  |  3.4 KB  |  87 lines

  1. Newsgroups: comp.lang.modula2
  2. Path: 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
  3. From: borchert@titania.mathematik.uni-ulm.de (Andreas Borchert)
  4. Subject: Re: Oberon vs Modula-2
  5. Message-ID: <1992Nov19.081413.26687@informatik.uni-ulm.de>
  6. Sender: usenet@informatik.uni-ulm.de (Name for nntp-posting)
  7. Nntp-Posting-Host: titania.mathematik.uni-ulm.de
  8. Organization: University of Ulm, SAI
  9. References: <1992Nov16.080647.26783@informatik.uni-ulm.de> <gpjqq!h+@aix01.rz.fht-mannheim.de>
  10. Date: Thu, 19 Nov 92 08:14:13 GMT
  11. Lines: 74
  12.  
  13. In article <gpjqq!h+@aix01.rz.fht-mannheim.de>, mw%ki.fht-mannheim.de (Marc Wachowitz) writes:
  14. > Andreas Borchert (borchert@titania.mathematik.uni-ulm.de) wrote
  15. > in reply to Markku Sakkinen <sakkinen@jyu.fi>:
  16. > : Agreed, programmers shouldn't be enforced to use VAR-parameters
  17. > : for reasons of efficiency only. But, even with the semantics of
  18. > : Oberon or Modula-2, it's not to difficult for the compiler to
  19. > : detect that your 1000 x 1000 array isn't modified and, thus,
  20. > : doesn't need to be copied.
  21. > That doesn't work as soon as your procedure is public and (directly or
  22. > indirectly) calls some procedure not fully known to the compiler, since
  23. > the original argument may be accessible and modified behind the back of the
  24. > supposedly innocent routine. According to the current definition it only
  25. > sees a copy made at the entry and therefore would not be influenced by the
  26. > perfectly legal modification, but due to our smart optimizer ... :-(
  27.  
  28. Probably, you are speaking of a situation like the following:
  29.  
  30.    TYPE BigArray = ARRAY 1000, 1000 OF REAL;
  31.  
  32.    VAR
  33.       bigarray: BigArray; (* global accessible *)
  34.  
  35.    PROCEDURE NastyProcedure;
  36.       (* probably in another module, so we can't see it if
  37.      we are compiling InnocentProcedure
  38.       *)
  39.    BEGIN
  40.       bigarray[0][0] := 1.0; (* modify bigarray somewhere *)
  41.    END NastyProcedure;
  42.  
  43.    PROCEDURE InnocentProcedure(bigarray: BigArray);
  44.       (* bigarray is not modified by InnocentProcedure itself *)
  45.    BEGIN
  46.       NastyProcedure;
  47.    END InnocentProcedure;
  48.  
  49.    PROCEDURE CallingProcedure;
  50.    BEGIN
  51.       InnocentProcedure(bigarray);
  52.    END CallingProcedure;
  53.  
  54. There may be different viewpoints on this problem: either large
  55. parameters are copied by the calling procedure or by the called
  56. procedure (the latter case reduces code size if the procedure
  57. is at least called at one location which should be usually the case).
  58.  
  59. Generally, this kind of optimization is only possible if
  60.  
  61. (1)    we know the code of the called procedure (because it
  62.     is part of the same module), or if
  63. (2)    the code for copying large parameters is part of the
  64.     called procedure.
  65.  
  66. AND
  67.  
  68. (3)    the called procedure does not modify the parameter itself
  69.     or calls anything which may modify the parameter.
  70.     This requires all procedures to be known which
  71.     are called by InnocentProcedure or, if InnocentProcedure
  72.     is not exported, we may conclude from the inaccessibility
  73.     of all parameters (i.e. if only local parameters get
  74.     passed to InnocentProcedure).
  75.  
  76.  
  77. This, of course, means that there may be cases where we have to
  78. copy the big array without real necessity. But there still remain
  79. enough possibilities to apply this optimization technique.
  80.  
  81. -- 
  82. _______________________________________________________________________________
  83.  
  84. Andreas Borchert, University of Ulm, SAI, D-W-7900 Ulm, Germany
  85. Internet: borchert@mathematik.uni-ulm.de
  86.