Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macroexpand-1 handling of shadowing in lexical environment #1556

Closed
fb08af68 opened this issue Jan 30, 2024 · 1 comment · Fixed by #1557
Closed

macroexpand-1 handling of shadowing in lexical environment #1556

fb08af68 opened this issue Jan 30, 2024 · 1 comment · Fixed by #1557
Labels

Comments

@fb08af68
Copy link

Describe the bug

In a local lexical environment, functions defined by flet shadow macros introduced both by macrolet and defmacro. Normal execution implements this, but macroexpand-1 doesn't seem to.

Expected behavior

(macroexpand-1 '(f) env) returns (f) when f is in env as a function introduced by flet, regardless of presence of global macros defined by defmacro or lexically-scoped macros defined by macrolet.

Actual behavior

A macro is expanded. An older version failed to shadow both local and global ones, a fresh version shadows the local ones but the global macros are still not shadowed.

Code at issue

(defmacro g () 3)
(macrolet ((g () 1) 
                   (e (x &environment env) 
                   `',(macroexpand-1 x env)))
  (flet ((g () 2)) 
    (e (g))))

Expected: (g)
Actual on 2.2.0 from Nixpkgs: 1
Actual on 2.5.0 on Debian Bookworm from thirdlaw.tech repo: 3

If (e (g)) is replaced with (progn (g)), both expected an actual behaviour is to return 2.

Context

  • Versions or commit hashes of Clasp on which you observed the problem (if you have built from up to date source, saying so is fine, you don't need to dig around for hashes)

2.5.0-85-gd23de8b43

  • If relevant, your operating system and other aspects of your computing environment

Freshly installed Debian Bookworm VM

  • If you believe the compiler may be at fault, relevant declarations, including optimize settings (use (clasp-cltl2:declaration-information 'optimize))

Not changed; everything equal to 1

  • Any other context about the problem

Hopefully irrelevant, but https://gitlab.common-lisp.net/mraskin/agnostic-lizard/-/issues/6 (trying to check if examples.lisp failures are my fault or bugs in Clasp)

@fb08af68 fb08af68 added the bug label Jan 30, 2024
@Bike
Copy link
Member

Bike commented Jan 31, 2024

T_sp func = gc::As_unsafe<comp::Lexenv_sp>(env)->lookupMacro(symbol);
if (func.nilp() // not bound locally, try global
&& symbol->fboundp() && symbol->macroP())
return symbol->symbolFunction();
else
return func;
Here's the problem, or at least one problem. lookupMacro returns nil because the macro is shadowed, but macro-function takes this to mean it's not bound locally at all, so it uses the global definition.

Testing a fix.

Bike added a commit to s-expressionists/Cleavir that referenced this issue Jan 31, 2024
See clasp-developers/clasp#1556. macro-function did not respect
local function shadowing, so with code like
(macrolet ((g ...)) (flet ((g ...)) ...)) it would return the
macro, inappropriately.
Bike added a commit that referenced this issue Jan 31, 2024
Bike added a commit that referenced this issue Jan 31, 2024
There is a similar problem with Cleavir environments, so #1556 is
not fixed yet.
Bike added a commit that referenced this issue Jan 31, 2024
@Bike Bike mentioned this issue Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants