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

4478 commits

Author SHA1 Message Date
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
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
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
Andy Wingo
0922cbebb9 Include nfree in closure-ref, closure-set primcall params
* module/language/cps/closure-conversion.scm (convert-one): Add nfree to
the param.  This will help the wasm target.
* module/language/cps/effects-analysis.scm (closure-ref, closure-set!):
* module/language/cps/lower-primcalls.scm (closure-ref,closure-set!):
Adapt.
2023-08-17 14:16:12 +02:00
Andy Wingo
78948ae594 Add wasm32 and wasm64 CPU types
* module/system/base/target.scm (cpu-endianness): wasm targets are
little-endian.
2023-08-17 14:16:12 +02:00
Andy Wingo
941c757ab7 Introduce target-runtime parameter for backend-specific CPS lowering
* module/system/base/target.scm (target-runtime): New export.
* module/language/cps/optimize.scm (make-cps-lowerer): Load a
backend-specific lowering module dynamically.

* module/language/cps/guile-vm.scm: New module for lowering to Guile's
VM.
* module/language/cps/guile-vm/loop-instrumentation.scm:
* module/language/cps/guile-vm/lower-primcalls.scm:
* module/language/cps/guile-vm/reify-primitives.scm: Move here, from
parent dir.

* am/bootstrap.am: Update for new file list.
2023-08-17 14:16:12 +02:00
Ludovic Courtès
d5659b7869
r7rs: 'read-u8' now defaults to 'current-input-port'.
Fixes <https://bugs.gnu.org/62690>.
Reported by Rui Zhang <zrui16@hotmail.com>.

* module/scheme/base.scm (read-u8): Change default value of 'port'.
2023-07-16 22:31:19 +02:00
Timothy Sample
dcccaddf7b
Avoid module resolution in 'call-with-new-thread'.
Fixes <https://bugs.gnu.org/62691>.
Reported by Михаил Бахтерев <mike.bakhterev@gmail.com>.

