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

9538 commits

Author SHA1 Message Date
Ludovic Courtès
40f9a44c1b gdb: Delay type lookups.
This avoids errors while loading the file when types are not in scope.

* libguile/libguile-3.0-gdb.scm (%gdb-memory-backend)[void*]: Turn into
a promise and adjust user accordingly.
(ip-type, fp-type, sp-type, uint-type): Remove.
(vm-frame)[ip-type, uint-type]: New variables.
2020-03-17 22:57:41 +01:00
Ludovic Courtès
7c17655cd3 Fix incorrect allocation size in 'make-vtable-vtable'.
Fixes <https://bugs.gnu.org/39266>.
Thanks to <https://rr-project.org/> for its help!

* libguile/struct.c (set_vtable_access_fields): Fix first argument to
'scm_gc_malloc_pointerless'.
2020-03-09 15:22:53 +01:00
Ludovic Courtès
c5d3b45c9f 'hash' behaves like 'hashq' for tc7s without an 'equal?' implementation.
Fixes <https://bugs.gnu.org/39634>.

* libguile/hash.c (scm_raw_ihash): Add cases for scm_tc7 values that
were not explicitly listed.
2020-03-06 17:15:45 +01:00
Andy Wingo
5c950503a6 Add support for perf map creation
* libguile/jit.c (create_perf_map_once, create_perf_map, perf_map): New
  locals.
  (compute_mcode): Add an entry to perf_map for emitted JIT code.
