diff options
| author | Mattias EngdegÄrd | 2024-05-26 11:13:50 +0200 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2024-05-26 13:04:51 +0200 |
| commit | 236034a24d0e93e1796224e2ff4a14819fcfd559 (patch) | |
| tree | 17cbd8f643e1c03b61fdb5725600b04873a3b27b /src | |
| parent | cfd654c418658adacd6ab3717dc1b8cc95d99d44 (diff) | |
| download | emacs-236034a24d0e93e1796224e2ff4a14819fcfd559.tar.gz emacs-236034a24d0e93e1796224e2ff4a14819fcfd559.zip | |
Clean up legacy bytecode loading
Complete some unfinished work from the elimination of lazy bytecode
loading in 9bcc9690a8: remove code which became unreachable by that
reform. This simplifies some of the lower-level parts of the reader
which helps performance somewhat.
* src/doc.c (read_bytecode_pointer, read_bytecode_char)
(read_doc_string): Remove.
(get_doc_string): Remove last argument, all callers adapted. Simplify.
* src/lread.c (readbyte_for_lambda, readbyte_from_string)
(readbyte_for_lambda, readbyte_from_string): Remove.
(readchar, unreadchar): Remove unused code paths for Qlambda and cons
arguments.
(bytecode_from_rev_list): Remove last use of a quirky code path,
decoding force-loaded lazy bytecode explicitly.
Diffstat (limited to 'src')
| -rw-r--r-- | src/doc.c | 47 | ||||
| -rw-r--r-- | src/lisp.h | 4 | ||||
| -rw-r--r-- | src/lread.c | 77 |
3 files changed, 18 insertions, 110 deletions
| @@ -74,24 +74,8 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 74 | static char *get_doc_string_buffer; | 74 | static char *get_doc_string_buffer; |
| 75 | static ptrdiff_t get_doc_string_buffer_size; | 75 | static ptrdiff_t get_doc_string_buffer_size; |
| 76 | 76 | ||
| 77 | static unsigned char *read_bytecode_pointer; | ||
| 78 | |||
| 79 | static char const sibling_etc[] = "../etc/"; | 77 | static char const sibling_etc[] = "../etc/"; |
| 80 | 78 | ||
| 81 | /* `readchar' in lread.c calls back here to fetch the next byte. | ||
| 82 | If UNREADFLAG is 1, we unread a byte. */ | ||
| 83 | |||
| 84 | int | ||
| 85 | read_bytecode_char (bool unreadflag) | ||
| 86 | { | ||
| 87 | if (unreadflag) | ||
| 88 | { | ||
| 89 | read_bytecode_pointer--; | ||
| 90 | return 0; | ||
| 91 | } | ||
| 92 | return *read_bytecode_pointer++; | ||
| 93 | } | ||
| 94 | |||
| 95 | #ifdef USE_ANDROID_ASSETS | 79 | #ifdef USE_ANDROID_ASSETS |
| 96 | 80 | ||
| 97 | /* Like `close_file_unwind'. However, PTR is a pointer to an Android | 81 | /* Like `close_file_unwind'. However, PTR is a pointer to an Android |
| @@ -120,15 +104,10 @@ close_file_unwind_android_fd (void *ptr) | |||
| 120 | (e.g. because the file has been modified and the location is stale), | 104 | (e.g. because the file has been modified and the location is stale), |
| 121 | return nil. | 105 | return nil. |
| 122 | 106 | ||
| 123 | If UNIBYTE, always make a unibyte string. | 107 | If UNIBYTE, always make a unibyte string. */ |
| 124 | |||
| 125 | If DEFINITION, assume this is for reading | ||
| 126 | a dynamic function definition; convert the bytestring | ||
| 127 | and the constants vector with appropriate byte handling, | ||
| 128 | and return a cons cell. */ | ||
| 129 | 108 | ||
| 130 | Lisp_Object | 109 | Lisp_Object |
| 131 | get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) | 110 | get_doc_string (Lisp_Object filepos, bool unibyte) |
| 132 | { | 111 | { |
| 133 | char *from, *to, *name, *p, *p1; | 112 | char *from, *to, *name, *p, *p1; |
| 134 | Lisp_Object file, pos; | 113 | Lisp_Object file, pos; |
| @@ -312,14 +291,6 @@ Invalid data in documentation file -- %c followed by code %03o", | |||
| 312 | *to++ = *from++; | 291 | *to++ = *from++; |
| 313 | } | 292 | } |
| 314 | 293 | ||
| 315 | /* If DEFINITION, read from this buffer | ||
| 316 | the same way we would read bytes from a file. */ | ||
| 317 | if (definition) | ||
| 318 | { | ||
| 319 | read_bytecode_pointer = (unsigned char *) get_doc_string_buffer + offset; | ||
| 320 | return Fread (Qlambda); | ||
| 321 | } | ||
| 322 | |||
| 323 | if (unibyte) | 294 | if (unibyte) |
| 324 | return make_unibyte_string (get_doc_string_buffer + offset, | 295 | return make_unibyte_string (get_doc_string_buffer + offset, |
| 325 | to - (get_doc_string_buffer + offset)); | 296 | to - (get_doc_string_buffer + offset)); |
| @@ -336,16 +307,6 @@ Invalid data in documentation file -- %c followed by code %03o", | |||
| 336 | } | 307 | } |
| 337 | } | 308 | } |
| 338 | 309 | ||
| 339 | /* Get a string from position FILEPOS and pass it through the Lisp reader. | ||
| 340 | We use this for fetching the bytecode string and constants vector | ||
| 341 | of a compiled function from the .elc file. */ | ||
| 342 | |||
| 343 | Lisp_Object | ||
| 344 | read_doc_string (Lisp_Object filepos) | ||
| 345 | { | ||
| 346 | return get_doc_string (filepos, 0, 1); | ||
| 347 | } | ||
| 348 | |||
| 349 | static bool | 310 | static bool |
| 350 | reread_doc_file (Lisp_Object file) | 311 | reread_doc_file (Lisp_Object file) |
| 351 | { | 312 | { |
| @@ -406,7 +367,7 @@ string is passed through `substitute-command-keys'. */) | |||
| 406 | if (FIXNUMP (doc) || CONSP (doc)) | 367 | if (FIXNUMP (doc) || CONSP (doc)) |
| 407 | { | 368 | { |
| 408 | Lisp_Object tem; | 369 | Lisp_Object tem; |
| 409 | tem = get_doc_string (doc, 0, 0); | 370 | tem = get_doc_string (doc, 0); |
| 410 | if (NILP (tem) && try_reload) | 371 | if (NILP (tem) && try_reload) |
| 411 | { | 372 | { |
| 412 | /* The file is newer, we need to reset the pointers. */ | 373 | /* The file is newer, we need to reset the pointers. */ |
| @@ -481,7 +442,7 @@ aren't strings. */) | |||
| 481 | if (FIXNUMP (tem) || (CONSP (tem) && FIXNUMP (XCDR (tem)))) | 442 | if (FIXNUMP (tem) || (CONSP (tem) && FIXNUMP (XCDR (tem)))) |
| 482 | { | 443 | { |
| 483 | Lisp_Object doc = tem; | 444 | Lisp_Object doc = tem; |
| 484 | tem = get_doc_string (tem, 0, 0); | 445 | tem = get_doc_string (tem, 0); |
| 485 | if (NILP (tem) && try_reload) | 446 | if (NILP (tem) && try_reload) |
| 486 | { | 447 | { |
| 487 | /* The file is newer, we need to reset the pointers. */ | 448 | /* The file is newer, we need to reset the pointers. */ |
diff --git a/src/lisp.h b/src/lisp.h index 534a36499f1..f8d59b1e9fd 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -5273,10 +5273,8 @@ extern void set_initial_environment (void); | |||
| 5273 | extern void syms_of_callproc (void); | 5273 | extern void syms_of_callproc (void); |
| 5274 | 5274 | ||
| 5275 | /* Defined in doc.c. */ | 5275 | /* Defined in doc.c. */ |
| 5276 | extern Lisp_Object read_doc_string (Lisp_Object); | 5276 | extern Lisp_Object get_doc_string (Lisp_Object, bool); |
| 5277 | extern Lisp_Object get_doc_string (Lisp_Object, bool, bool); | ||
| 5278 | extern void syms_of_doc (void); | 5277 | extern void syms_of_doc (void); |
| 5279 | extern int read_bytecode_char (bool); | ||
| 5280 | 5278 | ||
| 5281 | /* Defined in bytecode.c. */ | 5279 | /* Defined in bytecode.c. */ |
| 5282 | extern void syms_of_bytecode (void); | 5280 | extern void syms_of_bytecode (void); |
diff --git a/src/lread.c b/src/lread.c index c92b2ede932..233f08b0727 100644 --- a/src/lread.c +++ b/src/lread.c | |||
| @@ -256,15 +256,13 @@ static Lisp_Object oblookup_considering_shorthand (Lisp_Object, const char *, | |||
| 256 | ptrdiff_t *); | 256 | ptrdiff_t *); |
| 257 | 257 | ||
| 258 | 258 | ||
| 259 | /* Functions that read one byte from the current source READCHARFUN | 259 | /* Function that reads one byte from the current source READCHARFUN |
| 260 | or unreads one byte. If the integer argument C is -1, it returns | 260 | or unreads one byte. If the integer argument C is -1, it returns |
| 261 | one read byte, or -1 when there's no more byte in the source. If C | 261 | one read byte, or -1 when there's no more byte in the source. If C |
| 262 | is 0 or positive, it unreads C, and the return value is not | 262 | is 0 or positive, it unreads C, and the return value is not |
| 263 | interesting. */ | 263 | interesting. */ |
| 264 | 264 | ||
| 265 | static int readbyte_for_lambda (int, Lisp_Object); | ||
| 266 | static int readbyte_from_file (int, Lisp_Object); | 265 | static int readbyte_from_file (int, Lisp_Object); |
| 267 | static int readbyte_from_string (int, Lisp_Object); | ||
| 268 | 266 | ||
| 269 | /* Handle unreading and rereading of characters. | 267 | /* Handle unreading and rereading of characters. |
| 270 | Write READCHAR to read a character, | 268 | Write READCHAR to read a character, |
| @@ -278,8 +276,8 @@ static int readbyte_from_string (int, Lisp_Object); | |||
| 278 | /* Same as READCHAR but set *MULTIBYTE to the multibyteness of the source. */ | 276 | /* Same as READCHAR but set *MULTIBYTE to the multibyteness of the source. */ |
| 279 | #define READCHAR_REPORT_MULTIBYTE(multibyte) readchar (readcharfun, multibyte) | 277 | #define READCHAR_REPORT_MULTIBYTE(multibyte) readchar (readcharfun, multibyte) |
| 280 | 278 | ||
| 281 | /* When READCHARFUN is Qget_file_char, Qget_emacs_mule_file_char, | 279 | /* When READCHARFUN is Qget_file_char or Qget_emacs_mule_file_char, |
| 282 | Qlambda, or a cons, we use this to keep an unread character because | 280 | we use this to keep an unread character because |
| 283 | a file stream can't handle multibyte-char unreading. The value -1 | 281 | a file stream can't handle multibyte-char unreading. The value -1 |
| 284 | means that there's no unread character. */ | 282 | means that there's no unread character. */ |
| 285 | static int unread_char = -1; | 283 | static int unread_char = -1; |
| @@ -365,12 +363,6 @@ readchar (Lisp_Object readcharfun, bool *multibyte) | |||
| 365 | return c; | 363 | return c; |
| 366 | } | 364 | } |
| 367 | 365 | ||
| 368 | if (EQ (readcharfun, Qlambda)) | ||
| 369 | { | ||
| 370 | readbyte = readbyte_for_lambda; | ||
| 371 | goto read_multibyte; | ||
| 372 | } | ||
| 373 | |||
| 374 | if (EQ (readcharfun, Qget_file_char)) | 366 | if (EQ (readcharfun, Qget_file_char)) |
| 375 | { | 367 | { |
| 376 | eassert (infile); | 368 | eassert (infile); |
| @@ -400,20 +392,6 @@ readchar (Lisp_Object readcharfun, bool *multibyte) | |||
| 400 | return c; | 392 | return c; |
| 401 | } | 393 | } |
| 402 | 394 | ||
| 403 | if (CONSP (readcharfun) && STRINGP (XCAR (readcharfun))) | ||
| 404 | { | ||
| 405 | /* This is the case that read_vector is reading from a unibyte | ||
| 406 | string that contains a byte sequence previously skipped | ||
| 407 | because of #@NUMBER. The car part of readcharfun is that | ||
| 408 | string, and the cdr part is a value of readcharfun given to | ||
| 409 | read_vector. */ | ||
| 410 | readbyte = readbyte_from_string; | ||
| 411 | eassert (infile); | ||
| 412 | if (EQ (XCDR (readcharfun), Qget_emacs_mule_file_char)) | ||
| 413 | emacs_mule_encoding = 1; | ||
| 414 | goto read_multibyte; | ||
| 415 | } | ||
| 416 | |||
| 417 | if (EQ (readcharfun, Qget_emacs_mule_file_char)) | 395 | if (EQ (readcharfun, Qget_emacs_mule_file_char)) |
| 418 | { | 396 | { |
| 419 | readbyte = readbyte_from_file; | 397 | readbyte = readbyte_from_file; |
| @@ -545,14 +523,6 @@ unreadchar (Lisp_Object readcharfun, int c) | |||
| 545 | read_from_string_index_byte | 523 | read_from_string_index_byte |
| 546 | = string_char_to_byte (readcharfun, read_from_string_index); | 524 | = string_char_to_byte (readcharfun, read_from_string_index); |
| 547 | } | 525 | } |
| 548 | else if (CONSP (readcharfun) && STRINGP (XCAR (readcharfun))) | ||
| 549 | { | ||
| 550 | unread_char = c; | ||
| 551 | } | ||
| 552 | else if (EQ (readcharfun, Qlambda)) | ||
| 553 | { | ||
| 554 | unread_char = c; | ||
| 555 | } | ||
| 556 | else if (FROM_FILE_P (readcharfun)) | 526 | else if (FROM_FILE_P (readcharfun)) |
| 557 | { | 527 | { |
| 558 | unread_char = c; | 528 | unread_char = c; |
| @@ -562,13 +532,6 @@ unreadchar (Lisp_Object readcharfun, int c) | |||
| 562 | } | 532 | } |
| 563 | 533 | ||
| 564 | static int | 534 | static int |
| 565 | readbyte_for_lambda (int c, Lisp_Object readcharfun) | ||
| 566 | { | ||
| 567 | return read_bytecode_char (c >= 0); | ||
| 568 | } | ||
| 569 | |||
| 570 | |||
| 571 | static int | ||
| 572 | readbyte_from_stdio (void) | 535 | readbyte_from_stdio (void) |
| 573 | { | 536 | { |
| 574 | if (infile->lookahead) | 537 | if (infile->lookahead) |
| @@ -638,26 +601,6 @@ readbyte_from_file (int c, Lisp_Object readcharfun) | |||
| 638 | return readbyte_from_stdio (); | 601 | return readbyte_from_stdio (); |
| 639 | } | 602 | } |
| 640 | 603 | ||
| 641 | static int | ||
| 642 | readbyte_from_string (int c, Lisp_Object readcharfun) | ||
| 643 | { | ||
| 644 | Lisp_Object string = XCAR (readcharfun); | ||
| 645 | |||
| 646 | if (c >= 0) | ||
| 647 | { | ||
| 648 | read_from_string_index--; | ||
| 649 | read_from_string_index_byte | ||
| 650 | = string_char_to_byte (string, read_from_string_index); | ||
| 651 | } | ||
| 652 | |||
| 653 | return (read_from_string_index < read_from_string_limit | ||
| 654 | ? fetch_string_char_advance (string, | ||
| 655 | &read_from_string_index, | ||
| 656 | &read_from_string_index_byte) | ||
| 657 | : -1); | ||
| 658 | } | ||
| 659 | |||
| 660 | |||
| 661 | /* Signal Qinvalid_read_syntax error. | 604 | /* Signal Qinvalid_read_syntax error. |
| 662 | S is error string of length N (if > 0) */ | 605 | S is error string of length N (if > 0) */ |
| 663 | 606 | ||
| @@ -3517,12 +3460,18 @@ bytecode_from_rev_list (Lisp_Object elems, Lisp_Object readcharfun) | |||
| 3517 | 3460 | ||
| 3518 | /* Lazily-loaded bytecode is represented by the constant slot being nil | 3461 | /* Lazily-loaded bytecode is represented by the constant slot being nil |
| 3519 | and the bytecode slot a (lazily loaded) string containing the | 3462 | and the bytecode slot a (lazily loaded) string containing the |
| 3520 | print representation of (BYTECODE . CONSTANTS). Unpack the | 3463 | print representation of (BYTECODE . CONSTANTS). */ |
| 3521 | pieces by coerceing the string to unibyte and reading the result. */ | ||
| 3522 | if (NILP (vec[CLOSURE_CONSTANTS]) && STRINGP (vec[CLOSURE_CODE])) | 3464 | if (NILP (vec[CLOSURE_CONSTANTS]) && STRINGP (vec[CLOSURE_CODE])) |
| 3523 | { | 3465 | { |
| 3524 | Lisp_Object enc = vec[CLOSURE_CODE]; | 3466 | Lisp_Object enc = vec[CLOSURE_CODE]; |
| 3525 | Lisp_Object pair = Fread (Fcons (enc, readcharfun)); | 3467 | eassert (!STRING_MULTIBYTE (enc)); |
| 3468 | /* The string (always unibyte) must be decoded to be parsed. */ | ||
| 3469 | enc = Fdecode_coding_string (enc, | ||
| 3470 | EQ (readcharfun, | ||
| 3471 | Qget_emacs_mule_file_char) | ||
| 3472 | ? Qemacs_mule : Qutf_8_emacs, | ||
| 3473 | Qt, Qnil); | ||
| 3474 | Lisp_Object pair = Fread (enc); | ||
| 3526 | if (!CONSP (pair)) | 3475 | if (!CONSP (pair)) |
| 3527 | invalid_syntax ("Invalid byte-code object", readcharfun); | 3476 | invalid_syntax ("Invalid byte-code object", readcharfun); |
| 3528 | 3477 | ||
| @@ -3772,7 +3721,7 @@ get_lazy_string (Lisp_Object val) | |||
| 3772 | && !(pos >= ss->position && pos < ss->position + ss->length)) | 3721 | && !(pos >= ss->position && pos < ss->position + ss->length)) |
| 3773 | ss++; | 3722 | ss++; |
| 3774 | if (ss >= ssend) | 3723 | if (ss >= ssend) |
| 3775 | return get_doc_string (val, 1, 0); | 3724 | return get_doc_string (val, 1); |
| 3776 | 3725 | ||
| 3777 | ptrdiff_t start = pos - ss->position; | 3726 | ptrdiff_t start = pos - ss->position; |
| 3778 | char *str = ss->string; | 3727 | char *str = ss->string; |