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

21330 commits

Author SHA1 Message Date
Ludovic Courtès
a09214fb86
build: Error out when ‘scmconfig.h’ generation fails.
So far the rule would silently create a broken file.

* libguile/Makefile.am (scmconfig.h): Add ‘set -e’.
2023-12-28 12:36:11 +01:00
Ludovic Courtès
7f26021c24
debug: Print wider stack frames when not writing to a tty.
This satisfies a longstanding complaint that Guile backtraces were being
truncated too much by default (72 columns), often hindering debugging.

* module/system/repl/debug.scm (default-frame-width): New variable.
(print-frames): Change default #:width value depending on whether PORT
is a tty.
2023-12-28 12:24:02 +01:00
無無
d8df317baf Minor typo in the manual
* doc/ref/api-modules.texi: Fix typo.

Fixes <https://bugs.gnu.org/67487>.

Signed-off-by: Mikael Djurfeldt <mikael@djurfeldt.com>
2023-11-28 11:18:05 +01:00
Andy Wingo
d7cf5bf373 Recognize append as a primcall and optimize it
* module/language/tree-il/primitives.scm (*primitive-constructors*):
(append): Recognize append and reduce it to only the two-operand form.
* module/language/tree-il/peval.scm (peval): Add optimizations to
append.
2023-11-27 14:30:41 +01:00
Andy Wingo
38e9bd7a2f Avoid swallowing errors for (values) operands of elided primcalls
* module/language/tree-il/peval.scm (peval): When visiting (values) in
anything other than an effect or values context,
residualize (values (values)), which will cause a run-time error.
* test-suite/tests/peval.test ("values"): Add test.
2023-11-27 14:24:50 +01:00
Andy Wingo
3b7c78cc83 Unbound vars fixup
* module/language/tree-il/compile-cps.scm (%box-ref): Fix untested bug.
The peril of a compiler spanning modules...
2023-11-23 12:37:20 +01:00
Andy Wingo
5ef0ea30fa Allow targets to preclude unbound variables
Allowing variables to hold an unbound value and requiring a check on
each load is suboptimal; the fixing letrec boolean check is better.  So
other runtimes (hoot) might preclude unbound variables by construction.
Allow them to do so.

* module/language/cps/guile-vm.scm (target-has-unbound-boxes?): New
definition.
* module/language/tree-il/compile-cps.scm (target-has-unbound-boxes?):
(%box-ref): Only residualize an unbound check if the target has unbound
boxes.
2023-11-23 12:31:38 +01:00
Andy Wingo
83449a8683 prompts avoid introducing throw; fixup peval test
* test-suite/tests/peval.test ("partial evaluation"): Fix to expect
raise-type-error from dynwind peval.  Update prompt expectation
similarly.
* module/language/tree-il/primitives.scm (call-with-prompt): Use
raise-type-error.
2023-11-23 12:30:36 +01:00
Andy Wingo
711077586b peval avoids introducing 'throw
* module/language/tree-il/peval.scm (peval): Introduce raise-type-error
for dynwind unwinder thunk check.
* module/language/tree-il/compile-cps.scm (raise-type-error):
* module/language/tree-il/compile-bytecode.scm (canonicalize): Handle
raise-type-error, as it can be in Tree-IL now.
2023-11-23 12:11:22 +01:00
Andy Wingo
4118f09030 CPS conversion does not introduce "throw"
This keeps things higher level, and is a step towards structured
exceptions in guile.

* module/language/cps/guile-vm/reify-primitives.scm (reify-primitives):
Turn raise-type-error, raise-range-error, and raise-arity-error into
variants of "throw".  Lower raise-exception to a non-tail primcall.

