Change `internScope` and `internScopeCreationData` to take pointers to objects instead of function closures that construct them.
Categories
(Core :: JavaScript Engine, task, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox88 | --- | fixed |
People
(Reporter: djvj, Assigned: snehasai01, Mentored)
References
(Blocks 1 open bug)
Details
(Keywords: good-first-bug, Whiteboard: [lang=c++])
Attachments
(2 files)
Motivation
This bug came about after discussing ongoing parser work with @mgaudet.
The internScope
and internScopeCreationData
functions are used to register new scope objects with an array of all generated scope objects. The former (internScope
) is "old" code - it was the original way in which scope objects were registered within the parser, and it accepts a closure that produces a "real" scope object (i.e. living on the JS heap).
The latter (internScopeCreationData
) is used by "new" parser code - matthew's work on moving the parser to not require any interaction with the GC or the GC heap.
Eventually, internScope
should go away, and the codepaths that use it deleted, and replaced with usages of internScopeCreationData
. This is almost already the case in many parts of the parser - scopes are emitted with a conditional that picks between either creating the scope object immediately within the GC heap, or creating a parser-internal scope object which will be later promoted to a full GC object (at parse complete).
Problem
The problem we've identified is that the internScope
and internScopeCreationData
functions both accept closures which produce the relevant objects, instead of accepting a pointer to the object itself.
Matthew and I tried to look for reasons it's done this way instead of just having the object created beforehand, there seems to be no compelling reason.
Changing the signatures of internScope
and internScopeCreationData
to accept object pointers directly instead of thunks, helps simplify the parser.
Notes
Example
Here's an example of where internScope
and internScopeCreationData
are used (two lines from the same function):
Note the calls are each in different branches of a conditional - this is an example where we currently implement the "old" and the "new" parser approach.
Uses-list
The following links shows all uses of internScope
and internScopeCreationData
in the code:
Notes on internBodyScope
and internBodyScopeCreationData
These two functions use internScope
and internScopeCreationData
internally, but also adjust some global state with the index of the newly added scope. This should be straightforward to fix as well (and its signature will need to be fixed), but I wanted to note it explicitly so that it's not alarming.
Updated•5 years ago
|
Updated•5 years ago
|
Comment 1•5 years ago
|
||
Hello, I'd like to work on this bug
Reporter | ||
Comment 2•5 years ago
|
||
Hi Khushal! Thanks for the interest! Feel free to take the bug and work on it. The initial comment should give you a good idea of where to start fixing things. I can review patches and answer questions you may have.
Comment 3•5 years ago
|
||
Hello, I think I understand this a bit, although I'm a beginner in contributing so I don't know much, I have few questions
- How do I test the changes I have done ? are there mochitests for it or something else ?
- Can you give a little example on how do I do this
From what I understood, I think I have to change these two functionsinternScope
andinternScopeCreationData
to accept object pointers instead of the closure (which I think isScopeCreator createScope
?) and the relevant objects which are created refer toScope* scope
So The object (which probably isScope* scope
) should be created beforehand in the places where these functions are being used ? (in the places mentioned in Uses-list)
Please correct me if I have misinterpreted anything
Reporter | ||
Comment 4•5 years ago
|
||
Hi Khushal,
-
Yeah, mochitests, the js shell test, and reference tests should be sufficient to cover testing for this. Do you have access to the try server? This allows you to push your changes to our CI infrastructure to run a gamut of tests against and check. Typically I run the mochitests and call it a day for these things.
-
Your understanding is correct. This bug came about because Matthew and I were looking at this code as part of the larger work of removing JSAtom* usage from the parser. It seemed kind of strange that these functions accepted closures and then invoked them to obtain the object they created, but didn't seem to be doing any real work in between being passed the closure and invoking it - suggesting that this is some extra bit of unnecessary complexity that was added for reasons that aren't relevant anymore.
Comment 5•5 years ago
|
||
Ok, as for try server I do not have access to it
So I tried doing changes by creating scope object beforehand and then passing it to 'internScope' and 'internScopeCreationData'
I am getting quite some errors one of them is
member reference type 'js::Scope *' is a pointer; did you mean to use '->'
when it runs the line hasEnvironment_ = scope.get().hasEnvironment();
inside the internScopeCreationData
function
What should I do?
Reporter | ||
Comment 6•5 years ago
|
||
Can you post (attach, or post via phabricator) a diff of your changes? It would make it easier to advise on what's going wrong.
Comment 7•5 years ago
|
||
Updated•5 years ago
|
Updated•5 years ago
|
Reporter | ||
Comment 9•5 years ago
|
||
Hey Khushal - will take a look at this and address with phab comments sometime soon. Things are a bit busy with preparation for the all-hands. Leaving needinfo-myself on.
Reporter | ||
Comment 10•5 years ago
|
||
Hi Khushal, taking a look at this patch again. Review comments in a bit.
Comment 11•5 years ago
|
||
I sincerely apologize but due to change in my schedule, I won't be able to work on this patch
Reporter | ||
Updated•5 years ago
|
Updated•4 years ago
|
Comment 12•4 years ago
|
||
This good-first-bug hasn't had any activity for 2 months, it is automatically unassigned.
For more information, please visit auto_nag documentation.
Updated•4 years ago
|
Assignee | ||
Comment 13•4 years ago
|
||
(In reply to Kannan Vijayan [:djvj] from comment #0)
Motivation
This bug came about after discussing ongoing parser work with @mgaudet.
The
internScope
andinternScopeCreationData
functions are used to register new scope objects with an array of all generated scope objects. The former (internScope
) is "old" code - it was the original way in which scope objects were registered within the parser, and it accepts a closure that produces a "real" scope object (i.e. living on the JS heap).The latter (
internScopeCreationData
) is used by "new" parser code - matthew's work on moving the parser to not require any interaction with the GC or the GC heap.Eventually,
internScope
should go away, and the codepaths that use it deleted, and replaced with usages ofinternScopeCreationData
. This is almost already the case in many parts of the parser - scopes are emitted with a conditional that picks between either creating the scope object immediately within the GC heap, or creating a parser-internal scope object which will be later promoted to a full GC object (at parse complete).Problem
The problem we've identified is that the
internScope
andinternScopeCreationData
functions both accept closures which produce the relevant objects, instead of accepting a pointer to the object itself.Matthew and I tried to look for reasons it's done this way instead of just having the object created beforehand, there seems to be no compelling reason.
Changing the signatures of
internScope
andinternScopeCreationData
to accept object pointers directly instead of thunks, helps simplify the parser.Notes
Example
Here's an example of where
internScope
andinternScopeCreationData
are used (two lines from the same function):Note the calls are each in different branches of a conditional - this is an example where we currently implement the "old" and the "new" parser approach.
Uses-list
The following links shows all uses of
internScope
andinternScopeCreationData
in the code:Notes on
internBodyScope
andinternBodyScopeCreationData
These two functions use
internScope
andinternScopeCreationData
internally, but also adjust some global state with the index of the newly added scope. This should be straightforward to fix as well (and its signature will need to be fixed), but I wanted to note it explicitly so that it's not alarming.
I want to work on this bug, I can only find internScopeCreationData in
https://searchfox.org/mozilla-central/search?q=internScopeCreationData&path=
how should I modify the parameters of internScopeCreationData ?
Comment 14•4 years ago
|
||
Hi sneha:
internBodyScope has become internBodyScopeCreationData;
In both functions, you'll notice they take as their second argument a C++ Lambda function; but if you look at the implementation of internScopeCreationData, you'll notice that the lambda is -immediately called-; so instead of calling the lambda, we can just replace the creation of a lambda with the body of the lambda, then pass the resulting ScopeIndex
that to internScopeCreationData or internBodyScopeCreationData, as appropriate.
Assignee | ||
Comment 15•4 years ago
|
||
(In reply to Matthew Gaudet (he/him) [:mgaudet] from comment #14)
Hi sneha:
internBodyScope has become internBodyScopeCreationData;
In both functions, you'll notice they take as their second argument a C++ Lambda function; but if you look at the implementation of internScopeCreationData, you'll notice that the lambda is -immediately called-; so instead of calling the lambda, we can just replace the creation of a lambda with the body of the lambda, then pass the resulting
ScopeIndex
that to internScopeCreationData or internBodyScopeCreationData, as appropriate.
https://paste.mozilla.org/tEsfA8dj
Does it have to be implemented like this?
Assignee | ||
Comment 16•4 years ago
|
||
(In reply to Matthew Gaudet (he/him) [:mgaudet] from comment #14)
Hi sneha:
internBodyScope has become internBodyScopeCreationData;
In both functions, you'll notice they take as their second argument a C++ Lambda function; but if you look at the implementation of internScopeCreationData, you'll notice that the lambda is -immediately called-; so instead of calling the lambda, we can just replace the creation of a lambda with the body of the lambda, then pass the resulting
ScopeIndex
that to internScopeCreationData or internBodyScopeCreationData, as appropriate.
sorry I forgot, the earlier link expires in an hour, here is the new one https://paste.mozilla.org/d1dCSU40
Assignee | ||
Comment 17•4 years ago
|
||
Updated•4 years ago
|
Comment 18•4 years ago
|
||
Comment 19•4 years ago
|
||
bugherder |
Description
•