1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-02 04:40:29 +02:00
Commit graph

3154 commits

Author SHA1 Message Date
Andy Wingo
e0e47cb527 Fix fixpoint
* module/language/cps2/utils.scm (fixpoint): Fix embarrassing bug
  where it wouldn't actually fixpoint!  Didn't show up in practice
  because CPS2 hasn't run after contification yet.
2015-05-20 19:18:45 +02:00
Andy Wingo
fa7df5ed3a Fix sub/- primcall bug
* module/language/tree-il/compile-cps2.scm (convert): Fix bug
  in (apply - ...), because the instruction for "-" is "sub", and
  "sub" lookup was failing.  Caught by numbers.test.  Really I would
  like to get rid of $prim, somehow.
2015-05-20 19:18:45 +02:00
Andy Wingo
ef5f2fcaaa Add optimization pass over CPS2
* module/language/cps2/optimize.scm: New file.
* module/language/cps2/simplify.scm: New file, factored out of
  simplify2.scm.

* module/language/cps/simplify2.scm: Remove, as it's obsolete.

* module/language/cps2/compile-cps.scm: Optimize the CPS.

* module/Makefile.am: Adapt for added and deleted files.
2015-05-12 21:53:42 +02:00
Andy Wingo
b31af02faf Consolidate CPS2 above CPS in the compiler
This is an intermediate step.  We'll replace CPS bit by bit.  If it
turns out to be a terrible idea we can just revert.

* module/Makefile.am (TREE_IL_LANG_SOURCES): Remove compile-cps.scm.
  (CPS_LANG_SOURCES): Remove arities.scm.

* module/language/cps/arities.scm: Remove.
* module/language/tree-il/compile-cps.scm: Remove.

* module/language/tree-il/spec.scm: Remove use of compile-cps.scm.

* module/language/cps/compile-bytecode.scm: Remove use of arities.scm.
  Instead, incoming terms are expected to call their continuations
  with the correct number of arguments.
2015-05-11 22:43:25 +02:00
Andy Wingo
9833c545cc Adapt return arities in Tree-IL -> CPS2 conversion
* module/language/tree-il/compile-cps2.scm (adapt-arity): New
  procedure.  This is equivalent to (language cps arities), but as it
  is a necessary pass and not an optimization it's more proper to put
  it in the converter itself.  Unlike with the nested CPS
  representation, it's possible to look up continuations without
  making a DFG.
  (convert): Adapt arities as necessary.
2015-05-11 22:43:20 +02:00
Andy Wingo
3ab3cdecda Build CPS2 with transient intmaps
* module/language/tree-il/compile-cps2.scm (with-cps)
  (cps-convert/thunk): Use transient intmaps.
2015-05-11 22:43:19 +02:00
Andy Wingo
5928d16a8e Tree-IL -> CPS2 -> CPS
* module/language/tree-il/spec.scm (tree-il): Compile to CPS2 instead of CPS.
2015-05-09 16:52:09 +02:00
Andy Wingo
219b6f82a2 compute-dom-edges returns a persistent intmap
* module/language/cps/utils.scm (compute-dom-edges): Return a
  persistent intmap.  Fixes strange bootstrapping failures that I
  don't understand :/.
2015-05-09 16:52:09 +02:00
Andy Wingo
7fedd7b7ad Fix another intset transient bug
* module/language/cps/intset.scm (intset-add!): If the root is a
  branch but isn't editable, be sure to actually update the transient
  intset's root to store the writable root.
2015-05-09 14:52:47 +02:00
Andy Wingo
f95a794a3d Fix intset-add! transient bug
* module/language/cps/intset.scm (intset-add!): Fix as in
  0f082bd3f7.
2015-05-09 13:46:18 +02:00
Andy Wingo
d99fedc5fd Fix convert-cps2 for "not" primcalls
* module/language/tree-il/compile-cps2.scm (convert): Fix typo in "not"
  compilation.
