* 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'.
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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
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.
* 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!
* 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.
* 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.
* 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.