#511 closed defect (worksforme)
Syntax-rules expansion uses unprefixed identifiers which can be captured by module imports
Reported by: | sjamaan | Owned by: | felix winkelmann |
---|---|---|---|
Priority: | critical | Milestone: | 4.9.0 |
Component: | expander | Version: | 4.6.x |
Keywords: | declare, macro-expanded code | Cc: | |
Estimated difficulty: |
Description
It appears that "declare" statements in macro expanded code don't work properly anymore: http://tests.call-cc.org/2011/02/19/salmonella-report/snowtar.html
Change History (15)
comment:1 Changed 14 years ago by
Priority: | major → critical |
---|
comment:2 follow-up: 4 Changed 14 years ago by
Owner: | changed from sjamaan to felix winkelmann |
---|---|
Status: | new → assigned |
comment:3 Changed 14 years ago by
Summary: | Expander problem with "declare" triggered by snowtar → Syntax-rules expansion uses unprefixed identifiers which can be captured by module imports |
---|
comment:4 Changed 14 years ago by
Replying to sjamaan:
We should check that the non-
##sys#
-prefixed identifiers like the special formsand
and such -- but also the free identifiers likecompare
and such! --
I got cut off there. I meant to say we should check that all non-prefixed identifiers are safe and cannot be captured in whatever way.
comment:5 Changed 14 years ago by
I was a bit surprised that snowtar complains that numbers#- is not defined though.
It's good that it does that, and I added a regression test that makes this behaviour explicitly defined: hashed prefixed references to other modules' identifiers should not work in modules.
See expander-simplifications
changeset 0862e159 for this regression test. I hope you agree this is a good idea.
comment:6 Changed 14 years ago by
I tried hard but couldn't break it. Possibly the problem does not occur for macros or free identifiers. Should we try to fix it for bound identifiers?
comment:8 Changed 14 years ago by
Replying to felix:
Sorry, Peter, but I don't understand a single word.
Ok, I tried to install snowtar - are you saying that the expansion of a syntax-rules
contains expander-specific code that captures identifiers? Is this the problem?
comment:9 Changed 14 years ago by
syntax-rules is a macro. Its expansion includes renamed identifiers for "length", among others.
But this renaming doesn't appear to work properly; if there are imported procedures with the same name, those are used instead of the ones from library.scm. So yes, I think the problem is "that the expansion of a syntax-rules contains expander-specific code that captures identifiers".
I think this has something to do with the fact that it's a macro-generating macro. I will try to come up with a simpler testcase.
comment:10 Changed 14 years ago by
My changes in git get rid of this problem by using only ##sys#
-prefixed names in its expansion.
comment:11 Changed 14 years ago by
I had another look at the generated code and it turns out I was wrong: the length
procedure is only used in the generated macro's code, not in the expansion of that macro. This makes it even more peculiar that it's not working!
It's as if the "rename" procecudure isn't working properly with imports. However, I'm not able to reproduce this. Possible it only happens with the "core" syntax env.
comment:12 Changed 14 years ago by
I mean I'm not able to reproduce this in a simple testcase!
I can easily reproduce it with the above code snippet in the second comment here, after I change this line in synrules.scm:
(define %length '##sys#length)
to
(define %length (r 'length)
comment:13 Changed 14 years ago by
Resolution: | → worksforme |
---|---|
Status: | assigned → closed |
Just ignore my silly ramblings
Turns out this has nothing to do with "declare" after all, but it was a bug in my patch for #379 (forgot to rename "-")
It turns out that even renaming it properly does not help - because the library imports an global identifier called "
-
", that will always be used. If this is a bug, we should really look at that! I suppose it may not really be a bug as syntax-rules is a macro-generating macro; it would have to have some way to refer to the definition of-
at the definition site of syntax-rules, not at the definition site of the macro that it generates (I hope this makes sense... *My* head almost exploded...).Another example is that I was unable to rename "length" in such a way that it couldn't be captured like this:
I had to work around that by adding a "safe"
##sys#length
tolibrary.scm
. The minus I simply changed to plus, and added -1 to the value. Alternatively, I could've done the same as for length, to add##sys#-
tolibrary.scm
.These immediate bugs in syntax-rules have been fixed in changeset 0eb8724 of the
expander-simplifications
branch; I've also removed a couple of unused local definitions there.We should check that the non-
##sys#
-prefixed identifiers like the special formsand
and such -- but also the free identifiers likecompare
and such! --