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

4577 commits

Author SHA1 Message Date
Andy Wingo
c6636ff312 Bump objcode minor version
* libguile/loader.h (SCM_OBJCODE_MINOR_VERSION):
* module/system/vm/assembler.scm (*bytecode-minor-version*): Bump, so
  that compiled files from Guile 3.0.3 will error when loaded on 3.0.2.
2020-05-13 09:37:54 +02:00
Andy Wingo
a165c49b29 Minor module/Makefile order tweak
* module/Makefile.am (ice-9/psyntax-pp.go): Add GUILE_OPTIMIZATIONS
  argument.
  (SOURCES): Reorder a bit for speed when bootstrapping.
2020-05-13 09:16:11 +02:00
Andy Wingo
c5da9d65a7 Fix optimizers after language lowerer refactor
* 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-13 09:04:16 +02:00
Andy Wingo
32eef3dd14 Slight optimization to baseline compiler
* 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-13 09:04:16 +02:00
Andy Wingo
9c4c6322f5 Whoops, fix bug in tree-il choose-compiler
* module/language/tree-il/spec.scm (choose-compiler): Fix spelling of
  "compile-cps" :)
2020-05-12 10:12:21 +02:00
Andy Wingo
cb8cabe85f Delay loading CPS unless CPS compiler used
* 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-12 09:54:19 +02:00
Andy Wingo
44ad8fbde5 Baseline FIXME's are done :)
* module/language/tree-il/compile-bytecode.scm: Remove FIXME comments.
2020-05-11 22:03:08 +02:00
Andy Wingo
b02a889659 Baseline compiler emits source locations
* module/language/tree-il/compile-bytecode.scm (compile-closure): Emit
  source annotations where we have them.
2020-05-11 16:53:23 +02:00
Andy Wingo
f66111a203 Baseline O(1) access to frame-base env
* module/language/tree-il/compile-bytecode.scm (compile-closure): No
  need to search for frame-base.
2020-05-11 16:43:08 +02:00
Andy Wingo
b35fd53664 Emit handle-interrupts in baseline compiler
* module/language/tree-il/compile-bytecode.scm (compile-closure): Handle
  interrupts before calls, returns, and tail calls.
2020-05-11 16:15:24 +02:00
Andy Wingo
b5108ccb2a Avoid having "guild compile" load optimizers
* 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-11 15:42:20 +02:00
Andy Wingo
2ba3eb4cf2 Fix shuffling assembler for new primcalls
* module/system/vm/assembler.scm (encode-X8_S8_C8_S8-C32!/shuffle): New
  shuffling assembler.
2020-05-11 15:03:19 +02:00
Andy Wingo
7f4bbc3dba Improve tail recursion in compiler
* 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-11 14:48:45 +02:00
Andy Wingo
73a23027f5 Fix module capture for closures in <fix>
* module/language/tree-il/compile-bytecode.scm (compile-closure):
  Capture closures for <fix> if needed.
2020-05-11 14:36:00 +02:00
Andy Wingo
4c3c35c536 Fix "cons" compilation in baseline compiler in some cases
* module/language/tree-il/compile-bytecode.scm (emit-cons): Fix for case
  where car is dst but cdr isn't.
2020-05-11 13:32:39 +02:00
Andy Wingo
3b6023d66d Baseline compiler: add pop-fluid primitive.
* module/language/tree-il/compile-bytecode.scm (pop-fluid): New
  primitive.
2020-05-11 13:32:19 +02:00
Andy Wingo
527262fef0 Fix baseline compilation error for make-struct/simple
* module/language/tree-il/compile-bytecode.scm (compile-closure):
  $allocate-struct takes an SCM.
2020-05-11 13:31:40 +02:00
Andy Wingo
c0a27de50d Fix baseline miscompilation of <
* module/language/tree-il/compile-bytecode.scm: Fix < miscompilation.
2020-05-11 13:18:50 +02:00
Andy Wingo
73ac53af73 Fix free var computation in baseline compiler for lexical set!
* module/language/tree-il/compile-bytecode.scm (split-closures): Adjoin
  lexical being set to free vars.
2020-05-11 11:39:53 +02:00
Andy Wingo
ffb210567d Declare #:cps? as an available optimization
* 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-11 11:23:24 +02:00
Andy Wingo
6c741a04ef Fix "fail" helper in guild compile
* module/scripts/compile.scm (fail): Users expect this to be a format
  string, so adapt.
  (compile): Fix use that passed multiple strings.
2020-05-11 11:14:30 +02:00
Andy Wingo
2e6f2feefc Fix baseline canonicalization of reifying prompts
* module/language/tree-il/compile-bytecode.scm (canonicalize): Fix arg
  order to make-prompt.
2020-05-11 11:05:06 +02:00
Andy Wingo
f9c9e71046 Fix compilation of prompt in tail context
* 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-11 10:57:29 +02:00
Andy Wingo
b99a63447b Fix kw initializer bug in baseline compiler
* module/language/tree-il/compile-bytecode.scm (compile-closure): The
  first sym has index 1, not 0, because of the closure.