* module/language/tree-il/compile-cps.scm: Instead of residualizing
"throw/value+data" throws, exceptions introduced by CPS lowering are
more structured: raise-type-error, raise-range-error, and
raise-arity-error.  Also, lower raise-exception to an ordinary `$throw`
instead of eagerly producing the non-tail call to a $prim.
2023-11-23 10:25:02 +01:00
Andy Wingo
d579848cb5 Fix bug lowering logand/immediate to ulogand/immediate
* module/language/cps/specialize-numbers.scm (logand/immediate): Define
a sigbits handler.
(specialize-operations): Require logand/immediate operand to be u64 to
lower to ulogand/immediate.  Shouldn't be necessary but even if only u64
bits are used, negative fixnums will have the sign bit set, which trips
up further unboxed uses which error if the operand to `scm->u64` is
negative.
* module/language/cps/type-fold.scm (rem): Emit logand/immediate.
2023-11-20 16:45:35 +01:00
Andy Wingo
89501a83ce Fix mistype in specialize-numbers
*
module/language/cps/specialize-numbers.scm (compute-specializable-u64-vars):
We were failing to match scm->u64/truncate.
2023-11-20 15:11:29 +01:00
Andy Wingo
5959531c54 Allow target runtime to override symbol hash
Also rework so that the symbol hash uses the low bits instead of high
bits.  We can do this because, for the guile-vm target, now we compute
the full target hash.

* module/language/cps/guile-vm.scm (jenkins-lookup3-hashword2):
(target-symbol-hash, target-symbol-hash-bits): New exported functions..
* module/language/cps/switch.scm (optimize-branch-chain): Change to use
target-symbol-hash and target-symbol-hash-bits from the current
target-runtime.
2023-11-20 14:23:14 +01:00
Andy Wingo
4d834bdc12 Add logand/immediate, ulogand/immediate primcalls
* libguile/jit.c (compile_ulogand_immediate, compile_ulogand_immediate_slow)
* libguile/vm-engine.c (ulogand_immediate): New JIT and interpreter
support for ulogand/immediate.

* module/language/cps/guile-vm/lower-primcalls.scm (string-ref):
(vtable-vtable?):
(vtable-field-boxed?): Emit ulogand/immediate.
* module/language/cps/guile-vm/reify-primitives.scm (reify-primitives):
Remove logand/immediate.  Only emit ulogand/immediate if the immediate
is a u8.  Refactor mul/immediate.

* module/language/cps/specialize-numbers.scm (specialize-operations):
Produce ulogand/immediate if the result is a u64.

* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm (logand/immediate): Add effect and type
inference for logand/immediate, ulogand/immediate,

* module/language/cps/utils.scm (primcall-raw-representations):
ulogand/immediate makes a u64.

* module/language/tree-il/compile-cps.scm (convert): Generate
logand/immediate if possible.

* module/language/cps/compile-bytecode.scm (compile-function):
* module/system/vm/assembler.scm (system): Add ulogand/immediate
emitter.

* libguile/loader.h (SCM_OBJCODE_MINOR_VERSION): Bump.
2023-11-20 13:43:47 +01:00
Andy Wingo
5b0c261b04 Mark symbol-hash primcall as having unboxed result
* module/language/cps/utils.scm (primcall-raw-representations): Add
symbol-hash.
2023-11-17 15:28:59 +01:00
Andy Wingo
49aa0940bc Add CPS primcall for symbol-hash
* module/language/cps/effects-analysis.scm: symbol-hash is effect-free.
* module/language/cps/guile-vm/lower-primcalls.scm (symbol-hash): Lower
to word-ref/immediate.
* module/language/cps/switch.scm (optimize-branch-chain): Emit
symbol-hash instead of word-ref/immediate.
* module/language/cps/types.scm (symbol-hash): Infer result.
2023-11-17 08:48:33 +01:00
Andy Wingo
c2a9380a42 peval: better primcall folding in effect contexts
* module/language/tree-il/peval.scm (peval): If a primcall is
effect-free, don't require that its args are too: just revisit args as a
sequence in effect context.
* module/language/tree-il/effects.scm (effect-free-primcall?): New
exported function.
2023-11-15 19:31:24 +01:00
Andy Wingo
28a428135f peval: elide effect-free primcalls in effect context
* module/language/tree-il/peval.scm (peval): fix-letrec can residualize
useless primcalls, when a let or letrec-bound var is unused.  Fix to
elide these.
2023-11-15 15:17:29 +01:00
Andy Wingo
e529db04a4 Add extensibility to Tree-IL effects analysis
* module/language/tree-il/effects.scm (add-primcall-effect-analyzer!):
New facility.
* module/language/tree-il/effects.scm (make-effects-analyzer): If a
primcall's args cause no effects, call out to a user-provided
effect-free? primitive for a primcall.  If true, the primcall will be
marked as depending on all effects but causing none; this will allow it
to be elided by letrectify or peval.
2023-11-15 14:59:02 +01:00
Andy Wingo
d08cc4f6e2 Allow string->utf8 to constant-fold
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*primitive-accessors*): Add string->utf8, utf8->string, and
string-utf8-length.
(primitive-module): New public function, moved here from (language
tree-il compile-bytecode).

