Project: KV Compiler: A compiler for the KV language
- Sub-organisation information
- Student Information
- University Information
- Platform Details
- Project Proposal Information
- Proposal Title
- Proposal Abstract
- Project Description
- Project Details
- Timeline
- Pre-GSoC + Community Bonding Period
- Week 1 and Week 2 (May 30 – June 13)
- Week 3 and Week 4 (June 13 – June 27)
- Week 5 and Week 6 (June 27 – July 11)
- Week 7 and Week 8 (July 11 – July 25)
- Week 9 and Week 10 (July 25 – August 08)
- Week 11 and Week 12 (August 08 – August 22)
- Week 13 (August 22 – August 29)
- Post-GSoC
- Link to a patch/code sample
- Other Commitments
- Why am I apt. for this project
- Other Schedule Information
- References
Sub-organisation with whom you hope to work: Kivy
- Name: Manthan Sharma
- Email: manthanfoss@gmail.com
- Telephone: +91-9462235282
- Time Zone: Jaipur, India UTC+5:30
- IRC: montem@irc.freenode.net
- Source Control Username: http://www.github.com/manthansharma
- Web: http://manthansharma.com/
- University: The LNM Institute of Information Technology, Jaipur
- Major: Computer Science and Engineering
- Current Year: 3rd Year
- Expected Graduation date: In June 2018
- Degree: B-Tech
- OS : macOS Sierra
- Hardware Configuration : 2.2 GHz Intel Core i7/ 16GB
- IDE :
- Python : PyCharm - JetBrains
- Editor : SublimeText 3
Kivy: KV Compiler: A compiler for the KV language
This Proposal is based on description of KV Compiler: A compiler for the KV language project in the ideas page provided by Kivy Organisation. The goal of the project it to develop a compiler which compiles kv code into python code. The compiler should be modular and extensible so that compiler can be continued to improve the kv language.
Speed is of the utmost importance for any Software Development and Execution.
The KV language was initially developed as fundamental component of Kivy which allows one to describe a GUI, from the creation of a Widget tree to the actions that should be taken in response value changes and events. Over the years, it has been matured enough to become concise way to create rule bindings using the Kivy properties and events.
Internally, python code that reflects these rules are created and bound to the properties and events. These bindings are not at all optimised because upon each widget creation all of these rules are re-evaluated and bound.
With the development of KV Compiler, this process can be significantly optimised by pre-compiling the kv
code, especially the bindings into python
code. On the other hand, this will also lead to update and fix some of the long-standing kv
language issues.
Current implementation of compiler use three phase batch binding:-
- First phase work as initialisation phase, children are created for rules and literals and non-literals are initialised to those values.
- The middle phase or binding phase creates bindings for all the rules for binding for the calling of bindings it used
__delayed_call_fn
to bind the rules in iterative. - Final post initialisation phase, all the property rules are re-evaluated, all the
on_prop
observer are triggered, then all child widget dispatch eventon_kv_apply
indicating all the rules are done being applied, finally root widget dispatcheson_kv_apply
to itself.
This sets of bindings stop unnecessary dispatching and updation of property during creation of widgets. Batch Binding helps to remove any intermediate dispatching but in case there isn't any intermediate value of rules batch binding works heavy in comparison to past implementation.
I initially wanted to implement my proposal with keeping optimisation as upmost priority. However, after talks with Matthew and Dessant, it soon turned out that this was not a correct approach to move forward. As such, this proposal currently takes consistency with optimisation approach, The main idea of this approach is that the existing functionality related work should occur first with succeeded by implementing binding and optimisation and finally testing and documentation.
Currently, kv-compiler
has already progressed quite far, it's in pre-alpha stage but in scope of improvement. Since the period of GSoC may lead to the further development of modules and sub-modules through other contributions. I plan on executing this proposal in three inter-mixing phases:
In this phase, the idea, basically is to refurbish (completely or partially) all the method that are already implemented in KVCompiler
and lang.py
. As such, no new functionality is expected to be implemented in Compiler Front End
(Line reconstruction, Lexical analysis, Preprocessing, Syntax analysis, Semantic analysis). Current, alpha stage PR has conflicts that has be to resolved to rebase it with the current kivy development branch. Compiler has some bugs in showing syntax or id error in .kv
code that has to solved to help developer find bugs in his/her code.
For example: If there is some unknown id in .kv code instead of showing
Error: id not found
it's show traceback with errorNameError: global name 'level' is not defined
.Link: https://gist.github.com/manthansharma/18fccae332e9dbbe0dd0c9caf33f7366
There are some small bugs like this which can be solved with some tweaks and changes in compiler code.
Testing and documentation, if required for already implemented ones and implementing documentation of binding in compiled code will also occur during this period. It will also serve as warm-up for the next two phases, which would be more code sensitive and can be initiated before and during completion of Phase I
Submission.
This phase will primarily focus on implementing specific functionalities that aren't currently implemented in kvcompiler.py
and lang.py
but can be implemented within a stipulated amount of time. This includes adding analysing the widget tree and rebind the bindings (working on update_intermediates
and unbind_widget
it has been mostly implemented but some changes and optimisation can be done with this.). Currently compiler is lacking in field of optimisation which can be added to it (basic idea behind this proposal). Some of the optimisation algorithm which can be implemented are
- Constant folding: At time of
property_handlers(self)
constant folding can be applied to property value and can be bind to property it depends to update with dependant property. (Max. Depth level: 1) - Automatic parallelisation (New feature for KV Lang): Part of Additional Goals (if possible will be implemented in gsoc period.)
- Inline Compression
These are written in basis of importance from top to bottom but before adding optimisation to compiler Analysis has to be done b'coz Accurate analysis is the basis for any compiler optimisation
.
This is not the final work that need to be done as Phase II is most important one for this proposal which needs to be updated constantly by discussion with mentor.
This phase would largely be a follow-up of the first two phases, especially the second phase. This phase will focus more on extensive testing, debugging and final integration of compiler with existing Kivy Development Branch
rather than implementing.
There are ways by which KV Compiler can work with real live project, We can compile all .kv
files at execution of Kivy Code into a folder recursively or user can override this by giving path of all .kv
files to be compiled in Class(App)
or somewhere in main .py
which initiate the execution of the Kivy App.
Remaining compatibility issues, if they arise, will also be dealt with during this phase. The proposal would be finished off with a final update to the documentation. Also, stop printing error traceback if error is based on .kv lang
when kivy is not running in development mode.
These are Post-GSoC
goals. I haven't work on how to implement them. These goals can be added in compiler in future. This is just basic description of implementation.
As proposed by Depaulicious in issues kivy/kivy#2727 can be easily implemented.
In addition to proposal, selectors can be enclosed in some other brackets or can be written in different syntax compared to that of Widgets.
In the compiler, same as all other widgets selectors will be compiled to __s
functions and called to execute the KV Selectors rule and set the property and in the post-initialisation phase __s
function is called after inherited rules are post initialised.
I haven't think much on this part but can worked on it with help of selectors as proposed by tito in issues kivy/kivy#691
For understanding KVCompiler I need to understand all three Cython, Python, and Kivy with kivy bindings and widget behaviours for which I will be learning more about Cython, Kivy Event Dispatcher and Bindings with also optimisation of Compiler.
I will be reading about these, gain more knowledge of all and will go through required documentations (Mentioned in “References” below).
I will be in constant touch with my mentors and take suggestions. During this time, if my mentor thinks that I am ready to start programming then I will start working on Phase I.
- Rebase the work done on compiler till now with
master
branch as an initiation to Phase I. - Start writing some kivy code which will covers all the aspect of
Kivy
which will help in testing of current compiler or with updates that will be done inPhase II
- Discuss optimisation technique that needs to be worked in initial aspect of
Phase II
. - Documentation will be done for already implemented modules (will also help in future goals).
- Testing already written modules of compiler and updating any modules.
- Benchmark the results obtained from testing, and make changes to the Phase II work approaches if required.
- Using benchmark mark to decide whether to continue with batch binding or not.
- Will start working on Phase II (subject to the availability of time and if mentor thinks).
- Make Preparation for the Phase I evaluation with completion of documentation.
My goal up till Phase 1 evaluations would be to finish off with Phase I and start implementation work of Phase II.
- Implement modules needed for analysis of compiled code needed for optimisation.
- Implement
Optimisation techniques
that were finalised during Phase I.
- Write basic test and resolving bugs found for module implemented, so that it will not break during extensive testing in Phase III.
- These both weeks will mostly be same as of Week 5 and 6.
- Make Preparation for the mid-term evaluation.
- Write extensive testing for compiler which covers all the aspects of
Kivy Language
. - Update
lang.py
if required, to support the KV Compiler in correct way and utilise most of it. - Work on integration of compiler for no. of
.kv
files in optimise manner which are proposed in Phase III.
- Investigate
Optimisation
algorithm inKVCompiler
for a possible update on their usage with.kv lang
. - Final check for any issues or conflicts in compiler or between
compiler
andmaster
branch. - Final benchmarking the results obtained from extensive testing and update to
Kivy
wikis.
- Buffer time for finishing up on documentation or any other piece of implementation that needs refactoring, or wrapping up any functionality left untouched due to delays.
- Work on the additional goals planned (subject to the availability of time).
Kivy is the first open-source organisation that I contributed to, and the journey has been simply amazing. Over time, I have realised that collaborating with the sharpest minds of the world is a pleasure beyond words. The experience I have gained so far is enriching in itself. I have the following plans post-GSoC:
- Keep contributing to
Kivy
and its sister projects and will continue to work on KVCompiler. - Lastly, I also hope to represent team
Kivy
at the upcoming conventions (PyCon India
), and talks organised at my college.
I have implemented the following for Kivy Designer:
- Update start page design (Waiting for approval)
- Create temporary directory for new-project (Waiting for approval)
- Add New Project Wizard (Waiting for approval)
- Add File Patch (Merged)
I have implemented the following for Plyer:
- Multilingual Support for TextToSpeech (Waiting for approval)
- QRCode Support (Waiting for approval)
- Speech to Text (WIP) (Work in Progress)
Other contributions:
- Do you have any other commitments during the main GSoC time period, May 23rd to August 23rd? No.
- Do you have exams or classes that overlap with this period? I have no exam in the period of gsoc. I can commit more than 6-7 hours from Monday to Friday and every alternate weekend. My next semester classes will commence from end of July, So I will not be able to work full time except for the weekends. As it will be my 4th year, so work load from academic side will be less.
- Do you plan to have any other jobs or internships during this period? No.
- Do you have any other short term commitments during this period? No.
- Have you applied to any other organisation? If so, do you have a preferred project/org? No.
Familiarity with KV Compiler and its coding style. I love to code and have been doing it for past 2 years with principle language Python, Php, C and JS. I have been contributing to Kivy and its sister projects for past 3-4 months(mainly Kivy-Designer and Plyer). I have learn the basic of Compiler Designing will be learning more in the Community Bonding Period and have understand the working of compiler already progressed here. I have done freelancing project using open source technologies and some python projects in Kivy, Django and PyQt some of them could be found at my GitHub profile. One 1K+ code project in Kivy could be found here and I have also worked on compiler 2-Pass Assembler
. After some years when millions of people would be using KV Compiler to design and develop beautiful Kivy App with fast execution and build time, I want to be remembered as the guy who contributed towards it.
None.
- kivy/kivy#3456
- kivy/kivy#2727
- kivy/kivy#691
- https://kivy.org/docs/guide/lang.html
- https://kivy.org/docs/guide/events.html
- https://en.wikipedia.org/wiki/Optimizing_compiler
- I would also like to mention that the structure and format of this proposal is inspired from a number of outstanding proposals from previous year GSoCers and proposal template provided by Python Software Foundation.