Git Product home page Git Product logo

recki-ct's Introduction

Recki-CT

Build Status Coverage Status

The Recki Compiler Toolkit for PHP

Disclaimer: This is not an official Google product.

Warning: This is an incomplete work-in-progress.

Stability

Recki-CT is pre-alpha quality right now. This means that it shouldn't be used in production at all.

What Is Recki-CT?

Recki-CT is a set of tools that implement a compiler for PHP, and is written in PHP!

Specifically, Recki-CT compiles a subset of PHP code. The subset is designed to allow a code base to be statically analyzed. This means that global variables, dynamic variables (variable-variables, variable function calls, etc) and references are not allowed.

What Isn't Recki-CT?

Recki-CT is not a re-implementation of PHP. It aims to be a limited subset of the language (one that can be staticly reasoned about).

This means that it is not designed to replace PHP, but instead augment it.

Why?

PHP itself isn't slow. It's plenty fast enough for most use-cases. As a language, PHP has a lot of corner cases and results in a really complex engine implementation. As such, rewriting a new engine isn't going to gain you a lot. The complexity is going to be in there somewhere.

So with Recki-CT, we take a different approach. Rather than rewriting the entire engine, we sit on top of an existing engine. The compiler then can compile PHP code into native machine code which can out-perform most JIT compiled implementations (sometimes by very significant margins).

The designed mode of operation for Recki is as an AOT (Ahead-Of-Time) compiler. Since it uses aggressive analysis and optimizations, runtime compilation would be a inefficient target. Instead, an Intermediate Representation can be cached, leaving only the final conversion to machine code to happen at runtime.

Where can I find out more?

Check out the documentation!!!

  1. Introduction and FAQ
  2. Installation
  3. Basic Operation
  4. Types
  5. Intermediate Representation

How do I install Recki-CT?

See the Installation Documentation.

How do I use Recki-CT?

A very simple example:

/**
 * @return void
 */
function foo($bar) {}

// Instead of using:
foo($baz);

// Use:
$foo = Jit::JitFu('foo');
$foo($baz);

Note that a docblock must be present, and must document every parameter type and the return type.

Check out the examples folder for more examples!

License

Recki-CT is released under the Apache-2 License.

Contributing

See CONTRIBUTING.md

And join the Google Group mailing list.

recki-ct's People

Contributors

dave1010 avatar grahamcampbell avatar hikari-no-yume avatar ircmaxell avatar krakjoe avatar pborreli avatar ralt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

recki-ct's Issues

Supported types

I tried to modify 01-simple-usage.php to use string instead of int like this:

/**
 * @param string $n The parameter
 *
 * @return string The parameter, returned
 */
function test($n)
{
    return $n;
}

$func = Jit::jitfu('test');
benchmark($func, "ReckiCT");

function benchmark(callable $func, $label)
{
    $start = microtime(true);
    for ($i = 0; $i < 1000000; $i++) {
        $func('x');
    }
    $end = microtime(true);
    printf("%s completed in %01.4F seconds\n", $label, $end - $start);
}

And got a fatal error:

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 947180166 bytes) in ...

Then I tried array type:

/**
 * @param array $n The parameter
 *
 * @return array $n
 */
function test($n)
{
    return [$n];
}

...

function benchmark(callable $func, $label)
{
    ...
    $func([]);
    ....
}

And got:

Fatal error: Uncaught exception 'LogicException' with message 'Found node without parser rule: Expr_Array' ...

So I wonder which types are supported?

Does it really works?

I was testing this project but instead of a performance gain I see a performance degradation... Am I doing something wrong?

php -v
PHP 5.6.2 (cli) (built: Oct 17 2014 09:51:11) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies

php -r "phpinfo();" | grep JIT
JITFU
JIT-Fu support => enabled

php examples/01-basic-usage.php 
PHP completed in 0.0168 seconds
ReckiCT completed in 0.0326 seconds

ReckiCT\JitTest::testGetFunctionAstInternalFunction fails on Windows

PHP 5.6.4

Part of interest in the callstack + arguments.
Jit::parseFile($fileName = false)
Jit::getFunctionAst($name = 'strlen')

$fileName = realpath($fileName); returns the current working directory.

Since $this->parsedFiles[$fileName] (with the working path as $fileName) does not exist, it will enter the condition and attempt to read a file. In this particular case, it'll attempt to read the directory, which does not make sense. Thus, I end up with

file_get_contents(E:\GIT\recki-ct\test): failed to open stream: Permission denied

Is the project still in development

Hello @ircmaxell ,

Thanks for your work, I personally learn a lot from this codebase (and your blog :-) ).
I just want to know if you can share your vision/roadmap for recki-ct.

Is it an experimental project or a WIP.

Thanks a lot.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.