2015-05-08 15:44:50 +02:00
Andy Wingo
0f082bd3f7 Fix intmap-add! transient bug
* module/language/cps/intmap.scm (intmap-add!): Fix a bug creating a
  transient branch out of a persistent branch.
2015-05-08 14:09:40 +02:00
Andy Wingo
09869e781b Register up cps2 compiler with language tower
* module/language/tree-il/compile-cps2.scm (compile-cps2): Rename from compile-cps.
* module/language/cps2/spec.scm: New file.
* module/Makefile.am (CPS2_LANG_SOURCES): Add spec.scm.
* module/language/tree-il/spec.scm (tree-il): Declare compiler to cps2.
2015-05-08 13:35:08 +02:00
Andy Wingo
7cd61e2bf6 cps2: Fix parse-cps for `prompt'
* module/language/cps2.scm (parse-cps): Fix for `prompt'.
2015-05-08 13:19:59 +02:00
Andy Wingo
773595f0db Add compiler from tree-il to cps2
* module/language/tree-il/compile-cps2.scm: New file.
* module/Makefile.am: Add the file to the build.
2015-05-08 11:46:46 +02:00
Andy Wingo
6485e89276 Beginnings of CPS2 language.
The tentative plan is to replace CPS with CPS2, and to rename CPS2 to
CPS.  We will add a pass to compile tree-il to CPS2, then work from
the top down to replace the CPS compiler passes.

* module/language/cps2.scm:
* module/language/cps2/compile-cps.scm:
* module/language/cps2/renumber.scm:
* module/language/cps2/utils.scm: New files.

* module/Makefile.am: Add new files to build.
2015-05-08 11:46:46 +02:00
Andy Wingo
6ffb6e69ed Add printers for <intmap> and <transient-intmap>
* module/language/cps/intmap.scm (intmap->alist, print-intmap)
  (print-transient-intmap): New functions.
  Install the new functions as printers for <intmap> and <transient-intmap>.
2015-05-08 11:46:46 +02:00
Andy Wingo
eb9d442840 Add "cps2" experiment
* module/Makefile.am: Add new file to makefile.
* module/language/cps/simplify2.scm: New file.
2015-04-08 17:19:28 +02:00
Andy Wingo
49cc76ab75 Transient intsets
* module/language/cps/intset.scm (make-atomic-reference)
  (get-atomic-reference, set-atomic-reference!): New functions.
  (*branch-size-with-edit*, *edit-index*): New constants.
  (<transient-intset>): New data type.
  (new-branch, clone-branch-and-set): Adapt to set edit field.
  (transient-intset, persistent-intset): New exports.
  (intset-add!): New interface, supporting "transient" intsets.
  (intset-ref, intset-next, intset-prev, intset-fold, intset-fold2):
  Work with transients.
2015-04-08 17:18:04 +02:00
Andy Wingo
95db570528 Add "transient" intmap interface
* module/language/cps/intmap.scm (make-atomic-reference):
  (get-atomic-reference, set-atomic-reference!): New helpers.
  (*branch-size-with-edit*, *edit-index*): Branches now have a trailing
  field, an atomic reference to their owner.
  (<transient-intmap>): New record type.  A mutable intmap.
  (new-branch): Set the "edit" field on the branch.
  (clone-branch-and-set): No editor for this field.
  (assert-readable!, writable-branch): New helpers.
  (transient-intmap, persistent-intmap): New exported functions.
  (intmap-add!): New function.
  (intmap-next, intmap-prev, intmap-ref): Work on transient intmaps.
  (intmap-fold): Persist the intmap before folding over it.
2015-04-08 17:17:59 +02:00
Andy Wingo
cf512e3268 32-way branching in intmap.scm, not 16-way
* module/language/cps/intmap.scm (*branch-bits*): Switch to 32-way
  branching.  Marginally faster on lookup, and creation costs can be
  amortized via using the transient interface.  Marginal speedup for
  assembler.scm compilation.
