diff options
| author | Alan Mackenzie | 2021-11-29 11:19:31 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2021-11-29 11:19:31 +0000 |
| commit | 368570b3fd09d03ac5b9276d1ca85ae813c3f385 (patch) | |
| tree | 4d81fdc1a866120157147226c35597073592722d /src/data.c | |
| parent | 9721dcf2754ebad28ac60a9d3152fd26e4c652c4 (diff) | |
| download | emacs-368570b3fd09d03ac5b9276d1ca85ae813c3f385.tar.gz emacs-368570b3fd09d03ac5b9276d1ca85ae813c3f385.zip | |
First commit of scratch/correct-warning-pos.
This branch is intended to generate correct position information in warning
and error messages from the byte compiler, and is intended thereby to fix bugs
It introduces a new mechanism, the symbol with position. This is taken over
from the previous git branch scratch/accurate-warning-pos which was abandoned
for being too slow. The main difference in the current branch is that the
symbol `nil' is never given a position, thus speeding up NILP markedly.
* lisp/emacs-lisp/byte-opt.el (byte-compile-inline-expand)
(byte-optimize-form-code-walker, byte-optimize-let-form, byte-optimize-while)
(byte-optimize-apply): Use byte-compile-warn-x in place of byte-compile-warn.
* lisp/emacs-lisp/bytecomp.el (byte-compile--form-stack): New variable.
(byte-compile-strip-s-p-1, byte-compile-strip-symbol-positions): New
functions.
(byte-compile-recurse-toplevel, byte-compile-initial-macro-environment)
(byte-compile-preprocess, byte-compile-macroexpand-declare-function): Bind
print-symbols-bare to non-nil.
(byte-compile--first-symbol, byte-compile--warning-source-offset): New
functions.
(byte-compile-warning-prefix): Modify to output two sets of position
information, the old (incorrect) set and the new set.
(byte-compile-warn): Strip positions from symbols before outputting.
(byte-compile-warn-x): New function which outputs a correct position supplied
in an argument.
(byte-compile-warn-obsolete, byte-compile-emit-callargs-warn)
(byte-compile-format-warn, byte-compile-nogroup-warn)
(byte-compile-arglist-warn, byte-compile-docstring-length-warn)
(byte-compile-warn-about-unresolved-functions, byte-compile-file)
(byte-compile--check-prefixed-var, byte-compile--declare-var)
(byte-compile-file-form-defvar-function, byte-compile-file-form-defmumble)
(byte-compile-check-lambda-list, byte-compile--warn-lexical-dynamic)
(byte-compile-lambda, byte-compile-form, byte-compile-normal-call)
(byte-compile-check-variable, byte-compile-free-vars-warn)
(byte-compile-subr-wrong-args, byte-compile-fset, byte-compile-set-default)
(byte-compile-condition-case, byte-compile-save-excursion)
(byte-compile-defvar, byte-compile-autoload)
(byte-compile-make-variable-buffer-local, byte-compile-define-symbol-prop)
(byte-compile-define-keymap): Replace byte-compile-warn with
byte-compile-warn-x.
(byte-compile-file, compile-defun): Bind symbols-with-pos-enabled to non-nil.
(compile-defun, byte-compile-from-buffer): Use `read-positioning-symbols'
rather than plain `read'.
(byte-compile-toplevel-file-form, byte-compile-form): Dynamically bind
byte-compile--form-stack.
(byte-compile-file-form-autoload, byte-compile-file-form-defvar)
(byte-compile-file-form-make-obsolete, byte-compile-lambda)
(byte-compile-push-constant, byte-compile-cond-jump-table)
(byte-compile-define-keymap, byte-compile-annotate-call-tree):
Strip positions from symbols where they are unwanted.
(byte-compile-file-form-defvar): Strip positions from symbols using
`bare-symbol'.
(byte-compile-file-form-defmumble): New variable bare-name, a version of name
without its position.
(byte-compile-lambda): Similarly, new variable bare-arglist.
(byte-compile-free-vars-warn): New argument arg supplying position information
to byte-compile-warn-x.
(byte-compile-push-constant): Manipulation of symbol positions.
(display-call-tree): Strip positions from symbols.
* lisp/emacs-lisp/cconv.el (cconv-convert, cconv--analyze-use)
(cconv--analyze-function, cconv-analyze-form): Replace use of
byte-compile-warn with byte-compile-warn-x.
* lisp/emacs-lisp/cl-generic.el (cl-defmethod): New variable org-name which
will supply position information to a new macroexp-warn-and-return.
* lisp/emacs-lisp/cl-macs.el (cl-macs--strip-s-p-1)
(cl-macs--strip-symbol-positions): New functions to strip positions from
symbols in an expression. These duplicaate similarly named functions in
bytecomp.el.
* lisp/emacs-lisp/macroexpand.el (macroexp--warn-wrap): Calls
byte-compile-warn-x in place of byte-compile-warn.
(macroexp-warn-and-return): Commented out new position parameter _arg.
* src/.gdbinit: Add in code to handle symbols with position.
* src/alloc.c (XPNTR, set_symbol_name, valid_lisp_object_p, purecopy)
(mark_char_table, mark_object, survives_gc_p, symbol_uses_obj): Use
BARE_SYMBOL_P and XBARE_SYMBOL in place of the former SYMBOLP and XSYMBOL.
(build_symbol_with_pos): New function.
(Fgarbage_collect): Bind Qsymbols_with_pos_enabled to nil around the call to
garbage_collect.
* src/data.c (Ftype_of): Add case for PVEC_SYMBOL_WITH_POS.
(Fbare_symbol_p, Fsymbol_with_pos_p, Fbare_symbol, Fsymbol_with_pos_pos)
(Fposition_symbol): New functions.
(symbols_with_pos_enabled): New boolean variable.
* src/fns.c (internal_equal, hash_lookup): Handle symbols with position.
* src/keyboard.c (recursive_edit_1): Bind Qsymbols_with_pos_enabled and
Qprint_symbols_bare to nil.
* src/lisp.h (lisp_h_PSEUDOVECTORP): New macro.
(lisp_h_BASE_EQ): New name for the former lisp_h_EQ.
(lisp_h_EQ): Extended to handle symbols with position.
(lisp_h_NILP): Now uses BASE_EQ rather than EQ.
(lisp_h_SYMBOL_WITH_POS_P, lisp_h_BARE_SYMBOL_P): New macros.
(lisp_h_SYMBOLP): Redefined to handle symbols with position.
(BARE_SYMBOL_P, BASE_EQ): New macros.
(SYMBOLP (macro)): Removed.
(SYMBOLP (function), XSYMBOL, make_lisp_symbol, builtin_lisp_symbol)
(c_symbol_p): Moved to later in file.
(struct Lisp_Symbol_With_Pos): New data type.
(pvec_type): PVEC_SYMBOL_WITH_POS: New type code.
(PSEUDOVECTORP): Redefined to use the lisp_h_PSEUDOVECTORP.
(BARE_SYMBOL_P, SYMBOL_WITH_POS_P, SYMBOLP, XSYMBOL_WITH_POS, XBARE_SYMBOL)
(XSYMBOL, make_lisp_symbol, builtin_lisp_symbol, c_symbol_p, CHECK_SYMBOL)
(BASE_EQ): New functions, or functions moved from earlier in the file.
(SYMBOL_WITH_POS_SYM, SYMBOL_WITH_POS_POS): New INLINE functions.
* src/lread.c (read0, read1, read_list, read_vector, read_internal_start)
(list2): Add a new bool parameter locate_syms.
(Fread_positioning_symbols): New function.
(Fread_from_string, read_internal_start, read0, read1, read_list): Pass around
suitable values for locate_syms.
(read1): Build symbols with position when locate_syms is true.
* src/print.c (print_vectorlike): Add handling for PVEC_SYMBOL_WITH_POS.
(print_object): Replace EQ with BASE_EQ.
(print_symbols_bare): New boolean variable.
Diffstat (limited to 'src/data.c')
| -rw-r--r-- | src/data.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/data.c b/src/data.c index 0d3376f0903..b3b157a7f39 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -216,6 +216,7 @@ for example, (type-of 1) returns `integer'. */) | |||
| 216 | case PVEC_NORMAL_VECTOR: return Qvector; | 216 | case PVEC_NORMAL_VECTOR: return Qvector; |
| 217 | case PVEC_BIGNUM: return Qinteger; | 217 | case PVEC_BIGNUM: return Qinteger; |
| 218 | case PVEC_MARKER: return Qmarker; | 218 | case PVEC_MARKER: return Qmarker; |
| 219 | case PVEC_SYMBOL_WITH_POS: return Qsymbol_with_pos; | ||
| 219 | case PVEC_OVERLAY: return Qoverlay; | 220 | case PVEC_OVERLAY: return Qoverlay; |
| 220 | case PVEC_FINALIZER: return Qfinalizer; | 221 | case PVEC_FINALIZER: return Qfinalizer; |
| 221 | case PVEC_USER_PTR: return Quser_ptr; | 222 | case PVEC_USER_PTR: return Quser_ptr; |
| @@ -316,6 +317,26 @@ DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0, | |||
| 316 | return Qt; | 317 | return Qt; |
| 317 | } | 318 | } |
| 318 | 319 | ||
| 320 | DEFUN ("bare-symbol-p", Fbare_symbol_p, Sbare_symbol_p, 1, 1, 0, | ||
| 321 | doc: /* Return t if OBJECT is a symbol, but not a symbol together with position. */ | ||
| 322 | attributes: const) | ||
| 323 | (Lisp_Object object) | ||
| 324 | { | ||
| 325 | if (BARE_SYMBOL_P (object)) | ||
| 326 | return Qt; | ||
| 327 | return Qnil; | ||
| 328 | } | ||
| 329 | |||
| 330 | DEFUN ("symbol-with-pos-p", Fsymbol_with_pos_p, Ssymbol_with_pos_p, 1, 1, 0, | ||
| 331 | doc: /* Return t if OBJECT is a symbol together with position. */ | ||
| 332 | attributes: const) | ||
| 333 | (Lisp_Object object) | ||
| 334 | { | ||
| 335 | if (SYMBOL_WITH_POS_P (object)) | ||
| 336 | return Qt; | ||
| 337 | return Qnil; | ||
| 338 | } | ||
| 339 | |||
| 319 | DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0, | 340 | DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0, |
| 320 | doc: /* Return t if OBJECT is a symbol. */ | 341 | doc: /* Return t if OBJECT is a symbol. */ |
| 321 | attributes: const) | 342 | attributes: const) |
| @@ -753,6 +774,51 @@ DEFUN ("symbol-name", Fsymbol_name, Ssymbol_name, 1, 1, 0, | |||
| 753 | return name; | 774 | return name; |
| 754 | } | 775 | } |
| 755 | 776 | ||
| 777 | DEFUN ("bare-symbol", Fbare_symbol, Sbare_symbol, 1, 1, 0, | ||
| 778 | doc: /* Extract, if need be, the bare symbol from SYM, a symbol. */) | ||
| 779 | (register Lisp_Object sym) | ||
| 780 | { | ||
| 781 | if (BARE_SYMBOL_P (sym)) | ||
| 782 | return sym; | ||
| 783 | /* Type checking is done in the following macro. */ | ||
| 784 | return SYMBOL_WITH_POS_SYM (sym); | ||
| 785 | } | ||
| 786 | |||
| 787 | DEFUN ("symbol-with-pos-pos", Fsymbol_with_pos_pos, Ssymbol_with_pos_pos, 1, 1, 0, | ||
| 788 | doc: /* Extract the position from a symbol with position. */) | ||
| 789 | (register Lisp_Object ls) | ||
| 790 | { | ||
| 791 | /* Type checking is done in the following macro. */ | ||
| 792 | return SYMBOL_WITH_POS_POS (ls); | ||
| 793 | } | ||
| 794 | |||
| 795 | DEFUN ("position-symbol", Fposition_symbol, Sposition_symbol, 2, 2, 0, | ||
| 796 | doc: /* Create a new symbol with position. | ||
| 797 | SYM is a symbol, with or without position, the symbol to position. | ||
| 798 | POS, the position, is either a fixnum or a symbol with position from which | ||
| 799 | the position will be taken. */) | ||
| 800 | (register Lisp_Object sym, register Lisp_Object pos) | ||
| 801 | { | ||
| 802 | Lisp_Object bare; | ||
| 803 | Lisp_Object position; | ||
| 804 | |||
| 805 | if (BARE_SYMBOL_P (sym)) | ||
| 806 | bare = sym; | ||
| 807 | else if (SYMBOL_WITH_POS_P (sym)) | ||
| 808 | bare = XSYMBOL_WITH_POS (sym)->sym; | ||
| 809 | else | ||
| 810 | wrong_type_argument (Qsymbolp, sym); | ||
| 811 | |||
| 812 | if (FIXNUMP (pos)) | ||
| 813 | position = pos; | ||
| 814 | else if (SYMBOL_WITH_POS_P (pos)) | ||
| 815 | position = XSYMBOL_WITH_POS (pos)->pos; | ||
| 816 | else | ||
| 817 | wrong_type_argument (Qfixnum_or_symbol_with_pos_p, pos); | ||
| 818 | |||
| 819 | return build_symbol_with_pos (bare, position); | ||
| 820 | } | ||
| 821 | |||
| 756 | DEFUN ("fset", Ffset, Sfset, 2, 2, 0, | 822 | DEFUN ("fset", Ffset, Sfset, 2, 2, 0, |
| 757 | doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. */) | 823 | doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. */) |
| 758 | (register Lisp_Object symbol, Lisp_Object definition) | 824 | (register Lisp_Object symbol, Lisp_Object definition) |
| @@ -3929,6 +3995,8 @@ syms_of_data (void) | |||
| 3929 | 3995 | ||
| 3930 | DEFSYM (Qlistp, "listp"); | 3996 | DEFSYM (Qlistp, "listp"); |
| 3931 | DEFSYM (Qconsp, "consp"); | 3997 | DEFSYM (Qconsp, "consp"); |
| 3998 | DEFSYM (Qbare_symbol_p, "bare-symbol-p"); | ||
| 3999 | DEFSYM (Qsymbol_with_pos_p, "symbol-with-pos-p"); | ||
| 3932 | DEFSYM (Qsymbolp, "symbolp"); | 4000 | DEFSYM (Qsymbolp, "symbolp"); |
| 3933 | DEFSYM (Qfixnump, "fixnump"); | 4001 | DEFSYM (Qfixnump, "fixnump"); |
| 3934 | DEFSYM (Qintegerp, "integerp"); | 4002 | DEFSYM (Qintegerp, "integerp"); |
| @@ -3954,6 +4022,7 @@ syms_of_data (void) | |||
| 3954 | 4022 | ||
| 3955 | DEFSYM (Qchar_table_p, "char-table-p"); | 4023 | DEFSYM (Qchar_table_p, "char-table-p"); |
| 3956 | DEFSYM (Qvector_or_char_table_p, "vector-or-char-table-p"); | 4024 | DEFSYM (Qvector_or_char_table_p, "vector-or-char-table-p"); |
| 4025 | DEFSYM (Qfixnum_or_symbol_with_pos_p, "fixnum-or-symbol-with-pos-p"); | ||
| 3957 | 4026 | ||
| 3958 | DEFSYM (Qsubrp, "subrp"); | 4027 | DEFSYM (Qsubrp, "subrp"); |
| 3959 | DEFSYM (Qunevalled, "unevalled"); | 4028 | DEFSYM (Qunevalled, "unevalled"); |
| @@ -4038,6 +4107,7 @@ syms_of_data (void) | |||
| 4038 | DEFSYM (Qstring, "string"); | 4107 | DEFSYM (Qstring, "string"); |
| 4039 | DEFSYM (Qcons, "cons"); | 4108 | DEFSYM (Qcons, "cons"); |
| 4040 | DEFSYM (Qmarker, "marker"); | 4109 | DEFSYM (Qmarker, "marker"); |
| 4110 | DEFSYM (Qsymbol_with_pos, "symbol-with-pos"); | ||
| 4041 | DEFSYM (Qoverlay, "overlay"); | 4111 | DEFSYM (Qoverlay, "overlay"); |
| 4042 | DEFSYM (Qfinalizer, "finalizer"); | 4112 | DEFSYM (Qfinalizer, "finalizer"); |
| 4043 | DEFSYM (Qmodule_function, "module-function"); | 4113 | DEFSYM (Qmodule_function, "module-function"); |
| @@ -4089,6 +4159,8 @@ syms_of_data (void) | |||
| 4089 | defsubr (&Snumber_or_marker_p); | 4159 | defsubr (&Snumber_or_marker_p); |
| 4090 | defsubr (&Sfloatp); | 4160 | defsubr (&Sfloatp); |
| 4091 | defsubr (&Snatnump); | 4161 | defsubr (&Snatnump); |
| 4162 | defsubr (&Sbare_symbol_p); | ||
| 4163 | defsubr (&Ssymbol_with_pos_p); | ||
| 4092 | defsubr (&Ssymbolp); | 4164 | defsubr (&Ssymbolp); |
| 4093 | defsubr (&Skeywordp); | 4165 | defsubr (&Skeywordp); |
| 4094 | defsubr (&Sstringp); | 4166 | defsubr (&Sstringp); |
| @@ -4119,6 +4191,9 @@ syms_of_data (void) | |||
| 4119 | defsubr (&Sindirect_function); | 4191 | defsubr (&Sindirect_function); |
| 4120 | defsubr (&Ssymbol_plist); | 4192 | defsubr (&Ssymbol_plist); |
| 4121 | defsubr (&Ssymbol_name); | 4193 | defsubr (&Ssymbol_name); |
| 4194 | defsubr (&Sbare_symbol); | ||
| 4195 | defsubr (&Ssymbol_with_pos_pos); | ||
| 4196 | defsubr (&Sposition_symbol); | ||
| 4122 | defsubr (&Smakunbound); | 4197 | defsubr (&Smakunbound); |
| 4123 | defsubr (&Sfmakunbound); | 4198 | defsubr (&Sfmakunbound); |
| 4124 | defsubr (&Sboundp); | 4199 | defsubr (&Sboundp); |
| @@ -4201,6 +4276,12 @@ This variable cannot be set; trying to do so will signal an error. */); | |||
| 4201 | Vmost_negative_fixnum = make_fixnum (MOST_NEGATIVE_FIXNUM); | 4276 | Vmost_negative_fixnum = make_fixnum (MOST_NEGATIVE_FIXNUM); |
| 4202 | make_symbol_constant (intern_c_string ("most-negative-fixnum")); | 4277 | make_symbol_constant (intern_c_string ("most-negative-fixnum")); |
| 4203 | 4278 | ||
| 4279 | DEFSYM (Qsymbols_with_pos_enabled, "symbols-with-pos-enabled"); | ||
| 4280 | DEFVAR_BOOL ("symbols-with-pos-enabled", symbols_with_pos_enabled, | ||
| 4281 | doc: /* Non-nil when "symbols with position" can be used as symbols. | ||
| 4282 | Bind this to non-nil in applications such as the byte compiler. */); | ||
| 4283 | symbols_with_pos_enabled = false; | ||
| 4284 | |||
| 4204 | DEFSYM (Qwatchers, "watchers"); | 4285 | DEFSYM (Qwatchers, "watchers"); |
| 4205 | DEFSYM (Qmakunbound, "makunbound"); | 4286 | DEFSYM (Qmakunbound, "makunbound"); |
| 4206 | DEFSYM (Qunlet, "unlet"); | 4287 | DEFSYM (Qunlet, "unlet"); |