

Issue: LOCALLY-TOP-LEVEL (Version 1)

This is a cleanup issue, but I'm cc'ing the compiler committee
for their information.

Issue:         LOCALLY-TOP-LEVEL

References:    None



Edit history:  Version 1, 9-Mar-89, by Moon

Problem description:

  It is desirable to be able to wrap LOCALLY around one or more
  top-level forms and have them continue to be treated as top-level
  forms.  Three examples of how this is useful:

   - to put an OPTIMIZE or INLINE declaration into force around
     several related forms.

   - to put declarations into force around DEFCLASS, or any other
     top-level form that lacks a syntax for embedded declarations.

   - DECLARATION-SCOPE:LIMITED-HOISTING, which passed in January,
     removed the ability to use a DECLARE at the head of the body of a
     DEFUN or DEFMACRO to make a declaration that applies to the entire
     form, including the lambda-list.  We are supposed to use LOCALLY
     instead, but forms in the body of LOCALLY are not top-level,
     and that changes the semantics of DEFMACRO.

  Issue EVAL-WHEN-NON-TOP-LEVEL could not define LOCALLY to treat
  its body as top-level forms, because only a special form can do
  that and LOCALLY is a macro.

  Change LOCALLY from a macro to a special form, and change the
  definition of compiler processing (in EVAL-WHEN-NON-TOP-LEVEL)
  so that when a LOCALLY form appears at top level the forms in
  its body are processed at top level.


    (defmacro frob (&environment e x y &optional (z (foo x y)))
      (mumble x y z e)))

  Without this proposal, this would have to be written

  (defmacro frob (&environment e x y &optional (z (locally
                                                        (safety 3)
                                                        (space 3)
                                                        (speed 0)))
                                                    (foo x y))))
      (mumble x y z e)))


  Wrapping LOCALLY around a form should not change its semantics except
  as specified by the declarations, hence the body of a top-level
  LOCALLY should be top-level.

  A macro cannot have a top-level body unless it expands into a special
  form that has a top-level body; otherwise the macro invocation and
  the macro expansion would not have identical semantics as top-level
  forms.  There is no available special form for LOCALLY to macroexpand
  into (CLtL doesn't say, but presumably the intent was to expand into
  a LET with an empty binding list).

Current practice:

  The Zetalisp equivalent of LOCALLY worked to surround top-level forms,
  because it was a macro that expanded into COMPILER-LET (stashing the
  declarations in a special variable the compiler would look at).  This
  is of course the wrong way to do declarations, but it shows that the
  idea was that you could wrap declarations around a bunch of top-level

  Symbolics Genera 7.4.0 does not implement the proposal (but it does
  not implement DECLARATION-SCOPE:LIMITED-HOISTING either).  I did
  not survey any other implementations.

Cost to Implementors:

  A half dozen lines of code in the compiler and a smaller amount
  in the interpreter and any program-analyzing programs.

Cost to Users:


Cost of non-adoption:

  See the horrible example above.

Performance impact:



  More consistent language.