2015-04-01 10:53:23 +02:00
Andy Wingo
048d5d340e Intset-next micro-optimizations
* module/language/cps/intset.scm (intset-next): Micro-optimizations.
2015-04-01 10:53:23 +02:00
Andy Wingo
9c8d2b85e8 Add intset-fold, intset-fold2
* module/language/cps/intset.scm (intset-fold, intset-fold2): New
  functions.
2015-04-01 10:53:23 +02:00
Andy Wingo
b7668bd949 Add intmap-fold.
* module/language/cps/intmap.scm (intmap-fold): New function.
2015-04-01 10:53:21 +02:00
Andy Wingo
2a24395a0f Add intmap-prev
* module/language/cps/intmap.scm (intmap-next): Starting index is
  optional.
  (intmap-prev): New function.
2015-04-01 10:28:19 +02:00
Andy Wingo
33ab2838de Default "meet" operator is meet-error for intmap
* module/language/cps/intmap.scm (meet-error): New helper.
  (intmap-add, intmap-union, intmap-intersect): The "meet" argument is
  optional and defaults to meet-error.
2015-04-01 10:28:19 +02:00
Andy Wingo
50fcdfece3 Remove "free" field of $fun
* module/language/cps.scm ($fun): Remove unused "free" field.
* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/constructors.scm:
* module/language/cps/contification.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/elide-values.scm:
* module/language/cps/prune-bailouts.scm:
* module/language/cps/prune-top-level-scopes.scm:
* module/language/cps/renumber.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/type-fold.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Adapt all callers.
2015-04-01 10:10:10 +02:00
Andy Wingo
34ff3af9f0 Replace $letrec with $rec
* module/language/cps.scm ($rec): Replace $letrec with $rec, which is an
  expression, not a term.  This means that the names bound by the letrec
  appear twice: once in the $rec term, and once in the continuation.
  This is not very elegant, but the situation is better than it was
  before.  Adapt all callers.

* doc/ref/compiler.texi (CPS in Guile): Incomplete documentation
  updates.  I'll update these later when the IL settles down.
2015-04-01 10:10:10 +02:00
Andy Wingo
4ce1857019 Precise range inference on <, <=, >=, > branches
* module/language/cps/types.scm (restricted-comparison-ranges): New
  helper.
  (define-comparison-inferrer): New helper.
  (<, <=, >=, >): Infer ranges precisely.
2015-04-01 10:10:10 +02:00
Andy Wingo
ef7a71b768 Fix intmap bug for maps with only one element
* module/language/cps/intmap.scm (intmap-ref): Fix bug referencing
  values when there is only one value in the map.
2015-04-01 10:10:10 +02:00
Ludovic Courtès
dfa11aa3f6 elf: Add missing argument in 'elf-segment'.
* module/system/vm/elf.scm (elf-segment): Add missing argument N.
2015-03-30 15:19:58 +02:00
Andy Wingo
fe7ecee820 Only lazily compile where profitable
* module/ice-9/eval.scm (primitive-eval): Only lazily compile box-ref on
  toplevel variables; otherwise compile eagerly to avoid the
  indirection.
2015-03-12 14:48:03 +01:00
Andy Wingo
7fee63b947 Optimize branches in the evaluator
* module/ice-9/eval.scm (primitive-eval): Factor out primitive=?
  helper.  Simplify compile-top-call.  Add compile-top-branch for
  primcall branches, so the compiler can see the specialized branch
  operator.
2015-03-12 14:26:24 +01:00
Andy Wingo
d76d80d23c Primcall inlining in eval.scm, lazy function body compilation
* module/ice-9/eval.scm (primitive-eval): Lazily compile lambda bodies.
  Special-case calls to top-level or module variables, and recognize
  some of those calls as primcalls.  In that case, emit closures with
  the primcalls.
2015-03-12 14:06:15 +01:00
Andy Wingo
eb0376567d Remove unused "nargs" field of memoized call expressions
* libguile/eval.c (eval):
* libguile/memoize.c (MAKMEMO_CALL, memoize, unmemoize):
* module/ice-9/eval.scm (primitive-eval): Remove "nargs" field from
  memoized call expressions, and adapt callers.
