1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 20:00:19 +02:00
Commit graph

9315 commits

Author SHA1 Message Date
Mark H Weaver
fe73fedab4 Fix list validation of *list->bytevector procedures.
Fixes <https://bugs.gnu.org/32938>.
Reported by Josh Datko <jbd@cryptotronix.com>.

* libguile/validate.h (SCM_VALIDATE_LIST_COPYLEN)
(SCM_VALIDATE_NONEMPTYLIST_COPYLEN): Use '!=' instead of '>=' to
validate the result of 'scm_ilength' after it has been stored in
the user variable 'cvar'.
* test-suite/tests/bytevectors.test: Add tests.  Use '#:use-module'
instead of ':use-module' in 'define-module' form.
2018-10-14 02:27:23 -04:00
Mark H Weaver
b44f505f15 Improve the documentation for 'nil?'.
* libguile/boolean.c (scm_nil_p): Improve docstring.
* doc/ref/api-languages.texi (Nil): Add documentation for 'nil?', along
with a description of how Elisp interprets Scheme booleans and
end-of-list.
2018-10-14 01:37:37 -04:00
Daniel Llorens
b9cf3517ef Fix 32/64 bit bug in INTEGER_ACCESSOR_PROLOGUE 2018-10-10 19:51:58 +02:00
Andy Wingo
e08d10af67 Fix JIT of 64-bit comparisons on 32-bit architectures
* libguile/jit.c (compile_u64_imm_less): Compare high word using
  not-equal, to avoid a signedness compare.
(compile_s64_imm_less, compile_imm_s64_less): Fix the not-less cases.
2018-10-09 12:32:38 +02:00
Andy Wingo
d41f2e9978 Better ursh/ulsh/srsh JIT on 32-bit platforms
* libguile/jit.c (compile_ursh_immediate, compile_ulsh_immediate)
(compile_srsh_immediate): Special-case shifts by 32 bits on 32-bit
platforms.  Avoids shifting by 0.
2018-10-09 12:32:33 +02:00
Andy Wingo
afced398d4 Fix JIT register state tracking for use of SP or FP as temp
* libguile/jit.c (record_gpr_clobber): If we clobber SP or FP, clear the
  appropriate register state bits.  Only exercised for 32-bit targets in
  practice!
  (emit_alloc_frame, emit_push_frame): Fix a couple places where we were
  failing to track the register state correctly.
  (compile_umul): Remove a needless register state flush, nowthat
  qmulr_u has a wrapper that tracks this for us.
2018-10-09 08:55:34 +02:00
Andy Wingo
9feb3a633f Fix JIT compilation on 32-bit targets
* libguile/jit.c: Fix compilation on 32-bit targets.  Still not working
  however.
2018-10-08 15:24:03 +02:00
Andy Wingo
5787f4e516 Fix -Wunused-function error for x86 not on sun
* libguile/lightning/lib/jit_x86-x87.c (_fstcwm): Surround definition
  with ifdef(sun).
2018-10-07 16:44:13 +02:00
Andy Wingo
8bcba78eda Fix unused local warning in vm-engine.c
* libguile/vm-engine.c (return-values): Remove needless frame_size=3
  local var.
2018-10-07 16:33:04 +02:00
Andy Wingo
2388193bbf Fix lightning build with jit_names.c
* libguile/lightning/lightning.am (lightning_extra_files): Move
  jit_names.c here.
2018-10-07 16:30:17 +02:00
Andy Wingo
ae188ac6b7 Revert "Remove jit_names.c."
This reverts commit b74e1f0de3.
2018-10-07 16:29:18 +02:00
Andy Wingo
b74e1f0de3 Remove jit_names.c.
* libguile/lightning/lib/jit_names.c: Remove unused file.
* libguile/lightning/lightning.am (lightning_c_files): Remove
  jit_names.c.
* libguile/lightning/lib/jit_print.c: Remove jit_names.c inclusion.
2018-10-07 16:28:36 +02:00
Andy Wingo
173b44a224 Fix GCC warning with %char-set-dump.
* libguile/srfi-14.c (scm_sys_char_set_dump): Silence an erroneous
  -Wformat-overflow warning based on an incorrect range inference by
  increasing output buffer size.
