summaryrefslogtreecommitdiff
path: root/module/language/tree-il
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'.
* 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-071-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | 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 new pass to optimize away return value count checksAndy Wingo2021-11-151-1/+1
| | | | | | | | | * 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 unchecked functions to have unboxed argumentsAndy Wingo2021-10-011-1/+10
| | | | | | | * 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.
* 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*'.
* 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.
* 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.
* Simplify module variable lookup slow-pathAndy Wingo2021-04-261-7/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* 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.
* Optimize eof-object?Andy Wingo2021-02-031-2/+9
| | | | | | | * module/language/cps/types.scm (constant-type): Add case for EOF. * module/language/tree-il/primitives.scm (*interesting-primitive-names*): (*effect+exception-free-primitives*): Add case for eof-object?. (eof-object?): Expand to eq? on the-eof-object.
* New warnings: -Wuse-before-definition, -Wnon-idempotent-definitionAndy Wingo2021-01-071-161/+342
| | | | | | | | | | | | | | | | | | * module/ice-9/boot-9.scm (%auto-compilation-options): Add use-before-definition and non-idempotent-definition. * module/language/tree-il/analyze.scm (<use-before-def-info>): New analysis info. (make-use-before-definition-analysis): New function. (goops-toplevel-definition): Move down. (unbound-variable-analysis, macro-use-before-definition): Remove, as they are subsumed by use-before-def. There are some deprecated bindings though. (make-analyzer): Rework to allow for use-before-def analysis to handle multiple * module/system/base/message.scm (%warning-types): Add handlers for the new warning types. * test-suite/tests/tree-il.test: Add tests. * doc/ref/api-evaluation.texi (Compilation): Update.
* Fold eqv? to eq? on exact integers according to target fixnum rangeAndy Wingo2020-08-121-1/+9
| | | | | * module/language/tree-il/peval.scm (peval): Fix folding to only reduce to eq? for values within both host and target range.
* CPS compiler reduces eq? on constant to eq-constant?Andy Wingo2020-08-033-26/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * module/language/cps/compile-bytecode.scm (compile-function): Expect eq-constant? instead of eq-null?, etc. * module/language/cps/effects-analysis.scm: Likewise. * module/language/cps/reify-primitives.scm (reify-primitives): For eq-constant?, reify a $const unless the constant is an immediate whose encoding fits in 16 bits. * module/language/cps/type-fold.scm (materialize-constant): Helper to make a constant from a type, min, and max. (fold-eq-constant?): New helper. (eq-constant?): New folder. (undefined?): Define specifically. (define-nullish-predicate-folder): Renamd from define-special-immediate-predicate-folder. Use only for null?, false, and nil?. (*branch-reducers*): New mechanism. Reduce eq? to eq-constant? if possible. (local-type-fold): Refactor to use materialize-constant, and to allow reducing branches. * module/language/cps/types.scm (constant-type): Return three values instead of a type entry. (constant-type-entry): New function that returns a type entry. Adapt callers. (infer-constant-comparison): New helper. (eq-constant?): New inferrer. (undefined?): New inferrer. * module/language/tree-il/compile-bytecode.scm (eq-constant?): Fix truncate-bits signed arg. (define-immediate-type-predicate): Adapt to visit-immediate-tags change. * module/language/tree-il/compile-cps.scm (convert): Convert eq? to constant to eq-constant?. Advantaged is that it gets fixnums and chars in addition to special immediates. * module/language/tree-il/cps-primitives.scm (define-immediate-type-predicate): Adapt to allow #f as pred. * module/system/base/types/internal.scm (immediate-tags): Use #f as pred for false, nil, etc. (immediate-bits->scm): Adapt. * module/system/vm/assembler.scm (emit-eq-null?, emit-eq-nil?) (emit-eq-false?, emit-eq-true?, emit-unspecified?, emit-eof-object?): Remove specialized emitters. * module/system/vm/assembler.scm (define-immediate-tag=?-macro-assembler): Allow for pred to be #f. * module/system/vm/disassembler.scm (define-immediate-tag-annotation): Adapt to pred being #f.
* Baseline compiler emits eq-immediate? as appropriateAndy Wingo2020-08-031-19/+30
| | | | | | | | * module/language/tree-il/compile-bytecode.scm (eq?): Define eq-immediate? as immediate emitter. (canonicalize): Don't fuss so much about eq?; only if commutation is needed. (Perhaps a more generic commutation pass is needed.) (compile-closure): Add support for emit/immediate for branches.
* Improve code generation for eq? on immediatesAndy Wingo2020-07-302-0/+33
| | | | | | * module/language/tree-il/compile-bytecode.scm (canonicalize): * module/language/tree-il/compile-cps.scm (canonicalize): Specialize eq-false? and similar predicates.
* Tree-IL-to-CPS compiler delays calls to 'target-most-positive-fixnum'.Ludovic Courtès2020-06-191-35/+28
| | | | | | | | | | | | | | | | | Fixes a bug whereby, for example, "guild compile --target=i686-linux-gnu" running on x86_64 would generate invalid code for 'bytevector-u32-native-set!' because 'target-most-positive-fixnum' was called from the top-level when (language tree-il compile-cps) was loaded. Consequently, the .go files under prebuilt/ would be invalid, leading to build failures on 32-bit platforms. This issue became apparent with cb8cabe85f535542ac4fcb165d89722500e42653. * module/language/tree-il/compile-cps.scm (bytevector-ref-converter)[tag]: Turn into a lambda so that 'target-most-positive-fixnum' is called in the right context. (bytevector-set-converter)[integer-unboxer]: Likewise.
* Change -O1 compiler to use baseline and also resolve primitivesAndy Wingo2020-06-011-1/+1
| | | | | | | | * bootstrap/Makefile.am (GUILE_OPTIMIZATIONS): Change to just -O1. * module/language/tree-il/spec.scm (choose-compiler): Use CPS for -O2 and higher. * module/system/base/optimize.scm (available-optimizations): CPS for -O2 and higher, but -Oresolve-primitives now at -O1 also.
* Fix bug where private bindings would never be sealedAndy Wingo2020-05-311-1/+1
| | | | | * module/language/tree-il/optimize.scm (make-optimizer): Fix plumbing of -Oseal-private-bindings / -O3.
* Tree-IL lowerer only loads needed optimizationsAndy Wingo2020-05-141-37/+39
| | | | | | | | | * module/language/tree-il/optimize.scm (make-optimizer): New procedure, to compute an optimizer given options, lazily loading optimization modules. (optimize): Use make-optimizer. (make-lowerer): Use make-optimizer, so as to only load needed optimizations. Speeds up bootstrap times.
* More robust reduction of equal? and eqv?Andy Wingo2020-05-132-56/+66
| | | | | | | | | | | | | | * module/language/tree-il/primitives.scm (expand-eq): Just expand out to binary comparisons. Also expand eq?, which was missing. Leave strength reduction to peval. (character-comparison-expander): Move down, as it depends on <, <=, and so on. * module/language/tree-il/peval.scm (peval): Robustly reduce equal? and eqv?. * test-suite/tests/peval.test ("partial evaluation"): Expect fixnum comparison to reduce to eq?. ("eqv?", "equal?"): A new battery of tests. * test-suite/tests/tree-il.test ("primitives"): Remove reduction tests.
* Add with-lexicals helper; fix bug in (equal? #t (foo) #t)Andy Wingo2020-05-133-72/+33
| | | | | | | | | | | | | | | * module/language/tree-il.scm (with-lexicals): New public helper. * .dir-locals.el (with-lexicals): Add indentation rule. * module/language/tree-il/compile-bytecode.scm (canonicalize): Use with-lexicals. * module/language/tree-il/compile-cps.scm (canonicalize): Use with-lexicals from tree-il. * module/language/tree-il/primitives.scm (chained-comparison-expander): Remove duplicate expander definitions for <, <=, and so on. * module/language/tree-il/primitives.scm (maybe-simplify-to-eq): Avoid inadvertent code duplication by using with-lexicals. (expand-chained-comparisons): Likewise. (call-with-prompt): Simplify to use with-lexicals.
* Fix optimizers after language lowerer refactorAndy Wingo2020-05-131-13/+12
| | | | | | | | | | | * module/language/cps/optimize.scm (define-optimizer): (optimize-higher-order-cps, optimize-first-order-cps): (make-cps-lowerer): * module/language/tree-il/optimize.scm (optimize, make-lowerer): In an embarrassing bug, after parsing optimization arguments, we were aconsing them instead of the expected cons*. This meant the bootstrap was running all Tree-IL optimizations! Change to have optimizers not have defaults and use alists after parsing.
* Slight optimization to baseline compilerAndy Wingo2020-05-131-34/+34
| | | | | | * module/language/tree-il/compile-bytecode.scm (compile-closure): for-value-at and for-values-at take indexes instead of environments to denote destination.
* Whoops, fix bug in tree-il choose-compilerAndy Wingo2020-05-121-1/+1
| | | | | * module/language/tree-il/spec.scm (choose-compiler): Fix spelling of "compile-cps" :)
* Delay loading CPS unless CPS compiler usedAndy Wingo2020-05-121-7/+5
| | | | | | | | | | | | | * module/language/tree-il/spec.scm: Remove #:compilers declaration; instead rely on choose-compiler. (choose-compiler): Load compilers on demand. * module/system/base/compile.scm (find-language-joint): Use next-pass instead of lookup-compilation-order, to avoid loading unused compilers. (read-and-compile): Adapt to find-language-joint change. (compute-compiler): Export. * module/scripts/compile.scm (compile): Use compute-compiler to load compiler modules.
* Baseline FIXME's are done :)Andy Wingo2020-05-111-10/+0
| | | | * module/language/tree-il/compile-bytecode.scm: Remove FIXME comments.
* Baseline compiler emits source locationsAndy Wingo2020-05-111-6/+42
| | | | | * module/language/tree-il/compile-bytecode.scm (compile-closure): Emit source annotations where we have them.
* Baseline O(1) access to frame-base envAndy Wingo2020-05-111-15/+10
| | | | | * module/language/tree-il/compile-bytecode.scm (compile-closure): No need to search for frame-base.
* Emit handle-interrupts in baseline compilerAndy Wingo2020-05-111-2/+6
| | | | | * module/language/tree-il/compile-bytecode.scm (compile-closure): Handle interrupts before calls, returns, and tail calls.
* Avoid having "guild compile" load optimizersAndy Wingo2020-05-111-15/+2
| | | | | | | | | | * module/language/cps/optimize.scm (cps-optimizations): * module/language/tree-il/optimize.scm (tree-il-optimizations): * module/system/base/optimize.scm (available-optimizations): Invert the dependency tree to hold the names and default optimization levels in a central place instead of in the optimizers. It moves definitions farther from uses, but it avoids us having to load the CPS optimizer if we don't need it, which improves bootstrap times.
* Improve tail recursion in compilerAndy Wingo2020-05-111-12/+6
| | | | | | * module/language/tree-il/compile-bytecode.scm (compile-closure): Make it so that for-tail is actually tail-recursive. Likewise improve tail recursion for the other helpers.