source: trunk/abcl/src/org/armedbear/lisp/fdefinition.lisp @ 15388

Last change on this file since 15388 was 15388, checked in by Mark Evenson, 2 years ago

Ensure that SYS:CHECK-REDEFINITION does not signal error conditions

Unfortunately, SLIME v2.26 code can throw errors when compiling Emacs
buffers, namely the pathname may have a device containing the string
"emacs-buffer" whose PATHNAME name denotes the buffer which often
contain wild-pathname characters (e.g. "*slime-scratch*") causing a
naieve PROBE-FILE to throw errors.

TODO redo ABCL SLIME's use of PATHNAME-DEVICE components to mark a
source location.

Use IGNORE-ERRORS to be extra careful.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 7.6 KB
Line 
1;;; fdefinition.lisp
2;;;
3;;; Copyright (C) 2005-2006 Peter Graves
4;;; $Id: fdefinition.lisp 15388 2020-10-09 05:55:31Z mevenson $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19;;;
20;;; As a special exception, the copyright holders of this library give you
21;;; permission to link this library with independent modules to produce an
22;;; executable, regardless of the license terms of these independent
23;;; modules, and to copy and distribute the resulting executable under
24;;; terms of your choice, provided that you also meet, for each linked
25;;; independent module, the terms and conditions of the license of that
26;;; module.  An independent module is a module which is not derived from
27;;; or based on this library.  If you modify this library, you may extend
28;;; this exception to your version of the library, but you are not
29;;; obligated to do so.  If you do not wish to do so, delete this
30;;; exception statement from your version.
31
32(in-package #:system)
33
34(export '(record-source-information untraced-function))
35
36(defun check-redefinition (name)
37  (when (and *warn-on-redefinition* (fboundp name) (not (autoloadp name)))
38    (when (and (symbolp name)
39               (source-pathname name))
40      ;; SOURCE-PATHNAME is badly named as it is either a PATHNAME,
41      ;; the keyword :TOP-LEVEL.
42      ;;
43      ;; Unfortunately, as of SLIME v2.26 the pathname may have a
44      ;; device containing the string "emacs-buffer" whose PATHNAME
45      ;; name denotes the buffer, which often contain wild-pathname
46      ;; characters (e.g. "*slime-scratch*").  We code around that
47      ;; situation with the following convolution of intelligibility.
48      (flet ((truename-no-error (p)
49               (if (and (pathnamep p)
50      (not (and
51            (stringp (pathname-device p))
52            (string= (pathname-device p)
53               "emacs-buffer")))
54                        (not (wild-pathname-p p)))
55                   (probe-file p)
56                   p)))
57        (let ((source (source-pathname name)))
58          (let ((old-source 
59                  (if (keywordp source)
60                      source
61                      (truename-no-error source)))
62                (current-source
63                  (if (not *source*) 
64                      :top-level
65                      (truename-no-error source))))
66            (cond ((equal old-source 
67                          current-source)) ; OK
68                  (t
69                   (if (eq current-source :top-level)
70                       (style-warn "redefining ~S at top level" name)
71                       (let ((*package* +cl-package+))
72                         (if (eq old-source :top-level)
73                             (style-warn "redefining ~S in ~S (previously defined at top level)"
74                                         name current-source)
75                             (style-warn "redefining ~S in ~S (previously defined in ~S)"
76                                     name current-source old-source))))))))))))
77
78;;; DEPRECATED:  to be removed in abcl-1.7
79(defun record-source-information (name &optional source-pathname source-position)
80  (unless source-pathname
81    (setf source-pathname (or *source* :top-level)))
82  (unless source-position
83    (setf source-position *source-position*))
84  (let ((source (if source-position
85                    (cons source-pathname source-position)
86                    source-pathname)))
87    (cond ((symbolp name)
88           (put name '%source source)))))
89
90(defun record-source-information-for-type (name type &optional source-pathname source-position)
91  "Record source information on the SYS:SOURCE property for symbol with NAME
92
93TYPE is either a symbol or list.
94
95Source information for functions, methods, and generic functions are
96represented as lists of the following form:
97
98    (:generic-function function-name)
99    (:function function-name)
100    (:method method-name qualifiers specializers)
101
102Where FUNCTION-NAME or METHOD-NAME can be a either be of the form
103'symbol or '(setf symbol).
104
105Source information for all other forms have a symbol for TYPE which is
106one of the following:
107
108:class, :variable, :condition, :constant, :compiler-macro, :macro
109:package, :structure, :type, :setf-expander, :source-transform
110
111These values follow SBCL'S implemenation in SLIME
112c.f. <https://github.com/slime/slime/blob/bad2acf672c33b913aabc1a7facb9c3c16a4afe9/swank/sbcl.lisp#L748>
113
114"
115#|
116Modifications are in two places, one at the definitions, calling
117record-source-information-by-type and then again in the file-compiler,
118which writes forms like
119
120(put 'source name (cons (list type pathname position) (get 'source name)))
121
122In theory this can lead to redundancy if a fasl is loaded again and
123again. I'm not sure how to fix this yet. Forms in the __loader__ get
124called early in build when many of the sequence functions aren't
125present.  Will probably just filter when presenting in slime.
126
127|# 
128    (unless source-pathname
129      (setf source-pathname (or *source* :top-level)))
130    (unless source-position
131      (setf source-position *source-position*))
132    (let ((source (if source-position
133          (list source-pathname source-position)
134          (list source-pathname))))
135      (let ((sym (if (consp name) (second name) name))
136            (new `(,type ,(if (symbolp (car source)) (car source) (namestring (car source))) ,(second source))))
137        (if (autoloadp 'delete)
138   (put sym 'sys::source (cons new (get sym  'sys::source nil)))
139         (put sym 'sys::source (cons new (delete new (get sym  'sys::source nil) 
140               :test (lambda(a b) (and (equalp (car a) (car b)) (equalp (second a) (second b) ))))))))))
141
142;; Redefined in trace.lisp.
143(defun trace-redefined-update (&rest args)
144  (declare (ignore args)))
145
146;; Redefined in trace.lisp.
147(defun untraced-function (name)
148  (declare (ignore name))
149  nil)
150
151(%defvar '*fset-hooks* nil)
152
153(defun fset (name function &optional source-position arglist documentation)
154  (cond ((symbolp name)
155         (check-redefinition name)
156         (record-source-information name nil source-position)
157         (when arglist
158           (%set-arglist function arglist))
159         (%set-documentation function 'function documentation)
160         (%set-symbol-function name function))
161        ((setf-function-name-p name)
162         (check-redefinition name)
163         (record-source-information name nil source-position)
164         ;; FIXME arglist documentation
165         (setf (get (%cadr name) 'setf-function) function))
166        (t
167         (require-type name '(or symbol (cons (eql setf) (cons symbol null))))))
168  (when (functionp function) ; FIXME Is this test needed?
169    (%set-lambda-name function name))
170  (dolist (hook *fset-hooks*) (ignore-errors (funcall hook name function)))
171  (trace-redefined-update name function)
172  function)
173
174(defun fdefinition (name)
175  (cond ((symbolp name)
176         (symbol-function name))
177        ((setf-function-name-p name)
178         (or (get (%cadr name) 'setf-function)
179             (error 'undefined-function :name name)))
180        (t
181         (require-type name '(or symbol (cons (eql setf) (cons symbol null)))))))
182
183(defun %set-fdefinition (name function)
184  (fset name function))
185
186(defsetf fdefinition %set-fdefinition)
Note: See TracBrowser for help on using the repository browser.