* module/language/tree-il/compile-bytecode.scm: Use primitive-module
from (language tree-il primitives).

* module/language/tree-il/peval.scm (peval): A bugfix: load primitives
from their proper module.  Allows bytevector primitives to fold.

* module/language/cps/guile-vm/reify-primitives.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm
* module/language/tree-il/primitives.scm:
* module/language/tree-il/cps-primitives.scm:
* module/language/tree-il/effects.scm (make-effects-analyzer):
Add string->utf8, utf8->string, and string-utf8-length.

* module/language/tree-il/compile-cps.scm (string->utf8)
(string-utf8-length, utf8->string): New custom lowerers, including type
checks and an unboxed result for string-utf8-length.

* module/system/vm/assembler.scm:
* libguile/intrinsics.h:
* libguile/intrinsics.c: Because string-utf8-length returns an unboxed
value, we need an intrinsic for it; go ahead and add an intrinsic for
string->utf8 and utf8->string too, as we will likely be able to use
these in the future.
2023-11-15 10:44:21 +01:00
Andy Wingo
437e5ac43d Fix pretty-print with a per-line prefix
* module/ice-9/pretty-print.scm (pretty-print): Include the per-line
prefix in the indent.
* test-suite/tests/print.test ("pretty-print"): Add test.
2023-11-15 09:35:23 +01:00
Andy Wingo
75cd95060f Update set of decimal zeroes for Unicode 15.1.0
* module/scheme/char.scm (*decimal-zeroes*): Update.
2023-11-02 11:31:32 +01:00
Andy Wingo
79e836b8cc Fix branch fusing
* libguile/jit.c (analyze): Skip over drop and pop, if present, during
the analysis phase in addition to the compile phase.
2023-10-02 14:23:42 +02:00
Andy Wingo
624dd8a17a Improve handling of push/pop/drop in jit
Previously, these instructions were compiled directly.  However, the JIT
also wants to fuse comparisons with branches, and an intervening "drop"
breaks that.  Instead we take a different approach and rely on the
compiler only emitting push/pop/drop in a peephole sort of way, and we
can just simulate the temp stack space and dispatch directly.

