sb-cltl2::macroexpand-all doesn't track the lexenv properly

Bug #590076 reported by Attila Lendvai
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
SBCL
Triaged
Medium
Unassigned

Bug Description

on 1.0.39.4

see the pasted form below (the macro is expanded twice, although that's not illegal in itself).

the lexenv passed to the macrolet does not contain the tags of the tagbody, nor the blocks, and a throughout test would probably uncover other missing things.

(sb-cltl2::macroexpand-all
       '(BLOCK B1
         (TAGBODY
          T1
            (PROGN)
          T2
            (BLOCK B2
              (MACROLET ((INJECTOR-MACRO2131 (&ENVIRONMENT ENV)
                           (print env)
                           (VALUES)))
                (INJECTOR-MACRO2131))))))

will print this:

#S(SB-KERNEL:LEXENV
   :FUNS ((INJECTOR-MACRO2131 SB-SYS:MACRO . #) (#:G4 SB-SYS:MACRO . #) (#:G4 SB-SYS:MACRO . #))
   :VARS NIL
   :BLOCKS NIL
   :TAGS NIL
   :TYPE-RESTRICTIONS NIL
   :LAMBDA NIL
   :CLEANUP NIL
   :HANDLED-CONDITIONS NIL
   :DISABLED-PACKAGE-LOCKS NIL
   :%POLICY ((COMPILATION-SPEED . 1) (DEBUG . 3) (SB-EXT:INHIBIT-WARNINGS . 1) (SAFETY . 1) (SPACE . 1) (SPEED . 1))
   :USER-DATA NIL)
#S(SB-KERNEL:LEXENV
   :FUNS ((#:G4 SB-SYS:MACRO . #) (INJECTOR-MACRO2131 SB-SYS:MACRO . #) (#:G4 SB-SYS:MACRO . #) (#:G4 SB-SYS:MACRO . #))
   :VARS NIL
   :BLOCKS NIL
   :TAGS NIL
   :TYPE-RESTRICTIONS NIL
   :LAMBDA NIL
   :CLEANUP NIL
   :HANDLED-CONDITIONS NIL
   :DISABLED-PACKAGE-LOCKS NIL
   :%POLICY ((COMPILATION-SPEED . 1) (DEBUG . 3) (SB-EXT:INHIBIT-WARNINGS . 1) (SAFETY . 1) (SPACE . 1) (SPEED . 1))
   :USER-DATA NIL)

Tags: sb-cltl2
tags: added: sb-cltl2
Changed in sbcl:
importance: Undecided → Medium
status: New → Triaged
Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

This is clearly suboptimal, but given that there's no supported way (via sb-cltl2) to access block and tag names, non-critical.

The issue is with SB-WALKER not adding block and tag names into the environment in the first place.

Revision history for this message
Michael Raskin (nh6dwy2v2wew) wrote :

It looks like environments with blocks are fragile outside the expansion extent, it may create additional problems for a code walker.

For example,
(macrolet ((f (&environment e) (format t "~s~%" e) `(quote ,e))) (block a (f)))
prints the environment during the expansion, but then errors while trying to print the returned environment.

Revision history for this message
Douglas Katzman (dougk) wrote :

"... while trying to print the returned environment." - DON'T DO THAT.

See http://www.lispworks.com/documentation/HyperSpec/Issues/iss229_w.htm which discusses whether environments have indefinite or dynamic extent.
Our environments have dynamic extent, so of course you can't print them after return from the form that tried to capture one indefinitely.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.