2015-03-12 08:37:04 +01:00
Andy Wingo
af082f9b1c Marginal bootstrap memory improvements
* module/language/cps/compile-bytecode.scm (optimize, compile-bytecode):
  Marginally improve bootstrap memory usage by not retaining stale
  copies of already-rewritten terms.
2015-03-12 08:20:58 +01:00
Andy Wingo
a9ec16f9c5 Remove $void CPS expression type
* module/language/cps.scm: Remove the $void expression type, replaced by
  $const of the unspecified value.
* module/language/cps/arities.scm:
* module/language/cps/closure-conversion.scm:
* module/language/cps/compile-bytecode.scm:
* module/language/cps/cse.scm:
* module/language/cps/dce.scm:
* module/language/cps/dfg.scm:
* module/language/cps/effects-analysis.scm:
* module/language/cps/reify-primitives.scm:
* module/language/cps/renumber.scm:
* module/language/cps/self-references.scm:
* module/language/cps/simplify.scm:
* module/language/cps/slot-allocation.scm:
* module/language/cps/specialize-primcalls.scm:
* module/language/cps/types.scm:
* module/language/cps/verify.scm:
* module/language/tree-il/compile-cps.scm: Update callers.
2015-03-11 21:51:33 +01:00
Andy Wingo
aead655a45 Re-implement (ice-9 streams) in terms of (srfi srfi-41)
* module/ice-9/streams.scm: Re-implement in terms of SRFI-41.  Passes
  tests.
2015-03-09 13:48:38 +01:00
Andy Wingo
577eab817c (system base types) knows about variables
* module/system/base/types.scm (%tc7-variable): New tc7.
  (cell->object): Handle tc7-variable.

* test-suite/tests/types.test ("opaque objects"): Add a test.
2015-02-17 10:58:29 +01:00
Andy Wingo
37ae02ffa0 Fix infinite loop in expander
* module/ice-9/psyntax.scm (resolve-identifier): There is a case where a
  syntax object can resolve to itself.  Prevent an infinite loop in that
  case by continuing to resolve by name.

* module/ice-9/psyntax-pp.scm: Regenerate.

* test-suite/tests/syncase.test ("infinite loop bug"): Add a test.
2015-02-13 16:43:01 +01:00
Andy Wingo
e87f059319 Reify bytevector? in the correct module
* module/language/cps/reify-primitives.scm (primitive-module): Reify
  bytevector? in the correct module.  Thanks to Nala Ginrut for the
  report.
2015-02-06 15:13:32 +01:00
Andy Wingo
26350edcac Add #:static-slot-allocation?
* libguile/goops.h (SCM_VTABLE_FLAG_GOOPS_STATIC): Reserve the fourth
  GOOPS flag to indicate that a class has static slot allocation.

* libguile/goops.c (scm_init_goops_builtins): Define
  vtable-flag-goops-static for goops.scm.

* module/oop/goops.scm (class-has-statically-allocated-slots?): New
  helper.
  (build-slots-list): Instead of the ad-hoc checks for <class> or
  <slot>, use the new helper.
  (initialize): Accept #:static-slot-allocation? keyword.

* module/system/foreign-object.scm (make-foreign-object-type): Declare
  foreign object classes as having static slot allocation.

* test-suite/tests/goops.test ("static slot allocation"): Add tests.
2015-02-06 13:25:17 +01:00
Andy Wingo
05d0cdf18e Fix foreign objects for getter method change
* module/system/foreign-object.scm: Fix getters after change to make
  <accessor-method> instances only apply to their precise specializer
  types.
2015-02-06 12:27:56 +01:00
Andy Wingo
7b0a8dfb75 Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
	libguile/goops.c
	libguile/vm-engine.h
	module/oop/goops.scm
	module/oop/goops/compile.scm
	module/oop/goops/dispatch.scm
	test-suite/tests/goops.test
