GSOC | Extending Common Lisp support
Jamison Hope
jrh@theptrgroup.com
Sat Jun 2 22:47:00 GMT 2012
On Jun 2, 2012, at 6:13 PM, Per Bothner wrote:
> On 06/02/2012 02:06 PM, Jamison Hope wrote:
>> That seems to be a difference between running kawa
>> with or without -f:
>>
>> $ kawa --diagnostic-strip-directories -f
>> gnu/commonlisp/testsuite/warnings.lisp
>> warnings.lisp:1:1: warning - no declaration seen for x
>> 42
>> $ kawa --diagnostic-strip-directories
>> gnu/commonlisp/testsuite/warnings.lisp
>> warnings.lisp:1:1: warning - no declaration seen for x
>> warnings.lisp:4:8: warning - no declaration seen for x
>> 42
>
> The warning happens if there is no declaration in the
> lexical environment *and* there is no binding in the dynamic
> environment.
> In the -f case, evaluating line 1 emits a warning, but after
> executing x it gets added to the dynamic environment, which
> avoids the warning for line 4. In the non-f case, the file file is
> compiled
> as a unit.
>
> It may be reasonable to change the "no declaration seen for" so it
> only happens
> once per compilation unit. Perhaps move the warning into the method
> FindCapturedVars#allocUnboundDecl, though I'm not sure if that's
> right.
On a related note, occasionally the "no declaration seen for" warning is
just plain wrong:
$ cat /tmp/test.lisp
(defvar foo 42)
(write foo) (newline)
$ kawa /tmp/test.lisp
/tmp/test.lisp:2:8: warning - no declaration seen for foo
42
Line 2 apparently didn't notice the declaration of foo on line 1.
>> RunTestScript runs kawa like the latter, so fine, we'll add another
>> Diagnostic line. But if I then add
>>
>>> (defvar list-of-numbers (list 1 2 3))
>>> (defun list-of-numbers (start end)
>>> (if (> start end)
>>> nil
>>> (cons start (list-of-numbers (1+ start) end))))
>>>
>>> (write list-of-numbers)
>>
>> in order to test the different namespaces, I get this other
>> warning, which
>> seems like a bug:
>>
>> warnings.lisp:12:1: warning - duplicate declaration for `list-of-
>> numbers'
>>
>>
>> Especially considering the full -f/no -f output differences:
>>
>> $ kawa --diagnostic-strip-directories -f
>> gnu/commonlisp/testsuite/warnings.lisp
>> warnings.lisp:1:1: warning - no declaration seen for x
>> 42
>> warnings.lisp:15:17: warning - no declaration seen for list-of-
>> numbers
>> warnings.lisp:15:34: warning - no declaration seen for 1+
>> (1 2 3)
>> $ kawa --diagnostic-strip-directories
>> gnu/commonlisp/testsuite/warnings.lisp
>> warnings.lisp:12:1: warning - duplicate declaration for `list-of-
>> numbers'
>> warnings.lisp:1:1: warning - no declaration seen for x
>> warnings.lisp:4:8: warning - no declaration seen for x
>> warnings.lisp:15:17: warning - no declaration seen for list-of-
>> numbers
>> warnings.lisp:15:34: warning - no declaration seen for 1+
>> warnings.lisp:17:8: warning - no declaration seen for list-of-numbers
>> 42
>> #<procedure list-of-numbers>
>>
>>
>> That looks like running without -f (as RunTestScript does) just
>> doesn't
>> work correctly for Lisp2 languages.
>>
>> Should we change RunTestScript to pass -f, or try to figure out why
>> it's not respecting the separate namespaces?
>
> The latter. If running without -f doesn't work, then ahead-of-tie
> compilation (i.e. -C then) is unlikely to work. So that isn't the
> fix.
Yeah I figured the easy change wasn't the right one. ;-)
> The key method here is Language#getNamespaceOf, and the constants
> Language#VALUE_NAMESPACE and Language#FUNCTION_NAMESPACE.
> I think we want a duplicate declaration error if and only if
> the results of getNamespaceOf have overlapping bits.
>
> It's also worth noting the XQuery also hasSeparateFunctionNamespace,
> and the logic works there (though XQuery doesn't have local
> functions).
Note that here the problem is more than just a superfluous or erroneous
warning: without the -f, (write list-of-numbers) is writing the function
and not the list, indicating that the defun stored the procedure in the
wrong place. With the -f, the behavior is correct.
$ cat /tmp/namespaces.lisp
(defvar x "hello")
(defun x () 1)
(write x) (newline) ; should be TERPRI
(write #'x) (newline) ; and not NEWLINE
$ kawa -f /tmp/namespaces.lisp
"hello"
#<procedure x>
$ kawa /tmp/namespaces.lisp
/tmp/namespaces.lisp:2:1: warning - duplicate declaration for `x'
/tmp/namespaces.lisp:3:8: warning - no declaration seen for x
/tmp/namespaces.lisp:4:8: warning - no declaration seen for x
#<procedure x>
/tmp/namespaces.lisp:4:8: unbound location x (property (function))
at gnu.mapping.Location.get(Location.java:67)
at namespaces.run(namespaces.lisp:4)
at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:299)
at gnu.expr.CompiledModule.evalModule(CompiledModule.java:41)
at gnu.expr.CompiledModule.evalModule(CompiledModule.java:60)
at kawa.Shell.runFile(Shell.java:511)
at kawa.Shell.runFileOrClass(Shell.java:426)
at kawa.repl.main(repl.java:880)
--
Jamison Hope
The PTR Group
www.theptrgroup.com
More information about the Kawa
mailing list