| Summary: | [JSC] BigInt should work with Map / Set | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Product: | WebKit | Reporter: | Dwight House <dwighthouse> | ||||||||||||
| Component: | JavaScriptCore | Assignee: | Yusuke Suzuki <ysuzuki> | ||||||||||||
| Status: | RESOLVED FIXED | ||||||||||||||
| Severity: | Normal | CC: | alecflett, beidson, benjamin, cdumez, cmarcelo, ews-watchlist, fpizlo, jsbell, keith_miller, mark.lam, msaboff, rmorisset, saam, tzagallo, webkit-bug-importer, ysuzuki | ||||||||||||
| Priority: | P2 | Keywords: | InRadar | ||||||||||||
| Version: | Safari Technology Preview | ||||||||||||||
| Hardware: | Mac | ||||||||||||||
| OS: | macOS 10.15 | ||||||||||||||
| Attachments: |
|
||||||||||||||
|
Description
Dwight House
2020-09-17 15:14:35 PDT
Created attachment 409226 [details]
Patch
Created attachment 409227 [details]
Patch
Comment on attachment 409227 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=409227&action=review > Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:2381 > + else if (node->child2()->shouldSpeculateInt32()) typo: shouldSpeculateBigInt32 Comment on attachment 409227 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=409227&action=review >> Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:2381 >> + else if (node->child2()->shouldSpeculateInt32()) > > typo: shouldSpeculateBigInt32 Oops. Fixed. Created attachment 409246 [details]
Patch
Comment on attachment 409246 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=409246&action=review r=me, thanks for this patch! > Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:1384 > + SpeculatedType typeMaybeNormalized = (SpecFullNumber & ~SpecInt32Only) | SpecHeapBigInt; This looks like it is fixing a different bug? Maybe worth mentioning in the Changelog. > Source/JavaScriptCore/dfg/DFGDoesGC.cpp:520 > +#if USE(BIGINT32) This is a small unrelated optimization, right? (since doesGC is conservative) Comment on attachment 409246 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=409246&action=review >> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:1384 >> + SpeculatedType typeMaybeNormalized = (SpecFullNumber & ~SpecInt32Only) | SpecHeapBigInt; > > This looks like it is fixing a different bug? Maybe worth mentioning in the Changelog. No. After this change, NormalizeMapKey needs to convert JSBigInt to BigInt32 if (1) BigInt32 is supported and (2) JSBigInt's value is in range of BigInt32. So, NormalizeMapKey's AI conversion rule should care this case. This is part of (1) change in ChangeLog. >> Source/JavaScriptCore/dfg/DFGDoesGC.cpp:520 >> +#if USE(BIGINT32) > > This is a small unrelated optimization, right? (since doesGC is conservative) I think this is good. Since we should maintain the rules of DoesGC when we changed the behavior. And after this patch, BigInts are supported in MapHash correctly. So this is good timing to list up here :) Comment on attachment 409246 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=409246&action=review > Source/JavaScriptCore/runtime/JSBigInt.cpp:3059 > +unsigned JSBigInt::concurrentHash() > +{ > + Hasher hasher; > + WTF::add(hasher, m_sign); > + for (unsigned index = 0; index < length(); ++index) > + WTF::add(hasher, digit(index)); > + return hasher.hash(); > +} Temporary disable this (concurrentHash) since I'm not sure about the story between storage data and concurrent compiler thread read. We should fix it. Add FIXME. Committed r267373: <https://trac.webkit.org/changeset/267373> Comment on attachment 409246 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=409246&action=review LGTM overall too, but I have some comments >>> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:1384 >>> + SpeculatedType typeMaybeNormalized = (SpecFullNumber & ~SpecInt32Only) | SpecHeapBigInt; >> >> This looks like it is fixing a different bug? Maybe worth mentioning in the Changelog. > > No. After this change, NormalizeMapKey needs to convert JSBigInt to BigInt32 if (1) BigInt32 is supported and (2) JSBigInt's value is in range of BigInt32. > So, NormalizeMapKey's AI conversion rule should care this case. This is part of (1) change in ChangeLog. Yeah, this looks right to me. But maybe this variable could be renamed to something like "typesNeedingNormalization" or "typesThatNeedNormalization" to be less confusing. > Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:12547 > + addSlowPathGenerator(slowPathCall(slowPath, this, operationNormalizeMapKey, resultRegs, &vm(), keyRegs)); since this is just for heap big int, should we specialize "operationNormalizeMapKey" to not have to do type checks, etc (and to name it like "operationNormalizeMapKeyHeapBigInt")? > Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4465 > + callOperation(operationMapHash, resultGPR, TrustedImmPtr::weakPointer(m_graph, m_graph.globalObjectFor(node->origin.semantic)), inputGPR); should we specialize operationMapHash to be over BigInt? > Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4466 > + m_jit.exceptionCheck(); can this throw for HeapBigInt? > Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4495 > + addSlowPathGenerator(slowPathCall(isHeapBigInt, this, operationMapHash, resultGPR, TrustedImmPtr::weakPointer(m_graph, m_graph.globalObjectFor(node->origin.semantic)), inputGPR)); ditto about specializing > Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4549 > + addSlowPathGenerator(slowPathCall(isHeapBigInt, this, operationMapHash, resultGPR, TrustedImmPtr::weakPointer(m_graph, m_graph.globalObjectFor(node->origin.semantic)), inputGPR)); ditto about specializing it. > Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4641 > + auto isBucketString = m_jit.branchIfString(bucketGPR); nit: I'd have named this "bucketIsString" > Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4645 > + slowPathCases.append(m_jit.branchIfHeapBigInt(keyGPR)); why do we need the branch here? Isn't this guaranteed to be the case since we're the fall through from branchIfNotHeapBigInt > Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4679 > + loopAround.append(m_jit.branchIfNotHeapBigInt(bucketGPR)); > + // bucket is HeapBigInt. > + slowPathCases.append(m_jit.branchIfHeapBigInt(keyGPR)); isn't the second branch proven true by the first? > Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:11270 > + LBasicBlock notStringHeapBigIntCase = m_out.newBlock(); nit: I'd name this "notStringNorHeapBigIntCase" > Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:11286 > + ValueFromBlock heapBigIntResult = m_out.anchor(m_out.castToInt32(vmCall(Int64, operationMapHash, weakPointer(globalObject), value))); ditto about specializing a call of operationMapHash for HeapBigInt > Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:11372 > + m_out.branch(isNotHeapBigInt(key), unsure(continuation), unsure(isHeapBigIntCase)); should we use provenType in isNotHeapBigInt here? > Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:11375 > + ValueFromBlock bigIntResult = m_out.anchor(vmCall(Int64, operationNormalizeMapKey, m_vmValue, key)); ditto about specializing >> Source/JavaScriptCore/runtime/JSBigInt.cpp:3059 >> +} > > Temporary disable this (concurrentHash) since I'm not sure about the story between storage data and concurrent compiler thread read. We should fix it. Add FIXME. Why wouldn't it work? Aren't BigInts immutable? Also, do we have place to cache the result of the hash inline somewhere? Comment on attachment 409246 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=409246&action=review >>> Source/JavaScriptCore/runtime/JSBigInt.cpp:3059 >>> +} >> >> Temporary disable this (concurrentHash) since I'm not sure about the story between storage data and concurrent compiler thread read. We should fix it. Add FIXME. > > Why wouldn't it work? Aren't BigInts immutable? > > Also, do we have place to cache the result of the hash inline somewhere? immutable, but we are not ensuring when this baking process is done when it is exposed to concurrent compilers. And I'm not 100% confident. This should be done in a separate patch with careful investigation. And m_hash is added in the landed patch. Comment on attachment 409246 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=409246&action=review >>>> Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:1384 >>>> + SpeculatedType typeMaybeNormalized = (SpecFullNumber & ~SpecInt32Only) | SpecHeapBigInt; >>> >>> This looks like it is fixing a different bug? Maybe worth mentioning in the Changelog. >> >> No. After this change, NormalizeMapKey needs to convert JSBigInt to BigInt32 if (1) BigInt32 is supported and (2) JSBigInt's value is in range of BigInt32. >> So, NormalizeMapKey's AI conversion rule should care this case. This is part of (1) change in ChangeLog. > > Yeah, this looks right to me. > > But maybe this variable could be renamed to something like "typesNeedingNormalization" or "typesThatNeedNormalization" to be less confusing. Changed. >> Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:12547 >> + addSlowPathGenerator(slowPathCall(slowPath, this, operationNormalizeMapKey, resultRegs, &vm(), keyRegs)); > > since this is just for heap big int, should we specialize "operationNormalizeMapKey" to not have to do type checks, etc (and to name it like "operationNormalizeMapKeyHeapBigInt")? Added operationNormalizeMapKeyHeapBigInt >> Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4465 >> + callOperation(operationMapHash, resultGPR, TrustedImmPtr::weakPointer(m_graph, m_graph.globalObjectFor(node->origin.semantic)), inputGPR); > > should we specialize operationMapHash to be over BigInt? Added operationMapHashHeapBigInt. >> Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4466 >> + m_jit.exceptionCheck(); > > can this throw for HeapBigInt? If it is operationMapHash, we should insert check. We should not rely on the internal implementation detail. If we specialize it to operationMapHashHeapBigInt, we can remove it. >> Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4495 >> + addSlowPathGenerator(slowPathCall(isHeapBigInt, this, operationMapHash, resultGPR, TrustedImmPtr::weakPointer(m_graph, m_graph.globalObjectFor(node->origin.semantic)), inputGPR)); > > ditto about specializing Added. >> Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4549 >> + addSlowPathGenerator(slowPathCall(isHeapBigInt, this, operationMapHash, resultGPR, TrustedImmPtr::weakPointer(m_graph, m_graph.globalObjectFor(node->origin.semantic)), inputGPR)); > > ditto about specializing it. Added. >> Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4641 >> + auto isBucketString = m_jit.branchIfString(bucketGPR); > > nit: I'd have named this "bucketIsString" Changed. >> Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4645 >> + slowPathCases.append(m_jit.branchIfHeapBigInt(keyGPR)); > > why do we need the branch here? Isn't this guaranteed to be the case since we're the fall through from branchIfNotHeapBigInt No. We tested bucketGPR. This is testing keyGPR. >> Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:4679 >> + slowPathCases.append(m_jit.branchIfHeapBigInt(keyGPR)); > > isn't the second branch proven true by the first? No, this is for keyGPR. The first one is bucketGPR. >> Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:11270 >> + LBasicBlock notStringHeapBigIntCase = m_out.newBlock(); > > nit: I'd name this "notStringNorHeapBigIntCase" Changed. >> Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:11286 >> + ValueFromBlock heapBigIntResult = m_out.anchor(m_out.castToInt32(vmCall(Int64, operationMapHash, weakPointer(globalObject), value))); > > ditto about specializing a call of operationMapHash for HeapBigInt Added. >> Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:11372 >> + m_out.branch(isNotHeapBigInt(key), unsure(continuation), unsure(isHeapBigIntCase)); > > should we use provenType in isNotHeapBigInt here? provenType is added in the landed patch :) >> Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:11375 >> + ValueFromBlock bigIntResult = m_out.anchor(vmCall(Int64, operationNormalizeMapKey, m_vmValue, key)); > > ditto about specializing Added. Reopening to attach new patch. Created attachment 409772 [details]
Patch
Committed r267624: <https://trac.webkit.org/changeset/267624> |