2015-01-26 18:13:38 +01:00
Andy Wingo
649ec8d823 Accessor methods only apply to subclasses with their slot
* libguile/goops.c (is_accessor_method, scm_compute_applicable_methods):
  Fix regression from 51f66c9120 (2009).
  Accessor methods are added on each subclass on which the slot is
  present; therefore if a subclass doesn't have a method, then the
  methods doesn't apply.  Truly fixes #17355, unlike
  583a23bf10.

* module/oop/goops.scm (compute-cmethod, compute-getter-method)
  (compute-setter-method): Revert earlier changes.

* test-suite/tests/goops.test ("accessor slots"): Update for new
  expectations, in agreement with Guile 1.8.
2015-01-26 17:57:44 +01:00
Andy Wingo
15e4746f17 Fix verify-cps
* module/language/cps/verify.scm (verify-cps): Fix.  Thanks to Steven
  H. Margolis for the note.  Fixes bug #19389.
2015-01-25 11:39:42 +01:00
Andy Wingo
583a23bf10 Fix accessor struct field inlining
* module/oop/goops/compile.scm: Inline into goops.scm, leaving a
  compatible interface stub behind.

* module/oop/goops/dispatch.scm: Don't import (oop goops compile), to
  break circularities.

* module/oop/goops.scm: Move (oop goops util) include up to the top, and
  import (ice-9 match).
  (compute-cmethod): Move here from compile.scm.  Add a special case for
  accessor methods, so as to fix bug #17355.
  (compute-getter-method, compute-setter-method): #:procedure slot is
  now generic.

* test-suite/tests/goops.test ("accessor slots"): New test.
2015-01-24 19:23:08 +01:00
Andy Wingo
e7097386cb Fix accessor struct inlining in GOOPS
Fixes bug #17355.

* module/oop/goops.scm (memoize-effective-method!): Adapt to
  compute-effective-method change.
  (compute-effective-method, %compute-effective-method): Renamed from
  compute-cmethod; now a generic protocol.
  (compute-specialized-effective-method)
  (%compute-specialized-effective-method): New sub-protocol.
  (memoize-generic-function-application!): Adapt to call the hard-wired
  compute-applicable-methods based on the concrete arguments types --
  the semantics is that %compute-applicable-methods is the
  implementation for <generic> functions.  Perhaps we should do the same
  for sort-applicable-methods and method-more-specific?.
  (compute-getter-method, compute-setter-method): The standard
  #:procedure is now a generic slot-ref.  It wasn't valid to inline
  field access here, because subtypes could have different field
  layouts.
  (compute-applicable-methods): Refactor generic definition to use
  lexical scoping.
  (compute-specialized-effective-method): New method for
  <accessor-method>, which does field access inlining based on the
  concrete types being applied.

* test-suite/tests/goops.test ("accessor slots"): New test.
2015-01-24 18:59:15 +01:00
Andy Wingo
4bde3f04ea Simplify and optimize slot access
* module/oop/goops.scm (fold-slot-slots): Add `slot-ref/raw' slot, which
  is what the slot-ref slot was.  Now the slot-ref slot checks that the
  slot is bound, if needed.
  (slot-definition-slot-ref/raw): Define.
  (make-slot): Adapt.  Also, effective slot definition slots have no
  initargs.
  (define-standard-accessor-method, bound-check-get, standard-get)
  (standard-set): Move definitions up.
  (allocate-slots): Adapt.  If the slot has an init thunk, we don't need
  to check that it's bound.
  (slot-ref, slot-set!, slot-bound?): Simplify.
  (class-slot-ref): Use the raw getter so that we can call
  `slot-unbound' with just the class.
  (compute-getter-method, compute-setter-method): Simplify to just use
  the slot-ref / slot-set! functions from the slot.
  (%initialize-object): Simplify.
2015-01-23 16:16:04 +01:00
Andy Wingo
193e2c52dc Export <slot> from GOOPS
* module/oop/goops.scm (<slot>): Export.  This is the way to tell if you
  have new GOOPS or not: whether <slot> is defined.
2015-01-23 16:16:04 +01:00