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

OS#16244108: Small refactor of Parser::CreateCallNode and Parser::CreateSuperCallNode #4804

Merged
merged 1 commit into from
Mar 12, 2018

Conversation

IrinaYatsenko
Copy link
Contributor

https://microsoft.visualstudio.com/OS/_workitems/edit/16244108

The uninitialized field was introduced by #3917. The only read of the field is in EmitArgList, and if it ends up "true" instead of the default "false" an extra defensive load will be emitted for the constructor parameters so not a security/correctness concern.

@IrinaYatsenko IrinaYatsenko requested a review from boingoing March 9, 2018 23:31
{
pnode->nop = nop;

// make Parser::Init public?
Copy link
Contributor

@MSLaguana MSLaguana Mar 9, 2018

Choose a reason for hiding this comment

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

Alternately, make this Parser::InitCallNode and have it delegate this first part to Parser::InitNode? #Resolved

Copy link
Contributor Author

@IrinaYatsenko IrinaYatsenko Mar 9, 2018

Choose a reason for hiding this comment

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

Yes, could do that too. What is our philosophy on free functions versus members? :) #Resolved

Copy link
Contributor

@MSLaguana MSLaguana Mar 9, 2018

Choose a reason for hiding this comment

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

Judging by this file, I think that static class functions would fit in well. I also noticed something similar to what you are doing here:

https://github.com/irinayat-MS/ChakraCore/blob/97412c4447799ed3931f85caabdcaa989564ae33/lib/Parser/Parse.cpp#L713-L718

Perhaps instead of allocating space explicitly in Create[Super]CallNode, it would be cleaner to StaticCreateNodeT<kcbPn[Super]Call>(m_nodeAllocator, ...) and then InitCallNode on the result of that? #Resolved

Copy link
Contributor

@boingoing boingoing Mar 10, 2018

Choose a reason for hiding this comment

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

As we've been generally making a push to move the ParseNodes into a real class hierarchy, I am kind of a fan of adding a method like ParseNodeCall::Init which would do this stuff and delegate up to an ParseNode::Init for the base class stuff. Or just continue to rely on InitNode for that. Could use pnode->AsParseNodeCall()->Init or something along those lines. Regardless, I prefer to avoid the duplication of initializing these members in two places. #Resolved

Copy link
Contributor

@boingoing boingoing Mar 10, 2018

Choose a reason for hiding this comment

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

To be clear, this is fine though. Just been thinking about cleanups in this area since Curtis refactored the ParseNodes recently. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I find private static methods on a class somewhat weird. Made a step towards class hierarchy with type dependent "Init" methods. Is that what you had in mind?


In reply to: 173598566 [](ancestors = 173598566)

Copy link
Contributor

@boingoing boingoing Mar 10, 2018

Choose a reason for hiding this comment

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

Yes, that's what I was thinking about. 👍 #Resolved

Copy link
Contributor

@boingoing boingoing left a comment

Choose a reason for hiding this comment

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

👍

@@ -380,7 +377,6 @@ class Parser
ParseNodePtr CreateIntNodeWithScanner(int32 lw);
ParseNodePtr CreateProgNodeWithScanner(bool isModuleSource);

static void InitNode(OpCode nop,ParseNodePtr pnode);
static void InitBlockNode(ParseNodePtr pnode, int blockId, PnodeBlockType blockType);

Copy link
Contributor Author

@IrinaYatsenko IrinaYatsenko Mar 10, 2018

Choose a reason for hiding this comment

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

Should I go through the exercise of replacing this static method with an instance Init as well? #Resolved

Copy link
Contributor

@boingoing boingoing Mar 10, 2018

Choose a reason for hiding this comment

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

If you're feeling motivated. #Resolved

@@ -4,6 +4,20 @@
//-------------------------------------------------------------------------------------------------------
#include "ParserPch.h"

void ParseNode::Init(OpCode nop, charcount_t ichMin, charcount_t ichLim)
Copy link
Contributor

@digitalinfinity digitalinfinity Mar 10, 2018

Choose a reason for hiding this comment

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

Dumb question, and maybe @boingoing knows the answer- why not just make this a constructor instead of an explicitly named Init function? #WontFix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and then use placement new at the call sites? Is that what you mean?


In reply to: 173610992 [](ancestors = 173610992)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the placement new is wrapped by AllocatorNew


In reply to: 173858893 [](ancestors = 173858893,173610992)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the inits could be replaced by constructors + AllocatorNew at the callsite, however the constructors have to be propagated through the inheritance hierarchy and would hide default ones. I think we could wait with this till ParseNode* classes get more flesh and then we should consistently provide all of them with constructors (and remove Init methods if any).


In reply to: 173897962 [](ancestors = 173897962,173858893,173610992)

Copy link
Contributor

@digitalinfinity digitalinfinity left a comment

Choose a reason for hiding this comment

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

:shipit:

@MSLaguana
Copy link
Contributor

MSLaguana commented Mar 12, 2018

It looks like this has had some semantic changes; the "hello world" test we run on release builds is failing with

11:23:56 SyntaxError: Declaration outside statement context
11:23:56 	at code (hello.js:6:13)
``` #Pending

@chakrabot chakrabot merged commit bb68776 into chakra-core:master Mar 12, 2018
chakrabot pushed a commit that referenced this pull request Mar 12, 2018
…ateCallNode and Parser::CreateSuperCallNode

Merge pull request #4804 from irinayat-MS:ParseNodeCall

https://microsoft.visualstudio.com/OS/_workitems/edit/16244108

The uninitialized field was introduced by #3917. The only read of the field is in EmitArgList, and if it ends up "true" instead of the default "false" an extra defensive load will be emitted for the constructor parameters so not a security/correctness concern.
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.

5 participants