aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Mackenzie2021-12-31 21:21:46 +0000
committerAlan Mackenzie2021-12-31 21:21:46 +0000
commitff9af1f1f69264bcbb7b926363293e55a6b3f330 (patch)
tree0ec9f8ce5850d6f6fd1defe23b1a42f45cb2a795 /src
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.
Diffstat (limited to 'src')
-rw-r--r--src/comp.c90
-rw-r--r--src/data.c16
-rw-r--r--src/eval.c7
-rw-r--r--src/lread.c2
4 files changed, 94 insertions, 21 deletions
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))