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

21920 commits

Author SHA1 Message Date
Andy Wingo
d6e59a1d3e Convert bitvectors to use inline-only word-size units
* libguile/bitvectors.h: Unit of bitvectors is scm_t_bits, not uint32_t.
* libguile/bitvectors.c: Adapt implementation.
(make_bitvector): Malloc pointerless instead, with inline bits.
* libguile/posix.c (scm_setaffinity):
* libguile/bytevectors.c (uniform-array->bytevector): Adapt to unit size
change.
* module/system/vm/assembler.scm (intern-constant, link-data): Adapt to
bitvector representation change.
2025-06-03 16:54:19 +02:00
Andy Wingo
9ff7c0651c Give arrays a proper type in C land
As long as we have a tc7 for arrays, we should be able to access it with
a struct type instead of casting each word.

* libguile/arrays-internal.h: New file.
* libguile/arrays.h (scm_array_p): Take just one argument.
(SCM_I_ARRAYP):
(SCM_I_ARRAY_NDIM):
(SCM_I_ARRAY_V):
(SCM_I_ARRAY_BASE):
(SCM_I_ARRAY_DIMS):
(SCM_I_ARRAY_SET_V):
(SCM_I_ARRAY_SET_BASE): Remove.
(scm_i_raw_array, scm_i_make_array, scm_i_shap2ra, scm_init_arrays):
Remove internally-linked decls.
* libguile/init.c:
* libguile/print.c:
* libguile/array-handle.c: Use interfaces from new file.
* module/system/vm/assembler.scm: Update, as we now shift the dimension
count by only 16.  Requires a rebuild!
2025-06-03 14:55:09 +02:00
Andy Wingo
12e8772403 Move array-map / array-cell functions to Scheme module
* libguile/array-map.c:
* libguile/array-map.h: Remove.

* module/ice-9/deprecated.scm:
* libguile/deprecated.h:
* libguile/deprecated.c: Add deprecation shims.

* module/ice-9/arrays.scm: Move all array-map functionality here.

* libguile/Makefile.am:
* libguile/init.c:
* libguile.h: Remove array-map.h use.

* libguile/arrays.c (scm_i_array_equal_p, scm_i_array_copy): New
helpers.
(scm_array_cell_ref, scm_array_cell_set_x): Move to Scheme.
* libguile/arrays.h:
* libguile/eq.c (scm_equal_p):
* libguile/sort.c (scm_sort): Use new arrays.c helpers.
* module/ice-9/pretty-print.scm:
* module/oop/goops/save.scm: Import (ice-9 arrays).
2025-06-03 14:34:26 +02:00
Andy Wingo
0134abce74 Move private bytevectors API to a separate header
Also give bytevectors a private type (a struct).

* libguile/bytevectors.h (SCM_BYTEVECTOR_HEADER_SIZE): Remove.
(SCM_BYTEVECTOR_LENGTH):
(SCM_BYTEVECTOR_CONTENTS): Proxy to the C accessors.
(SCM_BYTEVECTOR_PARENT): Remove from public API.
(SCM_BYTEVECTOR_P, SCM_VALIDATE_BYTEVECTOR): Make public.
(scm_c_bytevector_contents): New function.
* libguile/bytevectors-internal.h: New file.
* libguile/Makefile.am (noinst_HEADERS): Add new file.

* libguile/bytevectors.c:
* libguile/array-handle.c:
* libguile/arrays.c:
* libguile/foreign.c:
* libguile/goops.c:
* libguile/init.c:
* libguile/loader.c:
* libguile/print.c:
* libguile/r6rs-ports.c:
* libguile/srfi-4.c:
* libguile/strings.c: Adapt to use bytevectors-internal.h as needed, and
sometimes to use the internal bytevector type.
2025-06-02 09:51:47 +02:00
Andy Wingo
51bc69dd1c Fix bytevector mutators to correctly check for mutability
Previously, bytevectors that were serialized into binaries were actually
mutable by compiled bytevector-u8-set! et al.

* libguile/bytevectors.h (SCM_F_BYTEVECTOR_IMMUTABLE): Renumber to 0x80,
as for immutable vectors.
(SCM_BYTEVECTOR_CONTIGUOUS_P): Just use SCM_CELL_TYPE.
(SCM_BYTEVECTOR_FLAGS): Remove unused accessor.
* module/language/tree-il/compile-cps.scm (bytevector-set-converter):
Emit mutable-bytevector? instead of bytevector?.
* module/system/vm/assembler.scm (link-data): Update immutable flag.
* module/language/cps/compile-bytecode.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/type-fold.scm:
* module/language/cps/types.scm:
* module/system/base/types/internal.scm: Update for immutable-bytevector
predicates.
2025-05-30 16:48:26 +02:00
Andy Wingo
043a5b62bb Rework treatment of bytevector flags
Before, they were always shifted by 7.  Now the flags are just above
0x7f and just the element type is shifted, but by 16.

