Changeset 202795 in webkit


Ignore:
Timestamp:
Jul 3, 2016 2:36:48 PM (8 years ago)
Author:
sbarati@apple.com
Message:

BytecodeGenerator::getVariablesUnderTDZ is too conservative
https://bugs.webkit.org/show_bug.cgi?id=159387

Reviewed by Filip Pizlo.

Source/JavaScriptCore:

We were too conservative in the following type of programs:
`
{

{

let x;
...

}
let x;

}
`
We used to report "x" as under TDZ when calling getVariablesUnderTDZ at the
"...", even though "x" is not under TDZ. This patch removes this conservatism
and makes the algorithm precise.

  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::getVariablesUnderTDZ):

  • bytecompiler/BytecodeGenerator.h:

Source/WTF:

I've templatized SmallPtrSet on its SmallArraySize instead
of it always being 8.

  • wtf/SmallPtrSet.h:

(WTF::SmallPtrSet::SmallPtrSet):
(WTF::SmallPtrSet::add):
(WTF::SmallPtrSet::iterator::operator!=):
(WTF::SmallPtrSet::bucket):

Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r202792 r202795  
     12016-07-03  Saam Barati  <sbarati@apple.com>
     2
     3        BytecodeGenerator::getVariablesUnderTDZ is too conservative
     4        https://bugs.webkit.org/show_bug.cgi?id=159387
     5
     6        Reviewed by Filip Pizlo.
     7
     8        We were too conservative in the following type of programs:
     9        ```
     10        {
     11            {
     12                let x;
     13                ...
     14            }
     15            let x;
     16        }
     17        ```
     18        We used to report "x" as under TDZ when calling getVariablesUnderTDZ at the
     19        "...", even though "x" is not under TDZ. This patch removes this conservatism
     20        and makes the algorithm precise.
     21
     22        * bytecompiler/BytecodeGenerator.cpp:
     23        (JSC::BytecodeGenerator::getVariablesUnderTDZ):
     24        * bytecompiler/BytecodeGenerator.h:
     25
    1262016-07-03  Filip Pizlo  <fpizlo@apple.com>
    227
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r202778 r202795  
    4747#include "UnlinkedInstructionStream.h"
    4848#include <wtf/CommaPrinter.h>
     49#include <wtf/SmallPtrSet.h>
    4950#include <wtf/StdLibExtras.h>
    5051#include <wtf/text/WTFString.h>
     
    27922793void BytecodeGenerator::getVariablesUnderTDZ(VariableEnvironment& result)
    27932794{
    2794     // NOTE: This is conservative. If called at "...", it will report "x" as being under TDZ:
     2795    // We keep track of variablesThatDontNeedTDZ in this algorithm to prevent
     2796    // reporting that "x" is under TDZ if this function is called at "...".
    27952797    //
    27962798    //     {
     
    28022804    //     }
    28032805    //
    2804     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=159387
    2805     for (auto& map : m_TDZStack) {
     2806    SmallPtrSet<UniquedStringImpl*, 16> variablesThatDontNeedTDZ;
     2807    for (unsigned i = m_TDZStack.size(); i--; ) {
     2808        auto& map = m_TDZStack[i];
    28062809        for (auto& entry : map)  {
    2807             if (entry.value != TDZNecessityLevel::NotNeeded)
    2808                 result.add(entry.key.get());
     2810            if (entry.value != TDZNecessityLevel::NotNeeded) {
     2811                if (!variablesThatDontNeedTDZ.contains(entry.key.get()))
     2812                    result.add(entry.key.get());
     2813            } else
     2814                variablesThatDontNeedTDZ.add(entry.key.get());
    28092815        }
    28102816    }
  • trunk/Source/WTF/ChangeLog

    r202791 r202795  
     12016-07-03  Saam Barati  <sbarati@apple.com>
     2
     3        BytecodeGenerator::getVariablesUnderTDZ is too conservative
     4        https://bugs.webkit.org/show_bug.cgi?id=159387
     5
     6        Reviewed by Filip Pizlo.
     7
     8        I've templatized SmallPtrSet on its SmallArraySize instead
     9        of it always being 8. 
     10
     11        * wtf/SmallPtrSet.h:
     12        (WTF::SmallPtrSet::SmallPtrSet):
     13        (WTF::SmallPtrSet::add):
     14        (WTF::SmallPtrSet::iterator::operator!=):
     15        (WTF::SmallPtrSet::bucket):
     16
    1172016-07-03  Filip Pizlo  <fpizlo@apple.com>
    218
  • trunk/Source/WTF/wtf/SmallPtrSet.h

    r200380 r202795  
    3434namespace WTF {
    3535
    36 template<typename PtrType>
     36template<typename PtrType, unsigned SmallArraySize = 8>
    3737class SmallPtrSet {
    3838    WTF_MAKE_NONCOPYABLE(SmallPtrSet);
    3939    static_assert(std::is_trivially_destructible<PtrType>::value, "We currently don't support non-trivially destructible pointer types.");
    4040    static_assert(sizeof(PtrType) == sizeof(void*), "Only support pointer sized things.");
     41    static_assert(!(SmallArraySize & (SmallArraySize - 1)), "Inline size must be a power of two.");
    4142
    4243public:
     
    9192            }
    9293
    93             grow(64);
     94            grow(std::max(64u, SmallArraySize * 2));
    9495            // Fall through. We're no longer small :(
    9596        }
     
    139140
    140141    private:
    141         template<typename U> friend class WTF::SmallPtrSet;
     142        template<typename U, unsigned S> friend class WTF::SmallPtrSet;
    142143        unsigned m_index;
    143144        unsigned m_capacity;
     
    240241    }
    241242
    242     static const unsigned SmallArraySize = 8;
    243 
    244243    unsigned m_size;
    245244    unsigned m_capacity;
Note: See TracChangeset for help on using the changeset viewer.