[DFG] DFG should handle String#toString
[WebKit-https.git] / Source / JavaScriptCore / dfg / DFGAbstractInterpreterInlines.h
1 /*
2  * Copyright (C) 2013-2018 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #pragma once
27
28 #if ENABLE(DFG_JIT)
29
30 #include "ArrayConstructor.h"
31 #include "ArrayPrototype.h"
32 #include "DFGAbstractInterpreter.h"
33 #include "DFGAbstractInterpreterClobberState.h"
34 #include "DOMJITGetterSetter.h"
35 #include "DOMJITSignature.h"
36 #include "GetByIdStatus.h"
37 #include "GetterSetter.h"
38 #include "HashMapImpl.h"
39 #include "JITOperations.h"
40 #include "JSImmutableButterfly.h"
41 #include "MathCommon.h"
42 #include "NumberConstructor.h"
43 #include "Operations.h"
44 #include "PutByIdStatus.h"
45 #include "StringObject.h"
46 #include <wtf/BooleanLattice.h>
47 #include <wtf/CheckedArithmetic.h>
48
49 namespace JSC { namespace DFG {
50
51 template<typename AbstractStateType>
52 AbstractInterpreter<AbstractStateType>::AbstractInterpreter(Graph& graph, AbstractStateType& state)
53     : m_codeBlock(graph.m_codeBlock)
54     , m_graph(graph)
55     , m_vm(m_graph.m_vm)
56     , m_state(state)
57 {
58     if (m_graph.m_form == SSA)
59         m_phiChildren = std::make_unique<PhiChildren>(m_graph);
60 }
61
62 template<typename AbstractStateType>
63 AbstractInterpreter<AbstractStateType>::~AbstractInterpreter()
64 {
65 }
66
67 template<typename AbstractStateType>
68 typename AbstractInterpreter<AbstractStateType>::BooleanResult
69 AbstractInterpreter<AbstractStateType>::booleanResult(
70     Node* node, AbstractValue& value)
71 {
72     JSValue childConst = value.value();
73     if (childConst) {
74         if (childConst.toBoolean(m_codeBlock->globalObjectFor(node->origin.semantic)->globalExec()))
75             return DefinitelyTrue;
76         return DefinitelyFalse;
77     }
78
79     // Next check if we can fold because we know that the source is an object or string and does not equal undefined.
80     if (isCellSpeculation(value.m_type) && !value.m_structure.isTop()) {
81         bool allTrue = true;
82         for (unsigned i = value.m_structure.size(); i--;) {
83             RegisteredStructure structure = value.m_structure[i];
84             if (structure->masqueradesAsUndefined(m_codeBlock->globalObjectFor(node->origin.semantic))
85                 || structure->typeInfo().type() == StringType) {
86                 allTrue = false;
87                 break;
88             }
89         }
90         if (allTrue)
91             return DefinitelyTrue;
92     }
93     
94     return UnknownBooleanResult;
95 }
96
97 template<typename AbstractStateType>
98 void AbstractInterpreter<AbstractStateType>::startExecuting()
99 {
100     ASSERT(m_state.block());
101     ASSERT(m_state.isValid());
102     
103     m_state.setClobberState(AbstractInterpreterClobberState::NotClobbered);
104 }
105
106 template<typename AbstractStateType>
107 class AbstractInterpreterExecuteEdgesFunc {
108 public:
109     AbstractInterpreterExecuteEdgesFunc(AbstractInterpreter<AbstractStateType>& interpreter)
110         : m_interpreter(interpreter)
111     {
112     }
113     
114     // This func is manually written out so that we can put ALWAYS_INLINE on it.
115     ALWAYS_INLINE void operator()(Edge& edge) const
116     {
117         m_interpreter.filterEdgeByUse(edge);
118     }
119     
120 private:
121     AbstractInterpreter<AbstractStateType>& m_interpreter;
122 };
123
124 template<typename AbstractStateType>
125 void AbstractInterpreter<AbstractStateType>::executeEdges(Node* node)
126 {
127     m_graph.doToChildren(node, AbstractInterpreterExecuteEdgesFunc<AbstractStateType>(*this));
128 }
129
130 template<typename AbstractStateType>
131 void AbstractInterpreter<AbstractStateType>::executeKnownEdgeTypes(Node* node)
132 {
133     // Some use kinds are required to not have checks, because we know somehow that the incoming
134     // value will already have the type we want. In those cases, AI may not be smart enough to
135     // prove that this is indeed the case. But the existance of the edge is enough to prove that
136     // it is indeed the case. Taking advantage of this is not optional, since otherwise the DFG
137     // and FTL backends may emit checks in a node that lacks a valid exit origin.
138     m_graph.doToChildren(
139         node,
140         [&] (Edge& edge) {
141             if (mayHaveTypeCheck(edge.useKind()))
142                 return;
143             
144             filterEdgeByUse(edge);
145         });
146 }
147
148 template<typename AbstractStateType>
149 ALWAYS_INLINE void AbstractInterpreter<AbstractStateType>::filterByType(Edge& edge, SpeculatedType type)
150 {
151     AbstractValue& value = m_state.forNodeWithoutFastForward(edge);
152     if (value.isType(type)) {
153         m_state.setProofStatus(edge, IsProved);
154         return;
155     }
156     m_state.setProofStatus(edge, NeedsCheck);
157     m_state.fastForwardAndFilterUnproven(value, type);
158 }
159
160 template<typename AbstractStateType>
161 void AbstractInterpreter<AbstractStateType>::verifyEdge(Node* node, Edge edge)
162 {
163     if (!(m_state.forNodeWithoutFastForward(edge).m_type & ~typeFilterFor(edge.useKind())))
164         return;
165     
166     DFG_CRASH(m_graph, node, toCString("Edge verification error: ", node, "->", edge, " was expected to have type ", SpeculationDump(typeFilterFor(edge.useKind())), " but has type ", SpeculationDump(forNode(edge).m_type), " (", forNode(edge).m_type, ")").data(), AbstractInterpreterInvalidType, node->op(), edge->op(), edge.useKind(), forNode(edge).m_type);
167 }
168
169 template<typename AbstractStateType>
170 void AbstractInterpreter<AbstractStateType>::verifyEdges(Node* node)
171 {
172     DFG_NODE_DO_TO_CHILDREN(m_graph, node, verifyEdge);
173 }
174
175 enum class ToThisResult {
176     Identity,
177     Undefined,
178     GlobalThis,
179     Dynamic,
180 };
181 inline ToThisResult isToThisAnIdentity(VM& vm, bool isStrictMode, AbstractValue& valueForNode)
182 {
183     // We look at the type first since that will cover most cases and does not require iterating all the structures.
184     if (isStrictMode) {
185         if (valueForNode.m_type && !(valueForNode.m_type & SpecObjectOther))
186             return ToThisResult::Identity;
187     } else {
188         if (valueForNode.m_type && !(valueForNode.m_type & (~SpecObject | SpecObjectOther)))
189             return ToThisResult::Identity;
190     }
191
192     if (JSValue value = valueForNode.value()) {
193         if (value.isCell()) {
194             auto* toThisMethod = value.asCell()->classInfo(vm)->methodTable.toThis;
195             if (toThisMethod == &JSObject::toThis)
196                 return ToThisResult::Identity;
197             if (toThisMethod == &JSScope::toThis) {
198                 if (isStrictMode)
199                     return ToThisResult::Undefined;
200                 return ToThisResult::GlobalThis;
201             }
202         }
203     }
204
205     if ((isStrictMode || (valueForNode.m_type && !(valueForNode.m_type & ~SpecObject))) && valueForNode.m_structure.isFinite()) {
206         bool allStructuresAreJSScope = !valueForNode.m_structure.isClear();
207         bool overridesToThis = false;
208         valueForNode.m_structure.forEach([&](RegisteredStructure structure) {
209             TypeInfo type = structure->typeInfo();
210             ASSERT(type.isObject() || type.type() == StringType || type.type() == SymbolType || type.type() == BigIntType);
211             if (!isStrictMode)
212                 ASSERT(type.isObject());
213             // We don't need to worry about strings/symbols here since either:
214             // 1) We are in strict mode and strings/symbols are not wrapped
215             // 2) The AI has proven that the type of this is a subtype of object
216             if (type.isObject() && type.overridesToThis())
217                 overridesToThis = true;
218
219             // If all the structures are JSScope's ones, we know the details of JSScope::toThis() operation.
220             allStructuresAreJSScope &= structure->classInfo()->methodTable.toThis == JSScope::info()->methodTable.toThis;
221         });
222         if (!overridesToThis)
223             return ToThisResult::Identity;
224         if (allStructuresAreJSScope) {
225             if (isStrictMode)
226                 return ToThisResult::Undefined;
227             return ToThisResult::GlobalThis;
228         }
229     }
230
231     return ToThisResult::Dynamic;
232 }
233
234 template<typename AbstractStateType>
235 bool AbstractInterpreter<AbstractStateType>::executeEffects(unsigned clobberLimit, Node* node)
236 {
237     verifyEdges(node);
238     
239     m_state.createValueForNode(node);
240     
241     switch (node->op()) {
242     case JSConstant:
243     case DoubleConstant:
244     case Int52Constant: {
245         setBuiltInConstant(node, *node->constant());
246         break;
247     }
248
249     case LazyJSConstant: {
250         LazyJSValue value = node->lazyJSValue();
251         switch (value.kind()) {
252         case LazyJSValue::KnownValue:
253             setConstant(node, value.value()->value());
254             break;
255         case LazyJSValue::SingleCharacterString:
256         case LazyJSValue::KnownStringImpl:
257         case LazyJSValue::NewStringImpl:
258             setTypeForNode(node, SpecString);
259             break;
260         }
261         break;
262     }
263
264     case IdentityWithProfile:
265     case Identity: {
266         setForNode(node, forNode(node->child1()));
267         if (forNode(node).value())
268             m_state.setFoundConstants(true);
269         break;
270     }
271         
272     case ExtractCatchLocal:
273     case ExtractOSREntryLocal: {
274         makeBytecodeTopForNode(node);
275         break;
276     }
277             
278     case GetLocal: {
279         VariableAccessData* variableAccessData = node->variableAccessData();
280         AbstractValue value = m_state.operand(variableAccessData->local().offset());
281         // The value in the local should already be checked.
282         DFG_ASSERT(m_graph, node, value.isType(typeFilterFor(variableAccessData->flushFormat())));
283         if (value.value())
284             m_state.setFoundConstants(true);
285         setForNode(node, value);
286         break;
287     }
288         
289     case GetStack: {
290         StackAccessData* data = node->stackAccessData();
291         AbstractValue value = m_state.operand(data->local);
292         // The value in the local should already be checked.
293         DFG_ASSERT(m_graph, node, value.isType(typeFilterFor(data->format)));
294         if (value.value())
295             m_state.setFoundConstants(true);
296         setForNode(node, value);
297         break;
298     }
299         
300     case SetLocal: {
301         m_state.operand(node->local()) = forNode(node->child1());
302         break;
303     }
304         
305     case PutStack: {
306         m_state.operand(node->stackAccessData()->local) = forNode(node->child1());
307         break;
308     }
309         
310     case MovHint: {
311         // Don't need to do anything. A MovHint only informs us about what would have happened
312         // in bytecode, but this code is just concerned with what is actually happening during
313         // DFG execution.
314         break;
315     }
316
317     case KillStack: {
318         // This is just a hint telling us that the OSR state of the local is no longer inside the
319         // flushed data.
320         break;
321     }
322         
323     case SetArgument:
324         // Assert that the state of arguments has been set. SetArgument means that someone set
325         // the argument values out-of-band, and currently this always means setting to a
326         // non-clear value.
327         ASSERT(!m_state.operand(node->local()).isClear());
328         break;
329
330     case InitializeEntrypointArguments: {
331         unsigned entrypointIndex = node->entrypointIndex();
332         const Vector<FlushFormat>& argumentFormats = m_graph.m_argumentFormats[entrypointIndex];
333         for (unsigned argument = 0; argument < argumentFormats.size(); ++argument) {
334             AbstractValue& value = m_state.argument(argument);
335             switch (argumentFormats[argument]) {
336             case FlushedInt32:
337                 value.setNonCellType(SpecInt32Only);
338                 break;
339             case FlushedBoolean:
340                 value.setNonCellType(SpecBoolean);
341                 break;
342             case FlushedCell:
343                 value.setType(m_graph, SpecCell);
344                 break;
345             case FlushedJSValue:
346                 value.makeBytecodeTop();
347                 break;
348             default:
349                 DFG_CRASH(m_graph, node, "Bad flush format for argument");
350                 break;
351             }
352         }
353         break;
354     }
355
356     case LoadVarargs:
357     case ForwardVarargs: {
358         // FIXME: ForwardVarargs should check if the count becomes known, and if it does, it should turn
359         // itself into a straight-line sequence of GetStack/PutStack.
360         // https://bugs.webkit.org/show_bug.cgi?id=143071
361         switch (node->op()) {
362         case LoadVarargs:
363             clobberWorld();
364             break;
365         case ForwardVarargs:
366             break;
367         default:
368             DFG_CRASH(m_graph, node, "Bad opcode");
369             break;
370         }
371         LoadVarargsData* data = node->loadVarargsData();
372         m_state.operand(data->count).setNonCellType(SpecInt32Only);
373         for (unsigned i = data->limit - 1; i--;)
374             m_state.operand(data->start.offset() + i).makeHeapTop();
375         break;
376     }
377             
378     case BitAnd:
379     case BitOr:
380     case BitXor:
381     case BitRShift:
382     case BitLShift:
383     case BitURShift: {
384         if (node->child1().useKind() == UntypedUse || node->child2().useKind() == UntypedUse) {
385             clobberWorld();
386             setNonCellTypeForNode(node, SpecInt32Only);
387             break;
388         }
389
390         JSValue left = forNode(node->child1()).value();
391         JSValue right = forNode(node->child2()).value();
392         if (left && right && left.isInt32() && right.isInt32()) {
393             int32_t a = left.asInt32();
394             int32_t b = right.asInt32();
395             switch (node->op()) {
396             case BitAnd:
397                 setConstant(node, JSValue(a & b));
398                 break;
399             case BitOr:
400                 setConstant(node, JSValue(a | b));
401                 break;
402             case BitXor:
403                 setConstant(node, JSValue(a ^ b));
404                 break;
405             case BitRShift:
406                 setConstant(node, JSValue(a >> static_cast<uint32_t>(b)));
407                 break;
408             case BitLShift:
409                 setConstant(node, JSValue(a << static_cast<uint32_t>(b)));
410                 break;
411             case BitURShift:
412                 setConstant(node, JSValue(static_cast<uint32_t>(a) >> static_cast<uint32_t>(b)));
413                 break;
414             default:
415                 RELEASE_ASSERT_NOT_REACHED();
416                 break;
417             }
418             break;
419         }
420         
421         if (node->op() == BitAnd
422             && (isBoolInt32Speculation(forNode(node->child1()).m_type) ||
423                 isBoolInt32Speculation(forNode(node->child2()).m_type))) {
424             setNonCellTypeForNode(node, SpecBoolInt32);
425             break;
426         }
427         
428         setNonCellTypeForNode(node, SpecInt32Only);
429         break;
430     }
431         
432     case UInt32ToNumber: {
433         JSValue child = forNode(node->child1()).value();
434         if (doesOverflow(node->arithMode())) {
435             if (enableInt52()) {
436                 if (child && child.isAnyInt()) {
437                     int64_t machineInt = child.asAnyInt();
438                     setConstant(node, jsNumber(static_cast<uint32_t>(machineInt)));
439                     break;
440                 }
441                 setNonCellTypeForNode(node, SpecAnyInt);
442                 break;
443             }
444             if (child && child.isInt32()) {
445                 uint32_t value = child.asInt32();
446                 setConstant(node, jsNumber(value));
447                 break;
448             }
449             setNonCellTypeForNode(node, SpecAnyIntAsDouble);
450             break;
451         }
452         if (child && child.isInt32()) {
453             int32_t value = child.asInt32();
454             if (value >= 0) {
455                 setConstant(node, jsNumber(value));
456                 break;
457             }
458         }
459         setNonCellTypeForNode(node, SpecInt32Only);
460         break;
461     }
462         
463     case BooleanToNumber: {
464         JSValue concreteValue = forNode(node->child1()).value();
465         if (concreteValue) {
466             if (concreteValue.isBoolean())
467                 setConstant(node, jsNumber(concreteValue.asBoolean()));
468             else
469                 setConstant(node, *m_graph.freeze(concreteValue));
470             break;
471         }
472         AbstractValue& value = forNode(node);
473         value = forNode(node->child1());
474         if (node->child1().useKind() == UntypedUse && !(value.m_type & ~SpecBoolean))
475             m_state.setFoundConstants(true);
476         if (value.m_type & SpecBoolean) {
477             value.merge(SpecBoolInt32);
478             value.filter(~SpecBoolean);
479         }
480         break;
481     }
482             
483     case DoubleAsInt32: {
484         JSValue child = forNode(node->child1()).value();
485         if (child && child.isNumber()) {
486             double asDouble = child.asNumber();
487             int32_t asInt = JSC::toInt32(asDouble);
488             if (bitwise_cast<int64_t>(static_cast<double>(asInt)) == bitwise_cast<int64_t>(asDouble)) {
489                 setConstant(node, JSValue(asInt));
490                 break;
491             }
492         }
493         setNonCellTypeForNode(node, SpecInt32Only);
494         break;
495     }
496             
497     case ValueToInt32: {
498         JSValue child = forNode(node->child1()).value();
499         if (child) {
500             if (child.isNumber()) {
501                 if (child.isInt32())
502                     setConstant(node, child);
503                 else
504                     setConstant(node, JSValue(JSC::toInt32(child.asDouble())));
505                 break;
506             }
507             if (child.isBoolean()) {
508                 setConstant(node, jsNumber(child.asBoolean()));
509                 break;
510             }
511             if (child.isUndefinedOrNull()) {
512                 setConstant(node, jsNumber(0));
513                 break;
514             }
515         }
516         
517         if (isBooleanSpeculation(forNode(node->child1()).m_type)) {
518             setNonCellTypeForNode(node, SpecBoolInt32);
519             break;
520         }
521         
522         setNonCellTypeForNode(node, SpecInt32Only);
523         break;
524     }
525         
526     case DoubleRep: {
527         JSValue child = forNode(node->child1()).value();
528         if (std::optional<double> number = child.toNumberFromPrimitive()) {
529             setConstant(node, jsDoubleNumber(*number));
530             break;
531         }
532
533         SpeculatedType type = forNode(node->child1()).m_type;
534         switch (node->child1().useKind()) {
535         case NotCellUse: {
536             if (type & SpecOther) {
537                 type &= ~SpecOther;
538                 type |= SpecDoublePureNaN | SpecBoolInt32; // Null becomes zero, undefined becomes NaN.
539             }
540             if (type & SpecBoolean) {
541                 type &= ~SpecBoolean;
542                 type |= SpecBoolInt32; // True becomes 1, false becomes 0.
543             }
544             type &= SpecBytecodeNumber;
545             break;
546         }
547
548         case Int52RepUse:
549         case NumberUse:
550         case RealNumberUse:
551             break;
552
553         default:
554             RELEASE_ASSERT_NOT_REACHED();
555         }
556         setNonCellTypeForNode(node, type);
557         forNode(node).fixTypeForRepresentation(m_graph, node);
558         break;
559     }
560         
561     case Int52Rep: {
562         JSValue child = forNode(node->child1()).value();
563         if (child && child.isAnyInt()) {
564             setConstant(node, child);
565             break;
566         }
567         
568         setNonCellTypeForNode(node, SpecAnyInt);
569         break;
570     }
571         
572     case ValueRep: {
573         JSValue value = forNode(node->child1()).value();
574         if (value) {
575             setConstant(node, value);
576             break;
577         }
578         
579         setTypeForNode(node, forNode(node->child1()).m_type & ~SpecDoubleImpureNaN);
580         forNode(node).fixTypeForRepresentation(m_graph, node);
581         break;
582     }
583         
584     case ValueAdd: {
585         ASSERT(node->binaryUseKind() == UntypedUse);
586         clobberWorld();
587         setTypeForNode(node, SpecString | SpecBytecodeNumber);
588         break;
589     }
590
591     case StrCat: {
592         setTypeForNode(node, SpecString);
593         break;
594     }
595         
596     case ArithAdd: {
597         JSValue left = forNode(node->child1()).value();
598         JSValue right = forNode(node->child2()).value();
599         switch (node->binaryUseKind()) {
600         case Int32Use:
601             if (left && right && left.isInt32() && right.isInt32()) {
602                 if (!shouldCheckOverflow(node->arithMode())) {
603                     setConstant(node, jsNumber(left.asInt32() + right.asInt32()));
604                     break;
605                 }
606                 JSValue result = jsNumber(left.asNumber() + right.asNumber());
607                 if (result.isInt32()) {
608                     setConstant(node, result);
609                     break;
610                 }
611             }
612             setNonCellTypeForNode(node, SpecInt32Only);
613             break;
614         case Int52RepUse:
615             if (left && right && left.isAnyInt() && right.isAnyInt()) {
616                 JSValue result = jsNumber(left.asAnyInt() + right.asAnyInt());
617                 if (result.isAnyInt()) {
618                     setConstant(node, result);
619                     break;
620                 }
621             }
622             setNonCellTypeForNode(node, SpecAnyInt);
623             break;
624         case DoubleRepUse:
625             if (left && right && left.isNumber() && right.isNumber()) {
626                 setConstant(node, jsDoubleNumber(left.asNumber() + right.asNumber()));
627                 break;
628             }
629             setNonCellTypeForNode(node, 
630                 typeOfDoubleSum(
631                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
632             break;
633         default:
634             RELEASE_ASSERT_NOT_REACHED();
635             break;
636         }
637         break;
638     }
639         
640     case AtomicsIsLockFree: {
641         if (node->child1().useKind() != Int32Use)
642             clobberWorld();
643         setNonCellTypeForNode(node, SpecBoolInt32);
644         break;
645     }
646
647     case ArithClz32: {
648         JSValue operand = forNode(node->child1()).value();
649         if (std::optional<double> number = operand.toNumberFromPrimitive()) {
650             switch (node->child1().useKind()) {
651             case Int32Use:
652             case KnownInt32Use:
653                 break;
654             default:
655                 didFoldClobberWorld();
656                 break;
657             }
658             uint32_t value = toUInt32(*number);
659             setConstant(node, jsNumber(clz32(value)));
660             break;
661         }
662         switch (node->child1().useKind()) {
663         case Int32Use:
664         case KnownInt32Use:
665             break;
666         default:
667             clobberWorld();
668             break;
669         }
670         setNonCellTypeForNode(node, SpecInt32Only);
671         break;
672     }
673
674     case MakeRope: {
675         unsigned numberOfChildren = 0;
676         unsigned numberOfRemovedChildren = 0;
677         std::optional<unsigned> nonEmptyIndex;
678         for (unsigned i = 0; i < AdjacencyList::Size; ++i) {
679             Edge& edge = node->children.child(i);
680             if (!edge)
681                 break;
682             ++numberOfChildren;
683
684             JSValue childConstant = m_state.forNode(edge).value();
685             if (!childConstant) {
686                 nonEmptyIndex = i;
687                 continue;
688             }
689             if (!childConstant.isString()) {
690                 nonEmptyIndex = i;
691                 continue;
692             }
693             if (asString(childConstant)->length()) {
694                 nonEmptyIndex = i;
695                 continue;
696             }
697
698             ++numberOfRemovedChildren;
699         }
700
701         if (numberOfRemovedChildren) {
702             m_state.setFoundConstants(true);
703             if (numberOfRemovedChildren == numberOfChildren) {
704                 // Propagate the last child. This is the way taken in the constant folding phase.
705                 setForNode(node, forNode(node->children.child(numberOfChildren - 1)));
706                 break;
707             }
708             if ((numberOfRemovedChildren + 1) == numberOfChildren) {
709                 ASSERT(nonEmptyIndex);
710                 setForNode(node, forNode(node->children.child(nonEmptyIndex.value())));
711                 break;
712             }
713         }
714         setForNode(node, m_vm.stringStructure.get());
715         break;
716     }
717             
718     case ArithSub: {
719         JSValue left = forNode(node->child1()).value();
720         JSValue right = forNode(node->child2()).value();
721         switch (node->binaryUseKind()) {
722         case Int32Use:
723             if (left && right && left.isInt32() && right.isInt32()) {
724                 if (!shouldCheckOverflow(node->arithMode())) {
725                     setConstant(node, jsNumber(left.asInt32() - right.asInt32()));
726                     break;
727                 }
728                 JSValue result = jsNumber(left.asNumber() - right.asNumber());
729                 if (result.isInt32()) {
730                     setConstant(node, result);
731                     break;
732                 }
733             }
734             setNonCellTypeForNode(node, SpecInt32Only);
735             break;
736         case Int52RepUse:
737             if (left && right && left.isAnyInt() && right.isAnyInt()) {
738                 JSValue result = jsNumber(left.asAnyInt() - right.asAnyInt());
739                 if (result.isAnyInt() || !shouldCheckOverflow(node->arithMode())) {
740                     setConstant(node, result);
741                     break;
742                 }
743             }
744             setNonCellTypeForNode(node, SpecAnyInt);
745             break;
746         case DoubleRepUse:
747             if (left && right && left.isNumber() && right.isNumber()) {
748                 setConstant(node, jsDoubleNumber(left.asNumber() - right.asNumber()));
749                 break;
750             }
751             setNonCellTypeForNode(node, 
752                 typeOfDoubleDifference(
753                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
754             break;
755         case UntypedUse:
756             clobberWorld();
757             setNonCellTypeForNode(node, SpecBytecodeNumber);
758             break;
759         default:
760             RELEASE_ASSERT_NOT_REACHED();
761             break;
762         }
763         break;
764     }
765         
766     case ValueNegate: {
767         clobberWorld();
768         setTypeForNode(node, SpecBytecodeNumber | SpecBigInt);
769         break;
770     }
771
772     case ArithNegate: {
773         JSValue child = forNode(node->child1()).value();
774         switch (node->child1().useKind()) {
775         case Int32Use:
776             if (child && child.isInt32()) {
777                 if (!shouldCheckOverflow(node->arithMode())) {
778                     setConstant(node, jsNumber(-child.asInt32()));
779                     break;
780                 }
781                 double doubleResult;
782                 if (shouldCheckNegativeZero(node->arithMode()))
783                     doubleResult = -child.asNumber();
784                 else
785                     doubleResult = 0 - child.asNumber();
786                 JSValue valueResult = jsNumber(doubleResult);
787                 if (valueResult.isInt32()) {
788                     setConstant(node, valueResult);
789                     break;
790                 }
791             }
792             setNonCellTypeForNode(node, SpecInt32Only);
793             break;
794         case Int52RepUse:
795             if (child && child.isAnyInt()) {
796                 double doubleResult;
797                 if (shouldCheckNegativeZero(node->arithMode()))
798                     doubleResult = -child.asNumber();
799                 else
800                     doubleResult = 0 - child.asNumber();
801                 JSValue valueResult = jsNumber(doubleResult);
802                 if (valueResult.isAnyInt()) {
803                     setConstant(node, valueResult);
804                     break;
805                 }
806             }
807             setNonCellTypeForNode(node, SpecAnyInt);
808             break;
809         case DoubleRepUse:
810             if (child && child.isNumber()) {
811                 setConstant(node, jsDoubleNumber(-child.asNumber()));
812                 break;
813             }
814             setNonCellTypeForNode(node, 
815                 typeOfDoubleNegation(
816                     forNode(node->child1()).m_type));
817             break;
818         default:
819             RELEASE_ASSERT_NOT_REACHED();
820             break;
821         }
822         break;
823     }
824         
825     case ArithMul: {
826         JSValue left = forNode(node->child1()).value();
827         JSValue right = forNode(node->child2()).value();
828         switch (node->binaryUseKind()) {
829         case Int32Use:
830             if (left && right && left.isInt32() && right.isInt32()) {
831                 if (!shouldCheckOverflow(node->arithMode())) {
832                     setConstant(node, jsNumber(left.asInt32() * right.asInt32()));
833                     break;
834                 }
835                 double doubleResult = left.asNumber() * right.asNumber();
836                 if (!shouldCheckNegativeZero(node->arithMode()))
837                     doubleResult += 0; // Sanitizes zero.
838                 JSValue valueResult = jsNumber(doubleResult);
839                 if (valueResult.isInt32()) {
840                     setConstant(node, valueResult);
841                     break;
842                 }
843             }
844             setNonCellTypeForNode(node, SpecInt32Only);
845             break;
846         case Int52RepUse:
847             if (left && right && left.isAnyInt() && right.isAnyInt()) {
848                 double doubleResult = left.asNumber() * right.asNumber();
849                 if (!shouldCheckNegativeZero(node->arithMode()))
850                     doubleResult += 0;
851                 JSValue valueResult = jsNumber(doubleResult);
852                 if (valueResult.isAnyInt()) {
853                     setConstant(node, valueResult);
854                     break;
855                 }
856             }
857             setNonCellTypeForNode(node, SpecAnyInt);
858             break;
859         case DoubleRepUse:
860             if (left && right && left.isNumber() && right.isNumber()) {
861                 setConstant(node, jsDoubleNumber(left.asNumber() * right.asNumber()));
862                 break;
863             }
864             setNonCellTypeForNode(node, 
865                 typeOfDoubleProduct(
866                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
867             break;
868         case UntypedUse:
869             clobberWorld();
870             setNonCellTypeForNode(node, SpecBytecodeNumber);
871             break;
872         default:
873             RELEASE_ASSERT_NOT_REACHED();
874             break;
875         }
876         break;
877     }
878         
879     case ArithDiv: {
880         JSValue left = forNode(node->child1()).value();
881         JSValue right = forNode(node->child2()).value();
882         switch (node->binaryUseKind()) {
883         case Int32Use:
884             if (left && right && left.isInt32() && right.isInt32()) {
885                 double doubleResult = left.asNumber() / right.asNumber();
886                 if (!shouldCheckOverflow(node->arithMode()))
887                     doubleResult = toInt32(doubleResult);
888                 else if (!shouldCheckNegativeZero(node->arithMode()))
889                     doubleResult += 0; // Sanitizes zero.
890                 JSValue valueResult = jsNumber(doubleResult);
891                 if (valueResult.isInt32()) {
892                     setConstant(node, valueResult);
893                     break;
894                 }
895             }
896             setNonCellTypeForNode(node, SpecInt32Only);
897             break;
898         case DoubleRepUse:
899             if (left && right && left.isNumber() && right.isNumber()) {
900                 setConstant(node, jsDoubleNumber(left.asNumber() / right.asNumber()));
901                 break;
902             }
903             setNonCellTypeForNode(node, 
904                 typeOfDoubleQuotient(
905                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
906             break;
907         case UntypedUse:
908             clobberWorld();
909             setNonCellTypeForNode(node, SpecBytecodeNumber);
910             break;
911         default:
912             RELEASE_ASSERT_NOT_REACHED();
913             break;
914         }
915         break;
916     }
917
918     case ArithMod: {
919         JSValue left = forNode(node->child1()).value();
920         JSValue right = forNode(node->child2()).value();
921         switch (node->binaryUseKind()) {
922         case Int32Use:
923             if (left && right && left.isInt32() && right.isInt32()) {
924                 double doubleResult = fmod(left.asNumber(), right.asNumber());
925                 if (!shouldCheckOverflow(node->arithMode()))
926                     doubleResult = toInt32(doubleResult);
927                 else if (!shouldCheckNegativeZero(node->arithMode()))
928                     doubleResult += 0; // Sanitizes zero.
929                 JSValue valueResult = jsNumber(doubleResult);
930                 if (valueResult.isInt32()) {
931                     setConstant(node, valueResult);
932                     break;
933                 }
934             }
935             setNonCellTypeForNode(node, SpecInt32Only);
936             break;
937         case DoubleRepUse:
938             if (left && right && left.isNumber() && right.isNumber()) {
939                 setConstant(node, jsDoubleNumber(fmod(left.asNumber(), right.asNumber())));
940                 break;
941             }
942             setNonCellTypeForNode(node, 
943                 typeOfDoubleBinaryOp(
944                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
945             break;
946         default:
947             RELEASE_ASSERT_NOT_REACHED();
948             break;
949         }
950         break;
951     }
952
953     case ArithMin: {
954         JSValue left = forNode(node->child1()).value();
955         JSValue right = forNode(node->child2()).value();
956         switch (node->binaryUseKind()) {
957         case Int32Use:
958             if (left && right && left.isInt32() && right.isInt32()) {
959                 setConstant(node, jsNumber(std::min(left.asInt32(), right.asInt32())));
960                 break;
961             }
962             setNonCellTypeForNode(node, SpecInt32Only);
963             break;
964         case DoubleRepUse:
965             if (left && right && left.isNumber() && right.isNumber()) {
966                 double a = left.asNumber();
967                 double b = right.asNumber();
968                 setConstant(node, jsDoubleNumber(a < b ? a : (b <= a ? b : a + b)));
969                 break;
970             }
971             setNonCellTypeForNode(node, 
972                 typeOfDoubleMinMax(
973                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
974             break;
975         default:
976             RELEASE_ASSERT_NOT_REACHED();
977             break;
978         }
979         break;
980     }
981             
982     case ArithMax: {
983         JSValue left = forNode(node->child1()).value();
984         JSValue right = forNode(node->child2()).value();
985         switch (node->binaryUseKind()) {
986         case Int32Use:
987             if (left && right && left.isInt32() && right.isInt32()) {
988                 setConstant(node, jsNumber(std::max(left.asInt32(), right.asInt32())));
989                 break;
990             }
991             setNonCellTypeForNode(node, SpecInt32Only);
992             break;
993         case DoubleRepUse:
994             if (left && right && left.isNumber() && right.isNumber()) {
995                 double a = left.asNumber();
996                 double b = right.asNumber();
997                 setConstant(node, jsDoubleNumber(a > b ? a : (b >= a ? b : a + b)));
998                 break;
999             }
1000             setNonCellTypeForNode(node, 
1001                 typeOfDoubleMinMax(
1002                     forNode(node->child1()).m_type, forNode(node->child2()).m_type));
1003             break;
1004         default:
1005             RELEASE_ASSERT_NOT_REACHED();
1006             break;
1007         }
1008         break;
1009     }
1010             
1011     case ArithAbs: {
1012         JSValue child = forNode(node->child1()).value();
1013         switch (node->child1().useKind()) {
1014         case Int32Use:
1015             if (std::optional<double> number = child.toNumberFromPrimitive()) {
1016                 JSValue result = jsNumber(fabs(*number));
1017                 if (result.isInt32()) {
1018                     setConstant(node, result);
1019                     break;
1020                 }
1021             }
1022             setNonCellTypeForNode(node, SpecInt32Only);
1023             break;
1024         case DoubleRepUse:
1025             if (std::optional<double> number = child.toNumberFromPrimitive()) {
1026                 setConstant(node, jsDoubleNumber(fabs(*number)));
1027                 break;
1028             }
1029             setNonCellTypeForNode(node, typeOfDoubleAbs(forNode(node->child1()).m_type));
1030             break;
1031         default:
1032             DFG_ASSERT(m_graph, node, node->child1().useKind() == UntypedUse, node->child1().useKind());
1033             clobberWorld();
1034             setNonCellTypeForNode(node, SpecBytecodeNumber);
1035             break;
1036         }
1037         break;
1038     }
1039
1040     case ArithPow: {
1041         JSValue childY = forNode(node->child2()).value();
1042         if (childY && childY.isNumber()) {
1043             if (!childY.asNumber()) {
1044                 setConstant(node, jsDoubleNumber(1));
1045                 break;
1046             }
1047
1048             JSValue childX = forNode(node->child1()).value();
1049             if (childX && childX.isNumber()) {
1050                 setConstant(node, jsDoubleNumber(operationMathPow(childX.asNumber(), childY.asNumber())));
1051                 break;
1052             }
1053         }
1054         setNonCellTypeForNode(node, typeOfDoublePow(forNode(node->child1()).m_type, forNode(node->child2()).m_type));
1055         break;
1056     }
1057
1058     case ArithRandom: {
1059         setNonCellTypeForNode(node, SpecDoubleReal);
1060         break;
1061     }
1062
1063     case ArithRound:
1064     case ArithFloor:
1065     case ArithCeil:
1066     case ArithTrunc: {
1067         JSValue operand = forNode(node->child1()).value();
1068         if (std::optional<double> number = operand.toNumberFromPrimitive()) {
1069             if (node->child1().useKind() != DoubleRepUse)
1070                 didFoldClobberWorld();
1071             
1072             double roundedValue = 0;
1073             if (node->op() == ArithRound)
1074                 roundedValue = jsRound(*number);
1075             else if (node->op() == ArithFloor)
1076                 roundedValue = floor(*number);
1077             else if (node->op() == ArithCeil)
1078                 roundedValue = ceil(*number);
1079             else {
1080                 ASSERT(node->op() == ArithTrunc);
1081                 roundedValue = trunc(*number);
1082             }
1083
1084             if (node->child1().useKind() == UntypedUse) {
1085                 setConstant(node, jsNumber(roundedValue));
1086                 break;
1087             }
1088             if (producesInteger(node->arithRoundingMode())) {
1089                 int32_t roundedValueAsInt32 = static_cast<int32_t>(roundedValue);
1090                 if (roundedValueAsInt32 == roundedValue) {
1091                     if (shouldCheckNegativeZero(node->arithRoundingMode())) {
1092                         if (roundedValueAsInt32 || !std::signbit(roundedValue)) {
1093                             setConstant(node, jsNumber(roundedValueAsInt32));
1094                             break;
1095                         }
1096                     } else {
1097                         setConstant(node, jsNumber(roundedValueAsInt32));
1098                         break;
1099                     }
1100                 }
1101             } else {
1102                 setConstant(node, jsDoubleNumber(roundedValue));
1103                 break;
1104             }
1105         }
1106         if (node->child1().useKind() == DoubleRepUse) {
1107             if (producesInteger(node->arithRoundingMode()))
1108                 setNonCellTypeForNode(node, SpecInt32Only);
1109             else if (node->child1().useKind() == DoubleRepUse)
1110                 setNonCellTypeForNode(node, typeOfDoubleRounding(forNode(node->child1()).m_type));
1111         } else {
1112             DFG_ASSERT(m_graph, node, node->child1().useKind() == UntypedUse, node->child1().useKind());
1113             clobberWorld();
1114             setNonCellTypeForNode(node, SpecBytecodeNumber);
1115         }
1116         break;
1117     }
1118             
1119     case ArithSqrt:
1120         executeDoubleUnaryOpEffects(node, sqrt);
1121         break;
1122
1123     case ArithFRound:
1124         executeDoubleUnaryOpEffects(node, [](double value) -> double { return static_cast<float>(value); });
1125         break;
1126         
1127     case ArithUnary:
1128         executeDoubleUnaryOpEffects(node, arithUnaryFunction(node->arithUnaryType()));
1129         break;
1130             
1131     case LogicalNot: {
1132         switch (booleanResult(node, forNode(node->child1()))) {
1133         case DefinitelyTrue:
1134             setConstant(node, jsBoolean(false));
1135             break;
1136         case DefinitelyFalse:
1137             setConstant(node, jsBoolean(true));
1138             break;
1139         default:
1140             setNonCellTypeForNode(node, SpecBoolean);
1141             break;
1142         }
1143         break;
1144     }
1145
1146     case MapHash: {
1147         if (JSValue key = forNode(node->child1()).value()) {
1148             if (std::optional<uint32_t> hash = concurrentJSMapHash(key)) {
1149                 // Although C++ code uses uint32_t for the hash, the closest type in DFG IR is Int32
1150                 // and that's what MapHash returns. So, we have to cast to int32_t to avoid large
1151                 // unsigned values becoming doubles. This casting between signed and unsigned
1152                 // happens in the assembly code we emit when we don't constant fold this node.
1153                 setConstant(node, jsNumber(static_cast<int32_t>(*hash)));
1154                 break;
1155             }
1156         }
1157         setNonCellTypeForNode(node, SpecInt32Only);
1158         break;
1159     }
1160
1161     case NormalizeMapKey: {
1162         if (JSValue key = forNode(node->child1()).value()) {
1163             setConstant(node, *m_graph.freeze(normalizeMapKey(key)));
1164             break;
1165         }
1166
1167         SpeculatedType typeMaybeNormalized = (SpecFullNumber & ~SpecInt32Only);
1168         if (!(forNode(node->child1()).m_type & typeMaybeNormalized)) {
1169             m_state.setFoundConstants(true);
1170             forNode(node) = forNode(node->child1());
1171             break;
1172         }
1173
1174         makeHeapTopForNode(node);
1175         break;
1176     }
1177
1178     case StringValueOf: {
1179         clobberWorld();
1180         setTypeForNode(node, SpecString);
1181         break;
1182     }
1183
1184     case StringSlice: {
1185         setTypeForNode(node, SpecString);
1186         break;
1187     }
1188
1189     case ToLowerCase: {
1190         setTypeForNode(node, SpecString);
1191         break;
1192     }
1193
1194     case LoadKeyFromMapBucket:
1195     case LoadValueFromMapBucket:
1196     case ExtractValueFromWeakMapGet:
1197         makeHeapTopForNode(node);
1198         break;
1199
1200     case GetMapBucket:
1201     case GetMapBucketHead:
1202         if (node->child1().useKind() == MapObjectUse)
1203             setForNode(node, m_vm.hashMapBucketMapStructure.get());
1204         else {
1205             ASSERT(node->child1().useKind() == SetObjectUse);
1206             setForNode(node, m_vm.hashMapBucketSetStructure.get());
1207         }
1208         break;
1209
1210     case GetMapBucketNext:
1211         if (node->bucketOwnerType() == BucketOwnerType::Map)
1212             setForNode(node, m_vm.hashMapBucketMapStructure.get());
1213         else {
1214             ASSERT(node->bucketOwnerType() == BucketOwnerType::Set);
1215             setForNode(node, m_vm.hashMapBucketSetStructure.get());
1216         }
1217         break;
1218
1219     case SetAdd:
1220         setForNode(node, m_vm.hashMapBucketSetStructure.get());
1221         break;
1222
1223     case MapSet:
1224         setForNode(node, m_vm.hashMapBucketMapStructure.get());
1225         break;
1226
1227     case WeakSetAdd:
1228     case WeakMapSet:
1229         break;
1230
1231     case WeakMapGet:
1232         makeBytecodeTopForNode(node);
1233         break;
1234
1235     case IsEmpty:
1236     case IsUndefined:
1237     case IsBoolean:
1238     case IsNumber:
1239     case NumberIsInteger:
1240     case IsObject:
1241     case IsObjectOrNull:
1242     case IsFunction:
1243     case IsCellWithType:
1244     case IsTypedArrayView: {
1245         AbstractValue child = forNode(node->child1());
1246         if (child.value()) {
1247             bool constantWasSet = true;
1248             switch (node->op()) {
1249             case IsCellWithType:
1250                 setConstant(node, jsBoolean(child.value().isCell() && child.value().asCell()->type() == node->queriedType()));
1251                 break;
1252             case IsUndefined:
1253                 setConstant(node, jsBoolean(
1254                     child.value().isCell()
1255                     ? child.value().asCell()->structure(m_vm)->masqueradesAsUndefined(m_codeBlock->globalObjectFor(node->origin.semantic))
1256                     : child.value().isUndefined()));
1257                 break;
1258             case IsBoolean:
1259                 setConstant(node, jsBoolean(child.value().isBoolean()));
1260                 break;
1261             case IsNumber:
1262                 setConstant(node, jsBoolean(child.value().isNumber()));
1263                 break;
1264             case NumberIsInteger:
1265                 setConstant(node, jsBoolean(NumberConstructor::isIntegerImpl(child.value())));
1266                 break;
1267             case IsObject:
1268                 setConstant(node, jsBoolean(child.value().isObject()));
1269                 break;
1270             case IsObjectOrNull:
1271                 if (child.value().isObject()) {
1272                     JSObject* object = asObject(child.value());
1273                     if (object->type() == JSFunctionType)
1274                         setConstant(node, jsBoolean(false));
1275                     else if (!(object->inlineTypeFlags() & OverridesGetCallData))
1276                         setConstant(node, jsBoolean(!child.value().asCell()->structure(m_vm)->masqueradesAsUndefined(m_codeBlock->globalObjectFor(node->origin.semantic))));
1277                     else {
1278                         // FIXME: This could just call getCallData.
1279                         // https://bugs.webkit.org/show_bug.cgi?id=144457
1280                         constantWasSet = false;
1281                     }
1282                 } else
1283                     setConstant(node, jsBoolean(child.value().isNull()));
1284                 break;
1285             case IsFunction:
1286                 if (child.value().isObject()) {
1287                     JSObject* object = asObject(child.value());
1288                     if (object->type() == JSFunctionType)
1289                         setConstant(node, jsBoolean(true));
1290                     else if (!(object->inlineTypeFlags() & OverridesGetCallData))
1291                         setConstant(node, jsBoolean(false));
1292                     else {
1293                         // FIXME: This could just call getCallData.
1294                         // https://bugs.webkit.org/show_bug.cgi?id=144457
1295                         constantWasSet = false;
1296                     }
1297                 } else
1298                     setConstant(node, jsBoolean(false));
1299                 break;
1300             case IsEmpty:
1301                 setConstant(node, jsBoolean(child.value().isEmpty()));
1302                 break;
1303             case IsTypedArrayView:
1304                 setConstant(node, jsBoolean(child.value().isObject() && isTypedView(child.value().getObject()->classInfo(m_vm)->typedArrayStorageType)));
1305                 break;
1306             default:
1307                 constantWasSet = false;
1308                 break;
1309             }
1310             if (constantWasSet)
1311                 break;
1312         }
1313         
1314         // FIXME: This code should really use AbstractValue::isType() and
1315         // AbstractValue::couldBeType().
1316         // https://bugs.webkit.org/show_bug.cgi?id=146870
1317         
1318         bool constantWasSet = false;
1319         switch (node->op()) {
1320         case IsEmpty: {
1321             if (child.m_type && !(child.m_type & SpecEmpty)) {
1322                 setConstant(node, jsBoolean(false));
1323                 constantWasSet = true;
1324                 break;
1325             }
1326
1327             if (child.m_type && !(child.m_type & ~SpecEmpty)) {
1328                 setConstant(node, jsBoolean(true));
1329                 constantWasSet = true;
1330                 break;
1331             }
1332
1333             break;
1334         }
1335         case IsUndefined:
1336             // FIXME: Use the masquerades-as-undefined watchpoint thingy.
1337             // https://bugs.webkit.org/show_bug.cgi?id=144456
1338             
1339             if (!(child.m_type & (SpecOther | SpecObjectOther))) {
1340                 setConstant(node, jsBoolean(false));
1341                 constantWasSet = true;
1342                 break;
1343             }
1344             
1345             break;
1346         case IsBoolean:
1347             if (!(child.m_type & ~SpecBoolean)) {
1348                 setConstant(node, jsBoolean(true));
1349                 constantWasSet = true;
1350                 break;
1351             }
1352             
1353             if (!(child.m_type & SpecBoolean)) {
1354                 setConstant(node, jsBoolean(false));
1355                 constantWasSet = true;
1356                 break;
1357             }
1358             
1359             break;
1360         case IsNumber:
1361             if (!(child.m_type & ~SpecFullNumber)) {
1362                 setConstant(node, jsBoolean(true));
1363                 constantWasSet = true;
1364                 break;
1365             }
1366             
1367             if (!(child.m_type & SpecFullNumber)) {
1368                 setConstant(node, jsBoolean(false));
1369                 constantWasSet = true;
1370                 break;
1371             }
1372             
1373             break;
1374
1375         case NumberIsInteger:
1376             if (!(child.m_type & ~SpecInt32Only)) {
1377                 setConstant(node, jsBoolean(true));
1378                 constantWasSet = true;
1379                 break;
1380             }
1381             
1382             if (!(child.m_type & SpecFullNumber)) {
1383                 setConstant(node, jsBoolean(false));
1384                 constantWasSet = true;
1385                 break;
1386             }
1387             
1388             break;
1389
1390         case IsObject:
1391             if (!(child.m_type & ~SpecObject)) {
1392                 setConstant(node, jsBoolean(true));
1393                 constantWasSet = true;
1394                 break;
1395             }
1396             
1397             if (!(child.m_type & SpecObject)) {
1398                 setConstant(node, jsBoolean(false));
1399                 constantWasSet = true;
1400                 break;
1401             }
1402             
1403             break;
1404         case IsObjectOrNull:
1405             // FIXME: Use the masquerades-as-undefined watchpoint thingy.
1406             // https://bugs.webkit.org/show_bug.cgi?id=144456
1407             
1408             // These expressions are complicated to parse. A helpful way to parse this is that
1409             // "!(T & ~S)" means "T is a subset of S". Conversely, "!(T & S)" means "T is a
1410             // disjoint set from S". Things like "T - S" means that, provided that S is a
1411             // subset of T, it's the "set of all things in T but not in S". Things like "T | S"
1412             // mean the "union of T and S".
1413             
1414             // Is the child's type an object that isn't an other-object (i.e. object that could
1415             // have masquaredes-as-undefined traps) and isn't a function?  Then: we should fold
1416             // this to true.
1417             if (!(child.m_type & ~(SpecObject - SpecObjectOther - SpecFunction))) {
1418                 setConstant(node, jsBoolean(true));
1419                 constantWasSet = true;
1420                 break;
1421             }
1422             
1423             // Is the child's type definitely not either of: an object that isn't a function,
1424             // or either undefined or null?  Then: we should fold this to false.  This means
1425             // for example that if it's any non-function object, including those that have
1426             // masquerades-as-undefined traps, then we don't fold. It also means we won't fold
1427             // if it's undefined-or-null, since the type bits don't distinguish between
1428             // undefined (which should fold to false) and null (which should fold to true).
1429             if (!(child.m_type & ((SpecObject - SpecFunction) | SpecOther))) {
1430                 setConstant(node, jsBoolean(false));
1431                 constantWasSet = true;
1432                 break;
1433             }
1434             
1435             break;
1436         case IsFunction:
1437             if (!(child.m_type & ~SpecFunction)) {
1438                 setConstant(node, jsBoolean(true));
1439                 constantWasSet = true;
1440                 break;
1441             }
1442             
1443             if (!(child.m_type & (SpecFunction | SpecObjectOther | SpecProxyObject))) {
1444                 setConstant(node, jsBoolean(false));
1445                 constantWasSet = true;
1446                 break;
1447             }
1448             break;
1449
1450         case IsCellWithType:
1451             if (!(child.m_type & ~node->speculatedTypeForQuery())) {
1452                 setConstant(node, jsBoolean(true));
1453                 constantWasSet = true;
1454                 break;
1455             }
1456             if (!(child.m_type & node->speculatedTypeForQuery())) {
1457                 setConstant(node, jsBoolean(false));
1458                 constantWasSet = true;
1459                 break;
1460             }
1461             break;
1462
1463         case IsTypedArrayView:
1464             if (!(child.m_type & ~SpecTypedArrayView)) {
1465                 setConstant(node, jsBoolean(true));
1466                 constantWasSet = true;
1467                 break;
1468             }
1469             if (!(child.m_type & SpecTypedArrayView)) {
1470                 setConstant(node, jsBoolean(false));
1471                 constantWasSet = true;
1472                 break;
1473             }
1474             break;
1475
1476         default:
1477             break;
1478         }
1479         if (constantWasSet)
1480             break;
1481         
1482         setNonCellTypeForNode(node, SpecBoolean);
1483         break;
1484     }
1485
1486     case TypeOf: {
1487         JSValue child = forNode(node->child1()).value();
1488         AbstractValue& abstractChild = forNode(node->child1());
1489         if (child) {
1490             JSValue typeString = jsTypeStringForValue(m_vm, m_codeBlock->globalObjectFor(node->origin.semantic), child);
1491             setConstant(node, *m_graph.freeze(typeString));
1492             break;
1493         }
1494         
1495         if (isFullNumberSpeculation(abstractChild.m_type)) {
1496             setConstant(node, *m_graph.freeze(m_vm.smallStrings.numberString()));
1497             break;
1498         }
1499         
1500         if (isStringSpeculation(abstractChild.m_type)) {
1501             setConstant(node, *m_graph.freeze(m_vm.smallStrings.stringString()));
1502             break;
1503         }
1504
1505         // FIXME: We could use the masquerades-as-undefined watchpoint here.
1506         // https://bugs.webkit.org/show_bug.cgi?id=144456
1507         if (!(abstractChild.m_type & ~(SpecObject - SpecObjectOther - SpecFunction))) {
1508             setConstant(node, *m_graph.freeze(m_vm.smallStrings.objectString()));
1509             break;
1510         }
1511         
1512         if (isFunctionSpeculation(abstractChild.m_type)) {
1513             setConstant(node, *m_graph.freeze(m_vm.smallStrings.functionString()));
1514             break;
1515         }
1516         
1517         if (isBooleanSpeculation(abstractChild.m_type)) {
1518             setConstant(node, *m_graph.freeze(m_vm.smallStrings.booleanString()));
1519             break;
1520         }
1521
1522         if (isSymbolSpeculation(abstractChild.m_type)) {
1523             setConstant(node, *m_graph.freeze(m_vm.smallStrings.symbolString()));
1524             break;
1525         }
1526
1527         if (isBigIntSpeculation(abstractChild.m_type)) {
1528             setConstant(node, *m_graph.freeze(m_vm.smallStrings.bigintString()));
1529             break;
1530         }
1531
1532         setTypeForNode(node, SpecStringIdent);
1533         break;
1534     }
1535
1536     case CompareBelow:
1537     case CompareBelowEq: {
1538         JSValue leftConst = forNode(node->child1()).value();
1539         JSValue rightConst = forNode(node->child2()).value();
1540         if (leftConst && rightConst) {
1541             if (leftConst.isInt32() && rightConst.isInt32()) {
1542                 uint32_t a = static_cast<uint32_t>(leftConst.asInt32());
1543                 uint32_t b = static_cast<uint32_t>(rightConst.asInt32());
1544                 switch (node->op()) {
1545                 case CompareBelow:
1546                     setConstant(node, jsBoolean(a < b));
1547                     break;
1548                 case CompareBelowEq:
1549                     setConstant(node, jsBoolean(a <= b));
1550                     break;
1551                 default:
1552                     RELEASE_ASSERT_NOT_REACHED();
1553                     break;
1554                 }
1555                 break;
1556             }
1557         }
1558
1559         if (node->child1() == node->child2()) {
1560             switch (node->op()) {
1561             case CompareBelow:
1562                 setConstant(node, jsBoolean(false));
1563                 break;
1564             case CompareBelowEq:
1565                 setConstant(node, jsBoolean(true));
1566                 break;
1567             default:
1568                 DFG_CRASH(m_graph, node, "Unexpected node type");
1569                 break;
1570             }
1571             break;
1572         }
1573         setNonCellTypeForNode(node, SpecBoolean);
1574         break;
1575     }
1576
1577     case CompareLess:
1578     case CompareLessEq:
1579     case CompareGreater:
1580     case CompareGreaterEq:
1581     case CompareEq: {
1582         bool isClobbering = node->isBinaryUseKind(UntypedUse);
1583         
1584         if (isClobbering)
1585             didFoldClobberWorld();
1586         
1587         JSValue leftConst = forNode(node->child1()).value();
1588         JSValue rightConst = forNode(node->child2()).value();
1589         if (leftConst && rightConst) {
1590             if (leftConst.isNumber() && rightConst.isNumber()) {
1591                 double a = leftConst.asNumber();
1592                 double b = rightConst.asNumber();
1593                 switch (node->op()) {
1594                 case CompareLess:
1595                     setConstant(node, jsBoolean(a < b));
1596                     break;
1597                 case CompareLessEq:
1598                     setConstant(node, jsBoolean(a <= b));
1599                     break;
1600                 case CompareGreater:
1601                     setConstant(node, jsBoolean(a > b));
1602                     break;
1603                 case CompareGreaterEq:
1604                     setConstant(node, jsBoolean(a >= b));
1605                     break;
1606                 case CompareEq:
1607                     setConstant(node, jsBoolean(a == b));
1608                     break;
1609                 default:
1610                     RELEASE_ASSERT_NOT_REACHED();
1611                     break;
1612                 }
1613                 break;
1614             }
1615             
1616             if (leftConst.isString() && rightConst.isString()) {
1617                 const StringImpl* a = asString(leftConst)->tryGetValueImpl();
1618                 const StringImpl* b = asString(rightConst)->tryGetValueImpl();
1619                 if (a && b) {
1620                     bool result;
1621                     if (node->op() == CompareEq)
1622                         result = WTF::equal(a, b);
1623                     else if (node->op() == CompareLess)
1624                         result = codePointCompare(a, b) < 0;
1625                     else if (node->op() == CompareLessEq)
1626                         result = codePointCompare(a, b) <= 0;
1627                     else if (node->op() == CompareGreater)
1628                         result = codePointCompare(a, b) > 0;
1629                     else if (node->op() == CompareGreaterEq)
1630                         result = codePointCompare(a, b) >= 0;
1631                     else
1632                         RELEASE_ASSERT_NOT_REACHED();
1633                     setConstant(node, jsBoolean(result));
1634                     break;
1635                 }
1636             }
1637
1638             if (node->op() == CompareEq && leftConst.isSymbol() && rightConst.isSymbol()) {
1639                 setConstant(node, jsBoolean(asSymbol(leftConst) == asSymbol(rightConst)));
1640                 break;
1641             }
1642         }
1643         
1644         if (node->op() == CompareEq) {
1645             SpeculatedType leftType = forNode(node->child1()).m_type;
1646             SpeculatedType rightType = forNode(node->child2()).m_type;
1647             if (!valuesCouldBeEqual(leftType, rightType)) {
1648                 setConstant(node, jsBoolean(false));
1649                 break;
1650             }
1651
1652             if (leftType == SpecOther)
1653                 std::swap(leftType, rightType);
1654             if (rightType == SpecOther) {
1655                 // Undefined and Null are always equal when compared to eachother.
1656                 if (!(leftType & ~SpecOther)) {
1657                     setConstant(node, jsBoolean(true));
1658                     break;
1659                 }
1660
1661                 // Any other type compared to Null or Undefined is always false
1662                 // as long as the MasqueradesAsUndefined watchpoint is valid.
1663                 //
1664                 // MasqueradesAsUndefined only matters for SpecObjectOther, other
1665                 // cases are always "false".
1666                 if (!(leftType & (SpecObjectOther | SpecOther))) {
1667                     setConstant(node, jsBoolean(false));
1668                     break;
1669                 }
1670
1671                 if (!(leftType & SpecOther) && m_graph.masqueradesAsUndefinedWatchpointIsStillValid(node->origin.semantic)) {
1672                     JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
1673                     m_graph.watchpoints().addLazily(globalObject->masqueradesAsUndefinedWatchpoint());
1674                     setConstant(node, jsBoolean(false));
1675                     break;
1676                 }
1677             }
1678         }
1679         
1680         if (node->child1() == node->child2()) {
1681             if (node->isBinaryUseKind(Int32Use) ||
1682                 node->isBinaryUseKind(Int52RepUse) ||
1683                 node->isBinaryUseKind(StringUse) ||
1684                 node->isBinaryUseKind(BooleanUse) ||
1685                 node->isBinaryUseKind(SymbolUse) ||
1686                 node->isBinaryUseKind(StringIdentUse) ||
1687                 node->isBinaryUseKind(ObjectUse) ||
1688                 node->isBinaryUseKind(ObjectUse, ObjectOrOtherUse) ||
1689                 node->isBinaryUseKind(ObjectOrOtherUse, ObjectUse)) {
1690                 switch (node->op()) {
1691                 case CompareLess:
1692                 case CompareGreater:
1693                     setConstant(node, jsBoolean(false));
1694                     break;
1695                 case CompareLessEq:
1696                 case CompareGreaterEq:
1697                 case CompareEq:
1698                     setConstant(node, jsBoolean(true));
1699                     break;
1700                 default:
1701                     DFG_CRASH(m_graph, node, "Unexpected node type");
1702                     break;
1703                 }
1704                 break;
1705             }
1706         }
1707
1708         if (isClobbering)
1709             clobberWorld();
1710         setNonCellTypeForNode(node, SpecBoolean);
1711         break;
1712     }
1713             
1714     case CompareStrictEq:
1715     case SameValue: {
1716         Node* leftNode = node->child1().node();
1717         Node* rightNode = node->child2().node();
1718         JSValue left = forNode(leftNode).value();
1719         JSValue right = forNode(rightNode).value();
1720         if (left && right) {
1721             if (left.isString() && right.isString()) {
1722                 // We need this case because JSValue::strictEqual is otherwise too racy for
1723                 // string comparisons.
1724                 const StringImpl* a = asString(left)->tryGetValueImpl();
1725                 const StringImpl* b = asString(right)->tryGetValueImpl();
1726                 if (a && b) {
1727                     setConstant(node, jsBoolean(WTF::equal(a, b)));
1728                     break;
1729                 }
1730             } else {
1731                 if (node->op() == CompareStrictEq)
1732                     setConstant(node, jsBoolean(JSValue::strictEqual(nullptr, left, right)));
1733                 else
1734                     setConstant(node, jsBoolean(sameValue(nullptr, left, right)));
1735                 break;
1736             }
1737         }
1738
1739         if (node->isBinaryUseKind(UntypedUse)) {
1740             // FIXME: Revisit this condition when introducing BigInt to JSC.
1741             auto isNonStringCellConstant = [] (JSValue value) {
1742                 return value && value.isCell() && !value.isString();
1743             };
1744
1745             if (isNonStringCellConstant(left) || isNonStringCellConstant(right)) {
1746                 m_state.setFoundConstants(true);
1747                 setNonCellTypeForNode(node, SpecBoolean);
1748                 break;
1749             }
1750         }
1751         
1752         SpeculatedType leftLUB = leastUpperBoundOfStrictlyEquivalentSpeculations(forNode(leftNode).m_type);
1753         SpeculatedType rightLUB = leastUpperBoundOfStrictlyEquivalentSpeculations(forNode(rightNode).m_type);
1754         if (!(leftLUB & rightLUB)) {
1755             setConstant(node, jsBoolean(false));
1756             break;
1757         }
1758         
1759         if (node->child1() == node->child2()) {
1760             if (node->isBinaryUseKind(BooleanUse) ||
1761                 node->isBinaryUseKind(Int32Use) ||
1762                 node->isBinaryUseKind(Int52RepUse) ||
1763                 node->isBinaryUseKind(StringUse) ||
1764                 node->isBinaryUseKind(StringIdentUse) ||
1765                 node->isBinaryUseKind(SymbolUse) ||
1766                 node->isBinaryUseKind(ObjectUse) ||
1767                 node->isBinaryUseKind(MiscUse, UntypedUse) ||
1768                 node->isBinaryUseKind(UntypedUse, MiscUse) ||
1769                 node->isBinaryUseKind(StringIdentUse, NotStringVarUse) ||
1770                 node->isBinaryUseKind(NotStringVarUse, StringIdentUse) ||
1771                 node->isBinaryUseKind(StringUse, UntypedUse) ||
1772                 node->isBinaryUseKind(UntypedUse, StringUse)) {
1773                 setConstant(node, jsBoolean(true));
1774                 break;
1775             }
1776         }
1777
1778         setNonCellTypeForNode(node, SpecBoolean);
1779         break;
1780     }
1781         
1782     case CompareEqPtr: {
1783         Node* childNode = node->child1().node();
1784         JSValue childValue = forNode(childNode).value();
1785         if (childValue) {
1786             setConstant(node, jsBoolean(childValue.isCell() && childValue.asCell() == node->cellOperand()->cell()));
1787             break;
1788         }
1789         
1790         setNonCellTypeForNode(node, SpecBoolean);
1791         break;
1792     }
1793         
1794     case StringCharCodeAt:
1795         setNonCellTypeForNode(node, SpecInt32Only);
1796         break;
1797         
1798     case StringFromCharCode:
1799         switch (node->child1().useKind()) {
1800         case Int32Use:
1801             break;
1802         case UntypedUse:
1803             clobberWorld();
1804             break;
1805         default:
1806             DFG_CRASH(m_graph, node, "Bad use kind");
1807             break;
1808         }
1809         setTypeForNode(node, SpecString);
1810         break;
1811
1812     case StringCharAt:
1813         setForNode(node, m_vm.stringStructure.get());
1814         break;
1815             
1816     case GetByVal:
1817     case AtomicsAdd:
1818     case AtomicsAnd:
1819     case AtomicsCompareExchange:
1820     case AtomicsExchange:
1821     case AtomicsLoad:
1822     case AtomicsOr:
1823     case AtomicsStore:
1824     case AtomicsSub:
1825     case AtomicsXor: {
1826         if (node->op() == GetByVal) {
1827             auto foldGetByValOnConstantProperty = [&] (Edge& arrayEdge, Edge& indexEdge) {
1828                 // FIXME: We can expand this for non x86 environments.
1829                 // https://bugs.webkit.org/show_bug.cgi?id=134641
1830                 if (!isX86())
1831                     return false;
1832
1833                 AbstractValue& arrayValue = forNode(arrayEdge);
1834
1835                 // Check the structure set is finite. This means that this constant's structure is watched and guaranteed the one of this set.
1836                 // When the structure is changed, this code should be invalidated. This is important since the following code relies on the
1837                 // constant object's is not changed.
1838                 if (!arrayValue.m_structure.isFinite())
1839                     return false;
1840
1841                 JSValue arrayConstant = arrayValue.value();
1842                 if (!arrayConstant)
1843                     return false;
1844
1845                 JSObject* array = jsDynamicCast<JSObject*>(m_vm, arrayConstant);
1846                 if (!array)
1847                     return false;
1848
1849                 JSValue indexConstant = forNode(indexEdge).value();
1850                 if (!indexConstant || !indexConstant.isInt32() || indexConstant.asInt32() < 0)
1851                     return false;
1852                 uint32_t index = indexConstant.asUInt32();
1853
1854                 // Check that the early StructureID is not nuked, get the butterfly, and check the late StructureID again.
1855                 // And we check the indexing mode of the structure. If the indexing mode is CoW, the butterfly is
1856                 // definitely JSImmutableButterfly.
1857                 StructureID structureIDEarly = array->structureID();
1858                 if (isNuked(structureIDEarly))
1859                     return false;
1860
1861                 WTF::loadLoadFence();
1862                 Butterfly* butterfly = array->butterfly();
1863
1864                 WTF::loadLoadFence();
1865                 StructureID structureIDLate = array->structureID();
1866
1867                 if (structureIDEarly != structureIDLate)
1868                     return false;
1869
1870                 Structure* structure = m_vm.getStructure(structureIDLate);
1871                 if (node->arrayMode().arrayClass() == Array::OriginalCopyOnWriteArray) {
1872                     if (!isCopyOnWrite(structure->indexingMode()))
1873                         return false;
1874
1875                     JSImmutableButterfly* immutableButterfly = JSImmutableButterfly::fromButterfly(butterfly);
1876                     if (index < immutableButterfly->length()) {
1877                         JSValue value = immutableButterfly->get(index);
1878                         ASSERT(value);
1879                         if (value.isCell())
1880                             setConstant(node, *m_graph.freeze(value.asCell()));
1881                         else
1882                             setConstant(node, value);
1883                         return true;
1884                     }
1885
1886                     if (node->arrayMode().isOutOfBounds()) {
1887                         JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
1888                         Structure* arrayPrototypeStructure = globalObject->arrayPrototype()->structure(m_vm);
1889                         Structure* objectPrototypeStructure = globalObject->objectPrototype()->structure(m_vm);
1890                         if (arrayPrototypeStructure->transitionWatchpointSetIsStillValid()
1891                             && objectPrototypeStructure->transitionWatchpointSetIsStillValid()
1892                             && globalObject->arrayPrototypeChainIsSane()) {
1893                             m_graph.registerAndWatchStructureTransition(arrayPrototypeStructure);
1894                             m_graph.registerAndWatchStructureTransition(objectPrototypeStructure);
1895                             // Note that Array::Double and Array::Int32 return JSValue if array mode is OutOfBounds.
1896                             setConstant(node, jsUndefined());
1897                             return true;
1898                         }
1899                     }
1900                     return false;
1901                 }
1902
1903                 if (node->arrayMode().type() == Array::ArrayStorage || node->arrayMode().type() == Array::SlowPutArrayStorage) {
1904                     if (!hasAnyArrayStorage(structure->indexingMode()))
1905                         return false;
1906
1907                     if (structure->typeInfo().interceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero())
1908                         return false;
1909
1910                     JSValue value;
1911                     {
1912                         // ArrayStorage's Butterfly can be half-broken state.
1913                         auto locker = holdLock(array->cellLock());
1914
1915                         ArrayStorage* storage = butterfly->arrayStorage();
1916                         if (index >= storage->length())
1917                             return false;
1918
1919                         if (index < storage->vectorLength())
1920                             return false;
1921
1922                         SparseArrayValueMap* map = storage->m_sparseMap.get();
1923                         if (!map)
1924                             return false;
1925
1926                         value = map->getConcurrently(index);
1927                     }
1928                     if (!value)
1929                         return false;
1930
1931                     if (value.isCell())
1932                         setConstant(node, *m_graph.freeze(value.asCell()));
1933                     else
1934                         setConstant(node, value);
1935                     return true;
1936                 }
1937
1938                 return false;
1939             };
1940
1941             bool didFold = false;
1942             switch (node->arrayMode().type()) {
1943             case Array::Generic:
1944             case Array::Int32:
1945             case Array::Double:
1946             case Array::Contiguous:
1947             case Array::ArrayStorage:
1948             case Array::SlowPutArrayStorage:
1949                 if (foldGetByValOnConstantProperty(m_graph.child(node, 0), m_graph.child(node, 1))) {
1950                     if (!node->arrayMode().isInBounds())
1951                         didFoldClobberWorld();
1952                     didFold = true;
1953                 }
1954                 break;
1955             default:
1956                 break;
1957             }
1958
1959             if (didFold)
1960                 break;
1961         }
1962
1963         if (node->op() != GetByVal) {
1964             unsigned numExtraArgs = numExtraAtomicsArgs(node->op());
1965             Edge storageEdge = m_graph.child(node, 2 + numExtraArgs);
1966             if (!storageEdge)
1967                 clobberWorld();
1968         }
1969         switch (node->arrayMode().type()) {
1970         case Array::SelectUsingPredictions:
1971         case Array::Unprofiled:
1972         case Array::SelectUsingArguments:
1973             RELEASE_ASSERT_NOT_REACHED();
1974             break;
1975         case Array::ForceExit:
1976             m_state.setIsValid(false);
1977             break;
1978         case Array::Undecided: {
1979             JSValue index = forNode(m_graph.child(node, 1)).value();
1980             if (index && index.isInt32() && index.asInt32() >= 0) {
1981                 setConstant(node, jsUndefined());
1982                 break;
1983             }
1984             setNonCellTypeForNode(node, SpecOther);
1985             break;
1986         }
1987         case Array::Generic:
1988             clobberWorld();
1989             makeHeapTopForNode(node);
1990             break;
1991         case Array::String:
1992             if (node->arrayMode().isOutOfBounds()) {
1993                 // If the watchpoint was still valid we could totally set this to be
1994                 // SpecString | SpecOther. Except that we'd have to be careful. If we
1995                 // tested the watchpoint state here then it could change by the time
1996                 // we got to the backend. So to do this right, we'd have to get the
1997                 // fixup phase to check the watchpoint state and then bake into the
1998                 // GetByVal operation the fact that we're using a watchpoint, using
1999                 // something like Array::SaneChain (except not quite, because that
2000                 // implies an in-bounds access). None of this feels like it's worth it,
2001                 // so we're going with TOP for now. The same thing applies to
2002                 // clobbering the world.
2003                 clobberWorld();
2004                 makeHeapTopForNode(node);
2005             } else
2006                 setForNode(node, m_vm.stringStructure.get());
2007             break;
2008         case Array::DirectArguments:
2009         case Array::ScopedArguments:
2010             if (node->arrayMode().isOutOfBounds())
2011                 clobberWorld();
2012             makeHeapTopForNode(node);
2013             break;
2014         case Array::Int32:
2015             if (node->arrayMode().isOutOfBounds()) {
2016                 clobberWorld();
2017                 makeHeapTopForNode(node);
2018             } else
2019                 setNonCellTypeForNode(node, SpecInt32Only);
2020             break;
2021         case Array::Double:
2022             if (node->arrayMode().isOutOfBounds()) {
2023                 clobberWorld();
2024                 makeHeapTopForNode(node);
2025             } else if (node->arrayMode().isSaneChain())
2026                 setNonCellTypeForNode(node, SpecBytecodeDouble);
2027             else
2028                 setNonCellTypeForNode(node, SpecDoubleReal);
2029             break;
2030         case Array::Contiguous:
2031         case Array::ArrayStorage:
2032         case Array::SlowPutArrayStorage:
2033             if (node->arrayMode().isOutOfBounds())
2034                 clobberWorld();
2035             makeHeapTopForNode(node);
2036             break;
2037         case Array::Int8Array:
2038             setNonCellTypeForNode(node, SpecInt32Only);
2039             break;
2040         case Array::Int16Array:
2041             setNonCellTypeForNode(node, SpecInt32Only);
2042             break;
2043         case Array::Int32Array:
2044             setNonCellTypeForNode(node, SpecInt32Only);
2045             break;
2046         case Array::Uint8Array:
2047             setNonCellTypeForNode(node, SpecInt32Only);
2048             break;
2049         case Array::Uint8ClampedArray:
2050             setNonCellTypeForNode(node, SpecInt32Only);
2051             break;
2052         case Array::Uint16Array:
2053             setNonCellTypeForNode(node, SpecInt32Only);
2054             break;
2055         case Array::Uint32Array:
2056             if (node->shouldSpeculateInt32())
2057                 setNonCellTypeForNode(node, SpecInt32Only);
2058             else if (enableInt52() && node->shouldSpeculateAnyInt())
2059                 setNonCellTypeForNode(node, SpecAnyInt);
2060             else
2061                 setNonCellTypeForNode(node, SpecAnyIntAsDouble);
2062             break;
2063         case Array::Float32Array:
2064             setNonCellTypeForNode(node, SpecFullDouble);
2065             break;
2066         case Array::Float64Array:
2067             setNonCellTypeForNode(node, SpecFullDouble);
2068             break;
2069         default:
2070             RELEASE_ASSERT_NOT_REACHED();
2071             break;
2072         }
2073         break;
2074     }
2075             
2076     case PutByValDirect:
2077     case PutByVal:
2078     case PutByValAlias: {
2079         switch (node->arrayMode().modeForPut().type()) {
2080         case Array::ForceExit:
2081             m_state.setIsValid(false);
2082             break;
2083         case Array::Generic:
2084             clobberWorld();
2085             break;
2086         case Array::Int32:
2087             if (node->arrayMode().isOutOfBounds())
2088                 clobberWorld();
2089             break;
2090         case Array::Double:
2091             if (node->arrayMode().isOutOfBounds())
2092                 clobberWorld();
2093             break;
2094         case Array::Contiguous:
2095         case Array::ArrayStorage:
2096             if (node->arrayMode().isOutOfBounds())
2097                 clobberWorld();
2098             break;
2099         case Array::SlowPutArrayStorage:
2100             if (node->arrayMode().mayStoreToHole())
2101                 clobberWorld();
2102             break;
2103         default:
2104             break;
2105         }
2106         break;
2107     }
2108             
2109     case ArrayPush:
2110         clobberWorld();
2111         setNonCellTypeForNode(node, SpecBytecodeNumber);
2112         break;
2113
2114     case ArraySlice: {
2115         JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
2116
2117         // FIXME: We could do better here if we prove that the
2118         // incoming value has only a single structure.
2119         RegisteredStructureSet structureSet;
2120         structureSet.add(m_graph.registerStructure(globalObject->originalArrayStructureForIndexingType(ArrayWithInt32)));
2121         structureSet.add(m_graph.registerStructure(globalObject->originalArrayStructureForIndexingType(ArrayWithContiguous)));
2122         structureSet.add(m_graph.registerStructure(globalObject->originalArrayStructureForIndexingType(ArrayWithDouble)));
2123
2124         setForNode(node, structureSet);
2125         break;
2126     }
2127
2128     case ArrayIndexOf: {
2129         setNonCellTypeForNode(node, SpecInt32Only);
2130         break;
2131     }
2132             
2133     case ArrayPop:
2134         clobberWorld();
2135         makeHeapTopForNode(node);
2136         break;
2137         
2138     case GetMyArgumentByVal:
2139     case GetMyArgumentByValOutOfBounds: {
2140         JSValue index = forNode(node->child2()).m_value;
2141         InlineCallFrame* inlineCallFrame = node->child1()->origin.semantic.inlineCallFrame;
2142
2143         if (index && index.isUInt32()) {
2144             // This pretends to return TOP for accesses that are actually proven out-of-bounds because
2145             // that's the conservative thing to do. Otherwise we'd need to write more code to mark such
2146             // paths as unreachable, or to return undefined. We could implement that eventually.
2147
2148             Checked<unsigned, RecordOverflow> argumentIndexChecked = index.asUInt32();
2149             argumentIndexChecked += node->numberOfArgumentsToSkip();
2150             unsigned argumentIndex;
2151             if (argumentIndexChecked.safeGet(argumentIndex) != CheckedState::DidOverflow) {
2152                 if (inlineCallFrame) {
2153                     if (argumentIndex < inlineCallFrame->argumentCountIncludingThis - 1) {
2154                         setForNode(node, m_state.operand(
2155                             virtualRegisterForArgument(argumentIndex + 1) + inlineCallFrame->stackOffset));
2156                         m_state.setFoundConstants(true);
2157                         break;
2158                     }
2159                 } else {
2160                     if (argumentIndex < m_state.numberOfArguments() - 1) {
2161                         setForNode(node, m_state.argument(argumentIndex + 1));
2162                         m_state.setFoundConstants(true);
2163                         break;
2164                     }
2165                 }
2166             }
2167         }
2168         
2169         if (inlineCallFrame) {
2170             // We have a bound on the types even though it's random access. Take advantage of this.
2171             
2172             AbstractValue result;
2173             for (unsigned i = 1 + node->numberOfArgumentsToSkip(); i < inlineCallFrame->argumentCountIncludingThis; ++i) {
2174                 result.merge(
2175                     m_state.operand(
2176                         virtualRegisterForArgument(i) + inlineCallFrame->stackOffset));
2177             }
2178             
2179             if (node->op() == GetMyArgumentByValOutOfBounds)
2180                 result.merge(SpecOther);
2181             
2182             if (result.value())
2183                 m_state.setFoundConstants(true);
2184             
2185             setForNode(node, result);
2186             break;
2187         }
2188         
2189         makeHeapTopForNode(node);
2190         break;
2191     }
2192             
2193     case RegExpExec:
2194     case RegExpExecNonGlobalOrSticky:
2195         if (node->op() == RegExpExec) {
2196             // Even if we've proven known input types as RegExpObject and String,
2197             // accessing lastIndex is effectful if it's a global regexp.
2198             clobberWorld();
2199         }
2200
2201         if (JSValue globalObjectValue = forNode(node->child1()).m_value) {
2202             if (JSGlobalObject* globalObject = jsDynamicCast<JSGlobalObject*>(m_vm, globalObjectValue)) {
2203                 if (!globalObject->isHavingABadTime()) {
2204                     m_graph.watchpoints().addLazily(globalObject->havingABadTimeWatchpoint());
2205                     RegisteredStructureSet structureSet;
2206                     structureSet.add(m_graph.registerStructure(globalObject->regExpMatchesArrayStructure()));
2207                     structureSet.add(m_graph.registerStructure(globalObject->regExpMatchesArrayWithGroupsStructure()));
2208                     setForNode(node, structureSet);
2209                     forNode(node).merge(SpecOther);
2210                     break;
2211                 }
2212             }
2213         }
2214         setTypeForNode(node, SpecOther | SpecArray);
2215         break;
2216
2217     case RegExpTest:
2218         // Even if we've proven known input types as RegExpObject and String,
2219         // accessing lastIndex is effectful if it's a global regexp.
2220         clobberWorld();
2221         setNonCellTypeForNode(node, SpecBoolean);
2222         break;
2223
2224     case RegExpMatchFast:
2225         ASSERT(node->child2().useKind() == RegExpObjectUse);
2226         ASSERT(node->child3().useKind() == StringUse || node->child3().useKind() == KnownStringUse);
2227         setTypeForNode(node, SpecOther | SpecArray);
2228         break;
2229
2230     case RegExpMatchFastGlobal:
2231         ASSERT(node->child2().useKind() == StringUse || node->child2().useKind() == KnownStringUse);
2232         setTypeForNode(node, SpecOther | SpecArray);
2233         break;
2234             
2235     case StringReplace:
2236     case StringReplaceRegExp:
2237         if (node->child1().useKind() == StringUse
2238             && node->child2().useKind() == RegExpObjectUse
2239             && node->child3().useKind() == StringUse) {
2240             // This doesn't clobber the world. It just reads and writes regexp state.
2241         } else
2242             clobberWorld();
2243         setForNode(node, m_vm.stringStructure.get());
2244         break;
2245
2246     case Jump:
2247         break;
2248             
2249     case Branch: {
2250         Node* child = node->child1().node();
2251         BooleanResult result = booleanResult(node, forNode(child));
2252         if (result == DefinitelyTrue) {
2253             m_state.setBranchDirection(TakeTrue);
2254             break;
2255         }
2256         if (result == DefinitelyFalse) {
2257             m_state.setBranchDirection(TakeFalse);
2258             break;
2259         }
2260         // FIXME: The above handles the trivial cases of sparse conditional
2261         // constant propagation, but we can do better:
2262         // We can specialize the source variable's value on each direction of
2263         // the branch.
2264         m_state.setBranchDirection(TakeBoth);
2265         break;
2266     }
2267         
2268     case Switch: {
2269         // Nothing to do for now.
2270         // FIXME: Do sparse conditional things.
2271         break;
2272     }
2273
2274     case EntrySwitch:
2275         break;
2276
2277     case Return:
2278         m_state.setIsValid(false);
2279         break;
2280
2281     case Throw:
2282     case ThrowStaticError:
2283     case TailCall:
2284     case DirectTailCall:
2285     case TailCallVarargs:
2286     case TailCallForwardVarargs:
2287         clobberWorld();
2288         m_state.setIsValid(false);
2289         break;
2290         
2291     case ToPrimitive: {
2292         JSValue childConst = forNode(node->child1()).value();
2293         if (childConst && childConst.isNumber()) {
2294             didFoldClobberWorld();
2295             setConstant(node, childConst);
2296             break;
2297         }
2298         
2299         ASSERT(node->child1().useKind() == UntypedUse);
2300         
2301         if (!(forNode(node->child1()).m_type & ~(SpecFullNumber | SpecBoolean | SpecString | SpecSymbol | SpecBigInt))) {
2302             m_state.setFoundConstants(true);
2303             didFoldClobberWorld();
2304             setForNode(node, forNode(node->child1()));
2305             break;
2306         }
2307         
2308         clobberWorld();
2309         
2310         setTypeForNode(node, SpecHeapTop & ~SpecObject);
2311         break;
2312     }
2313
2314     case ToNumber: {
2315         JSValue childConst = forNode(node->child1()).value();
2316         if (childConst && childConst.isNumber()) {
2317             didFoldClobberWorld();
2318             setConstant(node, childConst);
2319             break;
2320         }
2321
2322         ASSERT(node->child1().useKind() == UntypedUse);
2323
2324         if (!(forNode(node->child1()).m_type & ~SpecBytecodeNumber)) {
2325             m_state.setFoundConstants(true);
2326             didFoldClobberWorld();
2327             setForNode(node, forNode(node->child1()));
2328             break;
2329         }
2330
2331         clobberWorld();
2332         setNonCellTypeForNode(node, SpecBytecodeNumber);
2333         break;
2334     }
2335         
2336     case ToString:
2337     case CallStringConstructor: {
2338         switch (node->child1().useKind()) {
2339         case StringObjectUse:
2340             // This also filters that the StringObject has the primordial StringObject
2341             // structure.
2342             filter(
2343                 node->child1(),
2344                 m_graph.registerStructure(m_graph.globalObjectFor(node->origin.semantic)->stringObjectStructure()));
2345             break;
2346         case StringOrStringObjectUse:
2347         case Int32Use:
2348         case Int52RepUse:
2349         case DoubleRepUse:
2350         case NotCellUse:
2351             break;
2352         case CellUse:
2353         case UntypedUse:
2354             clobberWorld();
2355             break;
2356         default:
2357             RELEASE_ASSERT_NOT_REACHED();
2358             break;
2359         }
2360         setForNode(node, m_vm.stringStructure.get());
2361         break;
2362     }
2363
2364     case NumberToStringWithRadix: {
2365         JSValue radixValue = forNode(node->child2()).m_value;
2366         if (radixValue && radixValue.isInt32()) {
2367             int32_t radix = radixValue.asInt32();
2368             if (2 <= radix && radix <= 36) {
2369                 m_state.setFoundConstants(true);
2370                 didFoldClobberWorld();
2371                 setForNode(node, m_graph.m_vm.stringStructure.get());
2372                 break;
2373             }
2374         }
2375         clobberWorld();
2376         setForNode(node, m_graph.m_vm.stringStructure.get());
2377         break;
2378     }
2379
2380     case NumberToStringWithValidRadixConstant: {
2381         setForNode(node, m_graph.m_vm.stringStructure.get());
2382         break;
2383     }
2384         
2385     case NewStringObject: {
2386         ASSERT(node->structure()->classInfo() == StringObject::info());
2387         setForNode(node, node->structure());
2388         break;
2389     }
2390             
2391     case NewArray:
2392         ASSERT(node->indexingMode() == node->indexingType()); // Copy on write arrays should only be created by NewArrayBuffer.
2393         setForNode(node,
2394             m_graph.globalObjectFor(node->origin.semantic)->arrayStructureForIndexingTypeDuringAllocation(node->indexingType()));
2395         break;
2396
2397     case NewArrayWithSpread:
2398         if (m_graph.isWatchingHavingABadTimeWatchpoint(node)) {
2399             // We've compiled assuming we're not having a bad time, so to be consistent
2400             // with StructureRegisterationPhase we must say we produce an original array
2401             // allocation structure.
2402             setForNode(node, 
2403                 m_graph.globalObjectFor(node->origin.semantic)->originalArrayStructureForIndexingType(ArrayWithContiguous));
2404         } else {
2405             setForNode(node, 
2406                 m_graph.globalObjectFor(node->origin.semantic)->arrayStructureForIndexingTypeDuringAllocation(ArrayWithContiguous));
2407         }
2408
2409         break;
2410
2411     case Spread:
2412         switch (node->child1()->op()) {
2413         case PhantomNewArrayBuffer:
2414         case PhantomCreateRest:
2415             break;
2416         default:
2417             if (!m_graph.canDoFastSpread(node, forNode(node->child1())))
2418                 clobberWorld();
2419             else
2420                 didFoldClobberWorld();
2421             break;
2422         }
2423
2424         setForNode(node, 
2425             m_vm.fixedArrayStructure.get());
2426         break;
2427         
2428     case NewArrayBuffer:
2429         setForNode(node,
2430             m_graph.globalObjectFor(node->origin.semantic)->arrayStructureForIndexingTypeDuringAllocation(node->indexingMode()));
2431         break;
2432
2433     case NewArrayWithSize:
2434         setTypeForNode(node, SpecArray);
2435         break;
2436         
2437     case NewTypedArray:
2438         switch (node->child1().useKind()) {
2439         case Int32Use:
2440             break;
2441         case UntypedUse:
2442             clobberWorld();
2443             break;
2444         default:
2445             RELEASE_ASSERT_NOT_REACHED();
2446             break;
2447         }
2448         setForNode(node, 
2449             m_graph.globalObjectFor(node->origin.semantic)->typedArrayStructureConcurrently(
2450                 node->typedArrayType()));
2451         break;
2452         
2453     case NewRegexp:
2454         setForNode(node, m_graph.globalObjectFor(node->origin.semantic)->regExpStructure());
2455         break;
2456             
2457     case ToThis: {
2458         AbstractValue& source = forNode(node->child1());
2459         AbstractValue& destination = forNode(node);
2460         bool strictMode = m_graph.executableFor(node->origin.semantic)->isStrictMode();
2461
2462         ToThisResult result = isToThisAnIdentity(m_vm, strictMode, source);
2463         if (result != ToThisResult::Dynamic) {
2464             switch (result) {
2465             case ToThisResult::Identity:
2466                 m_state.setFoundConstants(true);
2467                 destination = source;
2468                 break;
2469             case ToThisResult::Undefined:
2470                 setConstant(node, jsUndefined());
2471                 break;
2472             case ToThisResult::GlobalThis:
2473                 m_state.setFoundConstants(true);
2474                 destination.setType(m_graph, SpecObject);
2475                 break;
2476             case ToThisResult::Dynamic:
2477                 RELEASE_ASSERT_NOT_REACHED();
2478             }
2479             break;
2480         }
2481
2482         if (strictMode)
2483             destination.makeHeapTop();
2484         else {
2485             destination = source;
2486             destination.merge(SpecObject);
2487         }
2488         break;
2489     }
2490
2491     case CreateThis: {
2492         if (JSValue base = forNode(node->child1()).m_value) {
2493             if (auto* function = jsDynamicCast<JSFunction*>(m_vm, base)) {
2494                 if (FunctionRareData* rareData = function->rareData()) {
2495                     if (Structure* structure = rareData->objectAllocationStructure()) {
2496                         m_graph.freeze(rareData);
2497                         m_graph.watchpoints().addLazily(rareData->allocationProfileWatchpointSet());
2498                         m_state.setFoundConstants(true);
2499                         didFoldClobberWorld();
2500                         setForNode(node, structure);
2501                         break;
2502                     }
2503                 }
2504             }
2505         }
2506         clobberWorld();
2507         setTypeForNode(node, SpecFinalObject);
2508         break;
2509     }
2510         
2511     case NewObject:
2512         ASSERT(!!node->structure().get());
2513         setForNode(node, node->structure());
2514         break;
2515
2516     case ObjectCreate: {
2517         if (JSValue base = forNode(node->child1()).m_value) {
2518             if (base.isNull()) {
2519                 JSGlobalObject* globalObject = m_graph.globalObjectFor(node->origin.semantic);
2520                 m_state.setFoundConstants(true);
2521                 if (node->child1().useKind() == UntypedUse)
2522                     didFoldClobberWorld();
2523                 setForNode(node, globalObject->nullPrototypeObjectStructure());
2524                 break;
2525             }
2526             // FIXME: We should get a structure for a constant prototype. We need to allow concurrent
2527             // access to StructureCache from compiler threads.
2528             // https://bugs.webkit.org/show_bug.cgi?id=186199
2529         }
2530         if (node->child1().useKind() == UntypedUse)
2531             clobberWorld();
2532         setTypeForNode(node, SpecFinalObject);
2533         break;
2534     }
2535
2536     case ToObject:
2537     case CallObjectConstructor: {
2538         AbstractValue& source = forNode(node->child1());
2539         AbstractValue& destination = forNode(node);
2540
2541         if (!(source.m_type & ~SpecObject)) {
2542             m_state.setFoundConstants(true);
2543             if (node->op() == ToObject)
2544                 didFoldClobberWorld();
2545             destination = source;
2546             break;
2547         }
2548
2549         if (node->op() == ToObject)
2550             clobberWorld();
2551         setTypeForNode(node, SpecObject);
2552         break;
2553     }
2554
2555     case PhantomNewObject:
2556     case PhantomNewFunction:
2557     case PhantomNewGeneratorFunction:
2558     case PhantomNewAsyncGeneratorFunction:
2559     case PhantomNewAsyncFunction:
2560     case PhantomCreateActivation:
2561     case PhantomDirectArguments:
2562     case PhantomClonedArguments:
2563     case PhantomCreateRest:
2564     case PhantomSpread:
2565     case PhantomNewArrayWithSpread:
2566     case PhantomNewArrayBuffer:
2567     case PhantomNewRegexp:
2568     case BottomValue:
2569         // This claims to return bottom.
2570         break;
2571         
2572     case PutHint:
2573         break;
2574         
2575     case MaterializeNewObject: {
2576         setForNode(node, node->structureSet());
2577         break;
2578     }
2579
2580     case PushWithScope:
2581         // We don't use the more precise withScopeStructure() here because it is a LazyProperty and may not yet be allocated.
2582         setTypeForNode(node, SpecObjectOther);
2583         break;
2584
2585     case CreateActivation:
2586     case MaterializeCreateActivation:
2587         setForNode(node, 
2588             m_codeBlock->globalObjectFor(node->origin.semantic)->activationStructure());
2589         break;
2590         
2591     case CreateDirectArguments:
2592         setForNode(node, m_codeBlock->globalObjectFor(node->origin.semantic)->directArgumentsStructure());
2593         break;
2594         
2595     case CreateScopedArguments:
2596         setForNode(node, m_codeBlock->globalObjectFor(node->origin.semantic)->scopedArgumentsStructure());
2597         break;
2598         
2599     case CreateClonedArguments:
2600         if (!m_graph.isWatchingHavingABadTimeWatchpoint(node)) {
2601             setTypeForNode(node, SpecObject);
2602             break;
2603         }
2604         setForNode(node, m_codeBlock->globalObjectFor(node->origin.semantic)->clonedArgumentsStructure());
2605         break;
2606
2607     case NewGeneratorFunction:
2608         setForNode(node, 
2609             m_codeBlock->globalObjectFor(node->origin.semantic)->generatorFunctionStructure());
2610         break;
2611
2612     case NewAsyncGeneratorFunction:
2613         setForNode(node, 
2614             m_codeBlock->globalObjectFor(node->origin.semantic)->asyncGeneratorFunctionStructure());
2615         break;
2616
2617     case NewAsyncFunction:
2618         setForNode(node, 
2619             m_codeBlock->globalObjectFor(node->origin.semantic)->asyncFunctionStructure());
2620         break;
2621
2622     case NewFunction: {
2623         JSGlobalObject* globalObject = m_codeBlock->globalObjectFor(node->origin.semantic);
2624         Structure* structure = JSFunction::selectStructureForNewFuncExp(globalObject, node->castOperand<FunctionExecutable*>());
2625         setForNode(node, structure);
2626         break;
2627     }
2628         
2629     case GetCallee:
2630         if (FunctionExecutable* executable = jsDynamicCast<FunctionExecutable*>(m_vm, m_codeBlock->ownerExecutable())) {
2631             InferredValue* singleton = executable->singletonFunction();
2632             if (JSValue value = singleton->inferredValue()) {
2633                 m_graph.watchpoints().addLazily(singleton);
2634                 JSFunction* function = jsCast<JSFunction*>(value);
2635                 setConstant(node, *m_graph.freeze(function));
2636                 break;
2637             }
2638         }
2639         setTypeForNode(node, SpecFunction);
2640         break;
2641         
2642     case GetArgumentCountIncludingThis:
2643         setTypeForNode(node, SpecInt32Only);
2644         break;
2645
2646     case SetCallee:
2647     case SetArgumentCountIncludingThis:
2648         break;
2649         
2650     case GetRestLength:
2651         setNonCellTypeForNode(node, SpecInt32Only);
2652         break;
2653         
2654     case GetGetter: {
2655         JSValue base = forNode(node->child1()).m_value;
2656         if (base) {
2657             GetterSetter* getterSetter = jsCast<GetterSetter*>(base);
2658             if (!getterSetter->isGetterNull()) {
2659                 setConstant(node, *m_graph.freeze(getterSetter->getterConcurrently()));
2660                 break;
2661             }
2662         }
2663         
2664         setTypeForNode(node, SpecObject);
2665         break;
2666     }
2667         
2668     case GetSetter: {
2669         JSValue base = forNode(node->child1()).m_value;
2670         if (base) {
2671             GetterSetter* getterSetter = jsCast<GetterSetter*>(base);
2672             if (!getterSetter->isSetterNull()) {
2673                 setConstant(node, *m_graph.freeze(getterSetter->setterConcurrently()));
2674                 break;
2675             }
2676         }
2677         
2678         setTypeForNode(node, SpecObject);
2679         break;
2680     }
2681         
2682     case GetScope:
2683         if (JSValue base = forNode(node->child1()).m_value) {
2684             if (JSFunction* function = jsDynamicCast<JSFunction*>(m_vm, base)) {
2685                 setConstant(node, *m_graph.freeze(function->scope()));
2686                 break;
2687             }
2688         }
2689         setTypeForNode(node, SpecObjectOther);
2690         break;
2691
2692     case SkipScope: {
2693         JSValue child = forNode(node->child1()).value();
2694         if (child) {
2695             setConstant(node, *m_graph.freeze(JSValue(jsCast<JSScope*>(child.asCell())->next())));
2696             break;
2697         }
2698         setTypeForNode(node, SpecObjectOther);
2699         break;
2700     }
2701
2702     case GetGlobalObject: {
2703         JSValue child = forNode(node->child1()).value();
2704         if (child) {
2705             setConstant(node, *m_graph.freeze(JSValue(asObject(child)->globalObject(m_vm))));
2706             break;
2707         }
2708
2709         if (forNode(node->child1()).m_structure.isFinite()) {
2710             JSGlobalObject* globalObject = nullptr;
2711             bool ok = true;
2712             forNode(node->child1()).m_structure.forEach(
2713                 [&] (RegisteredStructure structure) {
2714                     if (!globalObject)
2715                         globalObject = structure->globalObject();
2716                     else if (globalObject != structure->globalObject())
2717                         ok = false;
2718                 });
2719             if (globalObject && ok) {
2720                 setConstant(node, *m_graph.freeze(JSValue(globalObject)));
2721                 break;
2722             }
2723         }
2724
2725         setTypeForNode(node, SpecObjectOther);
2726         break;
2727     }
2728
2729     case GetGlobalThis: {
2730         setTypeForNode(node, SpecObject);
2731         break;
2732     }
2733
2734     case GetClosureVar:
2735         if (JSValue value = m_graph.tryGetConstantClosureVar(forNode(node->child1()), node->scopeOffset())) {
2736             setConstant(node, *m_graph.freeze(value));
2737             break;
2738         }
2739         makeBytecodeTopForNode(node);
2740         break;
2741             
2742     case PutClosureVar:
2743         break;
2744
2745     case GetRegExpObjectLastIndex:
2746         makeHeapTopForNode(node);
2747         break;
2748
2749     case SetRegExpObjectLastIndex:
2750     case RecordRegExpCachedResult:
2751         break;
2752         
2753     case GetFromArguments:
2754         makeHeapTopForNode(node);
2755         break;
2756         
2757     case PutToArguments:
2758         break;
2759
2760     case GetArgument:
2761         makeHeapTopForNode(node);
2762         break;
2763
2764     case TryGetById:
2765         // FIXME: This should constant fold at least as well as the normal GetById case.
2766         // https://bugs.webkit.org/show_bug.cgi?id=156422
2767         makeHeapTopForNode(node);
2768         break;
2769
2770     case GetByIdDirect:
2771     case GetByIdDirectFlush:
2772     case GetById:
2773     case GetByIdFlush: {
2774         AbstractValue& value = forNode(node->child1());
2775         if (value.m_structure.isFinite()
2776             && (node->child1().useKind() == CellUse || !(value.m_type & ~SpecCell))) {
2777             UniquedStringImpl* uid = m_graph.identifiers()[node->identifierNumber()];
2778             GetByIdStatus status = GetByIdStatus::computeFor(value.m_structure.toStructureSet(), uid);
2779             if (status.isSimple()) {
2780                 // Figure out what the result is going to be - is it TOP, a constant, or maybe
2781                 // something more subtle?
2782                 AbstractValue result;
2783                 for (unsigned i = status.numVariants(); i--;) {
2784                     // This thing won't give us a variant that involves prototypes. If it did, we'd
2785                     // have more work to do here.
2786                     DFG_ASSERT(m_graph, node, status[i].conditionSet().isEmpty());
2787
2788                     result.merge(
2789                         m_graph.inferredValueForProperty(
2790                             value, uid, status[i].offset(), m_state.structureClobberState()));
2791                 }
2792                 m_state.setFoundConstants(true);
2793                 didFoldClobberWorld();
2794                 forNode(node) = result;
2795                 break;
2796             }
2797         }
2798
2799         clobberWorld();
2800         makeHeapTopForNode(node);
2801         break;
2802     }
2803
2804     case GetByValWithThis:
2805     case GetByIdWithThis:
2806         clobberWorld();
2807         makeHeapTopForNode(node);
2808         break;
2809             
2810     case GetArrayLength: {
2811         JSArrayBufferView* view = m_graph.tryGetFoldableView(
2812             forNode(node->child1()).m_value, node->arrayMode());
2813         if (view) {
2814             setConstant(node, jsNumber(view->length()));
2815             break;
2816         }
2817         setNonCellTypeForNode(node, SpecInt32Only);
2818         break;
2819     }
2820
2821     case GetVectorLength: {
2822         setNonCellTypeForNode(node, SpecInt32Only);
2823         break;
2824     }
2825
2826     case DeleteById:
2827     case DeleteByVal: {
2828         // FIXME: This could decide if the delete will be successful based on the set of structures that
2829         // we get from our base value. https://bugs.webkit.org/show_bug.cgi?id=156611
2830         clobberWorld();
2831         setNonCellTypeForNode(node, SpecBoolean);
2832         break;
2833     }
2834         
2835     case CheckStructure: {
2836         AbstractValue& value = forNode(node->child1());
2837
2838         const RegisteredStructureSet& set = node->structureSet();
2839         
2840         // It's interesting that we could have proven that the object has a larger structure set
2841         // that includes the set we're testing. In that case we could make the structure check
2842         // more efficient. We currently don't.
2843         
2844         if (value.m_structure.isSubsetOf(set))
2845             m_state.setFoundConstants(true);
2846
2847         SpeculatedType admittedTypes = SpecNone;
2848         switch (node->child1().useKind()) {
2849         case CellUse:
2850         case KnownCellUse:
2851             admittedTypes = SpecNone;
2852             break;
2853         case CellOrOtherUse:
2854             admittedTypes = SpecOther;
2855             break;
2856         default:
2857             DFG_CRASH(m_graph, node, "Bad use kind");
2858             break;
2859         }
2860         
2861         filter(value, set, admittedTypes);
2862         break;
2863     }
2864
2865     case CheckStructureOrEmpty: {
2866         AbstractValue& value = forNode(node->child1());
2867
2868         bool mayBeEmpty = value.m_type & SpecEmpty;
2869         if (!mayBeEmpty)
2870             m_state.setFoundConstants(true);
2871
2872         SpeculatedType admittedTypes = mayBeEmpty ? SpecEmpty : SpecNone;
2873         filter(value, node->structureSet(), admittedTypes);
2874         break;
2875     }
2876         
2877     case CheckStructureImmediate: {
2878         // FIXME: This currently can only reason about one structure at a time.
2879         // https://bugs.webkit.org/show_bug.cgi?id=136988
2880         
2881         AbstractValue& value = forNode(node->child1());
2882         const RegisteredStructureSet& set = node->structureSet();
2883         
2884         if (value.value()) {
2885             if (Structure* structure = jsDynamicCast<Structure*>(m_vm, value.value())) {
2886                 if (set.contains(m_graph.registerStructure(structure))) {
2887                     m_state.setFoundConstants(true);
2888                     break;
2889                 }
2890             }
2891             m_state.setIsValid(false);
2892             break;
2893         }
2894         
2895         if (m_phiChildren) {
2896             bool allGood = true;
2897             m_phiChildren->forAllTransitiveIncomingValues(
2898                 node,
2899                 [&] (Node* incoming) {
2900                     if (Structure* structure = incoming->dynamicCastConstant<Structure*>(m_vm)) {
2901                         if (set.contains(m_graph.registerStructure(structure)))
2902                             return;
2903                     }
2904                     allGood = false;
2905                 });
2906             if (allGood) {
2907                 m_state.setFoundConstants(true);
2908                 break;
2909             }
2910         }
2911             
2912         if (RegisteredStructure structure = set.onlyStructure()) {
2913             filterByValue(node->child1(), *m_graph.freeze(structure.get()));
2914             break;
2915         }
2916         
2917         // Aw shucks, we can't do anything!
2918         break;
2919     }
2920         
2921     case PutStructure:
2922         if (!forNode(node->child1()).m_structure.isClear()) {
2923             if (forNode(node->child1()).m_structure.onlyStructure() == node->transition()->next) {
2924                 didFoldClobberStructures();
2925                 m_state.setFoundConstants(true);
2926             } else {
2927                 observeTransition(
2928                     clobberLimit, node->transition()->previous, node->transition()->next);
2929                 forNode(node->child1()).changeStructure(m_graph, node->transition()->next);
2930             }
2931         } else {
2932             // We're going to exit before we get here, but for the sake of validation, we've folded our write to StructureID.
2933             didFoldClobberStructures();
2934         }
2935         break;
2936     case GetButterfly:
2937     case AllocatePropertyStorage:
2938     case ReallocatePropertyStorage:
2939     case NukeStructureAndSetButterfly:
2940         // FIXME: We don't model the fact that the structureID is nuked, simply because currently
2941         // nobody would currently benefit from having that information. But it's a bug nonetheless.
2942         if (node->op() == NukeStructureAndSetButterfly)
2943             didFoldClobberStructures();
2944         clearForNode(node); // The result is not a JS value.
2945         break;
2946     case CheckSubClass: {
2947         JSValue constant = forNode(node->child1()).value();
2948         if (constant) {
2949             if (constant.isCell() && constant.asCell()->inherits(m_vm, node->classInfo())) {
2950                 m_state.setFoundConstants(true);
2951                 ASSERT(constant);
2952                 break;
2953             }
2954         }
2955
2956         AbstractValue& value = forNode(node->child1());
2957
2958         if (value.m_structure.isSubClassOf(node->classInfo()))
2959             m_state.setFoundConstants(true);
2960
2961         filterClassInfo(value, node->classInfo());
2962         break;
2963     }
2964     case CallDOMGetter: {
2965         CallDOMGetterData* callDOMGetterData = node->callDOMGetterData();
2966         DOMJIT::CallDOMGetterSnippet* snippet = callDOMGetterData->snippet;
2967         if (!snippet || snippet->effect.writes)
2968             clobberWorld();
2969         if (callDOMGetterData->domJIT)
2970             setTypeForNode(node, callDOMGetterData->domJIT->resultType());
2971         else
2972             makeBytecodeTopForNode(node);
2973         break;
2974     }
2975     case CallDOM: {
2976         const DOMJIT::Signature* signature = node->signature();
2977         if (signature->effect.writes)
2978             clobberWorld();
2979         setTypeForNode(node, signature->result);
2980         break;
2981     }
2982     case CheckArray: {
2983         if (node->arrayMode().alreadyChecked(m_graph, node, forNode(node->child1()))) {
2984             m_state.setFoundConstants(true);
2985             break;
2986         }
2987         switch (node->arrayMode().type()) {
2988         case Array::String:
2989             filter(node->child1(), SpecString);
2990             break;
2991         case Array::Int32:
2992         case Array::Double:
2993         case Array::Contiguous:
2994         case Array::Undecided:
2995         case Array::ArrayStorage:
2996         case Array::SlowPutArrayStorage:
2997             break;
2998         case Array::DirectArguments:
2999             filter(node->child1(), SpecDirectArguments);
3000             break;
3001         case Array::ScopedArguments:
3002             filter(node->child1(), SpecScopedArguments);
3003             break;
3004         case Array::Int8Array:
3005             filter(node->child1(), SpecInt8Array);
3006             break;
3007         case Array::Int16Array:
3008             filter(node->child1(), SpecInt16Array);
3009             break;
3010         case Array::Int32Array:
3011             filter(node->child1(), SpecInt32Array);
3012             break;
3013         case Array::Uint8Array:
3014             filter(node->child1(), SpecUint8Array);
3015             break;
3016         case Array::Uint8ClampedArray:
3017             filter(node->child1(), SpecUint8ClampedArray);
3018             break;
3019         case Array::Uint16Array:
3020             filter(node->child1(), SpecUint16Array);
3021             break;
3022         case Array::Uint32Array:
3023             filter(node->child1(), SpecUint32Array);
3024             break;
3025         case Array::Float32Array: