Last Comment Bug 691695 - Refactor RegExp components as prep for overhaul
: Refactor RegExp components as prep for overhaul
Status: RESOLVED FIXED
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: unspecified
: All All
: -- normal (vote)
: mozilla10
Assigned To: Chris Leary [:cdleary] (not checking bugmail)
:
: Jason Orendorff [:jorendorff]
Mentors:
Depends on:
Blocks: 673274 692069
  Show dependency treegraph
 
Reported: 2011-10-04 01:52 PDT by Chris Leary [:cdleary] (not checking bugmail)
Modified: 2011-10-07 12:40 PDT (History)
5 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
WIP: reorg before lazifying. (189.51 KB, patch)
2011-10-04 01:52 PDT, Chris Leary [:cdleary] (not checking bugmail)
no flags Details | Diff | Splinter Review
RegExp component reorg. (179.19 KB, patch)
2011-10-05 02:44 PDT, Chris Leary [:cdleary] (not checking bugmail)
luke: review+
Details | Diff | Splinter Review

Description Chris Leary [:cdleary] (not checking bugmail) 2011-10-04 01:52:10 PDT
Created attachment 564486 [details] [diff] [review]
WIP: reorg before lazifying.

+++ This bug was initially created as a clone of Bug #673274 +++

The code for the RegExp implementation wasn't well segregated. I talked to Luke today about the way that this should be organized (similar to vm/StringObject) and I belted out the attached patch, which is passing shell tests, but still needs some cleanup.

This patch introduces:

vm/RegExpObect
    - Extends JSObject with reserved slots accessors, js::Class (RegExpClass)
      vtable methods
    - RegExpPrivate, which is the C++ blobby that can be shared and holds code.
      This lives in the private slot of the RegExpObject

vm/RegExpStatics
    - VM data structure for the static regular expression results. These live
      in 1:1 correspondence with GlobalObject, but they have their own
      JSObject for finalization of the C++ blobby.

builtin/RegExp
    - Stuff necessary for performing js_InitRegExpClass; i.e. all the property
      and method implementation that gets stuck on in |RegExp.prototype|.
      This is a client of the vm data structures.
Comment 1 Chris Leary [:cdleary] (not checking bugmail) 2011-10-05 02:44:45 PDT
Created attachment 564771 [details] [diff] [review]
RegExp component reorg.

Aside from moving code around and renaming things, a few other small refactoring-like bits slipped in. (Sorry that it's a single patch, but these things just kind of started happening naturally as I defined the new interfaces.)

- Strengthened the RegExpObject invariant that it must have a RegExpPrivate if
  it has been properly initialized. (Uses PreInitRegExpObject guard thing to
  enforce this at several of the initialization sites.)
- Changed all the uses of RegExp flags. Compare the betterness of
  JSREG_FOLD vs IgnoreCaseFlag. (Statically asserted to be the same values.)
- Made GlobalObject return a pointer from getRegExpStatics instead of Value.
- I got rid of the horrible "Swap" terminology in the builtins and
  made everything simply "reset" -- sometimes you reset with statics, and
  sometimes you reset without statics. Reset is like "reinitialize", and exists
  because RegExps can't be normal children due to bug 691682 and its kin.

Passes shell tests and browser seem to work okay, so r? and pushing to try.
Comment 2 Chris Leary [:cdleary] (not checking bugmail) 2011-10-05 04:37:42 PDT
Also just realized that replacePrivate is vestigial.
Comment 3 Chris Leary [:cdleary] (not checking bugmail) 2011-10-05 11:34:18 PDT
Bah, and the second header declaration for ResetRegExpObject is missing a RegExpObject parameter (doesn't affect anything though, since it's declared/defined properly in the inlines file).
Comment 4 Chris Leary [:cdleary] (not checking bugmail) 2011-10-05 11:47:32 PDT
Cloning added a lot of people to this relatively unimportant refactoring bug. Fixing that, feel free to add yourself back if I've removed you in error.
Comment 5 Luke Wagner [:luke] 2011-10-05 15:29:47 PDT
Comment on attachment 564771 [details] [diff] [review]
RegExp component reorg.

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

Looks great.

::: js/src/builtin/RegExp.cpp
@@ +487,5 @@
> +
> +    return true;
> +}
> +
> +namespace js {

I don't think it's yet documented, but the style we've converged towards is, for namespace'd function definitions, to write js::foo instead of namespace js { foo }.  This has several benefits, so it would be good to do it here.

::: js/src/jsparse.cpp
@@ +8881,5 @@
>          } else {
> +            reobj = RegExpObject::createNoStatics(
> +                      context, tokenStream.getTokenbuf().begin(),
> +                      tokenStream.getTokenbuf().length(),
> +                      RegExpFlag(tokenStream.currentToken().t_reflags), &tokenStream);

Instead of of the two long blobs, could you compute the parameters into locals thereby making RegExpObject::create(NoStatics) each fit on a single line?  That avoids the problem that the indentation is not SM-style.

::: js/src/jsregexpinlines.h
@@ +100,5 @@
> +    return !v.isPrimitive() && v.toObject().isRegExp();
> +}
> +
> +inline bool
> +IsRegExpMetaChar(jschar c)

Can you re-evaluate, for reach of these inline functions, whether it really has to go in the -inl.h file?  Ideally, more of these would be statics in the .cpp or non-inline externs in the .h.
Comment 6 Chris Leary [:cdleary] (not checking bugmail) 2011-10-07 03:39:35 PDT
(In reply to Luke Wagner [:luke] from comment #5)
> Can you re-evaluate, for reach of these inline functions, whether it really
> has to go in the -inl.h file?  Ideally, more of these would be statics in
> the .cpp or non-inline externs in the .h.

I promise I'll do this in a followup patch! I've filed bug 692750 -- the issue I have is that I've made a queue on top of this patch (due to the surrounding bugs) and moving function bodies to the source file will prevent diffs from carrying. Maybe there's a better way of handling this in my future workflow?
Comment 7 Matt Brubeck (:mbrubeck) 2011-10-07 12:40:27 PDT
https://hg.mozilla.org/mozilla-central/rev/4d312cb93a94

Note You need to log in before you can comment on or make changes to this bug.