-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Functional features #42
Conversation
We use shadow_name for namespaces internally.
We should first try to find a function with the appropriate signature for producing a function reference. There are some issues with the lambdas we create: 1. Wrong signatures when using variance 2. Wrong lambdas in conditionals
Java known errorsIn 2000 programs 74 fail (26 are programming errors and 48 are javac issues marked as not an issue). False positives7/4000
Example final Function1<Ashlee, ? extends Integer> remedies = Main::falloffs;
final Function1<? super Ashlee, ? extends Integer> greenland = remedies;
Function1<? super Ashlee, ? extends Integer> x_7 = ((boxer) ?
remedies :
greenland);
Marked as not an issue41/4000
|
Groovy known errorsBetween 40% and 50% of the programs fail with the error message: If we disable the feature that triggers the above bug, we have: groovyc errors
|
example: python fetch_groovy_bugs.py bugs.json Note: it won't overwrite existing bugs in bugs.json, it will only update empty fields.
This PR was merged through integration |
This PR adds support for functional features such as lambdas and function references.
Specifically, it enhances the generator with capabilities for producing lambdas and function references. Furthermore, the generator can use function references to perform function calls.
The following example illustrates the capabilities of the features added in this PR.
Changes
--examine
option that must be combined with-R
to examine the AST of the produced program throughipdb
.logger
to the generator.Lambda
expression in AST. Lambda includes a field calledname
, which is used for internal purposes in the context.FunctionReference
expression in AST. This node contains a function name and a receiver expression. The receiver could be an expression such as a variable or anew
containing the function.get_signature
in FunctionDeclaration. This method returns a parameterized class type that represents the signature of a function.FunctionType
in builtin types. Function type represents the type contructor for function signatures.context
for lambdas. This field contains all lambda declarations.FunctionReference
s andLambda
s in get_type_hint.is_function_type
method toParameterizedType
.Lambda
s,FunctionReferences
s, and perform function calls by exploiting function references._namespace
dict incontext
to get the namespace of a declaration by usingget_namespace
.get_parent
incontext
Notes on
generator
In the
generator
we updatedgen_new
to produceFunctionReference
s andLambda
s. To do so, we have created the following functions.gen_func_ref
: It tries to create aFunctionDeclaration
for a given function signature, and if succeeds, it returns aFunctionReference
to that function.get_func_refs
: It finds allFunctionReferences
that can be use to return a specific type.gen_lambda
: Produces aLambda
expression.We also updated
gen_func_call
to call_gen_func_call_ref
that creates a function call through aFunctionReference
.TODOs
get_func_refs
. For instance, consider that we have the following class, and we search for functions withFunction1<Integer, Integer>
as a signature.Currently, we won't detect that the
foo
function can implement theFunction1<Integer, Integer>
signature.get_func_refs
. We won't detect that we can usea::foo
when searching for a function withFunction0<Integer>
signature in the following example.SAM
s and use function reference or lambdas instead of SAM objects.