summaryrefslogtreecommitdiff
path: root/libguile
AgeCommit message (Collapse)AuthorFilesLines
2019-08-02Revert scm_c_make_char renameAndy Wingo7-33/+33
This was, I think, an unintentional ABI change. Reverts 579dd2da449be194a95d41a27317a453c1aa0568.
2019-08-02Merge from stable-2.2Andy Wingo1-7/+2
2019-08-02Merge from stable-2.2Andy Wingo1-9/+38
2019-08-02Merge from stable-2.2Andy Wingo1-1/+1
2019-08-02Merge from stable-2.2Andy Wingo1-2/+2
2019-08-02Merge from stable-2.2Andy Wingo2-7/+50
2019-08-02Merge from stable-2.2Andy Wingo1-6/+5
2019-08-02Merge from stable-2.2Andy Wingo1-2/+2
2019-08-02Merge from stable-2.2Andy Wingo1-0/+2
2019-08-02Merge from stable-2.2Andy Wingo8-71/+139
2019-08-02Merge from stable-2.2Andy Wingo1-4/+13
2019-06-20Add an inlined jit fast-path for allocate-words/immediateAndy Wingo3-7/+46
* libguile/intrinsics.c (allocate_words_with_freelist) (scm_bootstrap_intrinsics): * libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): New intrinsic. * libguile/jit.c (compile_allocate_words_immediate): Add fast-path. A marginal improvement.
2019-06-20Inline freelist vectors into scm_threadAndy Wingo3-35/+27
* libguile/gc-inline.h: * libguile/threads.h (SCM_INLINE_GC_GRANULE_WORDS) (SCM_INLINE_GC_GRANULE_BYTES, SCM_INLINE_GC_FREELIST_COUNT): Move definitions here, from gc-inline.h. (struct scm_thread): Inline freelist vectors. * libguile/threads.c (thread_mark): Update marker for pointerless freelists. (on_thread_exit): Clear individual freelist entries, instead of the vector as a whole. (guilify_self_2): No need to alloc freelist vectors.
2019-06-20Rearrange scm_thread for better localityAndy Wingo1-12/+12
* libguile/threads.h (struct scm_thread): Move async-related bits up, so that the VM can access them easier. Likewise for freelists (which we will inline soon).
2019-06-20Fix compilation on GCC 5.5Andy Wingo1-5/+8
* libguile/jit.c (OLD_FP_FOR_RETURN_TRAMPOLINE): Initialize static const var from CPP define instead of T0. (compile_return_values, emit_return_to_interpreter_trampoline): Adapt to upper-casing.
2019-06-20Use call/return instructions for non-tail callsAndy Wingo1-24/+34
This change speeds up the indirect branches at return sites by taking advantage of the CPU's return address stack. * libguile/jit.c (emit_push_frame): Don't store the mra; we do that via a trampoline. (emit_handle_interrupts_trampoline): Take MRA from link register instead of T0. (compile_call, compile_call_label): Compute MRA via the new jmpi_with_link lightening instruction. (compile_return_values): Return to caller via ret instead of jmp. (compile_handle_interrupts): Jump to handle-interrupts trampoline via jmpi_with_link, to provide the MRA. (initialize_jit): Bless the trampolines so that they are valid operands to BX on ARM.
2019-06-20Merge remote-tracking branch 'lightening/master'Andy Wingo1-0/+9
2019-06-20Merge remote-tracking branch 'lightening/master'Andy Wingo8-0/+92
2019-06-18Speed up returns in JITAndy Wingo4-27/+49
This patch is a bit unfortunate, in the sense that it exposes some of the JIT guts to the rest of the VM. Code needs to treat "machine return addresses" as valid if non-NULL (as before) and also not equal to a tier-down trampoline. This is because tier-down at a return needs the old frame pointer to load the "virtual return address", and the way this patch works is that it passes the vra in a well-known register. It's a custom calling convention for a certain kind of return. * libguile/jit.h (scm_jit_return_to_interpreter_trampoline): New internal global. * libguile/jit.c: (scm_jit_clear_mcode_return_addresses): Move here, from vm.c. Instead of zeroing return addresses, set them to the return-to-interpreter trampoline. * libguile/vm-engine.c (return-values): Don't enter mcode if the mra is scm_jit_return_to_interpreter_trampoline. * libguile/vm.c (capture_continuation): Treat the tier-down trampoline as NULL.
2019-06-18jit: Direct tail calls assert that target can have mcodeAndy Wingo1-6/+2
* libguile/jit.c (emit_direct_tail_call): Assert that the callee label starts with an instrument-entry.
2019-06-18fport_seek: Eliminate a fruitless use of 'off_t_or_off64_t'.Mark H Weaver1-7/+2
This is a followup to commit 91ba73b397fcc2a36ae7e434522a924c7a8887d0. * libguile/fports.c (fport_seek): Use 'lseek' instead of 'lseek_or_lseek64', and use 'scm_t_off' uniformly. That's the type used in the function signature, and there's no benefit to using a wider type internally. Remove the overflow check, which is no longer needed.
2019-06-18open-process: Fix dup(2) and execvp(2) error handling.Mark H Weaver1-9/+38
Previously, in the case where OUT is 0, or ERR is 0 or 1, e.g. when (current-error-port) points to STDOUT, the code in 'start_child' to relocate OUT/ERR out of the way to another file descriptor had multiple bugs: (1) It neglected to close the original file descriptor. (2) It checked 'errno' without first checking the return value of dup(2). This doesn't work because dup(2) leaves 'errno' unchanged if there's no error. (3) In case 'errno' contained EINTR, the retry code failed because OUT (or ERR) was overwritten by the result of the previous failed dup(2) call. This commit fixes these problems, as well as another problem with 'execvp' error reporting. * libguile/posix.c (renumber_file_descriptor): New static helper function. (start_child): Use 'renumber_file_descriptor'. If 'execvp' fails, write the error message to file descriptor 2. Previously, we wrote the error message to ERR, which was the old file descriptor before being relocated to 2.
2019-06-18Refresh a stale comment.Mark H Weaver1-1/+1
* libguile/numbers.h: In a comment, update the count of number subtypes.
2019-06-18scm_mkstrport: Optimize the POS -> BYTE_POS conversion.Mark H Weaver1-2/+2
* libguile/strports.c (scm_mkstrport): Use 'scm_c_string_utf8_length' to avoid the conversion to UTF-8.
2019-06-18Add get-bytevector-some!.Mark H Weaver2-2/+48
* libguile/r6rs-ports.c (scm_get_bytevector_some_x): New procedure. * libguile/r6rs-ports.h (scm_get_bytevector_some_x): Add prototype. (scm_unget_bytevector): Move prototype next to 'scm_get_bytevector_some_x'. * module/ice-9/binary-ports.scm: Export 'get-bytevector-some!'. * doc/ref/api-io.texi (Binary I/O): Document it.
2019-06-18scm_to_stringn: Avoid passing NULL to c_strcasecmp.Mark H Weaver1-6/+5
Reported by Massimiliano Gubinelli <m.gubinelli@gmail.com> in <https://lists.gnu.org/archive/html/guile-user/2019-05/msg00070.html>. * libguile/strings.c (scm_to_stringn): Check for (encoding == NULL) before passing it to 'c_strcasecmp'. Eliminate redundant 'enc' variable.
2019-06-18Fix typo in tags.h comment.Mark H Weaver1-1/+1
* libguile/tags.h: Fix typo in comment.
2019-06-18Save and restore errno in the signal handler.Mark H Weaver1-0/+2
* libguile/scmsigs.c (take_signal): Save and restore errno.
2019-06-18Improve overflow checks in bytevector, string, and I/O operations.Mark H Weaver8-76/+142
* libguile/bytevectors.c (INTEGER_ACCESSOR_PROLOGUE) (scm_bytevector_copy_x, bytevector_large_set): Rewrite checks to reliably detect overflows. (make_bytevector): Constrain the bytevector length to avoid later overflows during allocation. (make_bytevector_from_buffer): Fix indentation. (scm_bytevector_length): Use 'scm_from_size_t' to convert a 'size_t', not 'scm_from_uint'. * libguile/fports.c (fport_seek): Check for overflow before the implicit conversion of the return value. * libguile/guardians.c (guardian_print): Use 'scm_from_ulong' to convert an 'unsigned long', not 'scm_from_uint'. * libguile/ports.c (scm_unread_string): Change a variable to type 'size_t'. (scm_seek, scm_truncate_file): Use 'scm_t_off' instead of 'off_t_or_off64_t' to avoid implicit type conversions that could overflow, because 'ptob->seek' and 'ptob->truncate' use 'scm_t_off'. * libguile/r6rs-ports.c (bytevector_input_port_seek) (custom_binary_port_seek, bytevector_output_port_seek): Rewrite offset calculations to reliably detect overflows. Use 'scm_from_off_t' to convert a 'scm_t_off', not 'scm_from_long' nor 'scm_from_int'. (scm_get_bytevector_n_x, scm_get_bytevector_all, scm_unget_bytevector) (bytevector_output_port_write): Rewrite checks to reliably detect overflows. Use 'size_t' where appropriate. (bytevector_output_port_buffer_grow): Rewrite size calculations to reliably detect overflows. Minor change in the calculation of the new size: now it is max(min_size, 2*current_size), whereas previously it would multiply current_size by the smallest power of 2 needed to surpass min_size. * libguile/strings.c (make_stringbuf): Constrain the stringbuf length to avoid later overflows during allocation. (scm_string_append): Change overflow check to use INT_ADD_OVERFLOW. * libguile/strports.c (string_port_write): Rewrite size calculations to reliably detect overflows. (string_port_seek): Rewrite offset calculations to reliably detect overflows. Use 'scm_from_off_t' to convert a 'scm_t_off', not 'scm_from_long'. (string_port_truncate): Use 'scm_from_off_t' to convert a 'scm_t_off', not 'scm_from_off_t_or_off64_t'. * libguile/vectors.c (scm_c_make_vector): Change a variable to type 'size_t'.
2019-06-06VM does not initialize stack framesAndy Wingo2-51/+10
* libguile/jit.c (compile_alloc_frame): Stop initializing locals. (compile_bind_rest): Use emit_alloc_frame. * libguile/vm-engine.c (assert_nargs_ee_locals, allocate_frame): Don't initialize locals. (bind_rest): Don't initialize locals, and assert that the locals count has a minimum.
2019-06-06Allow for bind-optionals without alloc-frameAndy Wingo3-52/+90
This reduces subr trampoline instruction count for subrs with optional args. * libguile/gsubr.c (get_subr_stub_code): Insert bind-optionals instructions. (primitive_call_ip): Handle bind-optionals. * libguile/programs.c (try_parse_arity): Handle bind-optionals. * libguile/jit.c (struct scm_jit_state) (compile_call, compile_call_label, compile_tail_call) (compile_tail_call_label, compile_receive), compile_receive_values) (compile_shuffle_down, compile_return_values, compile_subr_call) (compile_foreign_call, compile_continuation_call) (compile_compose_continuation, compile_abort, compile_assert_nargs_ee) (compile_assert_nargs_ge, compile_assert_nargs_le) (compile_alloc_frame, compile_reset_frame, compile_push) (compile_pop, compile_drop, compile_expand_apply_argument) (compile_bind_kwargs, compile_bind_rest, compile_bind_optionals) (compile, compute_mcode): Separately track min and max frame sizes.
2019-06-06Add bind-optionals instructionAndy Wingo2-1/+53
* doc/ref/vm.texi (Function Prologue Instructions): Document new instruction. * libguile/jit.c (compile_bind_optionals): New compiler. * libguile/vm-engine.c (VM_NAME): New interpreter. * module/system/vm/assembler.scm (opt-prelude): Emit bind-optionals as appropriate. * module/system/vm/disassembler.scm (define-stack-effect-parser) (code-annotation): Handle bind-optionals.
2019-06-06Avoid saving IP for <? fast-pathAndy Wingo1-1/+1
* libguile/jit.c (compile_less): Only save IP on slow-path.
2019-06-04'basename' correctly handles "/" and "//".Ludovic Courtès1-4/+13
* libguile/filesys.c (scm_basename): Special-case "/" and "//". * test-suite/tests/filesys.test ("basename"): New test prefix.
2019-05-27Remove check for instrument-entryAndy Wingo1-7/+0
* libguile/jit.c (emit_indirect_tail_call): If everything starts with instrument-entry, and thus has a vcode pointer, no need to emit a dynamic check.
2019-05-27Dynamically assert functions start with instrument-entryAndy Wingo1-6/+4
* libguile/jit.c (emit_indirect_tail_call): Add dynamic assertion.
2019-05-27Reapply atomics inliningAndy Wingo4-49/+9
This patch reapplies 230a5559764679d75e3e8941e97a268a2b2e6a53 and e8d34258beab2799951e16d21d547299d4659364, but fixing a misplaced comma (!).
2019-05-27Revert "Inline the atomic intrinsics"Andy Wingo3-7/+39
This reverts commit 230a5559764679d75e3e8941e97a268a2b2e6a53.
2019-05-27Revert "Fix atomics usage in handle-interrupts JIT."Andy Wingo1-2/+10
This reverts commit e8d34258beab2799951e16d21d547299d4659364.
2019-05-27Merge remote-tracking branch 'lightening/master'Andy Wingo4-0/+34
2019-05-27Merge remote-tracking branch 'lightening/master'Andy Wingo1-1/+1
2019-05-27Fix atomics usage in handle-interrupts JIT.Andy Wingo1-10/+2
* libguile/jit.c (compile_handle_interrupts): Use atomics in handle-interrupts.
2019-05-27Inline the atomic intrinsicsAndy Wingo3-39/+7
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): * libguile/intrinsics.c (scm_bootstrap_intrinsics): Remove the atomic intrinsics, as the JIT no longer needs them. * libguile/vm-engine.c (VM_NAME): Inline the intrinsics.
2019-05-27Use new atomic instructions from lighteningAndy Wingo1-34/+19
* libguile/jit.c (compile_atomic_scm_ref_immediate): (compile_atomic_scm_set_immediate): (compile_atomic_scm_swap_immediate): (compile_atomic_scm_compare_and_swap_immediate): Use lightening instructions.
2019-05-27Merge remote-tracking branch 'lightening/master'Andy Wingo6-12/+286
2019-05-25Switch to use atomic_compare_exchange_strongAndy Wingo4-47/+27
* libguile/atomics-internal.h (scm_atomic_compare_and_swap_scm): Change to use same API as atomic-box-compare-and-swap!. * libguile/intrinsics.c (atomic_compare_and_swap_scm): Remove loop, as we're using the strong variant now. * libguile/async.c (scm_i_async_pop, scm_i_async_push): Adapt to new API of scm_atomic_compare_and_swap_scm.
2019-05-23Strings, i18n: Limit the use of alloca to approximately 8 kilobytes.Mark H Weaver2-36/+79
* libguile/i18n.c (SCM_MAX_ALLOCA): New macro. (SCM_STRING_TO_U32_BUF): Accept an additional variable to remember whether we used malloc to allocate the buffer. Use malloc if the allocation size is greater than SCM_MAX_ALLOCA. (SCM_CLEANUP_U32_BUF): New macro. (compare_u32_strings, compare_u32_strings_ci, str_to_case): Adapt. * libguile/strings.c (SCM_MAX_ALLOCA): New macro. (normalize_str, unistring_escapes_to_r6rs_escapes): Use malloc if the allocation size is greater than SCM_MAX_ALLOCA. * test-suite/tests/i18n.test, test-suite/tests/strings.test: Add tests.
2019-05-23put-u8: Always write a single byte, regardless of the port encoding.Mark H Weaver1-1/+1
Previously, 'put-u8' used textual I/O to write a single character, relying on the usual practice of setting the port encoding to ISO-8859-1 for binary ports. * libguile/r6rs-ports.c (scm_put_u8): Use 'scm_c_write', not 'scm_putc'.
2019-05-23Optimize fixnum exact integer square roots.Mark H Weaver1-31/+40
* libguile/numbers.c (scm_exact_integer_sqrt, scm_sqrt) (exact_integer_is_perfect_square, exact_integer_floor_square_root): Where it is trivial to do so, use GMP's low-level mpn functions to avoid heap allocation.
2019-05-23Fix indentation in scm_sum.Mark H Weaver1-67/+68