* libguile/bytevectors.h (SCM_BYTEVECTOR_FLAGS): Rework to not shift.
(SCM_SET_BYTEVECTOR_FLAGS): Remove.
(SCM_MUTABLE_BYTEVECTOR_P): Don't shift the immutable flag.
(SCM_BYTEVECTOR_ELEMENT_TYPE): Shift right by 16.
* libguile/bytevectors.c (SCM_BYTEVECTOR_SET_FLAG): Remove unused
helper.
(make_bytevector_tag): New helper.
(make_bytevector): Use new helper.
(make_bytevector_from_buffer): Add flags and parent args, and use new
helper.
(scm_c_take_gc_bytevector):
(scm_c_take_typed_bytevector):
(scm_bytevector_slice): Update callers.
* module/system/vm/assembler.scm (link-data): Don't shift the flag by 7;
instead shift the element type by 16.
2025-05-30 14:19:30 +02:00
Andy Wingo
464ec999de Make programs.h private
This header file turns out to only have internal details.  Users that
need introspection can use Scheme.

* libguile/programs.h (SCM_PROGRAM_P, SCM_PROGRAM_CODE)
(SCM_PROGRAM_FREE_VARIABLES, SCM_PROGRAM_FREE_VARIABLE_REF)
(SCM_PROGRAM_FREE_VARIABLE_SET, SCM_PROGRAM_NUM_FREE_VARIABLES)
(SCM_VALIDATE_PROGRAM, SCM_F_PROGRAM_IS_BOOT, SCM_F_PROGRAM_IS_PRIMITIVE)
(SCM_F_PROGRAM_IS_PRIMITIVE_GENERIC, SCM_F_PROGRAM_IS_CONTINUATION)
(SCM_F_PROGRAM_IS_PARTIAL_CONTINUATION, SCM_F_PROGRAM_IS_FOREIGN)
(SCM_PROGRAM_IS_BOOT, SCM_PROGRAM_IS_PRIMITIVE)
(SCM_PROGRAM_IS_PRIMITIVE_GENERIC, SCM_PROGRAM_IS_CONTINUATION)
(SCM_PROGRAM_IS_PARTIAL_CONTINUATION, SCM_PROGRAM_IS_FOREIGN): Remove
these macros, as we are making this whole API private.
(struct scm_program, scm_is_program, scm_to_program, scm_from_program)
(scm_program_flags, scm_program_is_boot, scm_program_is_primitive)
(scm_program_is_primitive_generic, scm_program_is_continuation)
(scm_program_is_partial_continuation, scm_program_is_foreign)
(scm_program_code, scm_program_free_variable_count)
(scm_program_free_variable_ref, scm_program_free_variable_set_x)
(scm_i_make_program): New inline functions.
* libguile/Makefile.am (noinst_HEADERS): Add programs.h; no longer
installed.  It was never directly included from libguile.h.
* libguile/continuations.c:
* libguile/continuations.h:
* libguile/control.c:
* libguile/foreign.c:
* libguile/frames.c:
* libguile/frames.h:
* libguile/goops.c:
* libguile/gsubr.c:
* libguile/gsubr.h:
* libguile/intrinsics.h:
* libguile/procprop.c:
* libguile/procs.c:
* libguile/programs.c:
* libguile/stacks.c:
* libguile/vm-engine.c:
* libguile/vm.c:
* libguile/vm.h: Adapt all users.
2025-05-30 12:52:54 +02:00
Andy Wingo
93e5a2454a Tighten up exported ABI / API of "programs"
* libguile/programs.h (scm_program_p, scm_program_code)
(scm_primitive_code_p, scm_primitive_code_name, scm_primitive_call_ip):
Don't expose these internal functions to C
ABI.
(scm_program_num_free_variables, scm_program_free_variable_ref,
scm_program_free_variable_set_x): Don't expose these previously-public
functions to C ABI.
(scm_is_program): New internal inline function.
* libguile/stacks.c (narrow_stack): Use new scm_is_program helper.
* libguile/programs.c: Adapt implementation to use SCM_DEFINE_STATIC.
2025-05-30 10:25:00 +02:00
Andy Wingo
224fb82a39 Give reified value objects a proper data type
* libguile/values.h (struct scm_values): New build-time definition.
(scm_to_values):
(scm_from_values):
(scm_values_count):
(scm_values_ref): New helpers.
* libguile/vm.c:
* libguile/values.c:
* libguile/print.c:
* libguile/numbers.c:
* libguile/eval.c: Adapt all callers.
2025-05-30 09:57:08 +02:00
Andy Wingo
aa73d31ded Inline "struct scm_frame" into tagged frame objects
This avoids an indirection and will make the tracer's job easier.

