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

4378 commits

Author SHA1 Message Date
Ludovic Courtès
de1ac71850 psyntax: Pass source vectors to tree-il constructors.
Avoiding systematic conversion from source vectors to property alists
saves 20% on the final heap size of a process doing:

  (compile-file FILE #:optimization-level 1)

where FILE is large.

* module/language/tree-il.scm (tree-il-src/ensure-alist): New procedure
with setter.  Export as 'tree-il-src'.
* module/ice-9/psyntax.scm (build-void, build-call)
(build-conditional, build-lexical-reference, build-lexical-assignment)
(build-global-reference, build-global-assignment)
(build-global-definition, build-simple-lambda, build-case-lambda)
(build-lambda-case, build-primcall, build-primref)
(build-data, build-sequence, build-let, build-named-let)
(build-letrec, expand-body): Remove (sourcev->alist src) calls.
* module/ice-9/psyntax-pp.scm: Regenerate.
* module/language/tree-il/analyze.scm (shadowed-toplevel-analysis): Use
'tree-il-src' instead of accessing the 'src' slot directly.
* module/system/vm/assembler.scm (link-debug): Adjust so PC can be
followed by a vector or an alist.
2022-02-06 22:59:41 +01:00
Ludovic Courtès
8e2e2ceb17 Deprecate symbol properties.
* libguile/strings.c (scm_i_make_symbol): Remove 'props' argument.  Use
3 words instead of 'scm_double_cell'.
* libguile/strings.h: Adjust accordingly.
* libguile/symbols.c (scm_i_str2symbol, scm_i_str2uninterned_symbol):
Likewise.
(scm_symbol_fref, scm_symbol_pref, scm_symbol_fset_x,
scm_symbol_pset_x): Move to...
* libguile/deprecated.c: ... here.  Rewrite in terms of object
properties.
(symbol_function_slot, symbol_property_slot): New variables.
* libguile/symbols.h (SCM_SYMBOL_FUNC, SCM_SET_SYMBOL_FUNC)
(SCM_SYMBOL_PROPS, SCM_SET_SYMBOL_PROPS)
(scm_symbol_fref, scm_symbol_pref, scm_symbol_fset_x)
(scm_symbol_pset_x): Move to...
* libguile/deprecated.h: ... here.  Mark declarations as 'SCM_DEPRECATED'.
* module/system/base/types.scm (cell->object): Remove 'props' field for
%TC7-SYMBOL.
* doc/ref/api-data.texi (Symbol Props): Remove.
* NEWS: Update.
2022-02-04 11:12:28 +01:00
Andy Wingo
54bbe0b284 Avoid source properties in psyntax
* module/ice-9/psyntax.scm (source-annotation): Only return source
properties from syntax objects.
(source-wrap): Don't look for source properties.
(expand-macro): Rebuild source properties on macro output via
source-wrap, not source properties.  Only annotate head of a chain of
pairs.
(strip): Here's the only use of set-source-properties!: when stripping
a syntax object to a datum.
(macroexpand): If the input expression is not a syntax object, eagerly
extract its source properties.
(datum->syntax): Fix case in which source is given as an alist.
* module/ice-9/psyntax-pp.scm: Regenerate.
2022-02-01 18:26:41 +01:00
Andy Wingo
9654ab1f21 Fix reproducibility for inlinable-exports
* module/language/tree-il/inlinable-exports.scm (compute-decoder): Map
items in order of their code.
2022-02-01 14:50:44 +01:00
Andy Wingo
9b9149a5bf Rework bootstrap to be reproducible
* configure.ac:
* Makefile.am (SUBDIRS): Replace bootstrap/ with stage0, stage1, and
stage2.
* am/bootstrap.am: Include all files and all rules.
* meta/build-env.in (GUILE_AUTO_COMPILE): Always turn off
auto-compilation.  Take a GUILE_BOOTSTRAP_STAGE argument, which can be
stage0, stage1, stage2, or unset.  Adapt the load-compiled path
accordingly.
* meta/uninstalled-env.in: Include .go files from stage2.
* module/Makefile.am: Rework to use boostrap.am.
* module/system/base/optimize.scm (available-optimizations): Punt the
inlinable-exports machinery to -O2.
* stage0/Makefile.am:
* stage1/Makefile.am:
* stage2/Makefile.am: New files.
2022-02-01 14:50:40 +01:00
Andy Wingo
373f35b5f7 peval cross-module-inlining gracefully handles missing interface
* module/language/tree-il/peval.scm (peval): The intention was for
resolve-interface to return an interface only if it exists, but actually
it throws if the interface isn't know.  Fix to do what we intended to
do.
2022-01-17 21:25:08 +01:00
Andy Wingo
d01ab7bf5c Fix inlinable-exports bug for pure modules
* module/language/tree-il/inlinable-exports.scm (compute-decoder): Fix
bug in which inlinable exports in a pure module would have a missing
make-struct/no-tail binding.
2022-01-17 21:07:22 +01:00
Andy Wingo
5481222670 Re-rewrite integer-expt in C
Calling out to Scheme was a performance regression.

* libguile/integers.h:
* libguile/integers.c (scm_integer_expt_ii, scm_integer_expt_zi): New
internal functions.
* libguile/numbers.c (scm_integer_expt): Go back to C.  But, include
fast cases for inums and doubles.
* module/ice-9/boot-9.scm: Revert addition of integer-expt.
2022-01-13 09:37:17 +01:00
Andy Wingo
3ad3ac740f Reimplement integer-expt in Scheme
* libguile/numbers.c (integer_expt_var): New static variable.
(init_integer_expt_var): New helper.
(scm_integer_expt): Delegate to Scheme.
* module/ice-9/boot-9.scm (integer-expt): Reimplement in Scheme.  Misses
some optimizations for fractions but that is probably OK!
2022-01-13 09:37:16 +01:00
Andy Wingo
52e310a2ac Avoid quadratic behavior in id-var-name
* module/ice-9/psyntax.scm (id-var-name): Avoid list-ref.
* module/ice-9/psyntax-pp.scm: Regenerate.
2022-01-13 09:35:53 +01:00
Andy Wingo
1148eb5051 -Oresolve-free-vars pass gracefully handles failed autoloads.
* module/language/tree-il/resolve-free-vars.scm (make-resolver):
Gracefully handle failed autoloads.
2022-01-11 21:32:40 +01:00
Daniel Llorens
5759e37181 New function srfi-4-vector-type-size in (srfi srfi-4 gnu)
This patch removes the undocumented function make-srfi-4-vector from
(guile). That function is still exported from (srfi srfi-4 gnu).

* libguile/srfi-4.h (scm_init_srfi_4): Split into scm_bootstrap_srfi_4()
  and scm_init_srfi_4(), after the pattern of scm_init_bytevectors() and
  scm_bootstrap_bytevectors().
* libguile/init.c: Replace scm_init_srfi_4() call by scm_bootstrap_srfi_4().
* module/srfi/srfi-4.scm: Load newly defined srfi-4 extension. This
  provides undocumented make-srfi-4-vector.
* module/srfi/srfi-4/gnu.scm: Export srfi-4-vector-type-size.
* doc/ref/srfi-modules.texi: Document srfi-4-vector-type-size.
2021-12-06 14:00:03 +01:00
Mikael Djurfeldt
6af3362b05 Support C99 complex types conditionally in (system foreign)
496f69dba2 introduced C99 complex types in
libguile/foreign.h and (system foreign). Since these types are provided
conditionally in foreign.h based on autoconf tests they need to be used
conditionally in (system foreign) based on their presence.
2021-12-01 18:40:19 +01:00
Andy Wingo
6f1b620b82 Add -Ooptimize-known-return-types at -O2
* module/language/cps/optimize.scm (optimize-first-order-cps):
* module/system/base/optimize.scm (available-optimizations): Add
optimize-known-return-types at -O2.
2021-11-15 15:32:54 +01:00
Andy Wingo
dad113d80f Add new pass to optimize away return value count checks
* module/language/cps/return-types.scm: New file.
* module/Makefile.am (SOURCES):
* am/bootstrap.am (SOURCES): Add new file.
* module/language/tree-il/compile-cps.scm (sanitize-meta): Strip
  "noreturn" and "return-type" properties -- these should only be
  computed by Guile.
2021-11-15 15:32:54 +01:00
Andy Wingo
5c76381625 Allow callk to continue to kargs
* module/language/cps/verify.scm (check-arities): If a callk continues
to kargs, the caller knows the number of return values that the callee
provides and no number-of-values check is needed.
* module/language/cps/contification.scm (apply-contification): Allow
contification of known-return-values calls.
* module/language/cps/reify-primitives.scm (uniquify-receive)
(reify-primitives): No need for uniquify-receive any more as receive
shuffles are attached to the call, not the continuation.
* module/language/cps/compile-bytecode.scm (compile-function): Add kargs
case.
2021-11-15 15:32:54 +01:00
Andy Wingo
4fcd643adb Refactor send and receive shuffles in slot allocation
* module/language/cps/slot-allocation.scm (lookup-send-parallel-moves):
Rename from `lookup-parallel-moves'.
(lookup-receive-parallel-moves): New function.  Now we attach "receive
moves" to call and prompt conts instead of to their continuations.
(compute-shuffles): Refactor to allow a continuation to have both send
and receive shuffles.
(compute-frame-size): Refactor for new shuffles mechanism
(allocate-slots): Allow calls to proceed directly to kargs.
2021-11-15 15:32:54 +01:00
Andy Wingo
a227c84a76 Refactor compile-bytecode
* module/language/cps/compile-bytecode.scm (compile-function): Treat
$kreceive as a forwarding cont, and refactor the treatment of calls and
$values.
2021-11-15 15:32:54 +01:00
Daniel Llorens
496f69dba2 Support C99 complex types in (system foreign)
* libguile/foreign.h (SCM_FOREIGN_TYPE_COMPLEX_FLOAT,
  SCM_FOREIGN_TYPE_COMPLEX_DOUBLE): New enums.
* module/system/foreign.scm (complex-float, complex-double): Export new types.
  (make-c-struct, parse-c-struct): Support the new types.
* libguile/foreign.c (complex-float, complex-double): Define new types.
  (alignof, sizeof, pack, unpack): Support the new types.
* test-suite/tests/foreign.test: Test.
2021-11-15 11:34:09 +01:00
Daniel Llorens
c6b1171c6b Avoid ash with arguments that might overflow in (language cps types)
Fixes https://debbugs.gnu.org/50609

* module/languages/cps/types.scm (ulsh): As stated.
2021-11-05 10:26:57 +01:00
Fabrice Fontaine
ffb33fd66b module/system/base/target.scm: support riscv32
Fix the following build failure on riscv32:

system/base/target.scm:132:16: In procedure triplet-pointer-size:
unknown CPU word size "riscv32"

Fixes:
 - http://autobuild.buildroot.org/results/6705630c1484239ec8b73d57ebc2e2570fbfc8f8

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2021-11-05 10:15:26 +01:00
Vineet Gupta
492bd63883 Add support for arc
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>

NB: closes https://debbugs.gnu.org/cgi/bugreport.cgi?bug=48816
2021-11-03 10:59:03 +01:00
Taylan Kammer
a960d7869b Improve support for R6/R7 SRFI module name formats.
Fixes <https://bugs.gnu.org/39601>.

Partly fixes <https://bugs.gnu.org/40371>.

It was already possible to import an SRFI module by referencing it
as (srfi :n) which is automatically translated to (srfi srfi-n), but
this conversion was only done during import.  After this change, it's
also possible to define a library as (srfi :n) which is automatically
translated to (srfi srfi-n) during definition.

It was not possible at all to define or import SRFI module names in the
R7RS format, (srfi n), where n is a non-negative exact integer.  It is
now possible both to define and import them as such, realized through
the same kind of conversion to a canonical (srfi srfi-n) name.

* module/ice-9/r6rs-libraries.scm: Numerous changes.
2021-11-02 10:02:29 +01:00
Ludovic Courtès
3b42b1eb52 sxml: Make parser thread-safe.
Fixes <https://bugs.gnu.org/51264>.

Lack of thread-safety would also affect the parser in (texinfo) because
it uses 'next-token-of'.

* module/sxml/upstream/input-parse.scm (input-parse:init-buffer): Always
return a fresh buffer.
2021-10-22 13:52:40 +02:00
Daniel Llorens
6be51f9bbf Provide xxvector-copy and xxvector-copy! for srfi-4 vectors
These use the argument conventions of vector-copy!, string-copy!,
etc. and not that of bytevector-copy! (which is from r6rs).

* module/srfi/srfi-4/gnu.scm: As stated.
* test-suite/tests/srfi-4.test: Tests.
* doc/ref/srfi-modules.texi: Documentation.
* libguile/bytevectors.c (bytevector-copy!): Add overlap note to
  docstring.
* libguile/vectors.c (vector-copy!): Reuse text for the overlap note.
2021-10-21 15:05:46 +02:00
Timothy Sample
c85724bd0a (ice-9 format): Fix scaling floats with leading zeros 2021-10-19 02:52:15 +02:00
Andy Wingo
e60469c8b6 Add primitive alias analysis to CSE
* module/language/cps/effects-analysis.scm (compute-known-allocations):
(compute-clobber-map): Add "conts" parameter, and use it to compute
primcalls that access known allocations.  A write to a known allocation
only clobbers a read to a known allocation if they are the same.
* module/language/cps/cse.scm (eliminate-common-subexpressions-in-fun):
Pass conts also to compute-clobber-map.
2021-10-03 21:39:46 +02:00
Andy Wingo
71e201d5c4 Use more logtest in cse.scm
* module/language/cps/effects-analysis.scm (causes-effect?):
(effect-clobbers?): Use logtest.
2021-10-03 21:09:41 +02:00
Andy Wingo
c9c16db694 Allow primcalls with multiple defs
* module/language/cps/types.scm (infer-types): Allow multiple defs.
2021-10-01 11:33:13 +02:00
Andy Wingo
c803566a17 Add ,optimize-cps REPL meta-command
* module/system/repl/command.scm (*command-table*): Add optimize-cps /
optx.
(optimize-cps): Define meta-command.
* module/system/repl/common.scm (optimize*): New helper.
(repl-optimize): Use helper.
(repl-optimize-cps): New public function.
2021-10-01 11:33:13 +02:00
Andy Wingo
426867ac7d Add CPS pretty-printer
* module/language/cps/dump.scm: New file.
* module/Makefile.am (SOURCES): Add to build.
2021-10-01 11:33:10 +02:00
Andy Wingo
c8c35c6987 Allow unchecked functions to have unboxed arguments
* module/language/cps/utils.scm (compute-var-representations): Use
'arg-representations from metadata for arg representations.
* module/language/tree-il/compile-cps.scm (sanitize-meta):
(convert): Make sure incoming terms have no arg representations.
2021-10-01 11:28:22 +02:00
Andy Wingo
8fab68f8b1 Move live variable computation routines to utils and graphs.
* module/language/cps/graphs.scm (rename-keys, rename-intset)
(rename-graph, compute-reverse-control-flow-order)
(compute-live-variables): Move here from slot-allocation.
* module/language/cps/utils.scm: Remove duplicate compute-idoms
definition.
(compute-defs-and-uses, compute-var-representations): Move here from
slot-allocation.
* module/language/cps/slot-allocation.scm: Move routines out to utils
and graphs.
2021-10-01 11:28:22 +02:00
Andy Wingo
d4d4336ede Hotfix to unify (x ...) patterns in match
* module/ice-9/match.upstream.scm (match-gen-ellipsis): Instead of just
binding the identifier when matching (x ...), go through match-one so
that if the id is already bound, we unify instead.
* test-suite/tests/match.test ("unify in list patterns"): Add test.
* test-suite/tests/match.test.upstream: Add additional tests from
upstream.

See commit 05c546e38 in Chibi Scheme.  Thanks to Alex Shinn for help
here!
2021-09-30 15:47:41 +02:00
Ludovic Courtès
74abae04aa Baseline compiler no longer swaps rsh/lsh when transforming ash calls.
Reported by Marius Bakke <marius@gnu.org>
at <https://issues.guix.gnu.org/50696>.

Previously, the baseline compiler would incorrectly emit a right shift
when for, say, (ash x 2), and a left shift for (ash x -2).

* module/language/tree-il/compile-bytecode.scm (canonicalize): When Y is
negative, emit 'rsh', not 'lsh'.
* test-suite/tests/numbers.test ("ash at -O1"): New test.
2021-09-20 23:27:39 +02:00
Ludovic Courtès
330c6ea83f Fix 'ash' primcall match clause in baseline compiler.
Previously the pattern would only match when the two 'src' values were
the same, which is not the case for example when running on the
interpreter.

* module/language/tree-il/compile-bytecode.scm (canonicalize): In 'ash
primcall pattern, rename second 'src' to 'src*'.
2021-09-20 23:24:24 +02:00
Ludovic Courtès
e304773416 srfi-1: 'find-tail' passes 'check-arg' the right procedure name.
* module/srfi/srfi-1.scm (find-tail): Pass 'find-tail' as the 3rd
argument to 'check-arg'.
2021-09-20 17:00:19 +02:00
Ludovic Courtès
5a389ca728 (system repl command) autoloads the compiler, disassembler, and profiler.
* module/system/repl/command.scm: Autoload (system base compile),
(system vm disassembler), and (statprof).
2021-09-20 17:00:19 +02:00
Daniel Llorens
96e3686db1 Revert shift of ndim in array tag from 3df3ba1a2c
To avoid breaking ABI.

* libguile/arrays.h (SCM_I_ARRAY_DIM, scm_i_raw_array): As stated.
* module/system/vm/assembler.scm: As stated.
2021-09-17 11:20:24 +02:00
Aleix Conchillo Flaqué
1f100a4f20 foreign-library: fix darwin detection
* module/system/foreign-library.scm (system-library-extensions): fix
darwin host detection. darwin host types have "-darwin" but not
"-darwin-".
2021-09-02 08:59:57 +02:00
Daniel Llorens
3df3ba1a2c Remove array contp flag
This flag was set, but never used in Guile, and there was no documented
API to access it.

To check if an array is contiguous, use (array-contents <> #t).

* libguile/arrays.h (scm_i_raw_array): New function.
  SCM_I_ARRAY_CONTIGUOUS, SCM_SET_ARRAY_CONTIGUOUS_FLAG,
  SCM_CLR_ARRAY_CONTIGUOUS_FLAG, SCM_I_ARRAY_CONTP: Remove.
  scm_t_array_dim: Declare here, not in array-handle.h.
  SCM_I_ARRAY_NDIM: Shift by one bit since the contp flag isn't there
  anymore.
* module/syste/vm/assembler.scm: Match removal of contp flag.
* libguile/arrays.c (scm_i_make_array): Reuse scm_i_raw_array.
  (scm_i_ra_set_contp): Remove.
  (scm_transpose_array): Don't set or clear the contp flag.
  (scm_make_shared_array): Don't set or clear the contp flag.
  (scm_make_typed_array): Don't set the contp flag.
* libguile/array-map.c (scm_i_array_rebase): Reuse scm_i_raw_array.
2021-08-16 19:02:43 +02:00
Daniel Llorens
5df5555d12 Add function vector-copy! to core
This is up to 20%-30% faster than the previous versions in (scheme base) or
(srfi srfi-43) that used vector-move-left!/vector-move-right!.

* libguile/vectors.h:
* libguile/vectors.c: As stated.
* doc/ref/api-data.texi (vector-copy!): Document the new function.
  (vector-fill!): Document optional arguments.
  (vector-copy): Document optional arguments.
* module/scheme/base.scm: Reuse core vector-copy!.
* module/srfi/srfi-43.scm: Reuse core vector-copy!.
2021-08-06 17:13:21 +02:00
Daniel Llorens
091f5062cb Reuse core vector-fill! in (scheme base)
module/scheme/base.scm: As stated.
2021-08-06 13:06:51 +02:00
Daniel Llorens
a34c762de0 Extend core vector-copy to r7rs vector-copy
* libguile/vectors.h: Declare scm_vector_copy_partial.
* libguile/vectors.c (scm_vector_copy_partial): As stated.
  (scm_vector_copy): Reuse scm_vector_copy_partial.
* module/scheme/base.scm: Reuse core vector-copy.
* module/srfi/srfi-43: Reuse core vector-copy.
* test-suite/tests/vectors.test: Test vector-copy.
2021-08-06 13:06:51 +02:00
Maxime Devos
c78c130b1d ice-9/read: Parse #{}}# properly.
This is a regression since Guile 3.0.2 and breaks compilation
of a Guile library.

* module/ice-9/read.scm
  (%read)[read-parenthesized]: When SAW-BRACE? is #t but CH isn't
  #\#, don't eat CH.
* test-suite/tests/reader.test
  ("#{}#): Add four test cases.
2021-08-02 12:15:59 +02:00
Rob Browning
d79a226359 Fix crash on #nil in syntaxes
In 3.0.7 (after 0cc7991855 "Ensure
that (syntax ()) results in ("), the use of #nil in syntax-rules
expansions like this:

  (define-syntax foo
    (syntax-rules ()
      ((_ x) (eq? #nil x))))

  (foo #t)

could cause a crash that looks like this:

  ice-9/psyntax.scm:2795:12: In procedure syntax-violation:
  Syntax error:
  unknown location: unexpected syntax in form ()

To fix it, add another special case (the commit mentioned above
special-cased the empty list) to preserve #nil

* module/ice-9/psyntax.scm (gen-syntax): Preserve #nil.
* test-suite/tests/syntax.test: Test #nil in syntax expansions.

Closes: 49305
2021-07-11 15:00:33 -05:00
Andy Wingo
17aab66e75 Fix bug in eq-constant? propagation in CSE if kf == kt
* module/language/cps/cse.scm (compute-out-edges): Only propagate
constant to successor if successor not kf.
* test-suite/tests/compiler.test ("cse auxiliary definitions"):
("closure conversion"): Refactor.
("constant propagation"): New test.

Fixes #48368.
2021-05-24 11:09:24 +02:00
Daniel Llorens
f499754bc8 Fix bug in nftw function
Fixes bug #44182. Thanks to Matija Obid for the report and RhodiumToad in
2021-05-21 14:19:49 +02:00
Robin Green
f9f55b9ce7 Fix trace-calls-to-procedure
Fixes #43102 and duplicate #48412.
2021-05-19 16:41:30 +02:00
Maxime Devos
221203b0df Add ‘expt’ to the list of effect-free primitives.
I find myself writing code like (- (expt 2 32) 1)
lately. Let's allow constant-folding that.

* module/language/tree-il/primitives.scm
  (*interesting-primitive-names*, *effect-free-primitives*):
  Add 'expt'.
2021-05-18 13:42:34 +02:00