GNU bug report logs -
#47552
27.1; cl-defstruct field names matching read-only variables -> bad code
Previous Next
Reported by: Matt Armstrong <matt <at> rfc20.org>
Date: Thu, 1 Apr 2021 18:39:01 UTC
Severity: normal
Found in versions 27.1, 28.2
Done: Stefan Monnier <monnier <at> iro.umontreal.ca>
Bug is archived. No further changes may be made.
Full log
Message #15 received at 47552 <at> debbugs.gnu.org (full text, mbox):
>> The issue is related to the generated code for `make-a', which boils
>> down to let binding gcs-done to nil:
>>
>> (let ((gcs-done)))
>>
>> Eval the above to get the same error.
>>
>> Perhaps the code generated for the make- functions should use
>> make-symbol or gensym instead? Or a fixed series of field0...fieldN
>> symbols? Why risk potentially binding dynamic vars?
>
> Using a gensym seems like an obvious solution to me, but perhaps Stefan
> has an opinion here (added to the CCs).
I'm pretty sure that's the right solution, *but* I don't think it's
obvious how to get there: `cl-defstruct` defines the constructor
using `cl-defsubst` and its `&key` arguments, so the `:gcs-gone` keyword
argument inevitably maps to a `gcs-done` variable by definition of how
`&key` is supposed to work.
So I suspect that in order to fix it, we'd need to stop using `&key`, or
to use a more sophisticated version (which I think we'd have to
implement first) which lets you specify separately the keyword and the
matching variable name (and then make sure that the inlining
optimizations still work for it).
Stefan
This bug report was last modified 2 years and 26 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.