* libguile/frames.h (struct scm_vm_frame): New data type.
(scm_is_vm_frame):
(scm_vm_frame):
(scm_vm_frame_kind):
(scm_vm_frame_fp):
(scm_vm_frame_sp):
(scm_vm_frame_ip):
(scm_frame_init_from_vm_frame): New helpers.

* libguile/frames.c:
* libguile/stacks.c:
* libguile/stacks.h:
* libguile/vm.c: Update all users of SCM_VM_FRAME_* macros to use new
helpers.
2025-05-29 21:53:36 +02:00
Andy Wingo
75842cf215 Simplify struct scm_bignum
* libguile/integers.c (struct scm_bignum): Now that SCM_I_BIG_MPZ is
gone with other deprecated code, we can simplify the bignum
representation.  Adapt all users.
2025-05-28 11:22:29 +02:00
Andy Wingo
0a0ecc518b Arrange to pin objects captured by a delimited continuation
* libguile/vm.h (struct scm_vm_cont): Include the tag word, and put
flags there.  Rename stack bottom to stack slice and make a flexible
array.
(scm_is_vm_cont):
(scm_to_vm_cont):
(scm_from_vm_cont):
(scm_vm_cont_is_partial):
(scm_vm_cont_is_rewindable): New build-time helpers.

* libguile/continuations.c (scm_i_make_continuation):
(scm_i_continuation_to_frame):
(copy_stack_and_call):
* libguile/continuations.h (scm_t_contregs):
* libguile/frames.c (frame_stack_top):
* libguile/stacks.c (scm_make_stack): Adapt to take struct scm_vm_cont*
instead of SCM for continuations.

