Type Slicing - #1830
Closed
MaxCarroll0 wants to merge 203 commits into
Closed
Conversation
Currently this gives a massive hit to performance of the statics. TODO: - Logic for slicing - UI for slicing - Ability to disable slicing
…s-refactor-type-slices
Code here is redundant and ugly, but it works.
…s-refactor-type-slices
Note: Type Slice Substitution currently drops all slices on the substituted term. Fix this for typfun slices to work.
This reverts commit 03530a1.
Member
Author
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.
Interactive Type Slicing
Implementation of Type Slicing and Cast Slicing as per my undergrad dissertation.
Type and cast slicing foundations and future directions/plans are summarised in a more readable in a shorter form in this progress paper.
Type Slicing
A type slice highlights parts of a term in order to explain it's (synthesised or analysed type)
For any term, a type slice is a minimal term and immediate context around the term which retains the same type information. That is, with all 'irrelevant' sub-term which don't give any new type information being replaced with holes. In this implementation, non-local context (variable definition and type definitions) are also highlighted (giving intuitive code slices for typing assumption slices). See examples below referring to terms at the red cursor):

Decomposability
This information is stored incrementally based upon the structure of the type of the expression in question. It tracks the part of a slice that results in, for example, the argument of a function having a type of
Int.Planned UI
Context Inspector
Decomposability by type
Emphasised Highlighting root constructors of types
Emphasise the parts of slices that actually sourced a particular type atom or constructor in question. That is, consider that
(fun x -> 0)(1)has typeIntbut must highlight both the function constructor and eliminators to be a valid slice, but the atom1is where the type actually originates, and is perhaps of greater interest, so should be emphasised.Emphasised Highlighting of root constructors of types in sub-slices
Distinguish between purely structural elements of sub-slices, and those which are root constructors of the (of part of the) type being scrutinised in the sub-slice. For example, a function may be a root constructor sourcing part of the type information, and must be present structurally to produce a valid slice, but might not actually be part of the part of the type being scrutinised, e.g.
? -> (? -> ?)when selecting the output function.Un-emphasised parts could be omitted from highlighting in general by default. They likely just add noise to the slices with little non-trivial information.
Static Error Slices
Checklist
Typ.t, be a record type, adding helper functions to be usable in exactly the same way as Typ.t is currentlyctx_used(as a list of slices)Bugs & Tests
Further Exploration
Decomposability by derivation & Tracking type eliminators
Type slices don't retain all information about derivations. For example, with type eliminators, lots of information is compressed into a single atomic part of the slice, as in
(fun x -> 0)(1)having typeIntso therefore not being decomposable (even though multiple rules were used in it's derivation).Exploring how this information could be tracked and presented to the user and mathematical foundations for this would be of great use. In particular, how to integrate such a method seamlessly with the current type-based indexing.
Formal definition for emphasising parts of sub-slices
Allowing for proofs that a sub-term is always emphasised and proving and giving semantic justification of the concept.
Semantic Properties of Current Cast Slicing
Explore if the current propagation of type slice info throughout evaluation gives rise to any semantic properties. Especially, in relation to dynamic errors and 'dynamicness' of code. For example, how does this relate to blame?
Dynamic Program Slicing and its Relation to Cast Slicing
Type slicing can, to an extent, help understand why a cast was inserted during elaboration. A useful further feature would be slicing a minimal programs that produces a specific cast to help users understand why a cast was evaluated to. This could be based more generally upon 'Functional Programs that Explain their Work' which slices programs producing any part of a result.
In particular, in a minimal program producing some cast, how does the type slice information in this cast relate to the dynamic program slice itself.
Non-local Constraints and Inference
Possible integration with the form of inference-mimicking errors proposed by #1803.
Propagation of slicing within constraint solving may also be possible, but might not be possible to remain well-formed.