Code Monkey home page Code Monkey logo

compgenerator's People

Contributors

carljm avatar jellezijlstra avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

compgenerator's Issues

constrain generation better to filter less?

We still filter out a lot of generated samples as non-compilable or not containing a listcomp. If we could constrain generation better and filter less (without excluding interesting examples), it would make the fuzzer run a lot faster.

Possible improvements

A couple of things we should consider changing:

  • Use __a and __b as the names, so we can catch name mangling bugs
  • Constrain what kind of expressions appear in subscripts, so we generate less code like (1)[a] that will fail at runtime. I feel such code is less likely to be interesting, as the TypeError from the subscript could hide more interesting errors.
  • In the function evaluation code from #2, first check how many arguments the function takes using inspect, and pass those arguments. That way, we get a bit more coverage of locals.

better handling of recursive strategies

We use recursive strategies in the AST. Currently we have an ugly hack where we first define simple strategies for List and Tuple that can only contain names and constants, and then later define more complex strategies that can include other expressions. This would be better handled using https://hypothesis.readthedocs.io/en/latest/data.html#hypothesis.strategies.recursive

Also, the inconsistency between use of st.from_type(NodeType) vs directly referring to a strategy function by name had something to do with working around recursion.

NameError vs. UnboundLocalError with walrus

The fuzzer found this (slightly simplified):

def a(b):
    [(1) for b in b if (a := a)]
a("a")

On main:

>>> a("a")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in a
UnboundLocalError: cannot access local variable 'a' where it is not associated with a value

On 3.11:

>>> a("a")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in a
  File "<stdin>", line 2, in <listcomp>
NameError: cannot access free variable 'a' where it is not associated with a value in enclosing scope

I think that's expected: previously a walrus like this would create an implicit nonlocal, but now it's just a local. Perhaps this should be documented somewhere, though it's hard to imagine real code being affected.

For the fuzzer, we should somehow ignore this difference; I'll try to think of a way.

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.