Expose HN: Program Synthesis for Ruby

Program synthesis for Ruby, guided by type and effect annotations. See the PLDI 2021 paper for more details on the approach. Given a method specification in the form of tests, type and effect annotations with RDL, this synthesizes a Ruby function that will pass the tests. This reduces programmer effort to just writing tests that…

41
Expose HN: Program Synthesis for Ruby

These plugins are rather trim!!

RbSyn Build Status

Program synthesis for Ruby, guided by form and carry out annotations. Survey the PLDI 2021 paper for added crucial substances on the attain.

Given a manner specification in the form of tests, form and carry out annotations with RDL, this synthesizes a Ruby aim that can paddle the tests. This reduces programmer effort to factual writing tests that specify the aim habits and the computer writing the aim implementation for you.

Installation

You wish a working Ruby set up with Bundler effect apart in. Then install your total dependencies by executing bundle install.

Now we possess tested RbSyn on Ruby 2.6.3 and 3.0.2 with Bundler 2.1.4. Other variations ought to work, but now we possess no longer tested it. Enable us to understand if there are any factors.

Running Assessments

The total benchmark applications would possibly moreover moreover be trot utilizing the next jabber:

Prefix the ambiance variable CONSOLE_LOG=1 to the above jabber to print the synthesized manner. To trot a single take a look at use the next jabber:

bundle exec rake bench TEST=

The total benchmarks would possibly moreover moreover be realized in take a look at/benchmark and custom benchmarks would possibly moreover moreover be trot by updating in Rakefile in line 15, for the t.test_files value.

Ambiance Variables

A pair of flags would possibly moreover moreover be passed to RbSyn to explore numerous configurations of synthesis:

  • CONSOLE_LOG=1: Print the applications which will be instruct synthesized.
  • DISABLE_TYPES=1: Disable form directed synthesis.
  • DISABLE_EFFECTS=1: Disable carry out guided synthesis.
  • EFFECT_PREC=0 or EFFECT_PREC=1 or EFFECT_PREC=2: Honest the level of carry out precision to utilize. 0 is possibly the most proper, 1 is class level precision and a pair of reduces annotations to pure or impure handiest.

These ambiance variables would possibly moreover moreover be passed in any aggregate in the bench jabber worship so:

CONSOLE_LOG=1 DISABLE_EFFECTS=1 bundle exec rake bench

The usage of RbSyn

That you just can strive and play with the implementation of RbSyn, the aim of one of the vital key modules are given in the file structure fragment above.

To write a contemporary take a look at, you would possibly moreover either reproduction an instance from the existing benchmark and regulate it. Change the Rakefile so the t.test_files hang your contemporary benchmark.

Benchmarks educate roughly this layout:

%bool” plan

spec “returns correct when user doesn’t exist” plan
username_available? ‘bruce1’

submit { |outcome|
outcome==correct
}
cease

spec “returns flawed when user exists” plan
setup {
u=User.secure(title: ‘Bruce Wayne’, username: ‘bruce1’, password: ‘coolcool’)
u.emails.secure(email: ‘bruce1@wayne.com’)
}

username_available? ‘bruce1’

submit { |outcome|
outcome==flawed
}
cease

puts generate_program
cease”>

# form definitions for methods that shall be former for synthesis
RDL.form Array, :first, '() -> t', wrap: flawed

clarify :username_available?, "(String) -> %bool" plan

  spec "returns correct when user doesn't exist" plan
    username_available? 'bruce1'

    submit { |outcome|
      outcome==correct
    }
  cease

  spec "returns flawed when user exists" plan
    setup {
      u = User.secure(title: 'Bruce Wayne', username: 'bruce1', password: 'coolcool')
      u.emails.secure(email: 'bruce1@wayne.com')
    }

    username_available? 'bruce1'

    submit { |outcome|
      outcome==flawed
    }
  cease

  puts generate_program
cease

The above generate_program runs RbSyn and produces the next snippet:

def username_available?(arg0)
  !User.exists?(username: arg0)
cease

By default RbSyn will handiest use “” (empty string), 0 and 1 for constants at some stage in synthesis. To encompass one other constants in this aim, add them to lib/rbsyn/context.rb traces 26 and 27.

nil is no longer synthesized by default, to enable the synthesis of nil aim the chance enable_nil: correct. For an instance search for, take a look at/benchmark/diaspora/user_confirm_email_benchmark.rb.

Concerns, questions or feedback?

Please file a problem on Github when you would possibly moreover possess distress operating RbSyn. If truth be told feel free to send an email to sankha@cs.umd.edu.


Logo derived from icon by ultimatearm from www.flaticon.com.

Read More
Fraction this on knowasiak.com to search advice from americans on this topicRegister on Knowasiak.com now when you secure yourself no longer registered yet.

Charlie Layers
WRITTEN BY

Charlie Layers

Fill your life with experiences so you always have a great story to tellBio: About: