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

[jackpot] Attempt to make JackpotTrees more robust. #3283

Merged
merged 1 commit into from Nov 2, 2021

Conversation

mbien
Copy link
Member

@mbien mbien commented Oct 28, 2021

  • JackpotTrees.createInstance() will match constructors directly - no filling up with null objects anymore
  • extracted typesafe factory methods to keep the fragile code in one place and make it hopefully easier to update it in future

@mbien mbien changed the title Attempt to make JackpotTrees more robust. [jackpot] Attempt to make JackpotTrees more robust. Oct 28, 2021
@mbien
Copy link
Member Author

mbien commented Oct 29, 2021

@jlahoda this should help with the issue in #3206 hopefully.

@matthiasblaesing
Copy link
Contributor

matthiasblaesing commented Oct 29, 2021

I gave this a spin together with #3206 and #3286 and it seems to work. We have to expect more breakage to creep up, but I think this is a step into the right direction.

Before this is merged the if and for statements need to add braces. Otherwise the implementation looked sane to me.

@mbien
Copy link
Member Author

mbien commented Oct 29, 2021

Before this is merged the if and for statements need to add braces. Otherwise the implementation looked sane to me.

i am surprised about this requirement given the code styles i have seen so far. The lambda in question is fairly concise and should be easy to read. The indentation makes it difficult to misinterpret what is going there.

@mbien
Copy link
Member Author

mbien commented Oct 29, 2021

@jlahoda should I remove the logic which fills unknown params with null values? Current impl won't fill primitives but will still fill objects.

I was hesitant in doing this because I thought there might be some JDK version compatibility issue this was supposed to solve - so i didn't want to cause a regression.

@matthiasblaesing
Copy link
Contributor

Before this is merged the if and for statements need to add braces. Otherwise the implementation looked sane to me.

i am surprised about this requirement given the code styles i have seen so far. The lambda in question is fairly concise and should be easy to read. The indentation makes it difficult to misinterpret what is going there.

My take on this: If I want indention based syntax, I go to python.

I had to look at it multiple times to see the right indentions and blocks. I looked through other classes in spi.java.hints and found only cases where the if is very trivial and none where nested.

This is what I had in mind:

matthiasblaesing@876c94f

IMHO lambdas get messy quickly if people put to much code in them and even more if braces are missing.

@mbien
Copy link
Member Author

mbien commented Oct 29, 2021

Before this is merged the if and for statements need to add braces. Otherwise the implementation looked sane to me.

i am surprised about this requirement given the code styles i have seen so far. The lambda in question is fairly concise and should be easy to read. The indentation makes it difficult to misinterpret what is going there.

My take on this: If I want indention based syntax, I go to python.

I didn't want to change the language just to fix this method :)

I had to look at it multiple times to see the right indentions and blocks. I looked through other classes in spi.java.hints and found only cases where the if is very trivial and none where nested.

I have seen files which looked like they tried intentionally to avoid any kinds of newlines. To achive that they re-assigning method params, inside other assignments or declarations. While loops without bodies, and i just replaced a for loop which used continue labels with this patch.

I don't actually mind having braces in that lambda i was just surprised to get that requirement, given the context.

IMHO lambdas get messy quickly if people put to much code in them and even more if braces are missing.

I can see that

@mbien
Copy link
Member Author

mbien commented Oct 29, 2021

but to bring this back to the more interesting questions:

  • does this issue also occur without the auto-javac patch
    • if yes this should land in 12.6 if somehow possible otherwise NB is broken on the ubuntu JDK (maybe others too)
  • should the method only allow direct constructor matches and remove the null filling entirely
    • could cause a regression if the reason for it was to solve another compatibility issue already

@jlahoda ping

@mbien mbien marked this pull request as ready for review October 29, 2021 19:58
Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

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

Just to make this formal - please add braces for if and for statements.

@matthiasblaesing
Copy link
Contributor

For the question: Could it happen with NB 12.6? Yes it could - the conflicting constructors are there (disassembled from the referenced binary):

        protected JCVariableDecl(JCModifiers mods, Name name, JCExpression vartype, JCExpression init, Symbol.VarSymbol sym) {
            this(mods, name, vartype, init, sym, false);
        }

        protected JCVariableDecl(JCModifiers mods, Name name, JCExpression vartype, JCExpression init, Symbol.VarSymbol sym, boolean declaredUsingVar) {
            this.mods = mods;
            this.name = name;
            this.vartype = vartype;
            this.init = init;
            this.sym = sym;
            this.declaredUsingVar = declaredUsingVar;
        }

