Closed Bug 750282 Opened 12 years ago Closed 12 years ago

Remove TCF_COMPILING

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla15

People

(Reporter: n.nethercote, Assigned: n.nethercote)

References

Details

Attachments

(1 file, 4 obsolete files)

TreeContext::asBytecodeEmitter is a down-cast.  It kinda sucks, because it exposes in an unclean way the fact that Parser::tc can be a TreeContext or a BytecodeEmitter, depending on the context.

This first patch adds BytecodeEmitter::parentBCE, which has the same value as TreeContext::parent, but a different type.  It allows us to remove the places where asBytecodeEmitter() is called where we know the down-cast will succeed.
Attachment #619572 - Flags: review?(jorendorff)
This second patch converts DefineGlobal and BindTopLevelVar to methods within TreeContext, which BytecodeEmitter overrides.  This allows us to remove the places where asBytecodeEmitter() is called where we are unsure if the down-cast will succeed.
Attachment #619574 - Flags: review?(jorendorff)
This third patch removes asBytecodeEmitter(), TCF_COMPILING, and compiling().
Attachment #619576 - Flags: review?(jorendorff)
Attached patch new patch (obsolete) — Splinter Review
Actually, the down-casts that are known to succeed (i.e. those removed in 
patch 1) aren't that bad;  no worse than adding a |parentBCE| field that has
the same value as |parent|.  

Here's a rolled-up patch that keeps those not-so-bad down-casts.
Summarizing its effects:

- It removes the can-fail down-casts by moving defineGlobal() and 
  bindTopLevelVar() into TreeContext.  

- It moves the down-cast method from TreeContext() into BytecodeEmitter(),
  which is a much better spot for it.
  
- TCF_COMPILING and compiling() are no longer necessary.
  
The main effect is that Parser doesn't need to know that its TreeContext 
might actually be a BytecodeEmitter.  This is a good thing in its own right
and a step towards making Parser.cpp module not depend on BytecodeEmitter.h.
Attachment #619572 - Attachment is obsolete: true
Attachment #619574 - Attachment is obsolete: true
Attachment #619576 - Attachment is obsolete: true
Attachment #619572 - Flags: review?(jorendorff)
Attachment #619574 - Flags: review?(jorendorff)
Attachment #619576 - Flags: review?(jorendorff)
Attachment #619781 - Flags: review?(jorendorff)
Summary: Don't down-cast TreeContext to BytecodeEmitter → Eliminate Parser's need to know about BytecodeEmitter
Blocks: 750580
Depends on: 751818
Summary: Eliminate Parser's need to know about BytecodeEmitter → Remove TCF_COMPILING
Attached patch newer patchSplinter Review
This patch is even simpler.  It applies on top of the patch in bug 751818.  Net effects:

- TCF_COMPILING and compiling() are removed.

- The TreeContext-to-BytecodeEmitter downcasts are moved.
Attachment #619781 - Attachment is obsolete: true
Attachment #619781 - Flags: review?(jorendorff)
Attachment #620977 - Flags: review?(jorendorff)
coool
Comment on attachment 619781 [details] [diff] [review]
new patch

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

r=me if what you intended is for the two methods to be virtual. Otherwise I'm confused and need to take another look.

I'm assuming the two functions you moved are pretty much unchanged, just moving them from one file to another and turning them into BytecodeEmitter methods.

::: js/src/frontend/BytecodeEmitter.h
@@ +372,5 @@
>      }
>  
>      OwnedAtomDefnMapPtr lexdeps;    /* unresolved lexical name dependencies */
>  
> +    TreeContext     *parent;        /* Enclosing function or global context.  */

Why do you think the longer comment here is no longer helpful?

@@ +484,5 @@
>          return flags & TCF_FUN_EXTENSIBLE_SCOPE;
>      }
>  
> +    bool defineGlobal(ParseNode *pn, PropertyName *name);
> +    bool bindTopLevelVar(BindData *data, ParseNode *pn);

Hmm. These are non-virtual. (more about this in two comments below)

@@ +641,5 @@
> +    // This is a down-cast.  It's necessary and safe -- although
> +    // TreeContext::parent is a |TreeContext *|, a BytecodeEmitter's parent is
> +    // always itself a BytecodeEmitter.
> +    BytecodeEmitter *parentBCE() {
> +        return static_cast<BytecodeEmitter *>(parent);

It would be cool if the parent data member was private, the base class had a parent() method, and this parent() method just hid that one. It wouldn't be necessary for either parent() to be virtual. Just a thought.

@@ +698,5 @@
>  
>      bool needsImplicitThis();
>  
> +    bool defineGlobal(ParseNode *pn, PropertyName *name);   // overrides
> +    bool bindTopLevelVar(BindData *data, ParseNode *pn);    // overrides

If these are supposed to be virtual, consider using MOZ_OVERRIDE instead of comments.

::: js/src/frontend/Parser.cpp
@@ +1703,5 @@
>          pn->pn_body = body;
>      }
>  
> +    if (!outertc->inFunction() && bodyLevel && kind == Statement) {
> +        if (!outertc->defineGlobal(pn, funName))

Because the method is nonvirtual, this will be dispatched to the base-class defineGlobal method which does nothing... right?

If so, it must be a bug. Make sure we have a test that fails here, adding one if needed.

Same goes for bindTopLevelVar.
Attachment #619781 - Attachment is obsolete: false
Comment on attachment 620977 [details] [diff] [review]
newer patch

r+ without the qualification on the previous version of the patch.

The nits about deleting comments still stand, otherwise this is fine.
Attachment #620977 - Flags: review?(jorendorff) → review+
I got rid of the comments mostly I have upcoming patches that will completely separate TreeContext and BytecodeEmitter, whereupon the comment will no longer be true.  I can put it back for the moment, though.
I ended up removing the comment, because I didn't want to put it back in just to remove it in a later patch.  Don't worry, things will be getting much better soon :)

https://hg.mozilla.org/integration/mozilla-inbound/rev/c6ea9609aa15
Attachment #619781 - Attachment is obsolete: true
https://hg.mozilla.org/mozilla-central/rev/c6ea9609aa15
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla15
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: