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

3884 commits

Author SHA1 Message Date
Andy Wingo
72c3107539 Remove thunk?, integer? simple predicate inferrers
* module/language/cps/types.scm (thunk?, integer?): Remove predicates;
  they were inferring incorrectly.  I don't think they were being used
  though (these primcalls don't reach here).
2017-11-24 10:37:48 +01:00
Andy Wingo
6866cbd676 Add support for bignum? CPS primitive.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/primitives.scm (*heap-type-predicates*): Add
  support for bignum? CPS primitive.
2017-11-24 10:37:46 +01:00
Andy Wingo
bd2c690901 intmap-remove returns empty-intmap if appropriate
* module/language/cps/intmap.scm (intmap-remove): Return empty-intmap if
  the result is indeed empty.
2017-11-24 10:37:44 +01:00
Andy Wingo
a3173d1758 DCE eliminates effect-free branches to the same continuation
* module/language/cps/dce.scm (compute-live-code): Eliminate some
  branches.
2017-11-24 10:37:04 +01:00
Andy Wingo
b2dc53a3e2 Fix type check elision for branches
* module/language/cps/type-checks.scm (elide-type-checks): Fix bug where
  we were matching against a list instead of a record.  Doh!
2017-11-24 10:36:14 +01:00
Andy Wingo
700ec791e7 Minor compile-cps refactor
* module/language/tree-il/compile-cps.scm (canonicalize): Refactor to
  make with-lexicals helper available to the whole function.
2017-11-24 10:30:28 +01:00
Andy Wingo
2f2e31e73e Remove effects-analysis exports that were undefined
* module/language/cps/effects-analysis.scm (exclude-effects)
  (effect-free?, constant?): Remove undefined exports.
2017-11-24 10:28:57 +01:00
Andy Wingo
73a636e08c Specialize fixnum and s64 phis
* module/language/cps/specialize-numbers.scm
  (compute-specializable-fixnum-vars, compute-specializable-s64-vars):
* module/language/cps/specialize-numbers.scm (compute-specializable-phis):
  (apply-specialization): Re-enable specialization of fixnum phis and
  also s64 phis.
2017-11-24 10:28:27 +01:00
Andy Wingo
aa22f1f677 Fix unboxed immediate range comparison type inference
* module/language/cps/types.scm (imm-u64-<, imm-s64-<): Fix minimum
  computations.
2017-11-24 10:25:13 +01:00
Andy Wingo
908d5ea169 Fix logand type inference
* module/language/cps/types.scm (logand): We were computing the wrong
  ranges when either argument was negative; a terrible bug!
  (logsub): Also fix range when A is negative and B is non-negative.
  (ulogand): Tighten up range.
2017-11-24 10:18:49 +01:00
Matt Wette
bb5d316b16 foreign: Add 'uintptr_t' and 'intptr_t'.
* libguile/foreign.c (scm_uintptr_t, scm_intptr_t): New variables.
(scm_init_foreign): Define them.
* module/system/foreign.scm: Export 'intptr_t' and 'uintptr_t'.
* doc/ref/api-foreign.texi (Foreign Types): Document them.

Co-authored-by: Ludovic Courtès <ludo@gnu.org>
2017-11-22 16:33:57 +01:00
Maxim Cournoyer
3e7c80a62f scripts: help: Fix reference to the "Using Guile Tools" node.
Fixes <https://bugs.gnu.org/28835>.

* module/scripts/help.scm (list-commands): Fix reference to the "Using
Guile Tools" node.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
2017-11-22 16:21:59 +01:00
Ludovic Courtès
83d4c4d622 Honor '%fresh-auto-compile'.
Fixes <https://bugs.gnu.org/29226>.

* libguile/load.c (scm_primitive_load_path): Set 'compiled_thunk' to
SCM_BOOL_F when *scm_loc_fresh_auto_compile is true.
* module/ice-9/boot-9.scm (load-in-vicinity)[load-absolute]: Call
'pre-compiled' only when %FRESH-AUTO-COMPILE is false.
2017-11-22 16:04:24 +01:00
Andy Wingo
5c38643fc6 Revert "Slot allocation allows s64/u64 representations of same var"
This reverts commit a88614fb17.
2017-11-20 20:03:07 +01:00
Andy Wingo
c22e61a7ff Fix u64/s64 typesafety around fixnum (un)tagging
* module/language/cps/type-fold.scm (u64->scm, scm->u64): Fix
  type-safety by adding casts.
* module/language/tree-il/compile-cps.scm (convert, canonicalize):
  Simplify rsh and lsh compilation by not trying to avoid scm->u64 in
  the early stages of the compiler.
2017-11-20 20:03:07 +01:00
Andy Wingo
072188618a Separate u64 and s64 type inferrers now that ops are monomorphic
* module/language/cps/types.scm: Remove some more needless type checker
  definitions.
  (u64-imm-=, u64-imm-<, imm-u64-<): Separate from the s64 definitions.
  (s64-imm-=, s64-imm-<, imm-s64-<): New definitions.
2017-11-20 18:36:00 +01:00
Andy Wingo
a48735f56c Fix s64->scm reducer
* module/language/cps/type-fold.scm (s64->scm): Fix reducer.
2017-11-20 18:36:00 +01:00
Andy Wingo
b0081accb6 Specialize-numbers reifies instructions that type-check
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Before, this pass would reify e.g. uadd for an addition of s64 values
  if it could prove that the result would be within the s64 range.  But
  this is really confusing if later we want to do range analysis over
  the result.  Additionally it would sometimes reify diamond control
  patterns that weren't really amenable to CSE.  So instead we now reify
  instructions that can pass type checks, like "sadd" instead of
  "uadd".
2017-11-20 18:36:00 +01:00
Andy Wingo
5fbd4b8f9e Better support for unboxed signed arithmetic
* module/language/cps/primitives.scm (*macro-instruction-arities*):
  Declare new u64->s64, s64->u64, sadd, ssub, smul, sadd/immediate,
  ssub/immediate, smul/immediate, slsh, and slsh/immediate primcalls
  that don't have corresponding VM instructions.
* module/language/cps/effects-analysis.scm: The new instructions are
  effect-free.
* module/language/cps/reify-primitives.scm (wrap-unary, wrap-binary):
  (wrap-binary/exp, reify-primitives): Add horrible code that turns
  e.g. sadd into a series of s64->u64, uadd, and then u64->s64.  This
  way we keep our ability to do range inference on unboxed signed
  arithmetic, but we still bottom out to the same instructions for both
  unboxed signed and unboxed unsigned arithmetic.
* module/language/cps/types.scm: Add type inferrers for new
  instructions.  Remove type checkers for some effect-free primitives.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  pseudo-emitter for u64->s64 and s64->u64 no-ops.
2017-11-20 18:36:00 +01:00
Andy Wingo
83c04003a2 Revert specialization of fixnum phi variables
* module/language/cps/specialize-numbers.scm
  (compute-specializable-fixnum-vars, compute-specializable-phis)
  (apply-specialization): Don't specialize phis as fixnums.  Need to try
  again with some proper range analysis, as a variable defined with
  tag-fixnum can indicate either a u64 or a s64.
2017-11-20 18:35:56 +01:00
Andy Wingo
8ce6f359bb ursh, ursh/immediate, etc only residualized if count < 64
* module/language/cps/reify-primitives.scm (reify-primitives): Remove
  cases for ursh/immediate etc, as these should all be within range, by
  construction.
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Only reify ursh/immediate, etc if the shift count is less than 64.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Remove specialization cases for ursh/immediate etc; this is the domain
  of specialize-numbers.
* module/language/cps/types.scm (ursh, srsh, ulsh): Limit arguments to
  be less than 63.
  (ulsh/immediate): Assume parameter is in range.
2017-11-15 19:57:36 +01:00
Andy Wingo
0951551fb4 Compiler specializes comparisons to immediate integers
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm (load-const/unlikely):
* module/language/cps/types.scm (load-const/unlikely):
* module/language/cps/primitives.scm (*macro-instruction-arities*): Add
  new primcall, load-const/unlikely.
* module/language/cps/specialize-numbers.scm: Rework comparison
  specialization.  Add support for specializing comparisons against
  integer immediates.
2017-11-15 14:19:09 +01:00
Andy Wingo
294dbaad35 Add support for comparisons against integer immediates
* libguile/vm-engine.c (s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?)
  (imm-s64<?): New instructions.
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add new
  X8_S12_Z12 word type used by the new S64/immediate instructions.  A
  Z12 is a 12-bit signed integer immediate.
* module/system/vm/assembler.scm: Export new instructions, and add
  X8_S12_Z12 support.  Also, add missing shufflers for X8_S12_C12.
* module/language/bytecode.scm (compute-instruction-arity):
* module/system/vm/disassembler.scm (unpack-s12, disassembler): Add
  support for X8_S12_Z12.
* module/language/cps/types.scm (define-predicate-inferrer/param): New
  helper.
  (u64-=, u64-<, s64-<): Remove type checkers; this procedure does not
  cause &type-check.
  (u64-imm=?, s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?, imm-s64<?):
  New type inferrers.
* module/language/cps/type-fold.scm (define-unary-branch-folder*): New
  helper.
  (u64-imm=?, s64-imm=?, u64-imm<?, imm-u64<?, s64-imm<?, imm-s64<?):
  New branch folders.
* module/language/cps/reify-primitives.scm (reify-primitives): Reify
  constants for new immediate branching primcalls if values out of
  range.
* module/language/cps/effects-analysis.scm: Add support for new
  primcalls.
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for new primcalls and instructions.  Compile u64-imm-= to
  s64-imm=?.
2017-11-15 14:18:39 +01:00
Andy Wingo
4a0a930f1c Don't fold comparisons that might contain a NaN.
* module/language/cps/type-fold.scm (compare-integer-ranges): Rename
  from compare-ranges, as we can't compare ranges that might include a
  NaN.
  (<, =): Update uses.
2017-11-14 10:40:02 +01:00
Andy Wingo
7e79a3291e Better untagging of fixnums
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for tag-fixnum/unlikely.
* module/language/cps/cse.scm (compute-equivalent-subexpressions): Add
  equivalent subexpressions for tag-fixnum.
* module/language/cps/effects-analysis.scm:
* module/language/cps/primitives.scm (*macro-instruction-arities*): Add
  tag-fixnum/unlikely.
* module/language/cps/specialize-numbers.scm (specialize-u64-unop)
  (specialize-u64-binop, specialize-u64-shift)
  (specialize-u64-comparison): Make the arg unboxers and result boxers
  into keyword arguments.
  (specialize-s64-unop): New helper.
  (specialize-fixnum-comparison, specialize-fixnum-scm-comparison)
  (specialize-scm-fixnum-comparison): Rename from
  specialize-s64-comparison et al.  Perhaps this should be expanded
  again to include the whole s64 range, once we start to expand scm->s64
  et al.
  (specialize-operations): Specialize arithmetic, etc on signed
  operands and results.  Use less powerful unboxing/boxing ops if
  possible -- e.g. tag-fixnum instead of u64->scm.  Prefer fixnum
  comparisons over u64 comparisons.
  (compute-specializable-fixnum-vars): New helper.
  (compute-specializable-phis): Specialize fixnum phis as well.
  (specialize-primcalls): Specialize untag-fixnum of a constant to
  load-s64.
* module/language/cps/type-fold.scm (u64->scm, s64->scm):
  (scm->s64, scm->u64): Reduce to fixnum ops where possible.
* module/language/cps/types.scm: Remove type checkers for ops that don't
  throw type errors.  Alias tag-fixnum/unlikely to tag-fixnum.
2017-11-13 14:39:30 +01:00
Andy Wingo
dae0004627 Better range inference
* module/language/cps/types.scm (&fx32-min, &fx32-max, &fx64-min)
  (&fx64-max): New internal definitions.
* module/language/cps/types.scm (type-entry-saturating-union): Add more
  stops as we saturate ranges towards infinity.
2017-11-13 14:32:53 +01:00
Andy Wingo
a88614fb17 Slot allocation allows s64/u64 representations of same var
* module/language/cps/slot-allocation.scm (compute-var-representations):
  If an optimization pass decided to e.g. use untag-fixnum for one
  definition of a variable and e.g. vector-length for the other, assume
  that their values are compatible.  We don't know at this point whether
  the values are meant to be s64 (e.g. because vector-length is a subset
  of the s64 range) or u64 (e.g. because although we're calling
  untag-fixnum on the value, actually we now that the value is
  non-negative, or actually we just want the unsigned bits).  Anyway we
  default to u64.  In the future we can perhasps be more precise.
2017-11-13 10:34:29 +01:00
Andy Wingo
b97321dbfd Add srsh, srsh/immediate instructions
* libguile/vm-engine.c (srsh, srsh/immediate): New instructions.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/reify-primitives.scm (reify-primitives):
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
* module/language/cps/types.scm (srsh, srsh/immediate):
* module/system/vm/assembler.scm: Add support for new instructions.

* module/language/cps/types.scm (ulsh, ursh): Remove type checkers, as
  these are effect-free.  Limit range of ursh count.
2017-11-13 10:25:20 +01:00
Andy Wingo
83a03a324b Specialize rsh/lsh, not ash
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Replace "ash" specializer with "rsh"/"lsh" specializer.
2017-11-11 22:08:22 +01:00
Andy Wingo
107f70a633 Add missing lsh/immediate, rsh/immediate type inferrers
* module/language/cps/types.scm (lsh/immediate, rsh/immediate): Add
  missing type inferrers.
2017-11-11 22:08:22 +01:00
Andy Wingo
e8226be0c0 Type folding has "macro reduction" phase
* module/language/cps/type-fold.scm (*primcall-macro-reducers*):
  (define-primcall-macro-reducer, define-unary-primcall-macro-reducer):
  (define-binary-primcall-macro-reducer): New facility, for reductions
  on which reductions should run.  Define macro reducers for mul, lsh,
  and rsh.  Move mul reducer to be a mul/immediate reducer.
  (logbit?): Use target fixnum range.
  (local-type-fold): Adapt to call macro reducers first.
* module/language/cps/reify-primitives.scm (reify-primitives): Reify
  mul/immediate back to mul.
2017-11-11 22:08:14 +01:00
Andy Wingo
b331ea3193 Convert "ash" to "lsh"/"rsh" when lowering to CPS
* module/language/cps/effects-analysis.scm: Remove case for "ash".
* module/language/cps/types.scm (ash): Remove.
* module/language/tree-il/compile-cps.scm (convert, canonicalize):
  Convert "ash" to "lsh"/"rsh" early on.
* module/system/base/target.scm (target-fixnum?): New procedure.
2017-11-11 22:08:14 +01:00
Andy Wingo
a268c02fa0 Compiler uses target fixnum range
* module/system/base/target.scm (target-most-negative-fixnum):
  (target-most-positive-fixnum): New definitions.
* module/language/cps/types.scm (constant-type, define-exact-integer!)
  (&min/fixnum, &max/fixnum): Use new definitions.
  (&max/vector): Use target-max-vector-length.
2017-11-11 22:08:14 +01:00
Andy Wingo
8b5f9648ff Add tag-fixnum instruction
* libguile/vm-engine.c (tag-fixnum): New instruction.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm (&min/fixnum, &max/fixnum, tag-fixnum):
* module/system/vm/assembler.scm: Add support for the new instruction.
2017-11-11 22:08:14 +01:00
Andy Wingo
7bfdd46ea5 Use immediate primcalls when unfolding constructors
* module/language/cps/constructors.scm (inline-vector): Use immediate
  primcalls.
2017-11-11 22:08:14 +01:00
Andy Wingo
b27065fdf2 Closure conversion uses immediate variants of vector instructions
* module/language/cps/closure-conversion.scm (convert-one): Use
  immediate variants of vector instructions.
2017-11-11 22:08:14 +01:00
Andy Wingo
9da03136e5 Specialize comparisons to SCM as s64
* module/language/cps/specialize-numbers.scm (specialize-s64-comparison)
  (specialize-s64-scm-comparison, specialize-scm-s64-comparison): New
  helpers.
  (specialize-scm-u64-comparison, specialize-u64-scm-comparison):
  Remove.  Comparing SCM as s64 is better as fixnums are a subset of
  s64, not u64.
  (specialize-operations): Prefer s64 comparisons when we can't
  specialize both arguments; this at least inlines the fixnum case.
2017-11-11 22:08:14 +01:00
Andy Wingo
7a7f71de5c Canonicalize <=, >=, and > primcalls to <
* module/language/tree-il/compile-cps.scm (canonicalize): Convert <=,
  >=, and > primcalls to <.
* module/language/cps/primitives.scm (*comparisons*):
* module/language/cps/effects-analysis.scm: Remove superfluous
  primcalls.
* module/language/cps/specialize-numbers.scm
  (specialize-u64-scm-comparison): Only emit < primcalls for ordered
  comparisons.
  (specialize-scm-u64-comparison): New helper.
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Remove support for >=, <=, and the like.
* module/language/cps/type-fold.scm: Remove folders for <= and so on.
* module/language/cps/types.scm (define-=-inferrer, define-<-inferrer):
  New helpers; use them for all = and < variants.  Remove checkers and
  inferrers for <= and the like.
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  unnecessary cases.
2017-11-11 22:08:14 +01:00
Andy Wingo
8b3258716c Refactor numeric comparison bytecode emission
* module/language/cps/compile-bytecode.scm (compile-function): Refactor.
2017-11-11 22:08:14 +01:00
Andy Wingo
375eab5610 Fix effects analysis bug introduced with primcall param
* module/language/cps/effects-analysis.scm (primitive-effects): Fix
  swapped name and param.  Embarrassing!
2017-11-11 22:08:14 +01:00
Ludovic Courtès
6ad28ae3bc http: Fix typo in proxy handling in 'write-request-line'.
Reported by Mark H Weaver <mhw@netris.org>
at <https://lists.gnu.org/archive/html/guix-devel/2017-11/msg00190.html>.

* module/web/http.scm (write-request-line): Fix more typos introduced in
96b994b6f8.
2017-11-11 15:14:54 +01:00
Ludovic Courtès
7d0d9e2c25 http: Fix typo in proxy handling in 'write-request-line'.
Reported by Konrad Hinsen <konrad.hinsen@fastmail.net>
at <https://lists.gnu.org/archive/html/guix-devel/2017-11/msg00070.html>.

* module/web/http.scm (write-request-line): Move 'string-index' first in
'cond' clause.  Fixes a regression introduced in
96b994b6f8.
2017-11-10 22:54:49 +01:00
Ludovic Courtès
b322ac67d3 Print exception location only once.
Fixes a regression introduced in commit
39090e677e.

* module/ice-9/boot-9.scm (exception-printers)[print-exception]: Remove
extraneous 'print-location' call.
2017-11-09 21:56:39 +01:00
Ludovic Courtès
81d2e35266 Allow GDB support to be used with GDB-linked-against-Guile-2.0.
* libguile/Makefile.am (INSTANTIATE): New variable.
(install-data-hook): Use it.
* libguile/libguile-2.2-gdb.scm: Autoload (system vm debug).
Augment %load-path and %load-compiled-path, and reload (system base
types).
* module/system/base/types.scm: Remove #:hide to be 2.0-compatible.
Use (system syntax internal) conditionally when on 2.2.
2017-11-05 18:21:35 +01:00
Andy Wingo
f96a670332 Add new "throw" VM ops
* libguile/throw.h (scm_ithrow, scm_throw): Mark as SCM_NORETURN.
* libguile/throw.c (scm_throw, scm_ithrow): Adapt to not return.
* libguile/vm-engine.c (throw, throw/value, throw/value+data): New
  instructions.
* libguile/vm.c (vm_throw, vm_throw_with_value)
  (vm_throw_with_value_and_data): New helpers.
* module/language/cps/compile-bytecode.scm (compile-function): Add cases
  for new instructions.
* module/language/cps/prune-bailouts.scm (prune-bailouts): More simple,
  now that there are no $kreceives in play.
* module/language/cps/reify-primitives.scm (reify-clause): Update
  reification of no-clause functions to use new throw op.
* module/language/tree-il/compile-cps.scm (convert): Convert invocations
  of the variable-arity 'throw primitive from Tree-IL to the new
  fixed-arity CPS instructions.
* module/system/vm/assembler.scm (emit-throw/value*)
  (emit-throw/value+data*, emit-throw): Export new instructions.
* module/system/vm/disassembler.scm (code-annotation): Add annotation.
2017-11-05 15:00:16 +01:00
Andy Wingo
cf486700b7 error, scm-error primcalls expand to `throw'
* module/language/tree-il/primitives.scm (scm-error, error): Expand
  into `throw'.
* module/language/tree-il/peval.scm (peval): Reify "throw" for dynwind
  error.
* module/language/tree-il/compile-cps.scm (canonicalize): Reify "throw"
  for call-with-prompt error.
* module/language/cps/prune-bailouts.scm (prune-bailouts): Don't expect
  "error" or "scm-error" here.
2017-11-05 15:00:16 +01:00
Andy Wingo
17bd5a8938 Add lsh, rsh instructions
* libguile/vm-engine.c (lsh, rsh, lsh/immediate, rsh/immediate): New
  instructions taking unboxed bit counts.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/effects-analysis.scm:
* module/language/cps/specialize-numbers.scm (specialize-f64-unop):
  (specialize-u64-unop): Add ability to specialize add/immediate, etc,
  and add lsh/immediate as well.
  (specialize-u64-binop, specialize-u64-shift): Move rsh/lsh
  specialization to its own procedure, given that the bit count is
  already unboxed.
  (specialize-operations): Adapt to support more /immediate
  instructions.
* module/language/cps/type-fold.scm (mul): Reify an lsh/immediate
  instead of an ash.
* module/language/cps/types.scm (compute-ash-range): Add type inferrers
  for lsh, rsh, and their immediate variants.
* module/system/vm/assembler.scm: Export emit-lsh and so on.
* module/language/tree-il/compile-cps.scm (convert): Convert "ash" on
  immediates to rsh/immediate or lsh/immediate.
2017-11-05 15:00:16 +01:00
Andy Wingo
dea84a46b4 Earlier conversion to /imm primcalls
* module/language/tree-il/compile-cps.scm (convert): Convert to /imm
  variants of primcalls early on, to decrease complexity of later
  passes.
2017-11-05 15:00:16 +01:00
Andy Wingo
5457f28af9 Specialize primcalls more aggressively
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Don't restrict /imm params to encodeable immediates; specialize any
  imm.  Rely on reify-primitives to undo the transformation if needed.
2017-11-05 15:00:16 +01:00
Andy Wingo
ecff426b89 (system base types) uses target's idea of max size_t
* module/system/base/target.scm (target-max-size-t):
  (target-max-size-t/scm, target-max-vector-length): New public
  functions.
* module/language/cps/types.scm (type-entry-saturating-union): Remove
  restriction of polymorphic types to be within max-size-t; this could
  incorrectly apply constraints on numeric values.
  (&max/size, &max/scm-size): Use target-max-size-t.
  (*max-size-t*): Remove; replace uses with (target-max-size-t).
2017-11-05 15:00:16 +01:00