2020-02-26 16:41:21 +01:00
Rob Browning
8b3cad6183 Implement hashing for keywords, i.e. (hash #:x ...)
Add keyword handling to (hash ...).  Previously it would just return the
same value for all keywords.

* libguile/hash.c (scm_raw_ihash): Add scm_tc7_keyword case.

* libguile/keywords.h (SCM_I_KEYWORD_HASH): New macro.
2020-02-21 01:36:14 -06:00
Andy Wingo
cc30168878 Fix bug restoring a JIT continuation from the interpreter
* libguile/vm.c (push_interrupt_frame, compose_continuation): In places
  where we push on synthetic frames before possibly going back to mcode,
  make sure that the return mcode will trampoline back to the
  interpreter.  Fixes compose-continuation from the interpreter to
  partial continuations with mcode.
2020-02-19 16:53:44 +01:00
Andy Wingo
18e9366142 Better debugging in jit.c
* libguile/jit.c (emit_direct_tail_call): Assert self-tail call has
  mcode.
  (opcodes_seen, bitvector_ref, bitvector_set, compile1): Make the
  opcodes_seen set more compact, and log all instruction emissions at
  level 3.
  (compute_mcode): Don't overwrite mcode if compilation fails.
2020-02-19 16:50:32 +01:00
Andy Wingo
74eafacff0 Merge remote-tracking branch 'lightening/master' 2020-02-17 22:04:07 +01:00
Ludovic Courtès
41d470f0e9 Reintroduce 'SCM_MEMORY_ERROR' in terms of 'scm_report_out_of_memory'.
Suggested by Dale P. Smith <dsmich@roadrunner.com>.

* libguile/deprecated.h (SCM_MEMORY_ERROR): New macro.
* doc/ref/api-control.texi (Dynamic Wind): Use 'scm_report_out_of_memory'.
2020-02-11 14:47:16 +01:00
Ludovic Courtès
1a3e316c32 Remove traces of 'scm_memory_error'.
'scm_memory_error' was deprecated in 2014 in commit
c2247b782a and removed in 2017 in commit
c248ea10be.  This is a followup.

* libguile/error.h (SCM_MEMORY_ERROR): Remove.
* doc/guile-api.alist: Remove 'scm_memory_error'.
* doc/ref/api-control.texi (Handling Errors): Likewise.
(Dynamic Wind): Use 'scm_misc_error' instead of 'scm_memory_error'.
2020-02-10 00:10:10 +01:00
John Paul Adrian Glaubitz
43cfae3634 Fix build on ia64.
* libguile/continuations.c (capture_auxiliary_stack): Fix
  logic in preprocessor code when checking for ia64 host;
  fix dereferencing of ctx variable.
* libguile/threads.h (struct scm_thread): Add missing member
  SCM_STACKITEM *auxiliary_stack_base.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2020-02-08 15:11:34 +01:00
John Paul Adrian Glaubitz
ad91517da1 Fix build on platforms where the stack grows upwards.
* libguile/continuations.c (scm_dynthrow): Fix missing mra
   parameter to grow_stack for SCM_STACK_GROWS_UP.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2020-02-08 15:11:33 +01:00
Ludovic Courtès
00fbdfa734 Handle GMP allocations through libgc and remove bignum finalizers.
This significantly speeds up loads that create lots of bignums, like
(language cps slot-allocation) for files with many top-level
definitions.  Compiling such a file is typically 2.5 times faster.

See <https://lists.gnu.org/archive/html/guile-devel/2020-02/msg00023.html>.

* libguile/numbers.c (custom_gmp_malloc): Use
'scm_gc_malloc_pointerless' instead of 'scm_malloc'.
(custom_gmp_realloc): Use 'scm_gc_realloc'.
(custom_gmp_free): Remove call to 'free'.
(make_bignum): Use 'scm_gc_malloc' instead of 'scm_gc_malloc_pointerless'.
Call 'scm_i_set_finalizer' only when SCM_INSTALL_GMP_MEMORY_FUNCTIONS is
false.
2020-02-08 11:40:17 +01:00
Ludovic Courtès
491cc23f93 build: Actually install libguile-3.0-gdb.scm.
Reported by brandelune on #guile.

* libguile/libguile-2.2-gdb.scm: Rename to...
* libguile/libguile-3.0-gdb.scm: ... this.
* libguile/Makefile.am (install-data-hook): Replace hard-coded "2.2"
with @GUILE_EFFECTIVE_VERSION@.
2020-01-21 17:51:37 +01:00
Ludovic Courtès
228ae549ca Make 'scm_sym_lambda', 'scm_sym_quote', etc. public again.
Fixes <https://bugs.gnu.org/39183>.

These symbols had been inadvertently removed from libguile, even though
they were intended to be public (as they were in 2.2).

* libguile/expand.c: Include "memoize.h".
2020-01-20 10:21:40 +01:00
Andy Wingo
53a3602b20 Bump objcode minor version in preparation for new stable series
* libguile/loader.h (SCM_OBJCODE_MINIMUM_MINOR_VERSION):
  (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump.
2020-01-13 08:01:40 +01:00
Rob Browning
2446e7dc29 Respect thread local fluid defaults
Previously (fluid-ref (make-thread-local-fluid #t)) would return #f via
scm_fluid_ref because the internal scm_hashq_ref would return #f when
the fluid had not been set, and that was interpreted as an actual value
for the fluid.

Instead, just pass the fluid default as the default for the hash table
lookups so that we don't need a second step to determine if the fluid
was set.

Thanks to Andrew Gierth for tracking down the problem.
2020-01-12 22:04:29 +01:00
Andy Wingo
74f46efc73 Fix build on 32-bit systems with JIT support
* libguile/intrinsics.h: Add s64->f64 intrinsic, for 32-bit targets.
* libguile/jit.c (compile_s64_to_f64): Call the intrinsic for 32-bit
  targets.
2020-01-11 10:28:36 +01:00
Andy Wingo
9f2b703101 Merge remote-tracking branch 'lightening/master' 2020-01-06 22:00:53 +01:00
Daniel Llorens
ddad8ae05a Extend core vector-fill! to handle a range
With this patch, these two lines

  (vector-fill! vec fill)
  (vector-fill! vec fill 0 end)

run at the same speed; before, the second one was much slower.

This patch also makes it an error to call vector-fill! with a non-vector
array. The previous implementation did not work correctly in this case.

* libguile/vectors.c (SCM_VALIDATE_MUTABLE_VECTOR): Better error message.
  (vector-fill!): Handle optional arguments start, end. Do not attempt
    to handle non-vector arrays. Rename the C binding to
    scm_vector_fill_partial_x.
  (scm_vector_fill_x): Reuse scm_vector_fill_partial_x.
* module/srfi/srfi-43.scm (vector-fill!): Remove & re-export the core
  version instead.
2020-01-03 13:01:04 +01:00
Daniel Llorens
6b0491233f Provide SCM_DEFINE_STATIC
From guile-gnome:plain/glib/gnome/gobject/private.h.

* libguile/gsubr.h (SCM_DEFINE_STATIC): As stated.
2020-01-03 12:45:07 +01:00
Andy Wingo
e3e3e691f8 Fix abort_to_prompt bug if dynwind leave thunk expands the stack
* libguile/vm.c (scm_i_vm_emergency_abort, abort_to_prompt): Unwinding
  the dynwind stack can run dynwind leave thunks, which may expand the
  stack, which may invalidate previously calculated SP / FP values.
  (Re)calculate SP/FP after unwinding, to avoid writing to unmapped
  memory.  Fixes compile errors seen on Ubuntu and some other ports.
2020-01-02 13:29:39 +01:00
Andy Wingo
dbc93d6195 Avoid throwing exceptions during early boot if stdin is closed
* libguile/fports.c (scm_i_fdes_is_valid): New internal helper.
  (scm_i_fdes_to_port): Use new helper.
* libguile/fports.h: Declare new helper.
* libguile/init.c (scm_standard_stream_to_port): Refactor to use
  scm_i_fdes_is_valid.
2019-12-13 13:52:58 +01:00
Andy Wingo
bcb4f7dca8 Merge remote-tracking branch 'origin/stable-2.2' 2019-12-11 21:26:54 +01:00
Andy Wingo
114198d15f Move less? slow path out of line
* libguile/jit.c (compile_less, compile_less_slow): Move slow path out
  of line.
2019-12-10 23:03:19 +01:00
Andy Wingo
5e41d58ab9 Add fixnum fast-path for =
* libguile/jit.c (compile_numerically_equal): Add fixnum fast-path.
  (compile_numerically_equal_slow): New slow path.
2019-12-10 22:54:17 +01:00
Andy Wingo
6b335506ef Move allocate-pointerless-words/immediate slow path out of line
* libguile/jit.c (compile_allocate_pointerless_words_immediate)
  (compile_allocate_pointerless_words_immediate_slow): Move slow path
  out of line.
2019-12-10 22:38:45 +01:00
Andy Wingo
f1578c98b2 Move allocate-words/immediate slow path out of line
* libguile/jit.c (compile_allocate_words_immediate)
  (compile_allocate_words_immediate_slow): Move slow path out of line.
2019-12-10 22:33:47 +01:00
Andy Wingo
0c8a4d3426 Move assert-nargs-le slow path out of line
* libguile/jit.c (compile_assert_nargs_le)
  (compile_assert_nargs_le_slow): Move slow path out of line.
2019-12-10 22:20:53 +01:00
Andy Wingo
45b936a8e3 Add out-of-line slow path for abort
* libguile/jit.c (compile_abort, compile_abort_slow): Move interpreter
  fallback to slow path.
2019-12-10 22:20:51 +01:00
Andy Wingo
7a6fdd4fb5 Add out-of-line slow path for compose-continuation
* libguile/jit.c (compile_compose_continuation)
  (compile_compose_continuation_slow): Move interpreter fallback to slow
  path.
2019-12-10 22:17:24 +01:00
Andy Wingo
76b8f107ca Add subr-call out-of-line slow path
* libguile/jit.c (emit_branch_if_heap_object_has_tc7): New helper.
  (compile_subr_call, compile_subr_call_slow): Add a slow path for the
  values case.
2019-12-10 22:02:45 +01:00
Andy Wingo
c9d29e4b4c Move alloc-frame slow path out of line
* libguile/jit.c (compile_alloc_frame, compile_alloc_frame_slow): Move
  slow path out of line.
  (emit_alloc_frame_for_sp_fast, emit_alloc_frame_for_sp_slow): New
  helpers.
  (emit_alloc_frame): Refactor to use the new helpers.
  (compile_push, compile_push_slow): Use the new helpers.
  (compile_assert_nargs_ee_locals, compile_assert_nargs_ee_locals_slow):
  Split off a slow path.
2019-12-10 17:12:35 +01:00
Andy Wingo
16c1a5d2cd Move assert-nargs-ge slow path out of line
* libguile/jit.c (compile_assert_nargs_ge)
  (compile_assert_nargs_ge_slow): Move slow path out of line.
2019-12-10 17:11:41 +01:00
Andy Wingo
7aad56105f Move assert-nargs-ee slow path out of line
* libguile/jit.c (compile_assert_nargs_ee)
  (compile_assert_nargs_ee_slow): Move slow path out of line.
2019-12-10 17:11:36 +01:00
Andy Wingo
8d8c52dde9 Move receive-values slow path out of line
* libguile/jit.c (compile_receive_values, compile_receive_values_slow):
  Move slow path out of line.
2019-12-10 17:09:59 +01:00
Andy Wingo
1152036333 Move receive slow path out of line
* libguile/jit.c (compile_receive, compile_receive_slow): Move slow path
  out of line.
2019-12-10 17:09:20 +01:00
Andy Wingo
a3be0b1e2d Move handle-interrupts slow path out of line
* libguile/jit.c (compile_handle_interrupts)
  (compile_handle_interrupts_slow): Move slow path out of line.
2019-12-10 17:08:22 +01:00
Andy Wingo
9c329776df Move add, sub slow paths out of line
* libguile/jit.c (compile_call_scm_from_scm_sc)
  (compile_call_scm_from_scm_scm_slow): Move non-fixnum path out of
  line.
2019-12-10 17:08:05 +01:00
Andy Wingo
fafa502875 Move add/immediate, sub/immediate slow paths out of line
* libguile/jit.c (compile_call_scm_from_scm_uimm)
  (compile_call_scm_from_scm_uimm_slow): Move non-fixnum path out of
  line.
2019-12-10 17:06:06 +01:00
Andy Wingo
d21c5a26da Add infrastructure for out-of-line JIT compilation of slow paths
* libguile/jit.c (struct pending_reloc): Rename target_vcode_offset
  field to target_label_offset.
  (inline_label_offset, slow_label_offset): New helpers.
  (emit_direct_tail_call): Use inline_label_offset helper.
  (add_pending_reloc): Factor out of add_inter_instruction_patch.
  (add_inter_instruction_patch): Use inline_label_offset helper.
  (add_slow_path_patch): New helper.
  (continue_after_slow_path): New helper.

  Add slow path compilers for all instructions.

  (compile_slow_path): New helper.
  (compile): Compile slow paths after main code.
  (compute_mcode): Allocate twice as many labels.
2019-12-10 17:05:03 +01:00
Andy Wingo
4a6a7e15d6 Remove vm->sp_min_since_gc
* libguile/jit.c (emit_alloc_frame_for_sp):
* libguile/vm-engine.c (ALLOC_FRAME, RESET_FRAME):
* libguile/vm.c (vm_increase_sp, scm_i_vm_prepare_stack):
  (return_unused_stack_to_os, vm_expand_stack, alloc_frame):
  (scm_call_with_stack_overflow_handler):
* libguile/vm.h (struct scm_vm): Remove sp_min_since_gc handling.  It
  was a very minor optimization when it was centralized in vm.c, but now
  with JIT it's causing too much duplicate code generation.
2019-12-09 22:03:34 +01:00
Ludovic Courtès
edf5aea7ac Fix non-deterministic crash in 'finalization_thread_proc'.
Fixes <https://bugs.gnu.org/37757>.
Reported by Jesse Gibbons <jgibbons2357@gmail.com>.

* libguile/finalizers.c (finalization_thread_proc): Do not enter the
"switch (data.byte)" condition when data.n <= 0.
2019-12-09 14:44:59 +01:00
Andy Wingo
a1e88ebc12 Fix JIT tier-up from within loops for already-JIT-compiled functions
* libguile/jit.c (scm_jit_compute_mcode): If a caller wants mcode for a
  loop but the function already has mcode, instead of punting, just
  compile again.
2019-12-08 21:44:47 +01:00
Andy Wingo
2fbc38f0d0 Fix stack overflow if printing a pre-boot error throws an error
* libguile/throw.c (scm_throw): Fall back to fprintf if all is lost.
2019-11-25 09:46:58 +01:00
Ludovic Courtès
659526d33b ports: 'scm_port_poll' honors "w" flags.
Fixes <https://bugs.gnu.org/36709>.
Reported by Mark H Weaver <mhw@netris.org>.

* libguile/ports.c (scm_port_poll): Replace second POLLIN by POLLOUT.
2019-11-18 15:14:56 +01:00
Andy Wingo
aabea7394a Allow equality between arrays of vu8 and u8
* libguile/array-map.c (scm_array_equal_p): Treat vu8 and u8 arrays as
  equivalent.
2019-11-16 14:34:53 +01:00
Andy Wingo
f4ca107f7f Rebase throw/catch on top of raise-exception/with-exception-handler
* libguile/exceptions.c:
* libguile/exceptions.h: New files.
* libguile.h: Add exceptions.h.
* libguile/Makefile.am (libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
  (DOT_X_FILES, DOT_DOC_FILES, modinclude_HEADERS): Add exceptions.c and
  exceptions.h.
* libguile/init.c (scm_i_init_guile): Initialize exceptions.
* libguile/threads.c (scm_spawn_thread): Use new names for
  scm_i_make_catch_handler and scm_c_make_thunk.
* libguile/throw.c: Rewrite to be implemented in terms of
  with-exception-handler / raise-exception.
* libguile/throw.h: Use data types from exceptions.h.  Move
  scm_report_stack_overflow and scm_report_out_of_memory to
  exceptions.[ch].
* module/ice-9/boot-9.scm (&error, &programming-error)
  (&non-continuable, make-exception-from-throw, raise-exception)
  (with-exception-handler): New top-level definitions.
  (throw, catch, with-throw-handler): Rewrite in terms of
  with-exception-handler and raise-exception.
: New top-level definitions.
* module/ice-9/exceptions.scm: Adapt to re-export &error,
  &programming-error, &non-continuable, raise-exception, and
  with-exception-handler from boot-9.
  (make-quit-exception, guile-quit-exception-converter): New exception
  converters.
  (make-exception-from-throw): Override core binding.
* test-suite/tests/eval.test ("inner trim with prompt tag"): Adapt to
  "with-exception-handler" being the procedure on the stack.
  ("outer trim with prompt tag"): Likewise.
* test-suite/tests/exceptions.test (throw-test): Use pass-if-equal.
* module/srfi/srfi-34.scm: Reimplement in terms of core exceptions, and
  make "guard" actually re-raise continuations with the original "raise"
  continuation.
2019-11-13 22:24:19 +01:00
Andy Wingo
f2c8ff5a52 Remove boot "catch" definition.
* libguile/throw.c (scm_init_throw): Remove boot definition of "catch".
2019-11-07 16:46:53 +01:00
Andy Wingo
d1cf892880 Optimize fixnum or s64 -> f64 conversions
* libguile/intrinsics.c (scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add "inexact"
  intrinsic.
* libguile/jit.c (compile_s64_to_f64): New compiler.
* libguile/vm-engine.c (s64->f64): New instruction.
* module/language/cps/effects-analysis.scm (heap-numbers-equal?):
* module/language/cps/reify-primitives.scm (compute-known-primitives):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/specialize-numbers.scm (fixnum->f64):
  (specialize-operations):
* module/language/cps/type-fold.scm (scm->f64, inexact):
* module/language/cps/types.scm (inexact, s64->f64):
* module/language/tree-il/cps-primitives.scm (exact->inexact):
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  (*effect-free-primitives*):
* module/system/vm/assembler.scm: Recognize exact->inexact as a
  primitive, and optimize it.  Add compiler support for new "inexact"
  and "s64->f64" primcalls.
2019-09-01 20:46:04 +02:00