2020-05-11 10:45:29 +02:00
Andy Wingo
dd4dc1f6c4 Use lookup, lookup-bound in baseline compiler
* 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-11 10:34:25 +02:00
Andy Wingo
85124b0d69 Top-level lookups raise exceptions in run-time
* 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-11 10:22:56 +02:00
Andy Wingo
4274d615cc Add new lookup, lookup-bound intrinsics
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS):
* libguile/intrinsics.c (lookup, lookup_bound):
* libguile/intrinsics.c (scm_bootstrap_intrinsics): New intrinsics.
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/effects-analysis.scm (current-module):
* module/language/cps/compile-bytecode.scm (compile-function):
* module/system/vm/assembler.scm: Add compiler support.
2020-05-11 10:22:34 +02:00
Andy Wingo
d6b6392cfb Rename "lookup" intrinsic to "module-variable"
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-11 09:46:40 +02:00
Andy Wingo
04e3cece45 Fix baseline compiler bugs
* module/language/tree-il/compile-bytecode.scm (compile-closure): Fix
  FP-relative computation for "receive" target.  Fix value-at syntax in
  conditional.
2020-05-09 22:23:00 +02:00
Andy Wingo
b5a52b4961 Wire up the baseline compiler to -O0
* module/language/tree-il/spec.scm (join): Use match rather than
  pmatch.
  (tree-il): Declare compiler to bytecode.
  (choose-compiler): New implementation.  Note, the baseline compiler
  probably doesn't even work!!!
2020-05-08 23:07:30 +02:00
Andy Wingo
f711ab85b2 Add compiler chooser implementation; fix bugs with previous commit
* module/system/base/compile.scm (next-pass): Invoke the language's
  compiler chooser if there is more than one compiler.
  (compute-compiler): Ensure from and to are languages.
* module/system/base/language.scm (<language>): Add compiler-chooser
  field.
* module/language/brainfuck/spec.scm (choose-compiler, brainfuck):
  Define a compiler chooser.
2020-05-08 22:56:37 +02:00
Andy Wingo
ded883b6f0 Sketch of how to choose different compiler based on -O0
* module/system/base/compile.scm (next-pass, compute-compiler): Allow
  optimization level to determine pass order.
2020-05-08 17:28:55 +02:00
Andy Wingo
4311dc9858 Define new "lowering" phase in compiler
* module/language/cps/compile-bytecode.scm (compile-bytecode):
* module/language/tree-il/compile-bytecode.scm (compile-bytecode):
* module/language/tree-il/compile-cps.scm (compile-cps): Rely on
  compiler to lower incoming term already.
* module/language/tree-il/optimize.scm (make-lowerer): New procedure.
* module/system/base/compile.scm (compute-lowerer): New procedure,
  replaceing add-default-optimizations.
  (compute-compiler): Lower before running compiler.
* module/system/base/language.scm (<language>): Change
  optimizations-for-level field to "lowerer".
* module/scripts/compile.scm (%options, compile): Parse -O0, -O1 and so
  on to #:optimization-level instead of expanding to all the
  optimization flags.
* module/language/cps/optimize.scm (lower-cps): Move here from
  compile-bytecode.scm.
  (make-cps-lowerer): New function.
* module/language/cps/spec.scm (cps): Declare lowerer.
2020-05-08 17:07:56 +02:00
Andy Wingo
e9c0f3071d Warning and optimization levels always small integers
* module/language/tree-il/analyze.scm (make-analyzer): Expect an int for
  optimization level.
* module/scripts/compile.scm (%options, show-warning-help): No more
  -Wnone / Wall; use -W0 or -W9 instead.
* module/system/base/compile.scm (level-validator): Validate small int.
  (compute-analyzer, add-default-optimizations): Likewise.
* test-suite/tests/optargs.test (without-compiler-warnings):
* test-suite/tests/tree-il.test (call-with-warnings): Parameterize level
  to 0, not #f.
* bootstrap/Makefile.am (GUILE_WARNINGS): Use -W0, not -Wnone.
2020-05-08 16:35:04 +02:00
Andy Wingo
220934c49d Wire up simplified warning levels in "guild compile"
* am/guilec (GUILE_WARNINGS):
* am/bootstrap.am (GUILE_WARNINGS): Explictly default to -W1.
* bootstrap/Makefile.am (GUILE_WARNINGS): Set to -Wnone, as the meaning
  of "no -W flags" has changed to be effectively -W1.
* module/scripts/compile.scm (%options): Adapt to parse -Wnone, -W2, and
  so on.
  (parse-args): Default to (default-warning-level).
  (show-warning-help): Add more warning help.
  (compile): Pass #:warning-level.
2020-05-08 16:03:32 +02:00
Andy Wingo
116f94d661 Add language-specific analysis pass to compiler infrastructure
* module/system/base/compile.scm (compute-analyzer): Compute analyzer to
  run on expressions before the compiler runs.
  (add-default-optimizations): Flesh out; still a stub.a
  (read-and-compile, compile, compile-and-load, compile-file): Default
  warning and optimization levels.
  (default-warning-level): New parameter, defaulting to 1.
  (default-optimization-level): New parameter, defaulting to 2.
  Currently unused.
