summaryrefslogtreecommitdiff
path: root/module/language/tree-il
AgeCommit message (Collapse)AuthorFilesLines
2021-10-01Allow unchecked functions to have unboxed argumentsAndy Wingo1-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.
2021-09-20Baseline compiler no longer swaps rsh/lsh when transforming ash calls.Ludovic Courtès1-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.
2021-09-20Fix 'ash' primcall match clause in baseline compiler.Ludovic Courtès1-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*'.
2021-05-18Add ‘expt’ to the list of effect-free primitives.Maxime Devos1-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'.
2021-05-11Implement cross-module inliningAndy Wingo2-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.
2021-05-11Add support for recording inlinable module exportsAndy Wingo2-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.
2021-05-11Add pass to resolve free toplevel references in declarative modulesAndy Wingo2-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.
2021-05-11Letrectify links module defs with usesAndy Wingo1-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".
2021-05-02analyze: 'unbound-variable' warning handles re-exported bindings.Ludovic Courtès1-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.
2021-05-01Fix bug if call-with-prompt tag not a lexicalAndy Wingo1-2/+2
* module/language/tree-il/peval.scm (peval): peval could throw if the call-with-prompt operand wasn't a lexical. Terrible!
2021-05-01Fix tree-il effects analysis for promptsAndy Wingo1-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.
2021-04-26CPS conversion calls module variables through trampolinesAndy Wingo1-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.
2021-04-26Simplify module variable lookup slow-pathAndy Wingo1-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.
2021-04-21Optimize letrec* binding order in fix-letrecAndy Wingo1-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.
2021-02-03Optimize eof-object?Andy Wingo1-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.
2021-01-07New warnings: -Wuse-before-definition, -Wnon-idempotent-definitionAndy Wingo1-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.
2020-08-12Fold eqv? to eq? on exact integers according to target fixnum rangeAndy Wingo1-1/+9
* module/language/tree-il/peval.scm (peval): Fix folding to only reduce to eq? for values within both host and target range.
2020-08-03CPS compiler reduces eq? on constant to eq-constant?Andy Wingo3-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.
2020-08-03Baseline compiler emits eq-immediate? as appropriateAndy Wingo1-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.
2020-07-30Improve code generation for eq? on immediatesAndy Wingo2-0/+33
* module/language/tree-il/compile-bytecode.scm (canonicalize): * module/language/tree-il/compile-cps.scm (canonicalize): Specialize eq-false? and similar predicates.
2020-06-19Tree-IL-to-CPS compiler delays calls to 'target-most-positive-fixnum'.Ludovic Courtès1-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.
2020-06-01Change -O1 compiler to use baseline and also resolve primitivesAndy Wingo1-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.
2020-05-31Fix bug where private bindings would never be sealedAndy Wingo1-1/+1
* module/language/tree-il/optimize.scm (make-optimizer): Fix plumbing of -Oseal-private-bindings / -O3.
2020-05-14Tree-IL lowerer only loads needed optimizationsAndy Wingo1-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.
2020-05-13More robust reduction of equal? and eqv?Andy Wingo2-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.
2020-05-13Add with-lexicals helper; fix bug in (equal? #t (foo) #t)Andy Wingo3-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.
2020-05-13Fix optimizers after language lowerer refactorAndy Wingo1-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.
2020-05-13Slight optimization to baseline compilerAndy Wingo1-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.
2020-05-12Whoops, fix bug in tree-il choose-compilerAndy Wingo1-1/+1
* module/language/tree-il/spec.scm (choose-compiler): Fix spelling of "compile-cps" :)
2020-05-12Delay loading CPS unless CPS compiler usedAndy Wingo1-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.
2020-05-11Baseline FIXME's are done :)Andy Wingo1-10/+0
* module/language/tree-il/compile-bytecode.scm: Remove FIXME comments.
2020-05-11Baseline compiler emits source locationsAndy Wingo1-6/+42
* module/language/tree-il/compile-bytecode.scm (compile-closure): Emit source annotations where we have them.
2020-05-11Baseline O(1) access to frame-base envAndy Wingo1-15/+10
* module/language/tree-il/compile-bytecode.scm (compile-closure): No need to search for frame-base.
2020-05-11Emit handle-interrupts in baseline compilerAndy Wingo1-2/+6
* module/language/tree-il/compile-bytecode.scm (compile-closure): Handle interrupts before calls, returns, and tail calls.
2020-05-11Avoid having "guild compile" load optimizersAndy Wingo1-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.
2020-05-11Improve tail recursion in compilerAndy Wingo1-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.
2020-05-11Fix module capture for closures in <fix>Andy Wingo1-0/+2
* module/language/tree-il/compile-bytecode.scm (compile-closure): Capture closures for <fix> if needed.
2020-05-11Fix "cons" compilation in baseline compiler in some casesAndy Wingo1-1/+1
* module/language/tree-il/compile-bytecode.scm (emit-cons): Fix for case where car is dst but cdr isn't.
2020-05-11Baseline compiler: add pop-fluid primitive.Andy Wingo1-0/+1
* module/language/tree-il/compile-bytecode.scm (pop-fluid): New primitive.
2020-05-11Fix baseline compilation error for make-struct/simpleAndy Wingo1-6/+8
* module/language/tree-il/compile-bytecode.scm (compile-closure): $allocate-struct takes an SCM.
2020-05-11Fix baseline miscompilation of <Andy Wingo1-1/+1
* module/language/tree-il/compile-bytecode.scm: Fix < miscompilation.
2020-05-11Fix free var computation in baseline compiler for lexical set!Andy Wingo1-2/+3
* module/language/tree-il/compile-bytecode.scm (split-closures): Adjoin lexical being set to free vars.
2020-05-11Declare #:cps? as an available optimizationAndy Wingo1-1/+2
* module/language/tree-il/optimize.scm (tree-il-optimizations): Add #:cps?, on by default from -O1. This enables "guild compile -O2 -Ono-cps foo.scm".
2020-05-11Fix baseline canonicalization of reifying promptsAndy Wingo1-1/+1
* module/language/tree-il/compile-bytecode.scm (canonicalize): Fix arg order to make-prompt.
2020-05-11Fix compilation of prompt in tail contextAndy Wingo1-1/+1
* module/language/tree-il/compile-bytecode.scm (compile-closure): Compile body of prompt in values-at context at the frame base, not the current env.
2020-05-11Fix kw initializer bug in baseline compilerAndy Wingo1-1/+1
* module/language/tree-il/compile-bytecode.scm (compile-closure): The first sym has index 1, not 0, because of the closure.
2020-05-11Use lookup, lookup-bound in baseline compilerAndy Wingo1-22/+30
* module/language/tree-il/compile-bytecode.scm (emit-box-set!): Fix to reference by SCM, not word. (emit-box-ref): New helper. (emit-cached-module-box, emit-cached-toplevel-box, emit-toplevel-box): Add bound? arg. Before these could produce #f instead of a variable, and unbound variable errors weren't any good as they didn't have the variable name. (compile-closure): Use more box-ref and box-set!. Pass bound? arg to the helpers.
2020-05-11Top-level lookups raise exceptions in run-timeAndy Wingo1-24/+4
* module/language/cps/reify-primitives.scm (reify-lookup): * module/language/tree-il/compile-cps.scm (toplevel-box): Instead of checking that the result of module-variable is a variable, and possibly checking that it's bound, we just call intrinsics that throw exceptions if the variable isn't bound. This reduces useless inlining that can't inform CPS optimizations, as they are tangled in diamond control flow.
2020-05-11Rename "lookup" intrinsic to "module-variable"Andy Wingo2-4/+4
It can return #f, unlike scm_(module_)?lookup. * libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): * libguile/intrinsics.c (module_variable, scm_bootstrap_intrinsics): Rename. * module/language/cps/compile-bytecode.scm (compile-function): * module/language/cps/effects-analysis.scm (current-module): * module/language/cps/reify-primitives.scm (reify-lookup) (compute-known-primitives): * module/language/tree-il/compile-bytecode.scm (emit-cached-module-box) (emit-cached-toplevel-box, emit-toplevel-box): * module/language/tree-il/compile-cps.scm (toplevel-box): * module/system/vm/assembler.scm (module-variable): Adapt users.
2020-05-09Fix baseline compiler bugsAndy Wingo1-3/+3
* module/language/tree-il/compile-bytecode.scm (compile-closure): Fix FP-relative computation for "receive" target. Fix value-at syntax in conditional.