* libguile/vm.c (capture_stack): Adapt to scm_vm_cont change.  Use new
gc_resolve_conservative_ref API to pin conservative refs from the
captured stack.
(scm_i_vm_cont_to_frame):
(scm_i_capture_current_stack):
(reinstate_continuation_x):
(capture_continuation):
(compose_continuation):
(capture_delimited_continuation):
(abort_to_prompt): Adapt to type changes.
2025-05-27 16:02:01 +02:00
Andy Wingo
177643d416 Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-05-27 15:50:57 +02:00
Andy Wingo
c49a372da7 Add gc_resolve_conservative_ref API 2025-05-27 15:50:28 +02:00
Andy Wingo
1abd5a310e Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-05-26 12:22:22 +02:00
Andy Wingo
d0337bf4fe Further fix inlining
I want to get the "possibly_interior" case to fold at compile-time.
2025-05-26 12:18:31 +02:00
Andy Wingo
a4c0f1e231 Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-05-26 11:58:48 +02:00
Andy Wingo
f5e10eb7c9 mmc: Speed up conservative ref resolution 2025-05-26 11:58:29 +02:00
Andy Wingo
94f6c8ce6a mmc: Fix inlining of trace_conservative_edges for pinned roots 2025-05-26 11:56:34 +02:00
Andy Wingo
e84dccb710 Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-05-26 10:34:54 +02:00
Andy Wingo
cc9eb16e92 Add heuristic to grow mmc heap if no progress in last mutator cycle 2025-05-26 10:34:03 +02:00
Andy Wingo
b3d874c804 Add JIT support for bump-pointer allocation fast paths
* libguile/jit.c (emit_update_alloc_table):
(emit_allocate_bytes_fast_bump_pointer): Add implementation.
(compile_allocate_words_immediate_with_kind):
(compile_allocate_words_immediate_slow_with_kind): New helpers.
(compile_allocate_words_immediate):
(compile_allocate_words_immediate_slow):
(compile_allocate_pointerless_words_immediate):
(compile_allocate_pointerless_words_immediate_slow): Use new helpers.
2025-05-24 21:45:25 +02:00
Andy Wingo
3147d313f9 Add Guile's CFLAGS to WHIPPET_IMPL_CFLAGS
* libguile/Makefile.am (WHIPPET_IMPL_CFLAGS): Add GCC_CFLAGS, to ensure
the same compilation options (notably -fwrapv), to prevent mismatches at
LTO-time.
2025-05-23 09:44:50 +02:00
Andy Wingo
5d94b78095 Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-05-23 09:44:31 +02:00
Andy Wingo
285ca65472 Fix missing static annotation on root_worklist_alloc 2025-05-23 09:44:20 +02:00
Andy Wingo
8c4866cd5c Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-05-23 09:39:59 +02:00
Andy Wingo
f12399ef7d mmc: Only add headroom to unfragmentable heaps if no progress 2025-05-23 09:38:36 +02:00
Andy Wingo
140a412ecd Fix crash in gc_visit_ephemeron_key on objects in extern space 2025-05-23 09:38:02 +02:00
Andy Wingo
6841c9509a Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-05-22 16:24:47 +02:00
Andy Wingo
0a6767b3b9 Fix a bug in after-gc Scheme hook
* libguile/gc.c (scm_gc_event_listener_restarting_mutators): Avoid
running hook before Guile is booted.
2025-05-22 16:24:16 +02:00
Andy Wingo
2db9cfa918 nofl: Limit sweeping if there are empty blocks 2025-05-22 16:23:04 +02:00
Andy Wingo
6d5e7c9b60 Fix bof returning blocks from the evacuation target list to empties 2025-05-22 16:15:31 +02:00
Andy Wingo
1d157a133d mmc: Add "headroom" for growable heaps that cannot defragment 2025-05-22 14:57:34 +02:00
Andy Wingo
eab463bd6c nofl: Include pending large object allocations in the live data size 2025-05-22 14:57:02 +02:00
Andy Wingo
47ddd3dd5a nofl: No evacuation reserve if evacuation is impossible 2025-05-22 14:56:43 +02:00
Andy Wingo
7b4f4427f8 Update for Whippet changes, VM stacks scanned partly-conservatively
* libguile/trace.h (scm_from_ref, scm_to_ref): Helpers moved here;
update all callers.
* libguile/loader.c (scm_trace_loader_roots):
* libguile/threads.c (scm_trace_thread_roots):
* libguile/vm.c (scm_trace_vm_roots): Update for new
pinned-roots prototype.
* libguile/whippet-embedder.h (gc_extern_space_visit): Update for
Whippet API changes.
2025-05-21 14:31:23 +02:00
Andy Wingo
fb5a99c752 Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-05-21 14:28:34 +02:00
Andy Wingo
41de2dfd91 Update conservative roots embedder interface 2025-05-21 14:27:17 +02:00
Andy Wingo
f12990bb64 Fix alignment for platform conservative roots visitor 2025-05-21 14:26:39 +02:00
Andy Wingo
eb5f9ff878 nofl: Add asserts when getting metadata for an object
The metadata byte should have a mark.
2025-05-21 14:20:53 +02:00
Andy Wingo
0277953efc gc_extern_space_visit doesn't take an edge
The whole extern space interface is a bit wonky but for now let's assume
that external objects can't move and therefore we don't need the edge.
2025-05-21 14:04:24 +02:00
Andy Wingo
8b9fe196a1 No need to clear allocation table during allocation
The mmc clears holes eagerly; there is no need to memset during
allocation.
2025-05-21 14:01:42 +02:00
Andy Wingo
72fbb05ee8 Fix Guile's whippet embedding for conservative roots tracing
* libguile/whippet-embedder.h (gc_extern_space_visit): Don't crash if
conservative tracing is enabled: these are already part of the root set.
2025-05-16 22:38:45 +02:00
Andy Wingo
0ffa6688aa Adapt to whippet change 2025-05-16 22:27:20 +02:00
Andy Wingo
a344c225c4 Merge remote-tracking branch 'whippet/main' into wip-whippet 2025-05-16 22:22:56 +02:00
Andy Wingo
b794e46635 mmc: Grow the heap if collection fails to find space for large alloc
For a pending large allocation, we will try to page out blocks from the
nofl space.  However sometimes we are not able to do so, especially if
evacuation is unavailable, as in a heap-conservative configuration.  In
that case, if the heap is growable, grow the heap after GC if there are
still bytes pending to page out.
2025-05-16 22:01:55 +02:00
Andy Wingo
fbcdffdc62 Fix bogus assert in mmc.c:deactivate_mutator 2025-05-16 22:01:15 +02:00
Andy Wingo
2018a77f36 Fix bogus static debug check in mmc init 2025-05-16 22:00:48 +02:00
Andy Wingo
e59fde2edf Fix build issue with mmc in Guile
For some reason we need to include gc-api with GC_IMPL already defined,
otherwise the attrs don't get picked up.
2025-05-16 22:00:02 +02:00
Andy Wingo
7010b4fce0 Fix --with-gc-debug in whippet.m4 2025-05-16 21:59:40 +02:00