2018-10-07 16:14:06 +02:00
Andy Wingo
f34d50ad6b Deprecate scm_find_executable
* libguile/deprecated.h:
* libguile/deprecated.c (scm_find_executable): Deprecate.  Use strdup
  instead of weird scm_cat_path function.
* libguile/script.h:
* libguile/script.c: Remove old decls.
2018-10-07 16:04:59 +02:00
Andy Wingo
edba440885 Remove unimplemented decl in script.h
* libguile/script.h (scm_find_impl_file): Remove unimplemented decl.
2018-10-07 15:57:50 +02:00
Andy Wingo
03581c04d7 Comment out some unused definitions
* libguile/jit.c: Comment out unused var decls.
2018-10-07 15:57:27 +02:00
Andy Wingo
6cd9b3114f Fix use of uninstalled header by installed headers
* libguile/Makefile.am (libpath.h): Remove definition of
  SCM_EFFECTIVE_VERSION, which is defined in version.h.
* libguile/extensions.h: Remove libpath.h inclusion, as it's not
  installed.
* libguile/atomic.c:
* libguile/bytevectors.c:
* libguile/control.c:
* libguile/fdes-finalizers.c:
* libguile/foreign-object.c:
* libguile/foreign.c:
* libguile/fports.c:
* libguile/frames.c:
* libguile/goops.c:
* libguile/i18n.c:
* libguile/instructions.c:
* libguile/intrinsics.c:
* libguile/ioext.c:
* libguile/load.c:
* libguile/loader.c:
* libguile/poll.c:
* libguile/ports.c:
* libguile/posix.c:
* libguile/programs.c:
* libguile/r6rs-ports.c:
* libguile/srfi-1.c:
* libguile/srfi-60.c:
* libguile/threads.c:
* libguile/unicode.c:
* libguile/vm.c:
* libguile/weak-vector.c: Include version.h for the
  SCM_EFFECTIVE_VERSION definition.
2018-10-07 15:15:02 +02:00
Mark H Weaver
2d09e0513f Fix 'atomic-box-compare-and-swap!'.
Fixes <https://bugs.gnu.org/32786>.

'scm_atomic_compare_and_swap_scm' is a thin wrapper around
'atomic_compare_exchange_weak' (where available), and therefore it may
spuriously fail on some platforms, leaving the atomic object unchanged
even when the observed value is equal to the expected value.  Since
'scm_atomic_compare_and_swap_scm' returns both a boolean result and the
observed value, the caller is able to detect spurious failures when
using that API.

'atomic-box-compare-and-swap!' presents a simpler API, returning only
the observed value.  The documentation advises callers to assume that
the exchange succeeded if the observed value is 'eq?' to the expected
value.  It's therefore not possible to report spurious failures with
this API.

'atomic-box-compare-and-swap!' uses 'scm_atomic_compare_and_swap_scm',
and prior to this commit would simply ignore the boolean result and
return the observed value.  In case of spurious failures, the caller
would legitimately conclude that the exchange had succeeded.

With this commit, 'atomic-box-compare-and-swap!' now retries in case of
spurious failures.

* libguile/atomic.c (scm_atomic_box_compare_and_swap_x): If
'scm_atomic_compare_and_swap_scm' returns false and the observed value
is equal to 'expected', then try again.
* libguile/vm-engine.c (atomic-box-compare-and-swap!): Ditto.
2018-10-05 18:19:34 -04:00
Andy Wingo
6f3357b0df Fix f32-set! JIT compilation
* libguile/jit.c (compile_f32_set): Fix to write an f32, not a f64.
2018-10-04 16:50:10 +02:00
Andy Wingo
4e8d27f0d1 Finish updating vm.texi
* doc/ref/compiler.texi (Bytecode): Update macro-assembler instructions,
  and move most of them to the instruction set reference.
* doc/ref/vm.texi (A Virtual Machine for Guile, VM Programs): Minor
  fixes.
(Instruction Set): Update for Guile 3 instruction set.
* libguile/vm-engine.c (vm_engine): Update a few instruction
  docstrings.
