summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/comp-cstr.el
Commit message (Collapse)AuthorAgeFilesLines
* Do not add unnecesary arg constraints (bug#45812 bug#45705 bug#45751).Andrea Corallo2021-01-191-0/+3
| | | | | | | | | These have the effect of bloating the IR for no effect killing compile time. The typical cases for that are extremely long backuoted lists. * lisp/emacs-lisp/comp-cstr.el (comp-cstr-t): New var. * lisp/emacs-lisp/comp.el (comp-add-call-cstr): No need to add arg call constraints if this is t.
* Fix type inference for bug#45635Andrea Corallo2021-01-041-0/+16
| | | | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-union-1-no-mem): Fix missing mixed pos neg handling. * test/lisp/emacs-lisp/comp-cstr-tests.el (comp-cstr-typespec-tests-alist): Add a test. * test/src/comp-tests.el (45635): New testcase. * test/src/comp-test-funcs.el (comp-test-45635-f): New function.
* Fix `functionp' contraining (bug#45576)Andrea Corallo2021-01-021-5/+1
| | | | | | | | | * lisp/emacs-lisp/comp.el (comp-known-predicates) (comp-known-predicates-h): New constants. (comp-known-predicate-p, comp-pred-to-cstr): New functions. * lisp/emacs-lisp/cl-macs.el (cl-deftype-satisfies): Don't define. * test/src/comp-tests.el (comp-test-45576): New testcase. * test/src/comp-test-funcs.el (comp-test-45576-f): New function.
* * Fix two predicates for missing negation handlingAndrea Corallo2021-01-011-5/+7
| | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-empty-p) (comp-cstr-null-p): Fix missing negation handling.
* * lisp/emacs-lisp/comp-cstr.el (comp-cstr): Better `comp-value-to-cstr'.Andrea Corallo2020-12-291-4/+7
|
* Constrain mvars under compare and branch with built-in predicatesAndrea Corallo2020-12-291-0/+11
| | | | | | | | | | * lisp/emacs-lisp/comp.el (comp-emit-assume): Update. (comp-known-predicate-p): New function. (comp-add-cond-cstrs): Extend to pattern match predicate calls. * lisp/emacs-lisp/comp-cstr.el (comp-cstr-null-p) (comp-pred-to-cstr): New function. * test/src/comp-tests.el (comp-tests-type-spec-tests): Add a number of tests and fix comments.
* * lisp/emacs-lisp/comp-cstr.el (comp-cstr): Better `comp-type-to-cstr'.Andrea Corallo2020-12-291-1/+10
|
* Add 1+ 1- integer range propagation supportAndrea Corallo2020-12-271-0/+4
| | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-one): New special var. * lisp/emacs-lisp/comp.el (comp-fwprop-call): Propagate integer ranges on +1 -1. * test/src/comp-tests.el (comp-tests-type-spec-tests): Add two tests.
* Add sum/subtraction integer range propagation supportAndrea Corallo2020-12-271-0/+63
| | | | | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-range-+, comp-range--): New functions. (comp-cstr-set-range-for-arithm): New macro. (comp-cstr-add-2, comp-cstr-sub-2, comp-cstr-add, comp-cstr-sub): New function. * lisp/emacs-lisp/comp.el (comp-fwprop-call): Wire-up + - integer range propagation.
* * lisp/emacs-lisp/comp-cstr.el (comp-cstr-set-cmp-range): Improve.Andrea Corallo2020-12-271-1/+4
|
* * Add comp-cstr-greatest-in-range comp-cstr-smallest-in-rangeAndrea Corallo2020-12-271-4/+12
| | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-smallest-in-range) (comp-cstr-greatest-in-range): New function. (comp-cstr->, comp-cstr->=, comp-cstr-<, comp-cstr-<=): Make use of.
* Fix missing float handling into `comp-cstr-set-cmp-range'Andrea Corallo2020-12-261-1/+1
| | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-set-cmp-range): Add float handling. * test/src/comp-tests.el (comp-tests-type-spec-tests): Update results.
* Enable integer range narrowing under compare and branchAndrea Corallo2020-12-261-0/+68
| | | | | | | | | | | | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-set-cmp-range) (comp-cstr->, comp-cstr->=, comp-cstr-<, comp-cstr-<=): New functions. * lisp/emacs-lisp/comp.el (comp-equality-fun-p) (comp-range-cmp-fun-p): New functions. (comp-collect-rhs): Use `comp-assign-op-p' in place of `comp-set-op-p'. (comp-negate-range-cmp-fun, comp-reverse-cmp-fun): New functions. (comp-emit-assume): Rework to be able to emit also comparision assumption. (comp-add-cond-cstrs-simple): Update for new `comp-emit-assume'. (comp-add-cond-cstrs-simple): Update to emit range assumption. (comp-fwprop-insn): Execute range assumptions. * test/src/comp-tests.el (comp-tests-type-spec-tests): Add tests.
* * Memoize `comp-subtype-p'Andrea Corallo2020-12-241-1/+8
| | | | | * lisp/emacs-lisp/comp-cstr.el (comp-subtype-p): Memoize. (comp-cstr-ctxt): Add `subtype-p-mem' slot.
* Symplify (not t) => nil and (not nil) => tAndrea Corallo2020-12-241-4/+21
| | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-negation): Symplify (not t) => nil and (not nil) => t. * test/lisp/emacs-lisp/comp-cstr-tests.el (comp-cstr-typespec-tests-alist): Add two tests.
* Negate only values while constraining variables (bug#45376)Andrea Corallo2020-12-231-0/+14
| | | | | | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-value-negation): New function. * lisp/emacs-lisp/comp.el (comp-fwprop-insn): Use `comp-cstr-value-negation'. * test/src/comp-test-funcs.el (comp-test-45376-1-f): Rename. (comp-test-45376-2-f): New funcion. * test/src/comp-tests.el (bug-45376-1): Rename test. (bug-45376-2): Add test.
* * Fix non range cstr union operationAndrea Corallo2020-12-231-8/+10
| | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-union-homogeneous): Add range parameter and handle the non range case. (comp-cstr-union-1-no-mem, comp-cstr-intersection-no-mem): Update `comp-cstr-union-homogeneous' call sites.
* Make input constraints into memoization hash immutable (bug#45376)Andrea Corallo2020-12-231-2/+2
| | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-union-1) (comp-cstr-intersection): Copy input before soting it into the memoization hash table.
* * lisp/emacs-lisp/comp-cstr.el (comp-cstr-copy): Tweak for perf.Andrea Corallo2020-12-231-3/+3
|
* Simplify correctly (or (integer 1 1) (not (integer 1 1))) as tAndrea Corallo2020-12-211-6/+11
| | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-union-1-no-mem): Logic update. * test/lisp/emacs-lisp/comp-cstr-tests.el (comp-cstr-typespec-tests-alist): Add a test.
* * Allow for overlapping src and dst in cstr set operationsAndrea Corallo2020-12-211-185/+185
| | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-union-1-no-mem) (comp-cstr-union-1, comp-cstr-intersection-no-mem) (comp-cstr-intersection): Logic update.
* Symplify type specifier (not t) as nilAndrea Corallo2020-12-211-0/+9
| | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-intersection-no-mem): Add logic. * test/lisp/emacs-lisp/comp-cstr-tests.el (comp-cstr-typespec-tests-alist): Add two tests.
* * Improve constraint simplification logic in comp-cstr.elAndrea Corallo2020-12-211-113/+131
| | | | | | | | | | | | | | | | | | * lisp/emacs-lisp/comp-cstr.el (with-comp-cstr-accessors): Simplify. (comp-cstr-empty-p): New Funchion. (comp-split-pos-neg): Minor. (comp-normalize-typeset): Logic update. (comp-union-typesets): Minor. (comp-intersect-two-typesets): New functio. (comp-intersect-typesets): Logic update. (comp-range-union, comp-range-intersection): Minor. (comp-cstr-union-homogeneous, comp-cstr-union-1-no-mem) (comp-cstr-intersection-homogeneous) (comp-cstr-intersection-no-mem, comp-cstr-negation) (comp-type-spec-to-cstr, comp-cstr-to-type-spec): Logic update. * lisp/emacs-lisp/comp-cstr.el (with-comp-cstr-accessors): Simplify.
* * Memoize `comp-cstr-intersection'Andrea Corallo2020-12-131-24/+44
| | | | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-ctxt): Add new slot `intersection-mem'. (comp-cstr-intersection-homogeneous): Fix non local exit target. (comp-cstr-intersection-no-mem): Rename from `comp-cstr-intersection'. (comp-cstr-intersection): New function.
* * Add initial negated non-negegated intersection supportAndrea Corallo2020-12-131-21/+93
| | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-range-intersection): Cosmetic. (comp-cstr-intersection-homogeneous): Rename from `comp-cstr-intersection'. (comp-cstr-intersection): New function.
* Normalize cstrs for cache hint effectiveness and test stabilityAndrea Corallo2020-12-121-15/+42
| | | | | | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-normalize-valset) (comp-union-valsets, comp-intersection-valsets) (comp-normalize-typeset): New functions. (comp-union-typesets, comp-intersect-typesets) (comp-cstr-union-homogeneous-no-range, comp-cstr-union-1-no-mem): Update to return normalized results. * test/lisp/emacs-lisp/comp-cstr-tests.el (comp-cstr-typespec-tests-alist): Normalize expected type specifiers.
* * Add `comp-split-pos-neg' functionAndrea Corallo2020-12-121-86/+91
| | | | | * lisp/emacs-lisp/comp-cstr.el (comp-split-pos-neg): New function. (comp-cstr-union-1-no-mem): Update to call `comp-split-pos-neg'.
* * Code rework add `comp-cstrs-homogeneous'Andrea Corallo2020-12-121-12/+19
| | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstrs-homogeneous): New function. (comp-cstr-union-1-no-mem): Make use of.
* * Unify common fallback exit point in `comp-cstr-union-1-no-mem'.Andrea Corallo2020-12-061-112/+106
| | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-union-1-no-mem): Define a local function `give-up' as a common fall-back exit point.
* Couple of `comp-cstr-union-1-no-mem' improvements for mixed neg pos unionAndrea Corallo2020-12-061-9/+23
| | | | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-union-1-no-mem): Generalize disjoint pos types vs neg values conditions. (comp-cstr-union-1-no-mem): Do not propagate ranges when we are already returning integer as generic type. * test/lisp/emacs-lisp/comp-cstr-tests.el (comp-cstr-typespec-tests-alist): Add corresponding tests.
* * Memoize `comp-cstr-union-1'Andrea Corallo2020-12-051-7/+42
| | | | | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr): Do not synthesize the copier. (comp-cstr-ctxt): Add `union-1-mem-no-range' `union-1-mem-range' slots. (comp-cstr-copy): New function. (comp-cstr-union-1-no-mem): Rename from `comp-cstr-union-1'. (comp-cstr-union-1): New function.
* More improvements to `comp-cstr-union-1' for mixed positive/negative casesAndrea Corallo2020-12-051-34/+54
| | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-union-1): Better handle mixed positive/negated cases. * test/lisp/emacs-lisp/comp-cstr-tests.el (comp-cstr-typespec-tests-alist): Add a number of tests.
* * Fix `comp-cstr-to-type-spec'Andrea Corallo2020-12-051-41/+44
| | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-star-or-num-p): New predicate. (comp-type-spec-to-cstr): Make use of. (comp-cstr-to-type-spec): Output correctly type specifiers as (not (or integer ...
* Fix union of homogeneously negated input constraintsAndrea Corallo2020-12-051-0/+2
| | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr-union-1): Fix logic. * test/lisp/emacs-lisp/comp-cstr-tests.el (comp-cstr-typespec-tests-alist): Add a couple of tests.
* * Add `with-comp-cstr-accessors' macro.Andrea Corallo2020-12-051-79/+94
| | | | | * lisp/emacs-lisp/comp-cstr.el (with-comp-cstr-accessors): New macro. (comp-cstr-union-1): Make use of `with-comp-cstr-accessors'.
* Initial support for union of negated constraintsAndrea Corallo2020-12-051-15/+118
| | | | | | | | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-range-negation): New function. (comp-cstr-union-homogeneous-no-range): Rename from `comp-cstr-union-no-range'. (comp-cstr-union-homogeneous): Rename from `comp-cstr-union'. (comp-cstr-union-1): New function. (comp-cstr-union-no-range, comp-cstr-union): Rewrite in function of `comp-cstr-union-1'. * test/lisp/emacs-lisp/comp-cstr-tests.el (comp-cstr-typespec-tests-alist): Add a bunch of tests.
* * lisp/emacs-lisp/comp-cstr.el (comp-cstr-union-no-range): Cosmetic.Andrea Corallo2020-12-051-20/+20
|
* Initial constraint negation supportAndrea Corallo2020-12-051-17/+48
| | | | | | | | | | * lisp/emacs-lisp/comp-cstr.el (comp-cstr): Add `neg' slot. (comp-range-negation, comp-cstr-negation) (comp-cstr-negation-make): New functions. (comp-type-spec-to-cstr): Enable `not` in type specifiers. (comp-cstr-to-type-spec): Update logic to handle negation. * test/lisp/emacs-lisp/comp-cstr-tests.el (comp-cstr-typespec-tests-alist): Add a test.
* Add intersection support into comp-cstr.elAndrea Corallo2020-11-271-7/+73
|
* Add comp-cstr.el and comp-cstr-tests.elAndrea Corallo2020-11-261-0/+363
As the constraint logic of the compiler is not trivial and largely independent from the rest of the code move it into comp-cstr.el to ease separation and maintainability. This commit improve the conversion type specifier -> constraint for generality. Lastly this should help with bootstrap time as comp.el compilation unit is slimmed down. * lisp/emacs-lisp/comp-cstr.el: New file. (comp--typeof-types, comp--all-builtin-types): Move from comp.el. (comp-cstr, comp-cstr-f): Same + rename. (comp-cstr-ctxt): New struct. (comp-supertypes, comp-common-supertype-2) (comp-common-supertype, comp-subtype-p, comp-union-typesets) (comp-range-1+, comp-range-1-, comp-range-<, comp-range-union) (comp-range-intersection): Move from comp.el. (comp-cstr-union-no-range, comp-cstr-union): Move from comp.el and rename. (comp-cstr-union-make): New function. (comp-type-spec-to-cstr, comp-cstr-to-type-spec): Move from comp.el, rename it and rework it. * lisp/emacs-lisp/comp.el (comp-known-func-cstr-h): Rework. (comp-ctxt): Remove two fields and include `comp-cstr-ctxt'. (comp-mvar, comp-fwprop-call): Update for `comp-cstr' being renamed. (comp-fwprop-insn): Use `comp-cstr-union-no-range' or `comp-cstr-union'. (comp-ret-type-spec): Use `comp-cstr-union' and rework. * test/lisp/emacs-lisp/comp-cstr-tests.el: New file. (comp-cstr-test-ts, comp-cstr-typespec-test): New functions. (comp-cstr-typespec-tests-alist): New defconst to generate tests on. (comp-cstr-generate-tests): New macro. * test/src/comp-tests.el (comp-tests-type-spec-tests): Update. (ret-type-spec): Initialize constraint context.