Commit graph

21 commits

Author SHA1 Message Date
Andrea Corallo
e0f20da6ec Simplify correctly (or (integer 1 1) (not (integer 1 1))) as t
* 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.
2020-12-21 20:22:03 +01:00
Andrea Corallo
c70c08013f * Allow for overlapping src and dst in cstr set operations
* 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.
2020-12-21 20:22:03 +01:00
Andrea Corallo
8e816b0ad5 Symplify type specifier (not t) as nil
* 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.
2020-12-21 20:22:03 +01:00
Andrea Corallo
48d43f579e * Improve constraint simplification logic in comp-cstr.el
* 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.
2020-12-21 20:21:33 +01:00
Andrea Corallo
5ca371b501 * Memoize `comp-cstr-intersection'
* 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.
2020-12-13 00:58:25 +01:00
Andrea Corallo
0ded37fdad * Add initial negated non-negegated intersection support
* lisp/emacs-lisp/comp-cstr.el (comp-range-intersection): Cosmetic.
	(comp-cstr-intersection-homogeneous): Rename from
	`comp-cstr-intersection'.
	(comp-cstr-intersection): New function.
2020-12-13 00:58:12 +01:00
Andrea Corallo
6286945396 Normalize cstrs for cache hint effectiveness and test stability
* 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.
2020-12-12 16:30:16 +01:00
Andrea Corallo
a6295d3150 * Add `comp-split-pos-neg' function
* 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'.
2020-12-12 16:30:16 +01:00
Andrea Corallo
73b5e40750 * Code rework add `comp-cstrs-homogeneous'
* lisp/emacs-lisp/comp-cstr.el (comp-cstrs-homogeneous): New
	function.
	(comp-cstr-union-1-no-mem): Make use of.
2020-12-12 16:30:16 +01:00
Andrea Corallo
27f666e111 * Unify common fallback exit point in `comp-cstr-union-1-no-mem'.
* 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.
2020-12-06 18:07:03 +01:00
Andrea Corallo
ac40a60696 Couple of `comp-cstr-union-1-no-mem' improvements for mixed neg pos union
* 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.
2020-12-06 18:02:18 +01:00
Andrea Corallo
09ec39e352 * Memoize `comp-cstr-union-1'
* 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.
2020-12-05 22:33:35 +01:00
Andrea Corallo
2eb41ec137 More improvements to `comp-cstr-union-1' for mixed positive/negative cases
* 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.
2020-12-05 19:01:04 +01:00
Andrea Corallo
f923de6853 * Fix `comp-cstr-to-type-spec'
* 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 ...
2020-12-05 19:01:04 +01:00
Andrea Corallo
726e40fb7c Fix union of homogeneously negated input constraints
* 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.
2020-12-05 19:01:03 +01:00
Andrea Corallo
cbbdb4e199 * Add `with-comp-cstr-accessors' macro.
* lisp/emacs-lisp/comp-cstr.el (with-comp-cstr-accessors): New macro.
	(comp-cstr-union-1): Make use of `with-comp-cstr-accessors'.
2020-12-05 19:01:03 +01:00
Andrea Corallo
7c1d90a41d Initial support for union of negated constraints
* 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.
2020-12-05 19:01:03 +01:00
Andrea Corallo
1fb249f6db * lisp/emacs-lisp/comp-cstr.el (comp-cstr-union-no-range): Cosmetic. 2020-12-05 19:01:03 +01:00
Andrea Corallo
9b85ae6aa5 Initial constraint negation support
* 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.
2020-12-05 19:01:03 +01:00
Andrea Corallo
2e0256e0a0 Add intersection support into comp-cstr.el 2020-11-27 23:30:02 +01:00
Andrea Corallo
23c082638e Add comp-cstr.el and comp-cstr-tests.el
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.
2020-11-26 22:02:30 +01:00