SpoonLabs/astor

Cardumen single change, expected different result

MaximoOliveira opened this issue · 6 comments

Hello @martinezmatias !

I'm testing something on Cardumen and am getting a different result than the expected. I've tried a couple of things and had no success. Maybe you could know what is causing this problem

Sorry for the long post :p I appreciate any help you can give!

I've made the following single change on Cardumen:
Removed part of code ''|| element instanceof CtVariableAccess", so that variables are also considered in the search space.

|| element instanceof CtVariableAccess || element instanceof CtLiteral)

And tested this change with the program DETECT_CYCLE from QuixBugs: https://github.com/KTH/quixbugs-experiment/blob/master/src/main/java/java_programs/DETECT_CYCLE.java

With these changes we should see that when the modification point at line 21 is the expression tortoise.getSuccessor():
image

We should have an ingredient in the form: _Node_0 , which we currently get:
image

However when the transformation is done:
image

the variables present do not replace the template _Node_0:
image

The ingredientsAfterTransformation list has 3 DynamicIngredient all with the shown expection, and when evaluating them the Ingredients are in the form: _Node_0 and not hare , (as expected)

I leave the test case here in case it helps:
`public void test_detect_cycle_cardumen() throws Exception {
AstorMain main1 = new AstorMain();

	CommandSummary command = (getQuixBugsCommand("detect_cycle"));
	command.command.put("-maxgen", "0");
	command.command.put("-mode", "cardumen");
	main1.execute(command.flat());

	CardumenApproach cardumen = (CardumenApproach) main1.getEngine();

	ExpressionTypeIngredientSpace ingredientSpace = (ExpressionTypeIngredientSpace) cardumen
			.getIngredientSearchStrategy().getIngredientSpace();
	ProbabilisticIngredientStrategy ingredientStrategy = (ProbabilisticIngredientStrategy) cardumen.getIngredientSearchStrategy();
	IngredientTransformationStrategy transformationStrategy = ingredientStrategy.getIngredientTransformationStrategy();
	ProgramVariant pvar = cardumen.getVariants().get(0);
	// ********************************************************************************************************//
	//Relevant test part starts here

	// The expression on line 21: tortoise.getSuccessor()
	CtElement suspiciousElement = getSuspiciousElement(pvar, "tortoise.getSuccessor()", 21);
	ModificationPoint modPoint = pvar.getModificationPoint(suspiciousElement);

	List<Ingredient> ingredients = ingredientSpace.getIngredients(suspiciousElement);
	// the template ingredient _Node_0
	Ingredient ingredient = ingredients.stream().filter(i ->
			i.toString().equals("_Node_0")).findFirst().orElse(null);

	/*  Im expecting 3 possible transformations to the _Node_0 template:
	 *        {hare, tortoise, node}
	 *   However i just get the ingredients: {_Node_0, _Node_0, _Node_0}
	 */
	List<Ingredient> ingredientsAfterTransformation = transformationStrategy.transform(modPoint, ingredient);
	assert (ingredientsAfterTransformation.stream().anyMatch(i ->
			i.toString().equals("hare"))); // this assert will fail
}`

Hi @MaximoOliveira

Thanks for the detailed report of the issue.

One question: If you don't apply the change you mention in the if (i.e., reducing the expression from the condition). Do you have the same issue? i.e., the ingredients are not transformed.

Regards
Matias

Hi @martinezmatias

If I dont apply the changes the ingredient _Node_0 does not appear:

image

Instead of 5 ingredients we have 3.

The transformations for these 3 ingredients are applied

I see, so that means that the bug (ingredients are not transformed) only appears when we include the CtVariables in the list of ingredients, right?

Correct!

okey, thanks.
I would say that CtVariable should not include as ingredients because they are not expressions thus, they cannot be evaluated (and Cardumen needs to evaluate the ingredient in order to replace one piece of code per another with compatible type).
An ingredient could be a CtVariableAccess (in particular CtVariableRead) which in that case the ingredient could be evaluated.

Thank you!