summaryrefslogtreecommitdiff
path: root/module/language
Commit message (Collapse)AuthorAgeFilesLines
* Fix no-clause case-lambda in pevalDaniel Llorens2023-03-171-0/+1
| | | | | | | | This is checked by optargs.test, which 3b47f87618047ebb8812788c64a44877a4f2e0dd broke. * module/language/tree-il/peval.scm (peval): Account for no clause (= no body) case-lambda.
* peval reduces some inlined case-lambda callsDaniel Llorens2023-02-271-0/+23
| | | | | | | * module/language/tree-il/peval.scm (peval): Reduce multiple case lambda in <call> trees according to the number of arguments. Do not try to reduce case-lambda using keyword arguments. * test-suite/tests/peval.test: Tests.
* Add -Wunused-module.Ludovic Courtès2023-02-241-1/+153
| | | | | | | | | | | * module/language/tree-il/analyze.scm (<module-info>): New record type. (unused-module-analysis): New variable. (make-unused-module-analysis): New analysis. (make-analyzer): Add it. * module/system/base/message.scm (%warning-types): Add 'unused-module'. * test-suite/tests/tree-il.test (%opts-w-unused-module): New variable. ("warnings")["unused-module"]: New test prefix. * NEWS: Update.
* Add 'record-case' to '.dir-locals.el'.Ludovic Courtès2023-02-241-4/+0
| | | | | | * module/language/tree-il/fix-letrec.scm (fix-letrec): Remove "Local Variables" bit. * .dir-locals.el (scheme-mode): Add 'record-case'.
* linker: Do not store entire ELF in memory when writing to a file.Ludovic Courtès2023-01-171-3/+14
| | | | | | | | | | | | | | | | | | | | | This reduces the amount of memory that needs to be allocated while writing the ELF file to disk. Note: We're abusing #:page-aligned? in 'link-elf' to choose whether to return a bytevector or a procedure. * module/system/vm/linker.scm (process-reloc): Subtract SECTION-OFFSET when writing to BV. (write-linker-object): Pass BV directly to the linker object writer. (link-elf): When PAGE-ALIGNED? is false, call 'bytevector-slice' from here. When it is true, return a procedure that takes a port and writes to it, without having to allocate a bytevector for the whole ELF container. * module/language/bytecode/spec.scm (bytecode->value): Handle X being a procedure instead of a bytevector. (bytecode) <#:printer>: Likewise. * test-suite/tests/linker.test (link-elf-with-one-main-section): Pass #:page-aligned? #f.
* Do not expand 'make-vector' primcall with wrong number of arguments.Ludovic Courtès2023-01-161-3/+3
| | | | | | | | | Fixes <https://bugs.gnu.org/60522>. Reported by Sascha Ziemann <ceving@gmail.com>. * module/language/tree-il/primitives.scm (make-vector): Return #f when passed an incorrect number of arguments. * test-suite/tests/peval.test ("partial evaluation"): Add tests.
* Fix peval bug when expand-primitives introduces lexicalsAndy Wingo2022-12-011-2/+38
| | | | | | | | * module/language/tree-il/peval.scm (augment-var-table-with-externally-introduced-lexicals): New helper. * module/language/tree-il/peval.scm (peval): Augment store with any lexicals introduced by expand-primitives. * test-suite/tests/peval.test ("partial evaluation"): Add tests.
* Fix order-of-side-effects bug in (eq? x y z) expansionAndy Wingo2022-12-011-12/+34
| | | | | | | | | * module/language/tree-il/primitives.scm (bind-lexicals): New helper. (expand-eq, expand-chained-comparisons): Ensure all arguments are eagerly evaluated. Previously an intermediate #f result would shortcut the evaluation. * test-suite/tests/compiler.test ("size effects in multi-arg eq / <"): Add test.
* Baseline compiler no longer crashes on (not (list 1 2)).Ludovic Courtès2022-10-011-1/+3
| | | | | | | | | | Fixes <https://bugs.gnu.org/58217>. * module/language/tree-il/compile-bytecode.scm (canonicalize) [finish-conditional](predicate?): Do not assume 'lookup-primitive' returns true. * test-suite/tests/compiler.test ("regression tests") ["(not (list 1 2))"]: New test.
* psyntax: Pass source vectors to tree-il constructors.Ludovic Courtès2022-02-072-7/+20
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* Fix reproducibility for inlinable-exportsAndy Wingo2022-02-011-2/+8
| | | | | * module/language/tree-il/inlinable-exports.scm (compute-decoder): Map items in order of their code.
* peval cross-module-inlining gracefully handles missing interfaceAndy Wingo2022-01-171-4/+6
| | | | | | | * 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.
* Fix inlinable-exports bug for pure modulesAndy Wingo2022-01-171-2/+2
| | | | | | * 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.
* -Oresolve-free-vars pass gracefully handles failed autoloads.Andy Wingo2022-01-111-15/+21
| | | | | * module/language/tree-il/resolve-free-vars.scm (make-resolver): Gracefully handle failed autoloads.
* Add -Ooptimize-known-return-types at -O2Andy Wingo2021-11-151-0/+2
| | | | | | * module/language/cps/optimize.scm (optimize-first-order-cps): * module/system/base/optimize.scm (available-optimizations): Add optimize-known-return-types at -O2.
* Add new pass to optimize away return value count checksAndy Wingo2021-11-152-1/+171
| | | | | | | | | * 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.
* Allow callk to continue to kargsAndy Wingo2021-11-155-30/+23
| | | | | | | | | | | | | * 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.
* Refactor send and receive shuffles in slot allocationAndy Wingo2021-11-152-46/+68
| | | | | | | | | | | * 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.
* Refactor compile-bytecodeAndy Wingo2021-11-151-142/+115
| | | | | | * module/language/cps/compile-bytecode.scm (compile-function): Treat $kreceive as a forwarding cont, and refactor the treatment of calls and $values.
* Avoid ash with arguments that might overflow in (language cps types)Daniel Llorens2021-11-051-1/+3
| | | | | | Fixes https://debbugs.gnu.org/50609 * module/languages/cps/types.scm (ulsh): As stated.
* Add primitive alias analysis to CSEAndy Wingo2021-10-032-5/+72
| | | | | | | | | * 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.
* Use more logtest in cse.scmAndy Wingo2021-10-031-3/+3
| | | | | * module/language/cps/effects-analysis.scm (causes-effect?): (effect-clobbers?): Use logtest.
* Allow primcalls with multiple defsAndy Wingo2021-10-011-1/+1
| | | | * module/language/cps/types.scm (infer-types): Allow multiple defs.
* Add CPS pretty-printerAndy Wingo2021-10-011-0/+317
| | | | | * module/language/cps/dump.scm: New file. * module/Makefile.am (SOURCES): Add to build.
* Allow unchecked functions to have unboxed argumentsAndy Wingo2021-10-012-6/+18
| | | | | | | * 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.
* Move live variable computation routines to utils and graphs.Andy Wingo2021-10-013-248/+225
| | | | | | | | | | | | * 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.
* Baseline compiler no longer swaps rsh/lsh when transforming ash calls.Ludovic Courtès2021-09-201-2/+2
| | | | | | | | | | | | 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.
* Fix 'ash' primcall match clause in baseline compiler.Ludovic Courtès2021-09-201-3/+3
| | | | | | | | | 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*'.
* Fix bug in eq-constant? propagation in CSE if kf == ktAndy Wingo2021-05-241-3/+3
| | | | | | | | | | * 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.
* Add ‘expt’ to the list of effect-free primitives.masterMaxime Devos2021-05-181-1/+2
| | | | | | | | | 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'.
* Implement cross-module inliningAndy Wingo2021-05-112-58/+137
| | | | | | | * module/language/tree-il/optimize.scm (make-optimizer): Pass cross-module-inlining? to peval. * module/language/tree-il/peval.scm (peval): Add cross-module-inlining? kwarg. Try to inline public module-ref.
* Add support for recording inlinable module exportsAndy Wingo2021-05-112-2/+873
| | | | | | | | | | | * module/language/tree-il/inlinable-exports.scm: New module. * am/bootstrap.am: * module/Makefile.am: * module/language/tree-il/optimize.scm (make-optimizer): * module/system/base/optimize.scm (available-optimizations): Wire up new module. * module/ice-9/boot-9.scm (module): Add inlinable-exports field. (define-module*): Add #:inlinable-exports kwarg.
* Add pass to resolve free toplevel references in declarative modulesAndy Wingo2021-05-112-0/+284
| | | | | | | | | | * am/bootstrap.am (SOURCES): * module/Makefile.am (SOURCES): * module/language/tree-il/optimize.scm (make-optimizer): Wire up the new pass. * module/language/tree-il/resolve-free-vars.scm: New pass. * module/system/base/optimize.scm (available-optimizations): Enable new pass at -O1.
* Letrectify links module defs with usesAndy Wingo2021-05-111-1/+19
| | | | | | | | | * module/language/tree-il/letrectify.scm (letrectify): Inline "let" bindings inside residualized "letrec*" forms, to allow the dominator relationship to be reflected in the scope tree. Also, detect "define-module*" invocations, and add these to the mod-vars set, so that residualized "module-ensure-local-variable!" primcalls can clearly denote their module without having to use "current-module".
* analyze: 'unbound-variable' warning handles re-exported bindings.Ludovic Courtès2021-05-021-0/+5
| | | | | | | | Fixes <https://bugs.gnu.org/47031>. * module/language/tree-il/analyze.scm (make-use-before-definition-analysis) [resolve]: Add case for when NAME is re-exported by MOD. * test-suite/tests/tree-il.test ("warnings")["re-exported binding"]: New test.
* Fix bug if call-with-prompt tag not a lexicalAndy Wingo2021-05-011-2/+2
| | | | | * module/language/tree-il/peval.scm (peval): peval could throw if the call-with-prompt operand wasn't a lexical. Terrible!
* Fix tree-il effects analysis for promptsAndy Wingo2021-05-011-3/+7
| | | | | | | | | | * module/language/tree-il/effects.scm (make-effects-analyzer): The body of a prompt is an expression only for escape-only prompts, and the handler is always a lambda. Fix bug where a prompt could be incorrectly marked effect-free. * test-suite/tests/tree-il.test ("optimize"): Add test for bug 48098. Fixes bug 48098.
* Fix closure-conversion bug for SCC with all free vars prunedAndy Wingo2021-04-271-5/+11
| | | | | | | | | * module/language/cps/closure-conversion.scm (convert-one): Fix bug when getting value of SCC whose free variables have been elided. Thanks to abcdw for the report! * test-suite/tests/compiler.test ("cse auxiliary definitions"): Remove spurious newline. ("closure conversion"): New test.
* Allow contification for $callkAndy Wingo2021-04-261-36/+132
| | | | | | | | | | | | | * module/language/cps/contification.scm (compute-first-class-functions): (compute-functions-called-by-label): (compute-functions): (compute-arities): (compute-contification-candidates): (compute-call-graph): (compute-contification): (apply-contification): (contify): Given that the frontend will produce $callk now, allow it to be contified if such callees are all called with the same continuation.
* CPS conversion calls module variables through trampolinesAndy Wingo2021-04-261-2/+86
| | | | | | | | * module/language/tree-il/compile-cps.scm (module-call-stubs): (module-call-label, convert, cps-convert/thunk): Arrange to call module variables through out-of-line trampolines with unchecked arity. This should speed up compile time in large files and reduce code size on hot paths.
* Fix CPS optimizations to allow callk in front halfAndy Wingo2021-04-264-34/+45
| | | | | | | | | | | * module/language/cps/closure-conversion.scm: Use standard compute-reachable-functions and intmap-select from utils to filter reachable functions, allowing us to pick up callk. Adapt some uses to expect callk for calls. * module/language/cps/self-references.scm (resolve-self-references): Subst the proc, if it's there. * module/language/cps/split-rec.scm (compute-free-vars): Add a case for callk.
* Simplify module variable lookup slow-pathAndy Wingo2021-04-264-9/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/intrinsics.h: * libguile/intrinsics.c (lookup_bound_public, lookup_bound_private): Two new intrinsics. (scm_bootstrap_intrinsics): Wire them up. * libguile/jit.c (compile_call_scm_from_scmn_scmn): (compile_call_scm_from_scmn_scmn_slow): (COMPILE_X8_S24__N32__N32__C32): Add JIT support for new instruction kind. * libguile/vm-engine.c (call-scm<-scmn-scmn): New instruction, takes arguments as non-immediate offsets, to avoid needless loads and register pressure. * module/language/cps/effects-analysis.scm: Add cases for new primcalls. * module/language/cps/compile-bytecode.scm (compile-function): Add new primcalls. * module/language/cps/reify-primitives.scm (cached-module-box): If the variable is bound, call lookup-bound-public / lookup-bound-private as appropriate instead of separately resolving the module, name, and doing the bound check. * module/language/tree-il/compile-bytecode.scm (emit-cached-module-box): Use new instructions. * module/system/vm/assembler.scm (define-scm<-scmn-scmn-intrinsic): (lookup-bound-public, lookup-bound-private): Add assembler support.
* Fix cached-module-box cache keysAndy Wingo2021-04-251-2/+2
| | | | | | | | * module/language/cps/reify-primitives.scm (cached-module-box): Include public? in cache key, so we don't accidentally alias private and exported names. Also include bound?, to avoid a window in which thread A resolves and caches var V in preparation for setting it, but thread B sees V for ref before it was initialized.
* Fix bugs introduced when allowing $kfun -> $kargsAndy Wingo2021-04-252-3/+6
| | | | | | * module/language/cps/dce.scm (compute-known-allocations): * module/language/cps/simplify.scm (eta-reduce): Allow the case-lambda without clauses.
* Fix comments in cps/compile-bytecodeAndy Wingo2021-04-231-2/+5
| | | | | * module/language/cps/compile-bytecode.scm (compile-function): Fix unfinished comments.
* New pass: elide-arity-checksAndy Wingo2021-04-212-1/+110
| | | | | | | | | | * module/language/cps/elide-arity-checks.scm: New file. Elides argument count checks for known callers. * am/bootstrap.am (SOURCES): * module/Makefile.am (SOURCES): Add new file. * module/language/cps/optimize.scm (optimize-first-order-cps): * module/system/base/optimize.scm (available-optimizations): Add new pass.
* Allow $kargs as entry of $kfunAndy Wingo2021-04-218-54/+86
| | | | | | | | | | | | | | | * module/language/cps.scm: * module/language/cps/contification.scm: * module/language/cps/cse.scm: * module/language/cps/dce.scm: * module/language/cps/simplify.scm: * module/language/cps/slot-allocation.scm: * module/language/cps/types.scm: Allow $kargs to follow $kfun. In that case, the function must be well-known and callers are responsible for calling with the appropriate arity. * module/language/cps/compile-bytecode.scm: Emit "unchecked-arity" for $kargs following $kfun. * module/system/vm/assembler.scm: Adapt.
* Mark some elisp runtime modules as non-declarativeAndy Wingo2021-04-212-2/+4
| | | | | | * module/language/elisp/runtime/function-slot.scm (language): * module/language/elisp/runtime/value-slot.scm (language): Non-declarative.
* Optimize letrec* binding order in fix-letrecAndy Wingo2021-04-211-3/+41
| | | | | | * module/language/tree-il/fix-letrec.scm (reorder-bindings): (fix-letrec): Reorder definitions so that lambdas tend to stick together, to avoid "complex" expressions interposing in lambda SCCs.
* Fix handling of parameter lists to elisp defun to allow nil.Mikael Djurfeldt2021-04-011-0/+1
| | | | Thanks to Vasilij Schneidermann.