Closed Bug 770865 Opened 12 years ago Closed 12 years ago

Rename TreeContext as ParseContext

Categories

(Core :: JavaScript Engine, defect)

Other Branch
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla17

People

(Reporter: jorendorff, Assigned: jorendorff)

Details

(Whiteboard: [js:t])

Attachments

(1 file, 1 obsolete file)

njn: You mentioned this would bitrot some work of yours, but by the time I read that I had already made this patch. So how bad is it? I'm sure we can figure something out. I can manually rebase your patch for you, if you like.
Attached patch v1 (obsolete) — Splinter Review
Huge, but quite mechanical.
Assignee: general → jorendorff
Attachment #639079 - Flags: review?(n.nethercote)
Comment on attachment 639079 [details] [diff] [review]
v1

Review of attachment 639079 [details] [diff] [review]:
-----------------------------------------------------------------

It will bit-rot me, but I'll take the hit for the greater good.

I like how you fixed a couple of incorrect comments;  that shows you were paying attention as you made the changes :)  The removal of unnecessary #includes is also good.

I looked at most of the patch closely, but I'll admit to skimming the Parser.cpp changes.

If you haven't already, can you grep for the following patterns to make sure you've changed everything you should:

  TreeContext
  \<tc\>
  TC\>

I think those patterns will catch everything.

If you want a follow-up:  you should be able to move ParseContext into Parser.h and rename the ParseContext module as SharedContext.
(In fact, if you did that before this patch, you'd be able to rename the TreeContext module as SharedContext directly, without calling it ParseContext as an intermediate step.  That's what I was planning to do.)

And then you'll be able to move StmtInfoPC into Parser.h.

Also, since we're clearly on the same wave-length at the moment:  if you're thinking of splitting BytecodeEmitter into BytecodeEmitter and BytecodeContext in order to mirror the Parser/ParseContext split, don't bother.  I tried it and it just made things more complicated;  having three fields that are the same in every BytecodeEmitter is a small price to pay to avoid the split into two classes.  (I even considered combining Parser and ParseContext into a single class, but that was too hard and ugly.)
Attachment #639079 - Flags: review?(n.nethercote) → review+
Whiteboard: [js:t]
This is bitrotted beyond belief. Fallout from the delay caused by bug 770865.
I saw this was backed out due to bustage.  Around the same time, there was a bug 771870 which caused anything to burn that added a file.  Just in case you wanted to reland it b/c boy is ParseContext a better name than TreeContext...
> I saw this was backed out due to bustage.

It never landed, AFAICT, but it would be nice if it did :)
Big and mechanical, like your previous patch.  This is applied on top of the
patches in bug 782871.
Attachment #652681 - Flags: review?(jorendorff)
Summary: Rename TreeContext to ParseContext → Rename TreeContext as ParseContext
Attachment #639079 - Attachment is obsolete: true
Comment on attachment 652681 [details] [diff] [review]
Rename TreeContext as ParseContext.

Review of attachment 652681 [details] [diff] [review]:
-----------------------------------------------------------------

Stealing with permission.

::: js/src/frontend/Parser-inl.h
@@ +42,5 @@
>      vars_(prs->context),
>      yieldNode(NULL),
>      functionList(NULL),
>      queuedStrictModeError(NULL),
> +    parserPC(&prs->pc),

Feel free to ignore, but I just happened to notice: could we just have ParseContext store a pointer to the Parser instead?  The only use seems to be in ~ParserContext which really just wants to write: "JS_ASSERT(parser->tc == this; parser->tc = parent;".

::: js/src/frontend/Parser.cpp
@@ +3279,5 @@
>      }
>  
>  #if JS_HAS_BLOCK_SCOPE
>      if (blockObj)
> +        PopStatementPC(context, pc);

I think it would be nice if we could have:
  pc->pushStatement / pc->popStatement
This would avoid the name Push/PopStatementPC which makes my brain thing "Program Counter".  (All uses of 'pc' do this a bit, but the name of this one is especially ambiguous-sounding.)  Up to you.
Attachment #652681 - Flags: review?(jorendorff) → review+
> Feel free to ignore, but I just happened to notice: could we just have
> ParseContext store a pointer to the Parser instead?  The only use seems to
> be in ~ParserContext which really just wants to write: "JS_ASSERT(parser->tc
> == this; parser->tc = parent;".

My motivation in not doing that was to avoid a cyclic dependency between ParseContext and Parser.  Now, because it's just a pointer we could just forward declare Parser before ParseContext, but it still felt nicer to store a ParseContext pointer instead.


> I think it would be nice if we could have:
>   pc->pushStatement / pc->popStatement
> This would avoid the name Push/PopStatementPC which makes my brain thing
> "Program Counter".  (All uses of 'pc' do this a bit, but the name of this
> one is especially ambiguous-sounding.)  Up to you.

I agree about the "PC" ambiguity.  But PushStatementPC and PopStatementPC are both local to Parser.cpp, and moving them into class ParseContext would expose them in ParseContext.h, which isn't great.

Maybe the existing |PushStatement| could become |PushStatementBase| and then |PushStatementPC| and |PushStatementBCE| could both be renamed as |PushStatement|?  The latter two are in separate files, so it wouldn't be too confusing.
(In reply to Nicholas Nethercote [:njn] from comment #8)
> My motivation in not doing that was to avoid a cyclic dependency between
> ParseContext and Parser.  Now, because it's just a pointer we could just
> forward declare Parser before ParseContext, but it still felt nicer to store
> a ParseContext pointer instead.

I'm not sure if anything is really gained by avoiding the forward decl (the structure is inherently cyclic, regardless of what type names we use).

> I agree about the "PC" ambiguity.  But PushStatementPC and PopStatementPC
> are both local to Parser.cpp, and moving them into class ParseContext would
> expose them in ParseContext.h, which isn't great.

Can we just make ParseContext.h only be #included by Parser.cpp?  I only see it used via pointers in Parser.h.  In fact, could we just move the contents of TreeContext.{h,cpp} into Parser.cpp?  It would avoid what feels like an artificial separation that I started with the new TreeContext::define et al (which I still think was the right thing to do, since it allowed me to encapsulate the declaration state in the right place).
Oh, hah, you just did move TreeContext stuff into Parser.cpp.  Seems like you could move the TreeContext decl from Parser.h into Parser.cpp w/o much trouble and then there would be no concern for putting pushStatement on ParserContext.
> Seems like you could move the TreeContext decl from Parser.h into Parser.cpp
> w/o much trouble

I just tried that but BytecodeCompiler.cpp needs access to ParseContext (formerly TreeContext) and its constructor and destructor :(
https://hg.mozilla.org/mozilla-central/rev/73de2885e0e3
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla17
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: