aboutsummaryrefslogtreecommitdiff
path: root/kernel
AgeCommit message (Collapse)Author
2021-02-26Merge PR #13676: Protect caml_process_pending_actions_exn with ↵Pierre-Marie Pédrot
caml_something_to_do. Reviewed-by: gasche Ack-by: ppedrot Reviewed-by: xavierleroy
2021-02-26Merge PR #13868: Make genOpcodeFiles.ml handle opcode arity.Pierre-Marie Pédrot
Reviewed-by: SkySkimmer Reviewed-by: gares Reviewed-by: ppedrot
2021-02-24Infrastructure for fine-grained debug flagsMaxime Dénès
2021-02-19Be less permissive with respect to nonsensical bytecode.Guillaume Melquiond
2021-02-19Make the generated file the official source of arity.Guillaume Melquiond
2021-02-19Add a file coq_arity.h generated by genOpcodeFiles.ml.Guillaume Melquiond
This avoids forgetting to add opcodes to coq_fix_code.c, and thus prevents arities being mistakenly set to zero.
2021-02-16Fix missing arities of VM opcodes.Guillaume Melquiond
Since the compiler initializes the arities to zero, coq_tcode_of_code wrongly believes that the word following a primitive operation contains an opcode, while it is the global index of the primitive operation. So, the function will try to translate it and thus corrupt it. But as long as the evaluated term fully reduces (which is always the case for CoqInterval), the corrupted word will never be read. At this point, it all depends on the arity of the global index (seen as an opcode). If it is zero, then coq_tcode_of_code will recover and correctly translate the following opcodes. If it is nonzero, then the function starts translating random words, possibly corrupting the memory past the end of the translation buffer. Independently of this memory corruption, coq_interprete will execute random code once it gets to the opcode following the primitive operation, since it has not been translated. The reason CoqInterval is not always crashing due to this bug is just plain luck. Indeed, the arity of the pseudo opcode only depends on the global index of the primitive operations. So, as long as this arity is zero, the memory corruption is fully contained. This happens in the vast majority of cases, since coq_tcode_of_code translates any unrecognized opcode to STOP, which has arity zero. This bug is exploitable.
2021-01-19Merge PR #13699: Fix #13579 (hnf on primitives raises an anomaly)Pierre-Marie Pédrot
Ack-by: SkySkimmer Reviewed-by: ppedrot
2021-01-18Merge PR #13454: Remove unused retro_reflPierre-Marie Pédrot
Reviewed-by: ppedrot
2021-01-18Fix #13579 (hnf on primitives raises an anomaly)Pierre Roux
Also works for simpl.
2021-01-10Remove MAKEPROD.Guillaume Melquiond
MAKEPROD is just MAKEBLOCK2(0), but one word shorter. Since this opcode is never encountered in the fast path, this optimization is not worth the extra complexity.
2021-01-10Remove SETFIELD0 and SETFIELD1.Guillaume Melquiond
The generated bytecode almost never needs to modify the field of an OCaml object. The only exception is the laziness mechanism of coinductive types. But it modifies field 2, and thus uses the generic opcode SETFIELD anyway.
2021-01-10Add a peephole optimization for PUSHFIELDS(1).Guillaume Melquiond
The PUSHFIELDS opcode is a costly one, yet lots of constructors have at most one usable argument (e.g., option, nat, positive, Z, Acc). For those constructors, PUSHFIELDS(1) is replaced by GETFIELD(0);PUSH, assuming the accu register is no longer used afterwards. Replacing one single opcode by two opcodes might seem like a pessimization, but it is not. Indeed, pattern-matching branches usually start by filling the accu register with a constructor argument or the value of a free variable or a constant. All of those offer peephole optimizations for PUSH, which means that the number of opcodes actually stay constant. Note that, for the same reason, the assumption above holds in practice: the accu register is no longer used after PUSHFIELDS.
2021-01-10Remove LSLINT63CONST1 and LSRINT63CONST1 as they are unused.Guillaume Melquiond
2021-01-10Remove PUSHACC0, as it is strictly equivalent to PUSH.Guillaume Melquiond
2021-01-07Merge PR #13718: Move printing and sorting out of AcyclicGraphcoqbot-app[bot]
Reviewed-by: SkySkimmer
2021-01-06Further pushing up the printing and sorting of universes.Pierre-Marie Pédrot
We expose the representation function in UGraph and change the printer signature to work over the representation instead of the abstract type. Similarly, the topological sorting algorithm is moved to Vernacentries. It is now even simpler.
2021-01-05Move universe printing out of AcyclicGraph.Pierre-Marie Pédrot
Instead we export a representation function that gives a high-level view of the data structure in terms of constraints.
2021-01-04Remove redundant univ and parameter info from CaseInvertGaëtan Gilbert
2021-01-04Change the representation of kernel case.Pierre-Marie Pédrot
We store bound variable names instead of functions for both branches and predicate, and we furthermore add the parameters in the node. Let bindings are not taken into account and require an environment lookup for retrieval.
2021-01-04Move the relative linking order of Inductive w.r.t. VM / native.Pierre-Marie Pédrot
We need this file for the upcoming kernel representation change there.
2021-01-04Merge PR #13685: Add a debug printer for fconstr substitutions.coqbot-app[bot]
Reviewed-by: SkySkimmer
2020-12-28Export a high-level representation of term substitutions.Pierre-Marie Pédrot
2020-12-26Protect caml_process_pending_actions_exn with caml_something_to_do.Guillaume Melquiond
When using OCaml >= 4.10, function caml_process_pending_actions_exn is called whenever the bytecode interpreter tries to apply a term. This function exits immediately when caml_something_to_do is not set. But since term application happens every few opcodes, even exiting immediately still accounts between 5% and 10% of the whole interpreter. So, this commit makes sure the function is not called unless caml_something_to_do is already set (i.e., when the user presses Ctrl+C). This means that this conditional branch is perfectly predicted by the processor. On the following benchmark, this commit makes the VM 13% faster. Time Eval vm_compute in Pos.iter (fun x => x) tt 100000000. Note that, before OCaml 4.10, the VM code was checking the value of caml_signals_are_pending before calling caml_process_pending_signals. So, this commit actually fixes a regression.
2020-12-21Move evaluable_global_reference from Names to Tacred.Pierre-Marie Pédrot
It is the only place where it starts making sense in the whole codebase. It also fits nicely there since there are other functions manipulating this type in that module. In any case this type does not belong to the kernel.
2020-12-11Merge PR #13519: Better primitive type support in custom string and numeral ↵coqbot-app[bot]
notations. Reviewed-by: jfehrle Reviewed-by: proux01 Ack-by: Zimmi48 Ack-by: SkySkimmer
2020-12-11Merge PR #13540: Clean support of primitive integersPierre-Marie Pédrot
Reviewed-by: ppedrot Reviewed-by: proux01
2020-12-09Please the god of nitpicking by renaming the shift monoid operations.Pierre-Marie Pédrot
2020-12-09Document Esubst API and implementation.Pierre-Marie Pédrot
2020-12-09Compact representation of identity substitutions.Pierre-Marie Pédrot
2020-12-09Optimization: take advantage that we don't use arrays anymore in substitutions.Pierre-Marie Pédrot
2020-12-09More efficient implementation for substitutions.Pierre-Marie Pédrot
We use a variant of skewed lists enriched over a monoid, whose purpose is to count the number of lifts added to the substitution. This makes addition O(1) and lookup O(log n).
2020-12-09Cleanup substitution API.Pierre-Marie Pédrot
2020-12-04Better primitive type support in custom string and numeral notations.Fabian Kunze
- float and array values are now supported for printing and parsing in custom notations (and in notations defined using the ocaml API) - the three constants bound to the primitive float, int and array type are now allowed anywhere inside a term to print, to handle them similar to `real` type constructors - Grants #13484: String notations for primitive arrays - Fixes #13517: String notation printing fails with primitive integers inside lists
2020-12-02Move *_with_full_binders variants out of the kernel.Pierre-Marie Pédrot
They are not used there, and removing the redundance of the the case representation requires access to the environment, so we push their use further up.
2020-12-02Make sure the msb is clear.Guillaume Melquiond
This is presumably not usable from the surface language. But an ML module could easily create a proof of false by passing a negative number to Const.mkInt.
2020-12-02Greatly simplify the conversion functions between Z.t and Uint63.t.Guillaume Melquiond
2020-12-01Make the code clearer and faster by calling mask63 explicitly at the end.Guillaume Melquiond
Before this commit, function mask63 was called implicitly at each step.
2020-12-01Avoid compiler warnings.Guillaume Melquiond
2020-12-01Added comment about l2r in check_correct_arityGaëtan Gilbert
2020-12-01Use ~l2r:true to restore previous order of unfolding when typing predicates ↵Matthieu Sozeau
of cases.
2020-11-30Merge PR #13501: [kernel] Fix #13495: incompleteness in cases typing for ↵coqbot-app[bot]
cumulative inductive types Reviewed-by: SkySkimmer
2020-11-27[kernel] Fix #13495: incompleteness in cases typing for cumulative inductive ↵Matthieu Sozeau
types
2020-11-26[environ] [typing_flags] Introduce helper function to remove duplicate codeEmilio Jesus Gallego Arias
2020-11-26[kernel] Allow to set typing flags in add_mind [inductive]Emilio Jesus Gallego Arias
2020-11-26[kernel] Allow to set typing flags in add_constantEmilio Jesus Gallego Arias
This is just an experiment, but makes the uses of the API easier as we don't mess with the global state anymore.
2020-11-25Separate interning and pretyping of universesGaëtan Gilbert
This allows proper treatment in notations, ie fixes #13303 The "glob" representation of universes (what pretyping sees) contains only fully interpreted (kernel) universes and unbound universe ids (for non Strict Universe Declaration). This means universes need to be understood at intern time, so intern now has a new "universe binders" argument. We cannot avoid this due to the following example: ~~~coq Module Import M. Universe i. End M. Definition foo@{i} := Type@{i}. ~~~ When interning `Type@{i}` we need to know that `i` is locally bound to avoid interning it as `M.i`. Extern has a symmetrical problem: ~~~coq Module Import M. Universe i. End M. Polymorphic Definition foo@{i} := Type@{M.i} -> Type@{i}. Print foo. (* must not print Type@{i} -> Type@{i} *) ~~~ (Polymorphic as otherwise the local `i` will be called `foo.i`) Therefore extern also takes a universe binders argument. Note that the current implementation actually replaces local universes with names at detype type. (Asymmetrical to pretyping which only gets names in glob terms for dynamically declared univs, although it's capable of understanding bound univs too) As such extern only really needs the domain of the universe binders (ie the set of bound universe ids), we just arbitrarily pass the whole universe binders to avoid putting `Id.Map.domain` at every entry point. Note that if we want to change so that detyping does not name locally bound univs we would need to pass the reverse universe binders (map from levels to ids, contained in the ustate ie in the evar map) to extern.
2020-11-24Merge PR #13411: Rename the confusing neutral annotation in CClosure.coqbot-app[bot]
Reviewed-by: SkySkimmer
2020-11-23Remove unused retro_reflGaëtan Gilbert
2020-11-21Rename the confusing neutral annotation in CClosure.Pierre-Marie Pédrot
The Norm name was confusing enough to have introduced a few kernel bugs, so it deserved to be changed as suggested in #13274. Contrarily to what it seemingly meant, it was actually standing for neutral terms rather than normal ones. I have kept the 4-letter naming scheme for simplicity and renamed it into Ntrl.