aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorAlan Mackenzie2021-11-29 11:19:31 +0000
committerAlan Mackenzie2021-11-29 11:19:31 +0000
commit368570b3fd09d03ac5b9276d1ca85ae813c3f385 (patch)
tree4d81fdc1a866120157147226c35597073592722d /src/alloc.c
parent9721dcf2754ebad28ac60a9d3152fd26e4c652c4 (diff)
downloademacs-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/alloc.c')
-rw-r--r--src/alloc.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/src/alloc.c b/src/alloc.c
index f8908c91dba..0d69f23048a 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -591,7 +591,7 @@ pointer_align (void *ptr, int alignment)
591static ATTRIBUTE_NO_SANITIZE_UNDEFINED void * 591static ATTRIBUTE_NO_SANITIZE_UNDEFINED void *
592XPNTR (Lisp_Object a) 592XPNTR (Lisp_Object a)
593{ 593{
594 return (SYMBOLP (a) 594 return (BARE_SYMBOL_P (a)
595 ? (char *) lispsym + (XLI (a) - LISP_WORD_TAG (Lisp_Symbol)) 595 ? (char *) lispsym + (XLI (a) - LISP_WORD_TAG (Lisp_Symbol))
596 : (char *) XLP (a) - (XLI (a) & ~VALMASK)); 596 : (char *) XLP (a) - (XLI (a) & ~VALMASK));
597} 597}
@@ -3598,13 +3598,13 @@ static struct Lisp_Symbol *symbol_free_list;
3598static void 3598static void
3599set_symbol_name (Lisp_Object sym, Lisp_Object name) 3599set_symbol_name (Lisp_Object sym, Lisp_Object name)
3600{ 3600{
3601 XSYMBOL (sym)->u.s.name = name; 3601 XBARE_SYMBOL (sym)->u.s.name = name;
3602} 3602}
3603 3603
3604void 3604void
3605init_symbol (Lisp_Object val, Lisp_Object name) 3605init_symbol (Lisp_Object val, Lisp_Object name)
3606{ 3606{
3607 struct Lisp_Symbol *p = XSYMBOL (val); 3607 struct Lisp_Symbol *p = XBARE_SYMBOL (val);
3608 set_symbol_name (val, name); 3608 set_symbol_name (val, name);
3609 set_symbol_plist (val, Qnil); 3609 set_symbol_plist (val, Qnil);
3610 p->u.s.redirect = SYMBOL_PLAINVAL; 3610 p->u.s.redirect = SYMBOL_PLAINVAL;
@@ -3667,6 +3667,21 @@ make_misc_ptr (void *a)
3667 return make_lisp_ptr (p, Lisp_Vectorlike); 3667 return make_lisp_ptr (p, Lisp_Vectorlike);
3668} 3668}
3669 3669
3670/* Return a new symbol with position with the specified SYMBOL and POSITION. */
3671Lisp_Object
3672build_symbol_with_pos (Lisp_Object symbol, Lisp_Object position)
3673{
3674 Lisp_Object val;
3675 struct Lisp_Symbol_With_Pos *p
3676 = (struct Lisp_Symbol_With_Pos *) allocate_vector (2);
3677 XSETVECTOR (val, p);
3678 XSETPVECTYPESIZE (XVECTOR (val), PVEC_SYMBOL_WITH_POS, 2, 0);
3679 p->sym = symbol;
3680 p->pos = position;
3681
3682 return val;
3683}
3684
3670/* Return a new overlay with specified START, END and PLIST. */ 3685/* Return a new overlay with specified START, END and PLIST. */
3671 3686
3672Lisp_Object 3687Lisp_Object
@@ -5210,7 +5225,7 @@ valid_lisp_object_p (Lisp_Object obj)
5210 if (PURE_P (p)) 5225 if (PURE_P (p))
5211 return 1; 5226 return 1;
5212 5227
5213 if (SYMBOLP (obj) && c_symbol_p (p)) 5228 if (BARE_SYMBOL_P (obj) && c_symbol_p (p))
5214 return ((char *) p - (char *) lispsym) % sizeof lispsym[0] == 0; 5229 return ((char *) p - (char *) lispsym) % sizeof lispsym[0] == 0;
5215 5230
5216 if (p == &buffer_defaults || p == &buffer_local_symbols) 5231 if (p == &buffer_defaults || p == &buffer_local_symbols)
@@ -5638,12 +5653,12 @@ purecopy (Lisp_Object obj)
5638 vec->contents[i] = purecopy (vec->contents[i]); 5653 vec->contents[i] = purecopy (vec->contents[i]);
5639 XSETVECTOR (obj, vec); 5654 XSETVECTOR (obj, vec);
5640 } 5655 }
5641 else if (SYMBOLP (obj)) 5656 else if (BARE_SYMBOL_P (obj))
5642 { 5657 {
5643 if (!XSYMBOL (obj)->u.s.pinned && !c_symbol_p (XSYMBOL (obj))) 5658 if (!XBARE_SYMBOL (obj)->u.s.pinned && !c_symbol_p (XBARE_SYMBOL (obj)))
5644 { /* We can't purify them, but they appear in many pure objects. 5659 { /* We can't purify them, but they appear in many pure objects.
5645 Mark them as `pinned' so we know to mark them at every GC cycle. */ 5660 Mark them as `pinned' so we know to mark them at every GC cycle. */
5646 XSYMBOL (obj)->u.s.pinned = true; 5661 XBARE_SYMBOL (obj)->u.s.pinned = true;
5647 symbol_block_pinned = symbol_block; 5662 symbol_block_pinned = symbol_block;
5648 } 5663 }
5649 /* Don't hash-cons it. */ 5664 /* Don't hash-cons it. */
@@ -6268,7 +6283,10 @@ For further details, see Info node `(elisp)Garbage Collection'. */)
6268 if (garbage_collection_inhibited) 6283 if (garbage_collection_inhibited)
6269 return Qnil; 6284 return Qnil;
6270 6285
6286 ptrdiff_t count = SPECPDL_INDEX ();
6287 specbind (Qsymbols_with_pos_enabled, Qnil);
6271 garbage_collect (); 6288 garbage_collect ();
6289 unbind_to (count, Qnil);
6272 struct gcstat gcst = gcstat; 6290 struct gcstat gcst = gcstat;
6273 6291
6274 Lisp_Object total[] = { 6292 Lisp_Object total[] = {
@@ -6407,7 +6425,7 @@ mark_char_table (struct Lisp_Vector *ptr, enum pvec_type pvectype)
6407 Lisp_Object val = ptr->contents[i]; 6425 Lisp_Object val = ptr->contents[i];
6408 6426
6409 if (FIXNUMP (val) || 6427 if (FIXNUMP (val) ||
6410 (SYMBOLP (val) && symbol_marked_p (XSYMBOL (val)))) 6428 (BARE_SYMBOL_P (val) && symbol_marked_p (XBARE_SYMBOL (val))))
6411 continue; 6429 continue;
6412 if (SUB_CHAR_TABLE_P (val)) 6430 if (SUB_CHAR_TABLE_P (val))
6413 { 6431 {
@@ -6809,7 +6827,7 @@ mark_object (Lisp_Object arg)
6809 6827
6810 case Lisp_Symbol: 6828 case Lisp_Symbol:
6811 { 6829 {
6812 struct Lisp_Symbol *ptr = XSYMBOL (obj); 6830 struct Lisp_Symbol *ptr = XBARE_SYMBOL (obj);
6813 nextsym: 6831 nextsym:
6814 if (symbol_marked_p (ptr)) 6832 if (symbol_marked_p (ptr))
6815 break; 6833 break;
@@ -6930,7 +6948,7 @@ survives_gc_p (Lisp_Object obj)
6930 break; 6948 break;
6931 6949
6932 case Lisp_Symbol: 6950 case Lisp_Symbol:
6933 survives_p = symbol_marked_p (XSYMBOL (obj)); 6951 survives_p = symbol_marked_p (XBARE_SYMBOL (obj));
6934 break; 6952 break;
6935 6953
6936 case Lisp_String: 6954 case Lisp_String:
@@ -7347,7 +7365,7 @@ arenas. */)
7347static bool 7365static bool
7348symbol_uses_obj (Lisp_Object symbol, Lisp_Object obj) 7366symbol_uses_obj (Lisp_Object symbol, Lisp_Object obj)
7349{ 7367{
7350 struct Lisp_Symbol *sym = XSYMBOL (symbol); 7368 struct Lisp_Symbol *sym = XBARE_SYMBOL (symbol);
7351 Lisp_Object val = find_symbol_value (symbol); 7369 Lisp_Object val = find_symbol_value (symbol);
7352 return (EQ (val, obj) 7370 return (EQ (val, obj)
7353 || EQ (sym->u.s.function, obj) 7371 || EQ (sym->u.s.function, obj)