* module/system/base/language.scm (<language>): Add
  optimizations-for-level and analyzer fields.
* module/language/tree-il/compile-bytecode.scm (compile-bytecode):
* module/language/tree-il/compile-cps.scm (optimize-tree-il): No need to
  run warnings passes here; compilers infrastructure will run them.
* module/language/tree-il/spec.scm (tree-il): Define make-analyzer as
  analyzer.
* module/language/tree-il/analyze.scm (make-analyzer): New exported
  procedure.
  (%warning-passes): New private variable.
* .dir-locals.el: Add with-test-prefix/c&e indent mode.
* test-suite/tests/cross-compilation.test:
* test-suite/tests/optargs.test:
* test-suite/tests/tree-il.test: Adjust to disable default warnings.
2020-05-08 15:39:41 +02:00
Andy Wingo
c8c19f2ef3 Add #:optimization-level, #:warning-level compile keyword args
* module/system/base/compile.scm (compile-file, compile-and-load)
  (read-and-compile, compile): New #:optimization-level, #:warning-level
  keyword args.
  (compute-analyzer, add-default-optimizations, compute-compiler): Add
  infra for pass-specific optimizations for a level.  Not yet wired up.
2020-05-08 12:17:30 +02:00
Andy Wingo
52f308e272 Rework compile-fold
Instead of returning a list of passes, returns a closure that does it
all.

* module/system/base/compile.scm (compute-compiler): New function.
  (read-and-compile, compile): Use compile-compiler.
2020-05-08 11:49:01 +02:00
Andy Wingo
6bb996ec66 Use more `match' in (system base compile)
* module/system/base/compile.scm (validate-options): New helper.
  (compile-file, compile-and-load, compile): Call the new helper.
  (compile-passes, compile-fold, find-language-joint):
  (default-language-joiner, decompile-passes, decompile-fold): Use more
  "match".
2020-05-08 10:12:33 +02:00
Andy Wingo
cdb9030f45 Slight (system base compile) refactor
* module/system/base/compile.scm (call-once): Use when instead of if.
2020-05-07 21:22:26 +02:00
Andy Wingo
f38735ffc6 Remove compilation order cache
* module/system/base/language.scm (define-language): Remove
  invalidate-compilation-cache! call.
  (invalidate-compilation-cache!): Deprecate.
  (*decompilation-cache*, *compilation-cache*): Remove.
  (lookup-compilation-order, lookup-decompilation-order): Don't use a
  cache.
  (*current-language*): Only define this when deprecation is enabled.
2020-05-07 21:16:13 +02:00
Andy Wingo
457bc9f1d3 Update (system base compile) header
* module/system/base/compile.scm (system): Clean up imports.
2020-05-05 22:15:46 +02:00
Andy Wingo
728de16911 Fix prompt compilation
* module/language/tree-il/compile-bytecode.scm (compile-closure): Fix
  emit-prompt invocation.
2020-05-04 22:56:23 +02:00
Andy Wingo
7a1b7bc485 Fix baseline compilation of let-values and prompt
* module/language/tree-il/compile-bytecode.scm (compile-closure): Fix
  fold invocation for visit-values-handler.
2020-05-04 22:37:49 +02:00
Andy Wingo
cfdaf35d73 Fix baseline compilation of conditionals
* module/language/tree-il/compile-bytecode.scm (canonicalize): Don't add
  an extra false? around predicates.
  (compile-closure): Fix predicate comparison instructions.
2020-05-04 22:28:34 +02:00
Andy Wingo
6b2d56ce15 Avoid shuffle-down for tail calls
* module/language/tree-il/compile-bytecode.scm (compile-closure): We can
  emit the precise move sequence and just do a reset-frame once, so go
  ahead and do that.
2020-05-04 21:58:10 +02:00
Andy Wingo
f0a9e537a0 Debugging names in baseline compiler; emit/immediate? fixes
* module/language/tree-il/compile-bytecode.scm (compile-closure):
  Provide names for locals, including the closure.  Fix emission of
  primitives with immediate args.
2020-05-04 16:20:06 +02:00
Andy Wingo
121ab14439 Add baseline compiler
* module/language/tree-il/compile-bytecode.scm: New file.
* module/Makefile.am (SOURCES):
* am/bootstrap.am (SOURCES): Add new file.
2020-05-04 15:23:04 +02:00
Andy Wingo
564f700771 Export emit-shuffle-down for baseline compiler
* module/system/vm/assembler.scm (emit-shuffle-down): Export.
2020-05-04 15:23:04 +02:00
Andy Wingo
3e90196729 Remove unused (language tree-il canonicalize)
* module/language/tree-il/canonicalize.scm: Remove.
* module/Makefile.am (SOURCES):
* am/bootstrap.am (SOURCES): Update.
2020-05-04 10:57:15 +02:00