Repository navigation
[WIP] Type annotations - #14
Draft
nikolaushuber wants to merge 20 commits into
Draft
nikolaushuber wants to merge 20 commits into
nikolaushuber wants to merge 20 commits into
Conversation
…tyco syntax hanlding to backend
Modules follow theories, and code equations may use constants of later theories, so generated modules import each other (about 50 HOL modules form one cycle). A module-level value that reads an attribute of a module still being imported fails, which broke almost every module of the slow suite. Such values are now printed as @functools.cache functions without arguments and called at their uses; all other values stay plain assignments. The slow suite now also imports every generated module.
A value whose right-hand side calls an aborting constant (no code equations, or declared undefined), or uses such a value, raised when its module was imported. It is now printed as a cached function like the values in an import cycle, so it raises only when used. This makes Code_Test of the slow suite import, and changes the golden of Example_no_eqs (uses_undefined = undefined).
Each example directory has its own copy of the library modules, so mypy checks them one at a time. Two annotations mypy rejects are changed: a polymorphic value gets Any for its type variables (`empty_list: list[Any] = []`), and a function without code returns Never rather than a type variable that only occurs in its return type.
Mypy infers the parameter types of a lambda passed to a generic function by checking it once per candidate type, so nested lambdas took exponential time: four modules of the slow suite (Quickcheck random generators in Tree, Records, RBT, RBT_Impl) did not finish in half an hour. With type annotations, every lambda, and every partial application that would be printed as one, is now hoisted into a def whose parameters and return type are annotated; the hoisted names differ within a statement, since mypy rejects defs of one name with different signatures in different match arms. Both slow-suite directories now check in about a second (75 and 40 errors). Output without annotations is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for adding type annotations to the generated code.
This is currently WIP, and must be switched on by an Isabelle option (see README).