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

539 commits

Author SHA1 Message Date
Ludovic Courtès
c6f70e4b04 Add -Wshadowed-toplevel.
* module/language/tree-il/analyze.scm (shadowed-toplevel-analysis): New
variable.
* module/language/tree-il/compile-cps.scm (%warning-passes): Add it.
* module/system/base/message.scm (%warning-types): Add it.
* test-suite/tests/tree-il.test ("warnings")["shadowed-toplevel"]: New
test prefix.
* module/ice-9/boot-9.scm (%auto-compilation-options): Add it.
* doc/ref/api-evaluation.texi (Compilation): Add 'shadowed-toplevel' and
'macro-use-before-definition'.
2018-08-07 12:34:32 +02:00
Mark H Weaver
6708acbf66 Fix eta-conversion edge cases in peval.
Fixes <https://bugs.gnu.org/29520>.
Reported by Stefan Israelsson Tampe <stefan.itampe@gmail.com>.

* module/language/tree-il/peval.scm (peval)[lift-applied-lambda]: Before
performing eta-conversion, check that the variable(s) passed to the
inner 'apply' are not referenced from the inner lambda, and that the
number of required arguments would not be reduced by the conversion.
2018-08-07 11:40:54 +02:00
Andy Wingo
76eac85084 Use intrinsics for top-level refs outside captured scopes
* module/language/tree-il/compile-cps.scm (toplevel-box): Reify
  intrinsic calls for top-level references outside captured scopes.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Update set of macro-instructions.
2018-05-14 16:25:50 +02:00
Andy Wingo
ceffb5e990 Compile "define!" via intrinsic
* libguile/intrinsics.c (scm_bootstrap_intrinsics):
* libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): Add new define!
  intrinsic.
* module/language/cps/compile-bytecode.scm (compile-function): Adapt
  compilation for define! to take two arguments.
* module/language/cps/effects-analysis.scm (current-module): Update
  define! for two arguments.
* module/language/tree-il/compile-cps.scm (convert): When reifying
  "define", grab the current module.
* module/system/vm/assembler.scm (define!): Define assembler as
  intrinsic.
2018-05-14 15:15:22 +02:00
Andy Wingo
dff85f6f9f Explode atomic box ops to new atomic instructions
* libguile/instructions.c (FOR_EACH_INSTRUCTION_WORD_TYPE): Add C8_S24
  word type.
* libguile/vm-engine.c (UNPACK_8_24): New helper.
  (atomic-scm-ref/immediate, atomic-scm-set!/immediate)
  (atomic-swap-scm!/immediate, atomic-scm-compare-and-swap!/immediate):
  New instructions.
  (make-atomic-box, atomic-box-ref, atomic-box-set!, atomic-box-swap!)
  (atomic-box-compare-and-swap!): Disable these ops.
* module/language/bytecode.scm (compute-instruction-arity): Add C8_S24
  support.
* module/system/vm/assembler.scm: Add C8_S24 support.  Export assemblers
  for new opcodes.
* module/system/vm/disassembler.scm (disassembler): Support C8_S24.
* module/language/cps/compile-bytecode.scm (compile-function): Replace
  old atomic-box assemblers with the new instructions.
* module/language/cps/effects-analysis.scm (annotation->memory-kind):
* module/language/cps/types.scm (annotation->type): Add cases for atomic
  boxes.  Mark as all memory kinds because atomic ops serialize memory
  accesses.
* module/language/tree-il/compile-cps.scm (make-atomic-box):
  (ensure-atomic-box, atomic-box-ref, atomic-box-set!):
  (atomic-box-swap!, atomic-box-compare-and-swap!): Explode these ops to
  more basic instructions.
* module/system/base/types/internal.scm (%tc7-atomic-box): Add forgotten
  export.
2018-04-13 10:09:56 +02:00
Andy Wingo
3047bcaefb Remove dead code in CPS converter
* module/language/tree-il/compile-cps.scm: Remove dead primcall
  expanders.
2018-04-10 14:10:03 +02:00
Andy Wingo
21d5897b4c Instruction explosion for char->integer
* module/language/cps/effects-analysis.scm:
* module/language/cps/slot-allocation.scm (compute-var-representations):
* module/language/cps/types.scm:
* module/language/cps/compile-bytecode.scm (compile-function): Remove
  char->integer cases.
* module/system/vm/assembler.scm: Remove emit-char->integer export.
* module/language/tree-il/compile-cps.scm (char->integer): Define
  instruction exploder.
2018-04-10 13:45:33 +02:00
Andy Wingo
880d68ea22 Instruction explosion for integer->char
* module/language/tree-il/compile-cps.scm (integer->char): Instruction
  explosion!
2018-04-10 13:22:59 +02:00
Andy Wingo
2964abad05 Explode "string-set!"
* module/language/cps/effects-analysis.scm (string-ref): Remove effects
  declaration, given that the primitive is exploded now.
* module/language/cps/reify-primitives.scm (compute-known-primitives):
  Add string-set!.
* libguile/vm-engine.c (string-set!): Disable opcode.
* module/language/cps/types.scm (string-ref, string-set!): Remove type
  checker and inferrers for string-ref and string-set!, as both are
  exploded.  In the case of string-set! there are still type-check
  effects in the intrinsic call but they can't be elided by the checker,
  as we don't track when strings are read-only.
* module/language/tree-il/compile-cps.scm (ensure-char): New helper.
  (string-set!): New primcall exploded converter.
2018-04-10 12:14:47 +02:00
Andy Wingo
7a109dddd7 Lower string-ref in CPS conversion
* module/language/cps/effects-analysis.scm (annotation->memory-kind):
* module/language/cps/types.scm (annotation->type): Hackily consider
  stringbuf memory to be string memory.
* module/language/tree-il/compile-cps.scm (string-ref): Add horrible
  lowering conversion for string-ref.
2018-04-09 10:13:09 +02:00
Andy Wingo
39fb7e540b CPS conversion lowers string-length
* module/language/cps/types.scm (annotation->type):
* module/language/cps/effects-analysis.scm (annotation->memory-kind):
  Add case for string memory kinds.  Remove special type and effect
  inferrers for string-length.
* module/language/cps/slot-allocation.scm (compute-var-representations):
  Remove string-length.
* module/language/tree-il/compile-cps.scm (ensure-string): New helper.
  (string-length): Add custom converter.
2018-04-08 10:27:52 +02:00
Andy Wingo
dd203e5d7d Remove optimizer and backend support for struct ops
* module/language/cps/compile-bytecode.scm:
* module/language/cps/cse.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/types.scm:
* module/language/tree-il/cps-primitives.scm:
* module/system/vm/assembler.scm: Remove support for struct-ref,
  struct-set!, allocate-struct, struct-vtable CPS primcalls and bytecode
  instructions.
2018-01-22 07:51:08 +01:00
Andy Wingo
91bf9b1db3 Lower "make-struct/simple" to CPS
* module/language/tree-il/cps-primitives.scm (struct-init!): Add
  primitive, just used in internal translations.
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  (*primitive-constructors*): Recognize "make-struct/simple" instead of
  allocate-struct.
* module/language/tree-il/compile-cps.scm (ensure-vtable): New helper.
  (allocate-struct, struct-init!): New lowerers.
  (convert): Add struct-init! case.
  (canonicalize): Convert make-struct/simple like vector.
2018-01-22 07:28:11 +01:00
Andy Wingo
557acdbbba Instruction explosion for struct-ref, struct-set!
* module/language/cps/effects-analysis.scm (&memory-kind-mask): Add
  &bitmask, for the bitmask in vtables.
  (annotation->memory-kind): Add 'bitmask case.
* module/language/tree-il/compile-cps.scm (ensure-struct-index-in-range):
  (prepare-struct-scm-access): New helpers.
  (struct-ref/immediate, struct-set!/immediate): New exploded lowering
  routines.
  (struct-ref, struct-set!): New lowering routines that just do a call.
  (canonicalize): Remove struct-ref hack; lowering procedures will
  handle it.
* module/language/tree-il/cps-primitives.scm (bytevector-length): Define
  struct-set! as returning a value.
2018-01-19 21:57:03 +01:00
Andy Wingo
42837e9108 Instruction explosion for bv-length
* module/language/tree-il/compile-cps.scm (ensure-vector):
  (prepare-bytevector-access): Add assumptions on lengths.
  (bv-length): New lowerer.
2018-01-16 16:43:10 +01:00
Andy Wingo
94fdc5cad9 Instruction explosion for bytevector setters
* module/language/cps/compile-bytecode.scm (compile-function): Fix
  emitters for u64-set! et al.
* module/language/tree-il/compile-cps.scm (bytevector-set-converter):
  New helper.  Lower bytevector setters to pointer ops.
2018-01-16 10:05:03 +01:00
Andy Wingo
1b955b01c3 Add f32-ref, f64-ref lowering procs
* module/language/tree-il/compile-cps.scm (bytevector-ref-converter):
  Take kind as tag, not boolean.  Support floats.  Adapt and add
  lowerers for float-ref procedures.
2018-01-15 20:51:00 +01:00
Andy Wingo
0270d235bd Instruction explosion for integer bytevector ref procedures
* module/language/cps/compile-bytecode.scm (compile-function): Fix
  emitters for u16-ref et al.
* module/language/tree-il/compile-cps.scm (bytevector-ref-converter):
  (define-bytevector-ref-converter, define-bytevector-ref-converters):
  New helpers.  Use to define lowerers for bv-s32-ref et al.
2018-01-15 20:25:53 +01:00
Andy Wingo
535d6fad80 Custom bv-u8-ref lowering procedure
* module/language/tree-il/compile-cps.scm (untag-bytevector-index):
  (ensure-bytevector, prepare-bytevector-access): New helpers.
  (bv-u8-ref): New lowerer.
* module/language/cps/types.scm (annotation->type):
* module/language/cps/effects-analysis.scm (annotation->memory-kind):
  Support bytevectors.
2018-01-14 14:38:35 +01:00
Andy Wingo
c7b3379a4c Instruction explosion for struct-vtable
* module/language/tree-il/compile-cps.scm (ensure-struct): New helper.xo
  (struct-vtable): New lowering procedure.
* module/language/cps/types.scm (annotation->type): Add struct.
  (scm-ref/tag, scm-set!/tag): Fix to get type from annotation.
* module/language/cps/effects-analysis.scm (annotation->memory-kind):
  Add struct.
2018-01-10 19:47:58 +01:00
Andy Wingo
24f998e4d2 Lower box, box-ref, box-set! primcalls
* module/language/tree-il/compile-cps.scm (box, ensure-box):
  (box-ref, box-set!): Lower box primcalls.
* module/language/cps/compile-bytecode.scm (compile-function):
* module/language/cps/cse.scm (compute-equivalent-subexpressions):
* module/language/cps/dce.scm (compute-live-code):
* module/language/cps/effects-analysis.scm:
* module/language/cps/types.scm: Remove special support for boxes.  What
  a pleasure!
2018-01-10 07:59:21 +01:00
Andy Wingo
55a8483435 Improve make-vector compilation for known big sizes
* module/language/tree-il/compile-cps.scm
  (emit-initializations-as-loop): New helper.
  (make-vector): Use new helper.
  (make-vector/immediate): Emit a loop if the number of words is greater
  than or equal to 32.  An arbitrary limit that could be adjusted later.
2018-01-07 23:07:12 +01:00
Andy Wingo
5e1109a97f Better compilation of vector constructors and initializers
* module/language/tree-il/cps-primitives.scm (allocate-vector)
  (vector-init!): Declare these primitives which later go away when
  lowering to CPS.
* module/language/tree-il/compile-cps.scm (vector-init!): New
  converter.
  (allocate-vector): New converter.
