aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2021-12-31 21:21:46 +0000
committerAlan Mackenzie2021-12-31 21:21:46 +0000
commitff9af1f1f69264bcbb7b926363293e55a6b3f330 (patch)
tree0ec9f8ce5850d6f6fd1defe23b1a42f45cb2a795
parent1cd188799f86bcb13ad76e82e3436b1b7e9f9e9f (diff)
downloademacs-ff9af1f1f69264bcbb7b926363293e55a6b3f330.tar.gz
emacs-ff9af1f1f69264bcbb7b926363293e55a6b3f330.zip
Miscellaneous enhancements to scratch/correct-warning-pos.
1. Check the type (symbol with position) of the argument given to the native compiled version of SYMBOL_WITH_POS_SYM. 2. Handle infinite recursion caused by circular lists, etc., in macroexp-strip-symbol-positions by using hash tables. 3. Read byte compiled functions without giving symbols positions. * lisp/emacs-lisp/comp.el (comp-finalize-relocs): Add symbol-with-pos-p into the list of relocated symbols. * lisp/emacs-lisp/macroexp.el (macroexp--ssp-conses-seen) (macroexp--ssp-vectors-seen, macroexp--ssp-records-seen): Renamed, and animated as hash tables. (macroexp--strip-s-p-2): Optionally tests for the presence of an argument in one of the above hash tables, so as to handle otherwise infinite recursion. (byte-compile-strip-s-p-1): Add a condition-case to handle infinite recursion caused by circular lists etc., using the above hash tables as required. * src/comp.c (comp_t): New element symbol_with_pos_sym. (emit_SYMBOL_WITH_POS_SYM): Amend just to call the new SYMBOL_WITH_POS_SYM. (emit_CHECK_SYMBOL_WITH_POS, define_SYMBOL_WITH_POS_SYM): New functions. (Fcomp__init_ctxt): Register an emitter for Qsymbol_with_pos_p. (Fcomp__compile_ctxt_to_file): Call define_SYMBOL_WITH_POS_SYM. (syms_of_comp): Define Qsymbol_with_pos_p. * src/data.c (syms_of_data): Define a new error symbol Qrecursion_error, an error category for the new error symbols Qexcessive_variable_binding and Qexcessive_lisp_nesting. * src/eval.c (grow_specpdl): Change the signal_error call to an xsignal0 call using the new error symbol Qexcessive_variable_binding. (eval_sub, Ffuncall): Change the `error' calls to xsignal using the new error symbol Qexcessive_lisp_nesting. * src/lread.c (read1): When reading a compiled function, read the components of the vector without giving its symbols a position.
-rw-r--r--lisp/emacs-lisp/comp.el2
-rw-r--r--lisp/emacs-lisp/macroexp.el40
-rw-r--r--src/comp.c90
-rw-r--r--src/data.c16
-rw-r--r--src/eval.c7
-rw-r--r--src/lread.c2
6 files changed, 122 insertions, 35 deletions
diff --git a/lisp/emacs-lisp/comp.el b/lisp/emacs-lisp/comp.el
index 8581fe80662..1912d0d0037 100644
--- a/lisp/emacs-lisp/comp.el
+++ b/lisp/emacs-lisp/comp.el
@@ -3576,7 +3576,7 @@ Update all insn accordingly."
3576 ;; Symbols imported by C inlined functions. We do this here because 3576 ;; Symbols imported by C inlined functions. We do this here because
3577 ;; is better to add all objs to the relocation containers before we 3577 ;; is better to add all objs to the relocation containers before we
3578 ;; compacting them. 3578 ;; compacting them.
3579 (mapc #'comp-add-const-to-relocs '(nil t consp listp)) 3579 (mapc #'comp-add-const-to-relocs '(nil t consp listp symbol-with-pos-p))
3580 3580
3581 (let* ((d-default (comp-ctxt-d-default comp-ctxt)) 3581 (let* ((d-default (comp-ctxt-d-default comp-ctxt))
3582 (d-default-idx (comp-data-container-idx d-default)) 3582 (d-default-idx (comp-data-container-idx d-default))
diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el
index dafd5497639..11204f7f7fb 100644
--- a/lisp/emacs-lisp/macroexp.el
+++ b/lisp/emacs-lisp/macroexp.el
@@ -32,11 +32,11 @@
32;; macros defined by `defmacro'. 32;; macros defined by `defmacro'.
33(defvar macroexpand-all-environment nil) 33(defvar macroexpand-all-environment nil)
34 34
35(defvar byte-compile--ssp-conses-seen nil 35(defvar macroexp--ssp-conses-seen nil
36 "Which conses have been processed in a strip-symbol-positions operation?") 36 "Which conses have been processed in a strip-symbol-positions operation?")
37(defvar byte-compile--ssp-vectors-seen nil 37(defvar macroexp--ssp-vectors-seen nil
38 "Which vectors have been processed in a strip-symbol-positions operation?") 38 "Which vectors have been processed in a strip-symbol-positions operation?")
39(defvar byte-compile--ssp-records-seen nil 39(defvar macroexp--ssp-records-seen nil
40 "Which records have been processed in a strip-symbol-positions operation?") 40 "Which records have been processed in a strip-symbol-positions operation?")
41 41
42(defun macroexp--strip-s-p-2 (arg) 42(defun macroexp--strip-s-p-2 (arg)
@@ -46,8 +46,10 @@ Return the modified ARG."
46 ((symbolp arg) 46 ((symbolp arg)
47 (bare-symbol arg)) 47 (bare-symbol arg))
48 ((consp arg) 48 ((consp arg)
49 (unless (memq arg byte-compile--ssp-conses-seen) 49 (unless (and macroexp--ssp-conses-seen
50 ;; (push arg byte-compile--ssp-conses-seen) 50 (gethash arg macroexp--ssp-conses-seen))
51 (if macroexp--ssp-conses-seen
52 (puthash arg t macroexp--ssp-conses-seen))
51 (let ((a arg)) 53 (let ((a arg))
52 (while (consp (cdr a)) 54 (while (consp (cdr a))
53 (setcar a (macroexp--strip-s-p-2 (car a))) 55 (setcar a (macroexp--strip-s-p-2 (car a)))
@@ -58,8 +60,10 @@ Return the modified ARG."
58 (setcdr a (macroexp--strip-s-p-2 (cdr a)))))) 60 (setcdr a (macroexp--strip-s-p-2 (cdr a))))))
59 arg) 61 arg)
60 ((vectorp arg) 62 ((vectorp arg)
61 (unless (memq arg byte-compile--ssp-vectors-seen) 63 (unless (and macroexp--ssp-vectors-seen
62 (push arg byte-compile--ssp-vectors-seen) 64 (gethash arg macroexp--ssp-vectors-seen))
65 (if macroexp--ssp-vectors-seen
66 (puthash arg t macroexp--ssp-vectors-seen))
63 (let ((i 0) 67 (let ((i 0)
64 (len (length arg))) 68 (len (length arg)))
65 (while (< i len) 69 (while (< i len)
@@ -67,8 +71,10 @@ Return the modified ARG."
67 (setq i (1+ i))))) 71 (setq i (1+ i)))))
68 arg) 72 arg)
69 ((recordp arg) 73 ((recordp arg)
70 (unless (memq arg byte-compile--ssp-records-seen) 74 (unless (and macroexp--ssp-records-seen
71 (push arg byte-compile--ssp-records-seen) 75 (gethash arg macroexp--ssp-records-seen))
76 (if macroexp--ssp-records-seen
77 (puthash arg t macroexp--ssp-records-seen))
72 (let ((i 0) 78 (let ((i 0)
73 (len (length arg))) 79 (len (length arg)))
74 (while (< i len) 80 (while (< i len)
@@ -80,10 +86,18 @@ Return the modified ARG."
80(defun byte-compile-strip-s-p-1 (arg) 86(defun byte-compile-strip-s-p-1 (arg)
81 "Strip all positions from symbols in ARG, destructively modifying ARG. 87 "Strip all positions from symbols in ARG, destructively modifying ARG.
82Return the modified ARG." 88Return the modified ARG."
83 (setq byte-compile--ssp-conses-seen nil) 89 (condition-case err
84 (setq byte-compile--ssp-vectors-seen nil) 90 (progn
85 (setq byte-compile--ssp-records-seen nil) 91 (setq macroexp--ssp-conses-seen nil)
86 (macroexp--strip-s-p-2 arg)) 92 (setq macroexp--ssp-vectors-seen nil)
93 (setq macroexp--ssp-records-seen nil)
94 (macroexp--strip-s-p-2 arg))
95 (recursion-error
96 (dolist (tab '(macroexp--ssp-conses-seen macroexp--ssp-vectors-seen
97 macroexp--ssp-records-seen))
98 (set tab (make-hash-table :test 'eq)))
99 (macroexp--strip-s-p-2 arg))
100 (error (signal (car err) (cdr err)))))
87 101
88(defun macroexp-strip-symbol-positions (arg) 102(defun macroexp-strip-symbol-positions (arg)
89 "Strip all positions from symbols (recursively) in ARG. Don't modify ARG." 103 "Strip all positions from symbols (recursively) in ARG. Don't modify ARG."
diff --git a/src/comp.c b/src/comp.c
index ac38c2131f9..834656897e4 100644
--- a/src/comp.c
+++ b/src/comp.c
@@ -574,6 +574,7 @@ typedef struct {
574 gcc_jit_type *lisp_symbol_with_position_type; 574 gcc_jit_type *lisp_symbol_with_position_type;
575 gcc_jit_type *lisp_symbol_with_position_ptr_type; 575 gcc_jit_type *lisp_symbol_with_position_ptr_type;
576 gcc_jit_function *get_symbol_with_position; 576 gcc_jit_function *get_symbol_with_position;
577 gcc_jit_function *symbol_with_pos_sym;
577 /* struct jmp_buf. */ 578 /* struct jmp_buf. */
578 gcc_jit_struct *jmp_buf_s; 579 gcc_jit_struct *jmp_buf_s;
579 /* struct handler. */ 580 /* struct handler. */
@@ -1475,21 +1476,12 @@ emit_SYMBOL_WITH_POS_SYM (gcc_jit_rvalue *obj)
1475{ 1476{
1476 emit_comment ("SYMBOL_WITH_POS_SYM"); 1477 emit_comment ("SYMBOL_WITH_POS_SYM");
1477 1478
1478 gcc_jit_rvalue *tmp2, *swp; 1479 gcc_jit_rvalue *arg [] = { obj };
1479 gcc_jit_lvalue *tmpl; 1480 return gcc_jit_context_new_call (comp.ctxt,
1480 1481 NULL,
1481 gcc_jit_rvalue *args[] = { obj }; 1482 comp.symbol_with_pos_sym,
1482 swp = gcc_jit_context_new_call (comp.ctxt, 1483 1,
1483 NULL, 1484 arg);
1484 comp.get_symbol_with_position,
1485 1,
1486 args);
1487 tmpl = gcc_jit_rvalue_dereference (swp, gcc_jit_context_new_location (comp.ctxt, "comp.c", __LINE__, 0));
1488 tmp2 = gcc_jit_lvalue_as_rvalue (tmpl);
1489 return
1490 gcc_jit_rvalue_access_field (tmp2,
1491 NULL,
1492 comp.lisp_symbol_with_position_sym);
1493} 1485}
1494 1486
1495static gcc_jit_rvalue * 1487static gcc_jit_rvalue *
@@ -1858,6 +1850,29 @@ emit_CHECK_CONS (gcc_jit_rvalue *x)
1858 args)); 1850 args));
1859} 1851}
1860 1852
1853static void
1854emit_CHECK_SYMBOL_WITH_POS (gcc_jit_rvalue *x)
1855{
1856 emit_comment ("CHECK_SYMBOL_WITH_POS");
1857
1858 gcc_jit_rvalue *args[] =
1859 { gcc_jit_context_new_cast (comp.ctxt,
1860 NULL,
1861 emit_SYMBOL_WITH_POS_P (x),
1862 comp.int_type),
1863 emit_lisp_obj_rval (Qsymbol_with_pos_p),
1864 x };
1865
1866 gcc_jit_block_add_eval (
1867 comp.block,
1868 NULL,
1869 gcc_jit_context_new_call (comp.ctxt,
1870 NULL,
1871 comp.check_type,
1872 3,
1873 args));
1874}
1875
1861static gcc_jit_rvalue * 1876static gcc_jit_rvalue *
1862emit_car_addr (gcc_jit_rvalue *c) 1877emit_car_addr (gcc_jit_rvalue *c)
1863{ 1878{
@@ -3886,6 +3901,48 @@ define_GET_SYMBOL_WITH_POSITION (void)
3886 1, args, false)); 3901 1, args, false));
3887} 3902}
3888 3903
3904static void define_SYMBOL_WITH_POS_SYM (void)
3905{
3906 gcc_jit_rvalue *tmpr, *swp;
3907 gcc_jit_lvalue *tmpl;
3908
3909 gcc_jit_param *param [] =
3910 { gcc_jit_context_new_param (comp.ctxt,
3911 NULL,
3912 comp.lisp_obj_type,
3913 "a") };
3914 comp.symbol_with_pos_sym =
3915 gcc_jit_context_new_function (comp.ctxt, NULL,
3916 GCC_JIT_FUNCTION_INTERNAL,
3917 comp.lisp_obj_type,
3918 "SYMBOL_WITH_POS_SYM",
3919 1,
3920 param,
3921 0);
3922
3923 DECL_BLOCK (entry_block, comp.symbol_with_pos_sym);
3924 comp.func = comp.symbol_with_pos_sym;
3925 comp.block = entry_block;
3926
3927 emit_CHECK_SYMBOL_WITH_POS (gcc_jit_param_as_rvalue (param [0]));
3928
3929 gcc_jit_rvalue *args[] = { gcc_jit_param_as_rvalue (param [0]) };
3930
3931 swp = gcc_jit_context_new_call (comp.ctxt,
3932 NULL,
3933 comp.get_symbol_with_position,
3934 1,
3935 args);
3936 tmpl = gcc_jit_rvalue_dereference (swp, NULL);
3937 tmpr = gcc_jit_lvalue_as_rvalue (tmpl);
3938 gcc_jit_block_end_with_return (entry_block,
3939 NULL,
3940 gcc_jit_rvalue_access_field (
3941 tmpr,
3942 NULL,
3943 comp.lisp_symbol_with_position_sym));
3944}
3945
3889static void 3946static void
3890define_CHECK_IMPURE (void) 3947define_CHECK_IMPURE (void)
3891{ 3948{
@@ -4504,6 +4561,7 @@ Return t on success. */)
4504 register_emitter (Qnumberp, emit_numperp); 4561 register_emitter (Qnumberp, emit_numperp);
4505 register_emitter (Qintegerp, emit_integerp); 4562 register_emitter (Qintegerp, emit_integerp);
4506 register_emitter (Qcomp_maybe_gc_or_quit, emit_maybe_gc_or_quit); 4563 register_emitter (Qcomp_maybe_gc_or_quit, emit_maybe_gc_or_quit);
4564 register_emitter (Qsymbol_with_pos_p, emit_SYMBOL_WITH_POS_P);
4507 } 4565 }
4508 4566
4509 comp.ctxt = gcc_jit_context_acquire (); 4567 comp.ctxt = gcc_jit_context_acquire ();
@@ -4820,6 +4878,7 @@ DEFUN ("comp--compile-ctxt-to-file", Fcomp__compile_ctxt_to_file,
4820 define_PSEUDOVECTORP (); 4878 define_PSEUDOVECTORP ();
4821 define_GET_SYMBOL_WITH_POSITION (); 4879 define_GET_SYMBOL_WITH_POSITION ();
4822 define_CHECK_TYPE (); 4880 define_CHECK_TYPE ();
4881 define_SYMBOL_WITH_POS_SYM ();
4823 define_CHECK_IMPURE (); 4882 define_CHECK_IMPURE ();
4824 define_bool_to_lisp_obj (); 4883 define_bool_to_lisp_obj ();
4825 define_setcar_setcdr (); 4884 define_setcar_setcdr ();
@@ -5618,6 +5677,7 @@ compiled one. */);
5618 DEFSYM (Qnumberp, "numberp"); 5677 DEFSYM (Qnumberp, "numberp");
5619 DEFSYM (Qintegerp, "integerp"); 5678 DEFSYM (Qintegerp, "integerp");
5620 DEFSYM (Qcomp_maybe_gc_or_quit, "comp-maybe-gc-or-quit"); 5679 DEFSYM (Qcomp_maybe_gc_or_quit, "comp-maybe-gc-or-quit");
5680 DEFSYM (Qsymbol_with_pos_p, "symbol-with-pos-p");
5621 5681
5622 /* Allocation classes. */ 5682 /* Allocation classes. */
5623 DEFSYM (Qd_default, "d-default"); 5683 DEFSYM (Qd_default, "d-default");
diff --git a/src/data.c b/src/data.c
index 1f2af6f4743..6d9c0aef933 100644
--- a/src/data.c
+++ b/src/data.c
@@ -3969,7 +3969,7 @@ A is a bool vector, B is t or nil, and I is an index into A. */)
3969void 3969void
3970syms_of_data (void) 3970syms_of_data (void)
3971{ 3971{
3972 Lisp_Object error_tail, arith_tail; 3972 Lisp_Object error_tail, arith_tail, recursion_tail;
3973 3973
3974 DEFSYM (Qquote, "quote"); 3974 DEFSYM (Qquote, "quote");
3975 DEFSYM (Qlambda, "lambda"); 3975 DEFSYM (Qlambda, "lambda");
@@ -4004,6 +4004,10 @@ syms_of_data (void)
4004 DEFSYM (Qmark_inactive, "mark-inactive"); 4004 DEFSYM (Qmark_inactive, "mark-inactive");
4005 DEFSYM (Qinhibited_interaction, "inhibited-interaction"); 4005 DEFSYM (Qinhibited_interaction, "inhibited-interaction");
4006 4006
4007 DEFSYM (Qrecursion_error, "recursion-error");
4008 DEFSYM (Qexcessive_variable_binding, "excessive-variable-binding");
4009 DEFSYM (Qexcessive_lisp_nesting, "excessive-lisp-nesting");
4010
4007 DEFSYM (Qlistp, "listp"); 4011 DEFSYM (Qlistp, "listp");
4008 DEFSYM (Qconsp, "consp"); 4012 DEFSYM (Qconsp, "consp");
4009 DEFSYM (Qbare_symbol_p, "bare-symbol-p"); 4013 DEFSYM (Qbare_symbol_p, "bare-symbol-p");
@@ -4112,6 +4116,16 @@ syms_of_data (void)
4112 PUT_ERROR (Qunderflow_error, Fcons (Qrange_error, arith_tail), 4116 PUT_ERROR (Qunderflow_error, Fcons (Qrange_error, arith_tail),
4113 "Arithmetic underflow error"); 4117 "Arithmetic underflow error");
4114 4118
4119 recursion_tail = pure_cons (Qrecursion_error, error_tail);
4120 Fput (Qrecursion_error, Qerror_conditions, recursion_tail);
4121 Fput (Qrecursion_error, Qerror_message, build_pure_c_string
4122 ("Excessive recursive calling error"));
4123
4124 PUT_ERROR (Qexcessive_variable_binding, recursion_tail,
4125 "Variable binding depth exceeds max-specpdl-size");
4126 PUT_ERROR (Qexcessive_lisp_nesting, recursion_tail,
4127 "Lisp nesting exceeds `max-lisp-eval-depth'");
4128
4115 /* Types that type-of returns. */ 4129 /* Types that type-of returns. */
4116 DEFSYM (Qinteger, "integer"); 4130 DEFSYM (Qinteger, "integer");
4117 DEFSYM (Qsymbol, "symbol"); 4131 DEFSYM (Qsymbol, "symbol");
diff --git a/src/eval.c b/src/eval.c
index 94ad0607732..5cb673ab223 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -2398,8 +2398,7 @@ grow_specpdl (void)
2398 if (max_specpdl_size < 400) 2398 if (max_specpdl_size < 400)
2399 max_size = max_specpdl_size = 400; 2399 max_size = max_specpdl_size = 400;
2400 if (max_size <= specpdl_size) 2400 if (max_size <= specpdl_size)
2401 signal_error ("Variable binding depth exceeds max-specpdl-size", 2401 xsignal0 (Qexcessive_variable_binding);
2402 Qnil);
2403 } 2402 }
2404 pdlvec = xpalloc (pdlvec, &pdlvecsize, 1, max_size + 1, sizeof *specpdl); 2403 pdlvec = xpalloc (pdlvec, &pdlvecsize, 1, max_size + 1, sizeof *specpdl);
2405 specpdl = pdlvec + 1; 2404 specpdl = pdlvec + 1;
@@ -2453,7 +2452,7 @@ eval_sub (Lisp_Object form)
2453 if (max_lisp_eval_depth < 100) 2452 if (max_lisp_eval_depth < 100)
2454 max_lisp_eval_depth = 100; 2453 max_lisp_eval_depth = 100;
2455 if (lisp_eval_depth > max_lisp_eval_depth) 2454 if (lisp_eval_depth > max_lisp_eval_depth)
2456 error ("Lisp nesting exceeds `max-lisp-eval-depth'"); 2455 xsignal0 (Qexcessive_lisp_nesting);
2457 } 2456 }
2458 2457
2459 Lisp_Object original_fun = XCAR (form); 2458 Lisp_Object original_fun = XCAR (form);
@@ -3044,7 +3043,7 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */)
3044 if (max_lisp_eval_depth < 100) 3043 if (max_lisp_eval_depth < 100)
3045 max_lisp_eval_depth = 100; 3044 max_lisp_eval_depth = 100;
3046 if (lisp_eval_depth > max_lisp_eval_depth) 3045 if (lisp_eval_depth > max_lisp_eval_depth)
3047 error ("Lisp nesting exceeds `max-lisp-eval-depth'"); 3046 xsignal0 (Qexcessive_lisp_nesting);
3048 } 3047 }
3049 3048
3050 count = record_in_backtrace (args[0], &args[1], nargs - 1); 3049 count = record_in_backtrace (args[0], &args[1], nargs - 1);
diff --git a/src/lread.c b/src/lread.c
index 1cc5acc6d3a..835228439f1 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3225,7 +3225,7 @@ read1 (Lisp_Object readcharfun, int *pch, bool first_in_list, bool locate_syms)
3225 build them using function calls. */ 3225 build them using function calls. */
3226 Lisp_Object tmp; 3226 Lisp_Object tmp;
3227 struct Lisp_Vector *vec; 3227 struct Lisp_Vector *vec;
3228 tmp = read_vector (readcharfun, 1, locate_syms); 3228 tmp = read_vector (readcharfun, 1, false);
3229 vec = XVECTOR (tmp); 3229 vec = XVECTOR (tmp);
3230 if (! (COMPILED_STACK_DEPTH < ASIZE (tmp) 3230 if (! (COMPILED_STACK_DEPTH < ASIZE (tmp)
3231 && (FIXNUMP (AREF (tmp, COMPILED_ARGLIST)) 3231 && (FIXNUMP (AREF (tmp, COMPILED_ARGLIST))