Skip to content
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

Remove addNodeLast from update chnages #18016

Open
wants to merge 4 commits into
base: Pharo13
Choose a base branch
from

Conversation

Alokzh
Copy link
Contributor

@Alokzh Alokzh commented Mar 18, 2025

Fixes: #17847

  1. Replaced addNodeLast from RBAddSubtreeTransformation & updated its logic
  2. Removed the addNodeLast method from OCSequenceNode
  3. All Tests pass locally

Alokzh added 2 commits March 19, 2025 02:02

Verified

This commit was signed with the committer’s verified signature.

Verified

This commit was signed with the committer’s verified signature.
Copy link
Member

@jecisc jecisc left a comment

Choose a reason for hiding this comment

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

This

jecisc and others added 2 commits March 20, 2025 15:01

Verified

This commit was signed with the committer’s verified signature.
johnsonjh Jeffrey H. Johnson
@Ducasse
Copy link
Member

Ducasse commented Mar 20, 2025

With Balsa we wrote a little visitor fully tested that adds the last node correctly.
I'm thinking that a good little project would to extract (rewrite out of the tree in a first place) the replacement logic. Because like that we could write nice tests and then remove the logic from the tree. Visitors are much nicer. If you are interested in this little project let me know.
the tasks would be

  • check the tests if any for the replace logic
  • enhance the tests following a systematic approach
  • reuse the tests to start moving the behavior in a separate visitor
  • replace existing code by a call to the new visitor.

@Alokzh
Copy link
Contributor Author

Alokzh commented Mar 21, 2025

Sure @Ducasse

I researched the whole codebase I could not find any visitor that adds the last node which you mentioned.
I found OCReturnNodeAdderVisitor so I tried to understand its implementation & probably got good idea how visitors work.

If you could help me finding where adding last node visitor is, I could definitely try this issue.

Comment on lines +114 to +120
parseTree body lastIsReturn
ifTrue: [
parseTree body
addNode: newNode
before: parseTree body statements last ]
ifFalse: [ parseTree body addNode: newNode ].
parseTree ].
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this a bit buggy?

I know you're just inlining the method here, but my point is:

  • sometimes it adds the node as the last one
  • sometimes as the one before the last one

I don't see how this could work in general, there are probably cases where this produces broken code

Copy link
Contributor Author

@Alokzh Alokzh Mar 21, 2025

Choose a reason for hiding this comment

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

Thnx @guillep

But according to this current implementation first it checks if the last statement is a return statement or not
If it is, only then it adds the new node one before the last one else it adds new node at the end ( Don't you think this is correct behaviour )

Yeah there could be case where this might lead to unexpected behaviour
In case if we find that last statement is not a return statement then it will add the node in last which could lead to some issue

For example:

calculateSum [
    | a b result |
    a := 5.
    b := 10.
    result := a + b.
    result
]

Here it returns result implicitly & if we use this logic to add a new node let's say ( a * b ) then it will be added to last according to logic & the method becomes this

calculateSum [
    | a b result |
    a := 5.
    b := 10.
    result := a + b.
    result.
    a * b
]

Now in this case it will start returning different value.

But for this what we can do is , here we can use OCReturnNodeAdderVisitor to first wrap the node as return & then add new node one before the last.

But there might be some methods which intentionally does not want to return any value in that case we are forcing to return value so maybe again we will have to come up with some logic to find whether it has implicit return or not then wotk out according to that. I just wanted to tell the idea I came up with .

Am I making any sense here or this is completely wrong approach ?

If you have some time could you give me some example where the already implemented logic would produces broken code as it would help me understand the issue better ?

Sorry this became a very long message

@guillep
Copy link
Member

guillep commented Mar 21, 2025

I think the original issue meant to remove this behavior entirely

#17847

Probably this means analysing in if there is not a bug there, propose some tests, do a bit of redesign...

@Ducasse
Copy link
Member

Ducasse commented Mar 21, 2025

Guille you are right I forgot what I wanted.
@Alokzh yes I meant OCReturnNodeAdderVisitor because we were not happy with addReturnNode logic.

@Alokzh
Copy link
Contributor Author

Alokzh commented Mar 21, 2025

Guille you are right I forgot what I wanted. @Alokzh yes I meant OCReturnNodeAdderVisitor because we were not happy with addReturnNode logic.

So you want me to replace the adding node logic using OCReturnNodeAdderVisitor but I am bit confused here as this particular visitor just wraps the last statement in a return node ( correct me if I am wrong ) & it does not add a new node.

@Ducasse
Copy link
Member

Ducasse commented Mar 21, 2025

Sorry I was confusing.
Now we want to remove the only user ot AddNodeLast
Then this is another issue we want to see if we can externalise the node replacement into a specific visitor. This follows what we did in the OCReturnNodeAdderVisitor because before it was a addReturnNode message that was half way tested and unclear.

@Ducasse
Copy link
Member

Ducasse commented Mar 21, 2025

I'm dead coming back from a long trip so my brain is out of order. I will have to take time to reply to you.

@Alokzh
Copy link
Contributor Author

Alokzh commented Mar 21, 2025

Sorry I was confusing. Now we want to remove the only user ot AddNodeLast Then this is another issue we want to see if we can externalise the node replacement into a specific visitor. This follows what we did in the OCReturnNodeAdderVisitor because before it was a addReturnNode message that was half way tested and unclear.

Yeah I get this now.

@Alokzh
Copy link
Contributor Author

Alokzh commented Mar 21, 2025

I'm dead coming back from a long trip so my brain is out of order. I will have to take time to reply to you.

For sure @Ducasse I am okay with it.
Please take rest , meanwhile if I get some idea i'll let you know later on.

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.

addNodeLast: should be removed because it is bogus and misleading
4 participants