2018-01-07 22:51:17 +01:00
Andy Wingo
49fa4980bb Expand pair-related primcalls
* module/language/tree-il/compile-cps.scm (ensure-pair): New helper.
  (cons, car, cdr, set-car!, set-cdr!): New expanders.
* module/language/cps/closure-conversion.scm (convert-one):
* module/language/cps/contification.scm (apply-contification): Emit
  lower-level instructions for making pairs.
2018-01-07 18:44:48 +01:00
Andy Wingo
9a1d2d8ec8 Minor compile-cps refactor for cons
* module/language/tree-il/compile-cps.scm (build-list): Pass cons
  through an expander.
2018-01-07 17:57:45 +01:00
Andy Wingo
ee84af1311 Compiler frontend support for vector mutability checks
* module/language/tree-il/compile-cps.scm (ensure-vector):
  (prepare-vector-access, prepare-vector-access/immediate):
  (vector-length, vector-ref, vector-ref/immediate):
  (vector-set!, vector-set!/immediate): Use mutable-vector? predicate
  for write access.
2018-01-07 17:38:40 +01:00
Andy Wingo
3cedc108d8 Add CPS compilation support for mutable-vector?
* module/system/base/types/internal.scm (heap-tags): Add
  immutable-vector? and mutable-vector?.
* module/language/tree-il/cps-primitives.scm:
* module/system/vm/disassembler.scm: Bump copyright lines.
2018-01-07 16:41:40 +01:00
Andy Wingo
f488bc53e7 Instruction explosion for /immediate variants of vector prims
* module/language/tree-il/compile-cps.scm
  (prepare-vector-access/immediate): New helper.
* module/language/tree-il/compile-cps.scm (vector-ref/immediate):
  (vector-set!/immediate, make-vector/immediate): New expanders.
2018-01-07 15:42:39 +01:00
Andy Wingo
c766a883d3 Instruction explosion for make-vector
* module/language/tree-il/compile-cps.scm (untag-fixnum-in-imm-range):
  New helper.
  (make-vector): New custom expander.  Gnarly; to refactor.
2018-01-07 15:42:39 +01:00
Andy Wingo
7486806ba3 Improve compilation of make-vector without init
* module/language/tree-il/primitives.scm (*primitive-expand-table*): Add
  expansion for one-argument make-vector.
2018-01-05 15:18:16 +01:00
Andy Wingo
a821042480 Allow peval to gnaw on string->symbol, symbol->string
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  (*effect-free-primitives*): Add string->symbol and symbol->string.
2018-01-05 15:17:46 +01:00
Andy Wingo
6fdbd3b17b Instruction explosion for vector-{length,ref,set!}
* module/language/tree-il/compile-cps.scm (ensure-vector)
  (untag-fixnum-index-in-range, compute-vector-access-pos)
  (prepare-vector-access): New helpers.
  (vector-length, vector-ref, vector-set!): New expanders.
2018-01-05 14:42:40 +01:00
Andy Wingo
51fd5952cb Disable resolve-primitives pass below -O2
* module/language/tree-il/optimize.scm (optimize): Disable
  resolve-primitives below -O2.  This is because compile-cps is going to
  start expanding all primcalls it sees.
2018-01-05 10:40:03 +01:00
Andy Wingo
16db934bbc Add (system base optimize) module
* module/system/base/optimize.scm: New module.
* module/Makefile.am (SOURCES):
* am/bootstrap.am (SOURCES): Add new module.
* module/language/tree-il/optimize.scm (tree-il-optimizations): Rename
  from tree-il-default-optimization-options.  Directly specify the
  optimization level at which a pass should be enabled.
* module/language/cps/optimize.scm (cps-optimizations): Likewise, rename
  from cps-default-optimization-options.
* module/scripts/compile.scm (%options, show-optimization-help): Adapt
  to use new module.
2018-01-05 10:19:54 +01:00
Andy Wingo
ad55ee83c3 $throw is a new kind of CPS term
* module/language/cps.scm ($throw): New term type that doesn't have a
  continuation.  Adapt all callers.  Remove now-unneeded
  "prune-bailouts" pass.