* module/ice-9/threads.scm (call-with-new-thread): Do not use 'set!'
to set object properties while the calling thread is waiting on the
new thread to initialize.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2023-07-16 22:26:51 +02:00
Morgan Smith
c7d170c5d1
Fix typos throughout codebase.
* NEWS:
* README:
* doc/r5rs/r5rs.texi:
* doc/ref/api-data.texi:
* doc/ref/api-debug.texi:
* doc/ref/api-evaluation.texi:
* doc/ref/api-io.texi:
* doc/ref/api-macros.texi:
* doc/ref/api-procedures.texi:
* doc/ref/api-scheduling.texi:
* doc/ref/api-undocumented.texi:
* doc/ref/libguile-concepts.texi:
* doc/ref/posix.texi:
* doc/ref/srfi-modules.texi:
* doc/ref/vm.texi:
* doc/ref/web.texi:
* examples/box-dynamic-module/box.c:
* examples/box-dynamic/box.c:
* examples/box-module/box.c:
* examples/box/box.c:
* examples/safe/safe:
* examples/scripts/README:
* examples/scripts/hello:
* gc-benchmarks/larceny/twobit-input-long.sch:
* gc-benchmarks/larceny/twobit-smaller.sch:
* gc-benchmarks/larceny/twobit.sch:
* libguile/expand.c:
* libguile/load.c:
* libguile/net_db.c:
* libguile/scmsigs.c:
* libguile/srfi-14.c:
* libguile/threads.c:
* meta/guile.m4:
* module/ice-9/match.upstream.scm:
* module/ice-9/ports.scm:
* module/language/cps/graphs.scm:
* module/scripts/doc-snarf.scm:
* module/srfi/srfi-19.scm:
* module/system/repl/command.scm:
* test-suite/tests/srfi-18.test:
Fix typos.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2023-07-16 22:09:01 +02:00
Andy Wingo
896960dade Add representations for new primcalls
* module/language/cps/utils.scm (compute-var-representations): Add
representations for vector-length and so on.
2023-06-22 16:19:15 +02:00
Andy Wingo
85f85a0fc0 Tree-IL-to-CPS lowers to high-level object reprs: vectors
* module/language/tree-il/compile-cps.scm: Lower to allocate-vector,
vector-ref/immediate, and so on.
2023-06-22 16:01:44 +02:00
Andy Wingo
069ed42f50 Tree-IL-to-CPS lowers to high-level object reprs: strings
* module/language/tree-il/compile-cps.scm: Lower to string-length,
string-ref, et al.
2023-06-22 16:01:44 +02:00
Andy Wingo
d0677a362d Tree-IL-to-CPS lowers to high-level object reprs: bytevectors
* module/language/tree-il/compile-cps.scm: Lower to bv-length,
bv-contents.
2023-06-22 16:01:44 +02:00
Andy Wingo
e6bd13ea1e Tree-IL-to-CPS lowers to high-level object reprs: structs
* module/language/tree-il/compile-cps.scm: Lower to allocate-struct,
struct-ref, and so on.
2023-06-22 16:01:44 +02:00
Andy Wingo
4fb4bebe41 Tree-IL-to-CPS lowers to high-level object reprs: pairs
* module/language/tree-il/compile-cps.scm: Lower to cons, car, set-car!,
etc.
2023-06-22 16:01:44 +02:00
Andy Wingo
5c5af6bc78 Tree-IL-to-CPS lowers to high-level object reprs: atomic boxes
* module/language/tree-il/compile-cps.scm: Lower to make-atomic-box,
atomic-box-ref, and so on.
2023-06-22 16:01:44 +02:00
Andy Wingo
2b88333426 Tree-IL-to-CPS lowers to high-level object representations: boxes
* module/language/tree-il/compile-cps.scm: Lower to box, box-ref, and
box-set!.
2023-06-22 16:01:44 +02:00
Andy Wingo
e4f9b203f7 Closure conversion produces high-level object representations
* module/language/cps/closure-conversion.scm (convert-one): Build
closures with make-closure, cons, and so on; leave lowering to scm-ref
to the backend.
2023-06-22 16:01:44 +02:00
Andy Wingo
a80a5ade78 Contification uses 'cons primcall
* module/language/cps/contification.scm (apply-contification): Reify
'cons instead of using the lower-level scm-set! etc.
2023-06-22 16:01:44 +02:00
Andy Wingo
26b43f35c5 DCE ignores setters to dead objects
* module/language/cps/dce.scm (compute-live-code): Add the new
higher-level object mutators.
2023-06-22 16:01:44 +02:00
Andy Wingo
125cb9fa6d Remove useless code in CSE
* module/language/cps/cse.scm (eliminate-common-subexpressions-in-fun):
Defs must be a list.
2023-06-22 16:01:44 +02:00
Andy Wingo
2534326e5e Add CSE auxiliary definitions for cons, set-car! etc
* module/language/cps/cse.scm (eliminate-common-subexpressions-in-fun):
Add cons, set-car!, etc.
2023-06-22 16:01:44 +02:00
Andy Wingo
e7e625b773 Fix effects analysis bug for synthesized definitions at allocations
* module/language/cps/effects-analysis.scm (compute-known-allocations):
For a primcall that allocates, sometimes we will synthesize auxiliary
definitions as part of CSE, for example to indicate that if (cons x y)
is bound to z, that a later call to (car z) should give x unless there
might be an intervening set-car!.  We had a bug in which aux definitions
attached to allocations were being incorrectly associated with the first
operand.  Probably this is a bug in other contexts but it really starts
to hit with the high-level constructors, e.g. `box`.
2023-06-22 16:01:44 +02:00
Andy Wingo
98178ac308 Add effects analysis for new high-level object accessors
* module/language/cps/effects-analysis.scm: Add car, box-ref, etc to
effects analysis.
2023-06-22 16:01:44 +02:00
Andy Wingo
a35cae5697 Add support for higher-level object representations in type analysis
* module/language/cps/types.scm: Add inferrers for vector-ref, car,
etc.
2023-06-22 16:01:44 +02:00
Andy Wingo
eb6d5abcbe Move f64->scm lowering to lower-primcalls
* module/language/cps/lower-primcalls.scm (f64->scm): Move here...
* module/language/cps/reify-primitives.scm (reify-primitives): from
here.  Seems a more fitting place.
2023-06-22 16:01:44 +02:00
Andy Wingo
a5b245d2d0 Wire in lower-primitives pass
* module/language/cps/optimize.scm (lower-cps/generic): Rename from
lower-cps; these are the lowerings that apply to everyone.
(select-opts-for-optimization-level): Factor out of make-cps-lowerer.
(make-backend-cps-lowerer): New procedure.  For the Guile VM backend, we
have a few mandatory passes, including the new lower-primitives.
(make-cps-lowerer): Apply backend-specific lowering pass.
2023-06-22 16:01:44 +02:00
Andy Wingo
b974405bce New CPS pass: lower-primcalls
This pass will implement the specialized lowering of object accessors to
Guile's VM primitives.

* am/bootstrap.am (SOURCES): Add new file.
* module/language/cps/lower-primcalls.scm: New file.
2023-06-22 16:01:44 +02:00
Andy Wingo
19c3bdc5ca Fix target-max-size-t/scm to not be a fraction (oops)
* module/system/base/target.scm (target-max-size-t/scm): Use floor/
instead of /.
2023-06-22 16:01:44 +02:00
Andy Wingo
aa2cfe7cf6 Consider $code to make 'ptr representation
* module/language/cps/utils.scm (compute-var-representations): For the
wasm target, these values are (ref $kvarargs), not i64.  Will need to
distinguish from bytevector pointers at some point, though.
2023-06-19 13:53:46 +02:00
Andy Wingo
db826ab909 Fix bug in compilation of rsh/lsh
* module/language/cps/compile-bytecode.scm (compile-function):
The rsh/lsh patterns would never match.  I think these would end up
dispatching through emit-text though.
2023-06-19 13:53:01 +02:00
Andy Wingo
2cd8b4160c Use tree-il-srcv instead of tree-il-src
This prevents eager conversion to alists.
2023-06-19 13:53:01 +02:00
Andy Wingo
b0a390db06 Excise use of record-case
This macro expands to field accessors, which in the case of tree-il-src
will force an eager conversion of the source info to alists.
2023-06-19 13:53:01 +02:00
Andy Wingo
02dfb6e776 Fix exn dispatch for exns within pre-unwind handlers
* libguile/exceptions.c (exception_epoch_fluid): Rename from
active_exception_handlers_fluid.
(scm_dynwind_throw_handler): Increment exception epoch instead of
resetting active exception handlers.
(scm_init_exceptions): Update.
* module/ice-9/boot-9.scm  (with-exception-handler): Rework to associate
an "epoch" fluid with each exception handler.
(with-throw-handler): Establish a new epoch, during the execution of a
throw handler.
(raise-exception): Rework to avoid capturing a list of exception
handlers, and to use epochs as a way to know which handlers have already
been examined and which are on the dispatch stack.
* test-suite/tests/exceptions.test ("throwing within exception
handlers"): New test.
2023-06-08 10:26:16 +02:00
Andy Wingo
ee18ca9a35 Deprecate (ice-9 lineio)
* module/ice-9/lineio.scm: Deprecate.
2023-06-08 10:21:28 +02:00
Andy Wingo
5af66570bb Fix allow-newline? in call-with-truncating-output-string
* module/ice-9/pretty-print.scm (call-with-truncating-output-string):
Actually detect newlines.
2023-06-08 10:21:28 +02:00
Andy Wingo
0e4334406a truncated-print: use call-with-truncating-output-string
* module/ice-9/pretty-print.scm (truncated-print): Use new
call-with-truncating-output-string, to allow for early bailout when
printing large records.
2023-06-08 10:21:28 +02:00
Andy Wingo
379a9a64c6 Inline generic-write into pretty-print
* module/ice-9/pretty-print.scm (pretty-print): Inline generic-write
into its only caller.
2023-06-08 10:21:28 +02:00
Andy Wingo
75f96e825c pretty-print: width arg is never false
* module/ice-9/pretty-print.scm (generic-write): width is never false.
2023-06-08 10:21:28 +02:00
Andy Wingo
29a9f26a36 Rewrite pretty-print to rely on port-column, abort early
* module/ice-9/pretty-print.scm (call-with-truncating-output-string):
New function.
* module/ice-9/pretty-print.scm (generic-write): Rewrite so that instead
of keeping track of the column, we just use port-column on the port.
Also, when checking if a possibly-improper list can print on one line,
use new call-with-truncating-output-string so as to always abort early,
even for long bytevectors.
2023-06-08 10:21:28 +02:00
Andy Wingo
f320ce8979 Modernize soft ports
* doc/ref/api-io.texi (Soft Ports): Update docs.
* module/ice-9/boot-9.scm (make-soft-port): Don't eagerly load soft
ports.
* module/ice-9/soft-ports.scm (deprecated-make-soft-port): Rename from
make-soft-port.
(make-soft-port): New interface.
2023-06-08 10:21:28 +02:00