Bug 157968 - REGRESSION(r199075): String.prototype.replace fails after being used many times with different replace values
Summary: REGRESSION(r199075): String.prototype.replace fails after being used many tim...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Saam Barati
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-05-20 21:30 PDT by Joseph Pecoraro
Modified: 2016-05-22 12:12 PDT (History)
12 users (show)

See Also:


Attachments
patch (2.48 KB, patch)
2016-05-21 00:33 PDT, Saam Barati
rniwa: review+
Details | Formatted Diff | Diff
patch for landing (3.15 KB, patch)
2016-05-22 11:42 PDT, Saam Barati
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 2016-05-20 21:30:37 PDT
* SUMMARY
String.prototype.replace fails used many times with different replace values.

* TEST
<script>
(function() {
    var result = "foo".replace(/f/g, "");
    if (result != "oo")
        throw "Error: bad result: "+ result;
    for (var i = 0; i < 100000; ++i)
        result = "foo".replace(/f/g, 42);
    if (result != "42oo")
        throw "Error: bad result: "+ result;
})();
</script>

* STEPS TO REPRODUCE
1. Run test
  => Unexpected Exception, test should not have an exception
  => The Error is: "Error: bad result: oo"
Comment 1 Radar WebKit Bug Importer 2016-05-20 21:31:04 PDT
<rdar://problem/26404735>
Comment 2 Joseph Pecoraro 2016-05-20 21:42:20 PDT
Bisection results: <http://trac.webkit.org/log/trunk/?rev=199084&stop_rev=199073>

Most likely culprit is:

  DFG and FTL should constant-fold RegExpExec, RegExpTest, and StringReplace
  <​https://bugs.webkit.org/show_bug.cgi?id=155270>
  <http://trac.webkit.org/changeset/199075>
Comment 3 Joseph Pecoraro 2016-05-20 22:20:05 PDT
Based on the order of tests run on the bots "js/regress/string-replace-generic.html" can fail if "js/regress/string-replace-empty.html" runs before it. So, in the mean time I am marking "js/regress/string-replace-generic.html" as [ Pass Fail ] in LayoutTests/TestExpectations. Please remove that entry when fixing!
Comment 4 Joseph Pecoraro 2016-05-20 22:22:08 PDT
> Please remove that entry when fixing!

Test marked flakey in: <http://trac.webkit.org/changeset/201240>
Comment 5 Saam Barati 2016-05-20 22:25:40 PDT
Sounds related to Fil's constant folding patch from a month ago.
Comment 6 Saam Barati 2016-05-20 23:57:42 PDT
(In reply to comment #5)
> Sounds related to Fil's constant folding patch from a month ago.

Oops. Looks like you already bisected to that patch
Comment 7 Saam Barati 2016-05-21 00:33:37 PDT
Created attachment 279539 [details]
patch
Comment 8 Saam Barati 2016-05-21 00:34:54 PDT
Fil, we currently won't constant fold the test case now.
It's because 42 is a number and not a string. Should we extend
LazyJSValue::tryGetStringImpl to handle numbers too? This
seems like something we really should constant fold.
Comment 9 Joseph Pecoraro 2016-05-21 02:22:39 PDT
Comment on attachment 279539 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=279539&action=review

> LayoutTests/TestExpectations:-984
> -webkit.org/b/157968 js/regress/string-replace-generic.html [ Pass Failure ]

We should add a new test for this. We got lucky that a bot ran 2 tests in sequence and triggered this. It seems worthwhile to have a single test that covers this on its own.
Comment 10 Saam Barati 2016-05-21 10:42:14 PDT
(In reply to comment #9)
> Comment on attachment 279539 [details]
> patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=279539&action=review
> 
> > LayoutTests/TestExpectations:-984
> > -webkit.org/b/157968 js/regress/string-replace-generic.html [ Pass Failure ]
> 
> We should add a new test for this. We got lucky that a bot ran 2 tests in
> sequence and triggered this. It seems worthwhile to have a single test that
> covers this on its own.

I'll add this to JSC's tests. It reproduces every time when run in JSC without
concurrent JIT
Comment 11 Ryosuke Niwa 2016-05-21 11:38:26 PDT
Comment on attachment 279539 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=279539&action=review

> Source/JavaScriptCore/ChangeLog:10
> +        There was a bug in the DFG where we were checking a condition
> +        on the wrong variable.

LOL, that won't do any good!
Comment 12 Ryosuke Niwa 2016-05-21 11:39:03 PDT
Please add a test as Joe pointed out.
Comment 13 Filip Pizlo 2016-05-21 11:40:26 PDT
Comment on attachment 279539 [details]
patch

Wow!!!  R=me too
Comment 14 Alexey Proskuryakov 2016-05-21 13:26:40 PDT
> Based on the order of tests run on the bots "js/regress/string-replace-generic.html" can fail if "js/regress/string-replace-empty.html" runs before it.

This should never happen. Tests in one directory are supposed to run sequentially, and alphabetically.

Do you have a link to a test run where this happened?
Comment 15 Saam Barati 2016-05-22 11:42:29 PDT
Created attachment 279551 [details]
patch for landing
Comment 16 WebKit Commit Bot 2016-05-22 12:12:18 PDT
Comment on attachment 279551 [details]
patch for landing

Clearing flags on attachment: 279551

Committed r201254: <http://trac.webkit.org/changeset/201254>
Comment 17 WebKit Commit Bot 2016-05-22 12:12:25 PDT
All reviewed patches have been landed.  Closing bug.