* libguile/jit.c (compile_push, compile_push_slow, compile_pop):
(compile_pop_slow, compile_drop, compile_drop_slow): Crash if these are
called.
(COMPILE_WIDE_OP1, COMPILE_WIDE_OP2, COMPILE_WIDE_OP3, COMPILE_WIDE_OP4)
(COMPILE_WIDE_OP5):
(COMPILE_WIDE_DOP1, COMPILE_WIDE_DOP2, COMPILE_WIDE_DOP3)
(COMPILE_WIDE_DOP4, COMPILE_WIDE_DOP5): New helpers.  I didn't manage to
share implementation with COMPILE_*.
(COMPILE_WIDE_*): New variants of compilers that take their operands
from an array instead of parsing the inline operands, relying on
convention for how the compiler emits these instructions.
(parse_wide_operands): New helper to parse out "wide" operands.
(compile1, compile_slow_path): If we see a "push", parse wide operands.
(compile): Move label capture for the slow path into compile_slow_path,
because wide operands may skip some instructions.
2023-10-02 14:05:24 +02:00
Andy Wingo
046378a917 Widen all jit compiler routines to take 32-bit operands
* libguile/jit.c (compile_*): Instead of using the minimum sized types
that can represent the instruction's operand, use uint32_t.  This will
allow us to handle push/pop/drop without moving the SP.
2023-10-02 14:05:24 +02:00
Daniel Llorens
4daf4664cf Add test for r7rs string-for-each
* test-suite/tests/r7rs.test: As stated.
* module/scheme/base.scm: Reindent and add minimal doc.
2023-09-29 16:51:27 +02:00
Taylan Kammer
3243d96bb5 Fix (scheme base) string-for-each.
* module/scheme/base.scm (r7:string-for-each): New procedure.

Fixes <https://bugs.gnu.org/40584>.
2023-09-29 15:28:20 +02:00
Ekaitz Zarraga
1e3b5390e3 Fix example in syntax-rules doc
* doc/ref/api-macros.texi (Macros): Fix doc1 macro example

Fixes debbugs.gnu.org/65132.
2023-09-28 12:11:10 +02:00
Andy Wingo
8441d8ff56 Fix docstring for symbol->string, string->symbol
* libguile/symbols.c (scm_symbol_to_string, scm_string_to_symbol):
Remove some confusing documentation that assumes that Guile is
case-insensitive, and which uses a word that may be perceived as a slur.
* module/ice-9/test.scm:
* test-suite/tests/r4rs.test: Rename a test to avoid using a slur.
2023-09-18 16:03:41 +02:00
Andy Wingo
850b724f85 More robust asyncs.test
* test-suite/tests/asyncs.test: Instead of wrapping abort-to-prompt with
false-if-exception, to handle edge cases, guard with
suspendable-continuation?: this also catches recursive invocations.
2023-09-18 15:24:37 +02:00
Andy Wingo
1ad31adf30 Better compilation for symbol->keyword, keyword->symbol
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*effect-free-primitives*): Recognize keyword->symbol, symbol->keyword.
* module/language/tree-il/cps-primitives.scm: Plumb through to CPS.
(keyword->symbol):
* module/language/cps/effects-analysis.scm: New prims have no effect.
Fix effects for string->symbol.
(annotation->memory-kind): Add keywords.
* module/language/cps/guile-vm/lower-primcalls.scm (keyword->symbol):
Lower to scm-ref/immediate.
* module/language/cps/types.scm (annotation->type): Add case for
keywords.
* module/language/tree-il/compile-cps.scm: Add converters for new prims,
with type guards.
2023-09-18 12:32:33 +02:00
Andy Wingo
55256ab33f Better compilation for rational?, exact?, and so on
These numeric predicates now have CPS branching primcalls, which allows
type inference and folding to reduce them to less-strong instructions.