I don't see it though, but we don't know what influences the reported order of the constructors.

@mbien
Copy link
Member Author

mbien commented Oct 30, 2021

i did some archeological digging to check usages and call site compatibility to get a better picture if a direct constructor match would work. Two instances are created using JackpotTrees: JCCase and JCVariableDecl

// JDK 8+11
JCCase(JCExpression pat, List<JCStatement> stats) 
// JDK 12-18
JCCase(CaseKind caseKind, List<JCCaseLabel> labels, List<JCStatement> stats, JCTree body)
// JDK 8+11
JCVariableDecl(JCModifiers mods, Name name, JCExpression vartype, JCExpression init, VarSymbol sym)
JCVariableDecl(JCModifiers mods, JCExpression nameexpr,  JCExpression vartype)

// JDK ?-18
JCVariableDecl(JCModifiers mods,  Name name, JCExpression vartype, JCExpression init, VarSymbol sym)
JCVariableDecl(JCModifiers mods,  Name name, JCExpression vartype, JCExpression init, VarSymbol sym, boolean declaredUsingVar)
JCVariableDecl(JCModifiers mods, JCExpression nameexpr, JCExpression vartype)

Given the new knowledge i don't think the filling-params-with-null logic was of any help so far. There is also a bytebuddy code path selectively calling the JCCase(JCExpression pat, List<JCStatement> stats)constructor which doesn't exist anymore in modern JDKs, CaseKind is also deprecated for removal, so there will be another change in future.

I did the following:

  • direct constructor matching, no variable guessing anymore
  • added typesafe utility methods to JackpotTrees to keep the fragile code in one place, hopefully making it easier to update

lets see if the tests are ok with it.

Copy link
Contributor

@jlahoda jlahoda left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me, thanks! (Seems the braces have been added.) Overall, I hope at some point we will only need to support ~1 version of the APIs/internal APIs, at which point we should be able to avoid all this reflection and class construction.

@matthiasblaesing
Copy link
Contributor

@mbien thanks for working through this and @jlahoda thank you for the review. As the analysis showed, that the problem could happen with the nbjavac version currently targetted for 12.6, I think we should retarget this to delivery.

As delivery and master did not diverge that much, I suggest this approach (if you don't need the instructions, just ignore them):

  • create a new branch 'happytrees2' from delivery git checkout -b github/happytrees2 (replace github with the name of your remote of the apache/netbeans repository)
  • cherry pick both changes into it git cherry-pick 69b73908b47d7e844d743dd69d7a14bc5a3d16f7 6e1289dc5c7f65cc2a141e4b30f27ee8380905d0
  • squash the two changes git rebase -i HEAD~2 (mark the second line as squash) save and create a new commit message for the final commit
  • remove the old branch git branch -D happytrees
  • rename the new branch git branch -m happytrees
  • force push the new branch into the old PR git push -u -f origin happytrees
  • update this PR with the right base branch (delivery)

After this you should only have a single commit in it.

@matthiasblaesing matthiasblaesing added this to the 12.6 milestone Nov 1, 2021
 - JackpotTrees.createInstance() will match constructors directly
   (no unknown parameter filling with null anymore)
 - extracted typesafe factory methods to keep the fragile code in one
   place and make it hopefully easier to update it in future
@neilcsmith-net neilcsmith-net merged commit e6bef73 into apache:delivery Nov 2, 2021
mbien added a commit to mbien/netbeans that referenced this pull request Jan 2, 2022
mbien added a commit to mbien/netbeans that referenced this pull request Jan 2, 2022
mbien added a commit to mbien/netbeans that referenced this pull request Jan 3, 2022
mbien added a commit to mbien/netbeans that referenced this pull request Jan 5, 2022
mbien added a commit to mbien/netbeans that referenced this pull request Jan 5, 2022
 - removed ByteBuddy interceptor and dead code path
mbien added a commit to mbien/netbeans that referenced this pull request Jan 6, 2022
 - removed ByteBuddy interceptor and dead code path
 - less reflection
mbien added a commit to mbien/netbeans that referenced this pull request Jan 6, 2022
 - removed ByteBuddy interceptors and dead code path
 - less reflection
@mbien mbien added the hints label Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants