Conversation
f4d884a to
cc54764
Compare
rhuanjl
left a comment
There was a problem hiding this comment.
I think this looks neater than my version was, though struggling to follow how it handles every branch. What happens if you do a function call in an optional chain does it crash?
(Not going to merge until we have some significant test coverage)
|
I'm currently working on function calls. Edit: Function call should work now but |
No copy of expression result needed anymore
|
The jitted code currently crashes at this assertion (causing the test-failures) ChakraCore/lib/Backend/GlobOpt.cpp Line 11384 in 1f6e17c |
aae4d9f to
a9a1c70
Compare
b132685 to
9904051
Compare
1a46f30 to
8baa9e6
Compare
5958fb4 to
8c4eddf
Compare
| EmitOptionalChainWrapper(pexpr->AsParseNodeUni(), byteCodeGenerator, funcInfo, [&](ParseNode *innerNode) { | ||
| EmitDelete(innerNode, innerNode, byteCodeGenerator, funcInfo); | ||
| }); | ||
| pnode->location = pexpr->location; |
There was a problem hiding this comment.
We "copy" the value from the knopOptChain node to the knopDelete node
| // Every `?.` node will call `EmitNullPropagation` | ||
| // `EmitNullPropagation` short-circuits to `skipLabel` in case of a nullish value | ||
| emitChainContent(innerNode); | ||
| pnodeOptChain->location = innerNode->location; |
There was a problem hiding this comment.
Instead of acquiring a tmp I copy the location of pnodeOptChain to innerNode
(In case the caller has already aquired a tmp)
And copy it back after emitting innerNode
(In case the location was NoRegister and the emission of innerNode aquired a tmp)
00c00c3 to
55dea9f
Compare
|
@rhuanjl Just in time for the first aniversary (🎉) of this PR, I'll mark it as ready for review!
|
|
I see that there has been more activity in the repository. Is there any chance of merging this PR? |
I'll take a look in the next week, back when we were last working on this I was worried about a couple of potentially untested code paths. FYI: the only people who contribute to this repository now do it as a hobby and have unrelated jobs hence the glacial progress. I'm happy to give a bit of time to help any new contributor learn the ropes if you're aware of interest it would be good to see more happening here. |
This PR aims to add support for the stage-4 proposal optional-chaining.
It's inspired by the work of @rhuanjl but uses a more hacky approach to parsing.
Goals
ToDo
eval?.('a'))eval)deletethis(a.b)().cshould be equivalent toa.b().ca?.[++x]++xshould not be evaluated ifaisnullorundefineda?.3:0(ternary) astkOptChain(?.)tmp-renaming forevalresulteval("foo?.()")oreval("foo?.property")applycall optimization?Only triggered for 2 nested
forloops with assignmentChakraCore/test/loop/loopinversion.js
Lines 60 to 66 in e26c81f
Out of scope
EmitInvoke(seems unused)Spec: Optional Chains
Fixes #6349