* module/language/cps/effects-analysis.scm (heap-numbers-equal?): Put
all the number predicates together.  None have type checks.
* module/language/cps/guile-vm/lower-primcalls.scm
(define-branching-primcall-alias): New helper.
(complex?): Same as number?.
* module/language/cps/guile-vm/lower-primcalls.scm (real?)
(rational?, integer?, exact-integer?, exact?, inexact?): Define
lowerers.
* module/language/cps/type-fold.scm (number?, complex?, real?)
(rational?, integer?, exact-integer?, exact?, inexact?): Add folders and
reducers for all of these.
* module/language/cps/type.scm (number?, complex?, real?)
(rational?, integer?, exact-integer?, exact?, inexact?): Add type
inference for these.
* module/language/tree-il/compile-cps.scm (convert): Add number? checks
before exact? and inexact?.  Remove the eager lowering of
exact-integer?; instead rely on folders.
* module/language/tree-il/cps-primitives.scm (number?, complex?)
(real?, rational?, integer?, exact-integer?, exact?, inexact?): Add
primitive decls.  Define as "number-type-predicates?", meaning they need
a number? guard.
2023-09-15 15:21:26 +02:00
Andy Wingo
d5347b59fb Better compilation of number?
* module/language/cps/guile-vm/lower-primcalls.scm (number?):
* module/language/tree-il/cps-primitives.scm (number?): Lower as CPS
branching predicate.
2023-09-15 11:19:55 +02:00
Andy Wingo
6756aeff95 Better compilation for symbol->string
* libguile/intrinsics.c (scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add symbol->string
intrinsic.
* module/language/cps/guile-vm/reify-primitives.scm (compute-known-primitives):
* module/language/tree-il/compile-bytecode.scm (+):
* module/language/tree-il/compile-cps.scm (symbol->string):
* module/language/tree-il/cps-primitives.scm (symbol->string):
* module/language/cps/effects-analysis.scm (symbol->string):
* module/language/cps/types.scm (symbol->keyword):
* module/system/vm/assembler.scm (symbol->string): Add the necessary
code to compile symbol->string.
2023-09-15 10:18:50 +02:00
Andy Wingo
c0715e0903 Recognize procedure? as a CPS primitive
* module/language/cps/effects-analysis.scm: Mark more predicates as
effect-free.  Sort the list.
* module/language/cps/guile-vm/lower-primcalls.scm (procedure?): Reify a
call to a primitive.  Sadly we can't elide the $kreceive, as even though
we know that it's single-valued, $call can't continue to $kargs (has to
be $callk).  Perhaps is worth relaxing in the future.
* module/language/cps/type-fold.scm: Define a number of additional
folders for disjoint types.
(procedure?): Define a folder for &procedure.  Has to include structs,
though.
* module/language/cps/types.scm: Same as for type-fold.scm.
* module/language/tree-il/cps-primitives.scm: Lower procedure? primcalls
to CPS.
2023-09-12 14:00:57 +02:00
Andy Wingo
b5bedf74ad Fix missing port in `pretty-print'
* module/ice-9/pretty-print.scm (pretty-print): We were defaulting to
the current output port.
2023-09-06 16:28:45 +02:00
Andy Wingo
a80ccec207 Add reprs for more s64 macro-instructions
* module/language/cps/utils.scm (primcall-raw-representations): Add
sadd, ssub, etc; these are lowered to uadd, usub, etc later for the
guile-vm target, but it is still useful to record their reprs for
pre-lowering analysis.
2023-09-05 11:54:31 +02:00
Andy Wingo
f31819b6b1 Recognize `make-variable' as primitive
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
(*primitive-constructors*):
(*effect+exception-free-primitives*): Add make-variable.
* module/language/tree-il/cps-primitives.scm (make-variable): Lower as
`box' primitive.
2023-09-04 10:09:53 +02:00
Andy Wingo
c2cba86785 Better compilation of calls to raise-exception
Recognize `raise-exception` in the same way we recognize `throw`, though
it is a bit less optimized and the boot story is not as complicated.

* doc/ref/vm.texi (Non-Local Control Flow Instructions):
* libguile/jit.c (compile_unreachable):
(compile_unreachable_slow):
* libguile/vm-engine.c (VM_NAME):
* module/language/cps/compile-bytecode.scm (compile-function):
* module/system/vm/assembler.scm (emit-unreachable): Add new
"unreachable" instruction, inserted after a call to non-continuable
`raise-exception`.
* module/language/tree-il/compile-cps.scm (raise-exception):
* module/language/tree-il/primitives.scm
(*interesting-primitive-names*): Recognize raise-exception, and if it is
called with just one argument, prune that branch of the control-flow
graph.
2023-08-28 12:11:19 +02:00
Daniel Llorens
a52c9cf7c3 Fix typo in documentation for (socket)
H/t cow_2001 on #guile.

* libguile/socket.c: As stated.
2023-08-28 11:29:42 +02:00
Andy Wingo
1f724ccd39 Fix embarrassing pretty-print bug
* module/ice-9/pretty-print.scm (pretty-print): We were never indenting
more than 8 spaces.  Doh!
* test-suite/tests/print.test (prints?, "pretty-print"): Add test.
2023-08-24 12:20:45 +02:00
Andy Wingo
19c7969fff define-inlinable marks residualized procedure as maybe-unused
* module/ice-9/boot-9.scm (define-inlinable):
* module/srfi/srfi-9.scm (define-tagged-inlinable): Add maybe-unused
declaration.  Also require at least one body expr, otherwise the
metadata declaration could escape as the proc body.
2023-08-24 11:43:31 +02:00
Andy Wingo
1f70d597db Allow functions to mark themselves as maybe-unused
* module/language/tree-il/analyze.scm (<reference-graph>): Oh my
goodness, constructor args were reversed relative to field order.
Constructor use was consistent but it was terribly confusing; fixed and
updated uses.
(unused-toplevel-analysis): Add ability for functions to mark themselves
as "maybe-unused"; such functions won't cause unused toplevel warnings.

* module/language/tree-il/compile-bytecode.scm (sanitize-meta):
(compile-closure):
* module/language/tree-il/compile-cps.scm (sanitize-meta): Prevent
maybe-unused from being needlessly written out to the binary.
2023-08-24 11:43:15 +02:00
Andy Wingo
55364184d7 Add "custom primcall converter" facility to tree-il->cps lowering
* module/language/tree-il/compile-cps.scm
(define-custom-primcall-converter): New exported macro, handling
primcalls that need special logic.  Fold "throw" and "values" into this
macro.  The goal is to allow the Hoot compiler to specially convert an
"inline assembly" primcall.
2023-08-24 09:56:50 +02:00
Andy Wingo
c7632b8f97 Revert recent change to r5rs.texi
* doc/r5rs/r5rs.texi: Revert c7d170c5d1,
as R5RS is a historical document, and our packaging of it is something
that other people rely on.  See also
7fb9c4aff2 when I was also bitten by this
error!
2023-08-17 14:37:30 +02:00
Andy Wingo
aa82f8227c Add unboxed representations for fadd/immediate, fmul/immediate
* module/language/cps/utils.scm (primcall-raw-representations): Add
fadd/immediate, fmul/immediate as f64.
2023-08-17 14:16:12 +02:00
Andy Wingo
b6022aeeb3 Allow compute-var-representations extensibility
* module/language/cps/utils.scm (primcall-raw-representations): New
function.
(compute-var-representations): Use #:primcall-raw-representations
keyword arg, which defaults to primcall-raw-representations.
2023-08-17 14:16:12 +02:00
Andy Wingo
27669781b7 More precise value representations for bv-contents, $code
* module/language/cps/utils.scm (compute-var-representations): $code
makes a 'code.  bv-contents makes a 'bv-contents.
* module/language/cps/slot-allocation.scm:
* module/language/cps/hoot/tailify.scm:
* module/system/vm/assembler.scm: Adapt.
2023-08-17 14:16:12 +02:00
Andy Wingo
dc4fe9741f Add new $calli expression type.
* module/language/cps.scm ($calli): New expression type which calls a
function entry as originally captured via $code.  Adapt all callers.
2023-08-17 14:16:12 +02:00
Andy Wingo
f8b1607602 Fix compute-defs-and-uses for $prim
* module/language/cps/utils.scm (compute-defs-and-uses): Add $prim.
Wasn't needed before because this function was only ever called after
reify-primitives.
2023-08-17 14:16:12 +02:00