Skip to content

Add Jit integration tests#2187

Merged
BenLewis-Seequent merged 4 commits into
RustPython:masterfrom
BenLewis-Seequent:jit-tests
Sep 18, 2020
Merged

Add Jit integration tests#2187
BenLewis-Seequent merged 4 commits into
RustPython:masterfrom
BenLewis-Seequent:jit-tests

Conversation

@BenLewis-Seequent
Copy link
Copy Markdown

This add a test utility macro jit_function, which allows declaring jitted python functions inside rust test functions. Example:

let add = jit_function! { add(a:i64, b:i64) -> i64 => r##"
    def add(a: int, b: int):
        return a + b
"## };

The above define the python function add, which is compiled to bytecode at compile time. That bytecode is then jitted into native code at runtime(we could also do this a compile time in the future). The return value of the macro is a lambda with the signature fn(i64, i64) -> i64.

As part of that I refactored py_compile_bytecode into two different macros py_compile and py_freeze.

Copy link
Copy Markdown
Member

@coolreader18 coolreader18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I really like the freeze/compile separation, and the tests for jit look good

Comment thread jit/tests/common.rs Outdated

// Pop all values from stack:
for _ in 0..amount {
values.push(self.stack.pop().unwrap());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to do something like values.extend(stack.drain(len-amount..).rev()) here

Comment thread jit/tests/common.rs Outdated

// Push other value back in order:
for value in values.into_iter().rev() {
self.stack.push(value);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use extend() here too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants