Skip to content

Conversation

@aneeshdk
Copy link
Contributor

cachedscope is not applicable to most of the normal functions. This change moves it out of the ScriptFunction to to a separate derived class which is instantiated if we decide to have cachedscope for that particular function.

@aneeshdk aneeshdk requested review from akroshg, curtisman and pleath May 10, 2018 23:15
{
pnodeFnc->SetHasCachedScope();
top->byteCodeFunction->GetFunctionInfo()->SetHasCachedScope();
/*top->originalAttributes = (Js::FunctionInfo::Attributes)(top->originalAttributes | Js::FunctionInfo::Attributes::CachedScope);*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the commented line be deleted?

kFunctionIsBaseClassConstructor = 1 << 19, // function is a base class constructor
kFunctionIsClassMember = 1 << 20, // function is a class member
// Free = 1 << 21,
kFunctionHasCachedScope = 1 << 21, // Function has cached scopes
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you point out the benefit of having this recorded on the parse node, since the byte code generator is already recording the attribute on the FuncInfo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used for creating the attributes in GetFunctionInfoAttributes

@pleath
Copy link
Contributor

pleath commented May 10, 2018

With this change, are we able to figure out, for all deferred functions that will have NewScFunc byte code emitted for them, which ones will require scope objects when we execute them? Given that that's what we need to do, I was expecting a bigger change.

static bool IsCoroutine(Attributes attributes) { return ((attributes & (Async | Generator)) != 0); }
bool IsCoroutine() const { return IsCoroutine(this->attributes); }
bool HasComputedName() const { return (this->attributes & Attributes::ComputedName) != 0; }
bool HasCachedScope() const { return (this->attributes & Attributes::CachedScope) != 0; }
Copy link
Contributor

@pleath pleath May 10, 2018

Choose a reason for hiding this comment

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

A naming question: is this attribute recording the fact that a function has a cached scope or that it needs a scope object and thus may have a cached scope? Seems like it's the latter. Does that change the way we want to describe this attribute?

virtual void SetCachedScope(ActivationObjectEx *obj) override { cachedScopeObj = obj; }

#if ENABLE_TTD
virtual void MarkVisitKindSpecificPtrs(TTD::SnapshotExtractor* extractor)
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason why this is not in the .cpp file?

bool canBeDeferred;
bool isBodyAndParamScopeMerged; // Indicates whether the param scope and the body scope of the function can be merged together or not.
// We cannot merge both scopes together if there is any closure capture or eval is present in the param scope.
bool needsScopeObject;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: should we move the all bools together (from line 464) for better packing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@aneeshdk aneeshdk force-pushed the MoveCachedScopeOutOfScriptFunc branch 2 times, most recently from 3362834 to 165a284 Compare May 11, 2018 23:00
@aneeshdk
Copy link
Contributor Author

@pleath yes it looks like this covers all cases for scope objects including with statements.

@pleath
Copy link
Contributor

pleath commented May 12, 2018

There are many calls to Scope::SetIsObject in the byte code generator that are not touched by your change. All that logic now has to be applied to top-level deferred functions as well as non-deferred ones.

cachedscope is not applicable to most of the normal functions. This change moves it out of the ScriptFunction to to a separate derived class which is instantiated if we decide to have cachedscope for that particular function.
@aneeshdk aneeshdk force-pushed the MoveCachedScopeOutOfScriptFunc branch from 165a284 to c8d82c4 Compare May 14, 2018 17:27
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.

3 participants