2018-09-30 16:08:40 +02:00
Ludovic Courtès
3ee7673cc9 Define AT_SYMLINK_NOFOLLOW et al.
* libguile/posix.c (scm_init_posix): Define AT_SYMLINK_NOFOLLOW,
AT_SYMLINK_FOLLOW, AT_NO_AUTOMOUNT, and AT_EMPTY_PATH when available.
(scm_utime): Mention AT_SYMLINK_NOFOLLOW.
* doc/ref/posix.texi (File System): Update accordingly.
* test-suite/tests/posix.test ("utime")["AT_SYMLINK_NOFOLLOW"]: New test.
2018-09-23 16:41:13 +02:00
Andy Wingo
a74b4a45fa Update comments in vm-engine.c
* libguile/jit.c (compile_s64_numerically_equal): Remove as this
instruction was removed in previous refactoring.
(compile_atomic_scm_set_immediate), compile_atomic_scm_ref_immediate):
Adapt to change in C name of these instructions.
* libguile/vm-engine.c: Add comments for all instructions.
2018-09-22 18:42:27 +02:00
Andy Wingo
1e7c541b2f Fix case where running abort hook could trash registers
* libguile/vm-engine.c (abort): If the abort doesn't need to longjmp and
  the abort hook was enabled, cache registers first to avoid restoring
  a bad IP to the VM.
2018-09-22 17:33:58 +02:00
Andy Wingo
4060728e0a Renumber instructions and bump objcode version
* libguile/loader.h (SCM_OBJCODE_MINIMUM_MINOR_VERSION):
  (SCM_OBJCODE_MINOR_VERSION): Bump version.
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
* libguile/vm-engine.c: Rearrange opcodes to be contiguous and in a
  somewhat sensible order.
2018-09-20 11:22:15 +02:00
Andy Wingo
ce9169804e Fix --disable-jit compilation
* libguile/jit.c: Wrap the whole thing in ENABLE_JIT.
* libguile/threads.c (on_thread_exit):
* libguile/vm.c (scm_call_n):
* libguile/init.c (scm_i_init_guile):
* libguile/vm-engine.c (VM_NAME): Wrap calls into jit.c with ENABLE_JIT.
* configure.ac: Move up AC_CANONICAL_TARGET, as autoconf was complaining
  about it coming after AC_ARG_PROGRAM.
* acinclude.m4 (GUILE_ENABLE_JIT): Fix to honor --enable-jit arg.
2018-09-17 09:28:41 +02:00
Andy Wingo
f03ff5304a Turn on automatic JIT compilation by default
* libguile/jit.c (default_jit_threshold): New static const variable.
(scm_sys_jit_compile): Remove.
(scm_init_jit): Rename GUILE_JIT_COUNTER_THRESHOLD to
GUILE_JIT_THRESHOLD, and default to default_jit_threshold.  Remove
%jit-compile definition.
2018-09-15 10:54:14 +02:00
Andy Wingo
883bdc7453 Fix emergency aborts to not expand the stack
* libguile/vm.c (scm_i_vm_emergency_abort): New helper: an abort that
  doesn't allocate, not even stack.
* libguile/throw.c (abort_to_prompt): Use scm_i_vm_emergency_abort.
* libguile/vm.h: Declare helper.
2018-09-15 10:41:35 +02:00
Andy Wingo
4dba01501c Fix scm_make_foreign_object_n.
* libguile/foreign-object.c (scm_make_foreign_object_n): Fix computation
  of slot count; broken in 34b9f22ca.
2018-09-14 16:11:48 +02:00
Andy Wingo
09b8f8ec06 Deoptimize to VM when hooks are enabled
* libguile/vm.c (vm_clear_mcode_return_addresses): New helper.
(vm_recompute_disable_mcode): Force a thread to deoptimize if hooks
become enabled.
(scm_call_n): Don't enter mcode if it's disabled.  Also check the right
flag for when to run the abort hook (the abort_hook_enabled flag).
* libguile/vm-engine.c (instrument-entry, instrument-loop)
(return-values, abort, compose-continuation): Don't enter mcode if mcode
is disabled for this thread.
2018-09-14 15:16:33 +02:00
Andy Wingo
12b125f2ad Hook refactors
* libguile/vm.h (SCM_VM_NUM_HOOKS): Remove hook enumeration.
(struct scm_vm): Re-arrange members to be more dense and to use common
cache lines for commonly-used members.  Declare hooks and their enabled
flags by name.
* libguile/vm-engine.c (RUN_HOOK): Refer to hooks by name.
* libguile/vm.c (FOR_EACH_HOOK): New helper.
(vm_hook_compute_enabled, vm_recompute_disable_mcode): New routines to
recompute when hooks are enabled, and whether to disable mcode because
hooks are active.
(set_vm_trace_level): New helper.
(invoke_hook): Take hook to invoke by value.
(DEFINE_INVOKE_HOOK): Refactor to use named hooks.
(scm_i_vm_prepare_stack): Init named hooks.
(VM_ADD_HOOK, VM_REMOVE_HOOK): Refactor to use named hooks, and also
recompute global disable_mcode flag.
(scm_set_vm_trace_level_x, scm_c_set_vm_engine_x): Use internal helper.
2018-09-14 13:02:44 +02:00
Andy Wingo
8bb9ae3b51 Micro-optimization of scm_vm placement in scm_thread
* libguile/threads.h (struct scm_thread): Move the embedded "struct
  scm_vm" earlier in the scm_thread.  Since the VM (and the JIT) access
  VM data (SP, FP, etc) through the thread pointer, this allows more
  accesses to be encoded in shorter instruction sequences.
2018-09-14 09:39:29 +02:00
Andy Wingo
0ccd2d0d9e Remove hook intrinsics: hooks are just for the VM
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Remove VM hook
  intrinsics, now that we're going to rely on the interpreter for
  stepping and breakpoints.
* libguile/jit.c (struct scm_jit_state): Remove "hooks_enabled" member,
  now that we won't JIT.  Remove all code related to calling hooks.
* libguile/vm-engine.c (RUN_HOOK): Call hooks directly instead of
  through intrinsics.  Use precise per-hook enable flags.
* libguile/vm.c (DEFINE_INVOKE_HOOK): New helper.  Use to define the
  hook invokers.
2018-09-14 09:34:31 +02:00
Andy Wingo
bf31fe4cf6 VM manages hook sets itself
* libguile/vm.h (SCM_VM_ABORT_HOOK): Rename from
  SCM_VM_ABORT_CONTINUATION_HOOK.
* libguile/vm-engine.c (ABORT_HOOK):
* libguile/vm.c (invoke_abort_hook): Adapt to SCM_VM_ABORT_HOOK name
change.
(reset_vm_hook_enabled): New helper.
(VM_ADD_HOOK, VM_REMOVE_HOOK): New helper macros, replacing
VM_DEFINE_HOOK.
(scm_vm_add_abort_hook_x, scm_vm_remove_abort_hook_x)
(scm_vm_add_apply_hook_x, scm_vm_remove_apply_hook_x)
(scm_vm_add_return_hook_x, scm_vm_remove_return_hook_x)
(scm_vm_add_next_hook_x, scm_vm_remove_next_hook_x): New functions,
replacing direct access to the hooks.  Allows us to know in a more
fine-grained way when to enable hooks.
(scm_set_vm_trace_level_x): Use reset_vm_hook_enabled to update the
individual hook_enabled flags.
* module/statprof.scm:
* module/system/vm/coverage.scm:
* module/system/vm/traps.scm:
* module/system/vm/vm.scm: Adapt VM hook users to the new API.
2018-09-14 08:52:24 +02:00
Andy Wingo
ce5c05ac4a Fix JIT compilation of intrinsics that return doubles
* libguile/jit.c (emit_retval_d): New helper.
(compile_call_f64_from_scm): Take the f64 result from the correct
registers.
2018-09-10 16:33:10 +02:00
Andy Wingo
46fe5b069b Fix positional-arguments<=? compilation
* libguile/jit.c (compile_check_positional_arguments): Fix.
2018-09-10 16:28:31 +02:00
Andy Wingo
18aa995cbb Fix compilation of compare-and-swap
* libguile/jit.c (compile_atomic_scm_compare_and_swap_immediate): Call
  the right intrinsic.
2018-09-07 15:19:19 +02:00
Andy Wingo
227c3acc5d Refactor handling of lightning state
* libguile/jit.c (prepare_jit_state, reset_jit_state): New helpers.
(emit_code): Prevent emission of auxiliary data.
(compile_handle_interrupts): Assume the handle_interrupts_trampoline is
compiled eagerly.
(initialize_thread_jit_state): New helper.
(initialize_jit): Refactor.  Emit handle-interrupts code here.
(compute_mcode): Adapt to initialize_jit refactorings.
(scm_jit_state_free): Nothing to do.
2018-09-07 15:06:28 +02:00
Andy Wingo
377c3e117e Fix compilation of handle-interrupts
* libguile/jit.c (compile_handle_interrupts): Fix check for blocked
  interrupts.
2018-09-07 14:22:48 +02:00
Andy Wingo
f8229c603d Use custom JIT code allocator
* libguile/jit.c (struct code_arena): New data type.
(struct scm_jit_state): Add code arena member.
(allocate_code_arena): New helper.
(emit_code): New helper.  Emits code into a thread-local code arena.
(compute_mcode): Allow for failure to JIT.
(scm_jit_compute_mcode): Stop automatic JIT compilation on resource
exhaustion.
2018-09-07 12:22:44 +02:00
Andy Wingo
3e2b173158 Revert "<?" fast path for now
* libguile/jit.c (compile_less): Revert fast path; causing errors in
  benchmarks.
2018-09-05 22:30:43 +02:00
Andy Wingo
93112d3ed5 Add JIT fast paths for inum arithmetic
* libguile/jit.c (compile_call_scm_from_scm_scm): Add fast paths for
  inum add and sub.
  (compile_call_scm_from_scm_uimm): Add fast paths for inum
  add/immediate and sub/immediate.
  (compile_less): Add fast path for inum compare.
2018-09-05 22:09:42 +02:00
Andy Wingo
218fe1b962 Fix JIT compilation of [positional-]arguments<=?
* libguile/jit.c (compile_check_arguments)
  (compile_check_positional_arguments): Fix these functions.  The
  compiler uses "jge" as a "compare result not NONE", but the VM
  instructions set NONE on greater-than, not greater-than-or-equal.
  Sad!
2018-09-05 21:53:56 +02:00
Andy Wingo
cf712c0eb1 Improve JIT cleanup a bit
* libguile/jit.c (initialize_jit): Improve cleanup a bit.
2018-09-05 16:35:00 +02:00
Andy Wingo
babd4118c2 Fix nonlocal abort to compiled continuation
* libguile/vm.c (scm_call_n): Fix failure to reset vm.registers after a
  nonlocal abort to a compiled continuation.
2018-09-03 18:31:41 +02:00
Andy Wingo
24b4d09394 Improve compute_mcode allocation logic
* libguile/jit.c (compute_mcode): Move up some assertions before using
  them to allocate.
2018-09-02 21:56:36 +02:00
Andy Wingo
162e313311 Fix a memory leak in JIT
* libguile/jit.c (compute_mcode): Fix memory leak.  Ultimate fix will be
  to use arena allocation, but that will come later.
2018-09-02 21:35:54 +02:00
Andy Wingo
e9b44c00fd Fix assertion error running compile-file with threshold 0
* libguile/jit.c (emit_alloc_frame_for_sp): Don't require that FP be in
  a register, but if it was and we call out, do restore it.
2018-09-02 21:29:24 +02:00
Andy Wingo
54b23adc13 Add ability to tier up from within loops
* libguile/jit.c (struct scm_jit_state): Add entry and entry_label
  members.
(analyze): Assert entry is jump target.
(compile): Record indirect entry label.
(compute_mcode): Record entry IP, and return entry mcode.
(scm_sys_jit_compile, scm_jit_compute_mcode): Adapt to compute_mcode
change.  Support hot-loop transfer.
2018-09-02 11:54:12 +02:00
Andy Wingo
076c3ad8d7 JIT counter tweaks
* libguile/vm-engine.c (instrument-entry, instrument-loop): Make the
  counter check >=, so that we can set the threshold to 0 and still get
  compilation.
* libguile/jit.h (enum scm_jit_counter_value): Make the increments
  event.
2018-09-02 11:00:24 +02:00
Andy Wingo
b176e714f8 Add configurable JIT logging levels
* libguile/jit.c (jit_log_level): New local.
(_LOG, INFO, DEBUG, LOG): New macros.
(compile1):
(compute_mcode):
(scm_jit_enter_mcode): Use new logging macros.
2018-09-02 10:49:24 +02:00