2018-01-03 21:25:55 +01:00
Andy Wingo
ee15ca1455 $prompt is now its own kind of CPS term.
* module/language/cps.scm ($prompt): Rework to be its own term kind.
  Now $continue always continues to a single continuation.  Adapt
  callers.
2018-01-03 17:32:43 +01:00
Andy Wingo
afb0a92d50 $branch is now a distinct CPS term type
* module/language/cps.scm ($branch): Refactor to be its own CPS term
  type, not relying on $continue to specify a continuation (which before
  was only for the false case) or a source location.  Update allllllll
  callers.
2018-01-03 16:16:39 +01:00
Andy Wingo
108ade6b0e Re-add support for logbit?
* module/language/cps/type-fold.scm (logbit?): Adapt for logbit?
  continuing to $kargs.
* module/language/tree-il/cps-primitives.scm (logbit?): Declare this CPS
  primitive.
2017-12-27 15:46:31 +01:00
Andy Wingo
bc5a599cad Unknown primcalls convert as calls
* module/language/cps/reify-primitives.scm (reify-primitives): Remove
  case where $prim could continue to $kreceive; this isn't possible.
  However when reifying an unknown primcall, always add a $kreceive, as
  the continuation has to be $kargs.
* module/language/tree-il/compile-cps.scm (convert): Unknown primcalls
  convert as calls.  With this change, all primcalls should continue to
  $kargs, with the exception of 'throw.
2017-12-27 15:46:31 +01:00
Andy Wingo
c9efff30de CPS conversion avoids residualizing unknown primcalls
* module/language/tree-il/compile-cps.scm: Avoid residualizing "apply"
  or "abort-to-prompt" primcalls; instead, these are just calls to
  $prim.
2017-12-27 15:46:31 +01:00
Andy Wingo
7f7cbe8b65 Inline "elide-values" optimization into CPS conversion
* module/language/tree-il/compile-cps.scm (adapt-arity, convert): Avoid
  reifying "values" primcalls unless necessary.  Effectively inlines the
  "elide-values" optimization into CPS conversion.
* module/language/cps/elide-values.scm: Remove, as it's now unneeded.
* module/language/cps/optimize.scm (optimize-higher-order-cps):
* module/Makefile.am:
* am/bootstrap.am: Remove elide-values references.
2017-12-27 15:46:31 +01:00
Andy Wingo
9111f8cdcd CPS conversion expands "list"
* module/language/tree-il/compile-cps.scm (build-list): New helper.
  (convert, canonicalize): Canonicalize "list" earlier.  Allow sinking
  of any initializer that can't capture the continuation, not just in
  cases where all initializers have this property.  Reify a cons chain
  internally as appropriate.
2017-12-27 15:46:31 +01:00
Andy Wingo
36e6a3daca Refactor lowering of Tree-IL primcalls to CPS
* module/language/tree-il/cps-primitives.scm: New file,
  replacing (language cps primitives).  Lists known primitives and their
  relation to Tree-IL explicitly, instead of assuming that any Tree-IL
  primcall that shares a name with a bytecode instruction is a CPS
  primcall.
* module/language/cps/verify.scm: Remove use of (language cps
  primitives) and primcall arity checking.  Would be nice to add this
  back at some point.
* module/language/tree-il/compile-cps.scm (convert): Refactor to use new
  tree-il-primitive->cps-primitive+nargs+nvalues helper.
* module/Makefile.am:
* am/bootstrap.am: Adapt.
2017-12-27 15:46:31 +01:00
Andy Wingo
8e7170a67a Refactor boxing/unboxing primcall args/results
This will allow individual primcall converters to define ad-hoc
conversion routines.

* module/language/tree-il/compile-cps.scm (convert-primcall/default)
  (convert-indexed-getter, convert-indexed-setter)
  (convert-indexed-getter/tag, convert-indexed-setter/untag)
  (convert-scm-u64->scm-primcall, convert-scm-u64-scm-primcall)
  (convert-scm-u64->f64-primcall, convert-scm-u64-f64-primcall)
  (convert-scm-u64->u64-primcall, convert-scm-u64-u64-primcall)
  (convert-scm-u64->s64-primcall, convert-scm-u64-s64-primcall)
  (convert-*->u64-primcall, convert-scm->u64-primcall)
  (convert-u64->scm-primcall): Define some primcall converter helpers.
  (*primcall-converters*, define-primcall-converter)
  (define-primcall-converters): Define converters for a number of
  primcalls.
  (convert-primcall*, convert-primcall): Interface to primcall
  converters.
  (convert): Pass most primcalls through convert-primcall, unless we
  know already that they don't need instruction explosion or
  boxing/unboxing.
2017-12-27 15:46:31 +01:00
Andy Wingo
eed4e09723 Assignment conversion uses unchecked memory accessors
* module/language/cps/effects-analysis.scm (annotation->memory-kind):
  Add box type annotation.
* module/language/cps/reify-primitives.scm (primitive-ref): Reify
  scm-ref/immediate instead of box-ref.
* module/language/cps/specialize-primcalls.scm (specialize-primcalls):
  Remove needless and unbound -> literal.
* module/language/cps/types.scm (annotation->type): Add box type.
* module/language/tree-il/compile-cps.scm (convert): Reify
  scm-ref/immediate / scm-set!/immediate instead of box-ref / box-set!.
2017-12-06 11:26:03 +01:00
Andy Wingo
f84474ef39 CPS conversion residualizes undefined? predicate
* module/language/tree-il/compile-cps.scm (init-default-value): Use
  undefined? predicate instead of reifying an unbound value in the CPS
  term.
* module/language/cps/compile-bytecode.scm (compile-function): Add cases
  for the special immediate predicates.  Evidently we aren't emitting
  these yet!
2017-12-06 11:13:31 +01:00
Andy Wingo
64acf24b40 Fix NaN handling in <= and >=
* module/language/cps/compile-bytecode.scm (compile-function): Add
  support for emitting <= via < and jge / jnge.
* module/language/cps/effects-analysis.scm: Declare effects for <= and
  f64-<=.
* module/language/cps/primitives.scm (*comparisons*): Add <=, f64-<=.
* module/language/cps/specialize-numbers.scm (specialize-operations):
  Specialize <= to < for integer comparisons.  Specialize to f64-<= for
  f64 ops.
* module/language/cps/type-fold.scm (<=): Add folder.
* module/language/cps/types.scm (infer-<=): Add inferrer.
* module/language/tree-il/compile-cps.scm (canonicalize): Canonicalize
  <= and >= to <=, so that nans are handled correctly.
2017-12-02 21:07:48 +01:00
Andy Wingo
0cbba8efe0 Avoid generating arity-adapting zero-value conts where possible
* module/language/tree-il/compile-cps.scm (adapt-arity, convert): Avoid
  generating arity-adapting continuations for nullary continuations.
2017-12-02 10:14:45 +01:00
Andy Wingo
4002849393 Avoid generating arity-adapting continuations if not needed
* module/language/tree-il/compile-cps.scm (adapt-arity): Allow k to be
  $kargs for the 1-valued case.
  (convert): For single-valued continuations where the definition is
  clearly single-valued, avoid making a needless $kreceive and extra
  "rest" binding that will just be filled with () and have to be
  eliminated later.
2017-12-02 10:14:25 +01:00
Andy Wingo
980de88902 Add exact-integer? as interesting Tree-IL effect-free primitive
* module/language/tree-il/primitives.scm (*interesting-primitive-names*):
  (*effect-free-primitives*, *effect+exception-free-primitives*): Detect
  use of exact-integer?.
* module/language/tree-il/compile-cps.scm (canonicalize): Compile
  exact-integer? to a fixnum?-or-bignum? check.
2017-11-24 10:37:50 +01:00