Bug 193869

Summary: [BigInt] Support constant fold of BigInts on DFG
Product: WebKit Reporter: Caio Lima <ticaiolima>
Component: JavaScriptCoreAssignee: Caio Lima <ticaiolima>
Status: NEW ---    
Severity: Normal CC: saam
Priority: P2    
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 186173    
Attachments:
Description Flags
WIP - Patch none

Description Caio Lima 2019-01-26 10:14:01 PST
...
Comment 1 Caio Lima 2019-01-26 10:28:14 PST
What I have in mind to make it possible is to follow what we do with Strings right now. The idea is to use LazyJSValue, since we can only allocate heap objects after compilation is finished. In the case of LazyJaValues of BigInts, the plan is to record following information:

1. lhs and rhs operands;
2. Type of operation;

To have a robust implementation and fold constants properly, lhs and rhs should be LazyJSValues that also can be computed on further steps.
We need to change JSBigInt API to support arithmetic operations that can't fail due OOM.
Also, we need to guarantee when constant fold happens that we won't overflow BigInt::maxSize.
Comment 2 Caio Lima 2019-01-26 10:33:08 PST
Created attachment 360242 [details]
WIP - Patch

Here is a very simple version to illustrate what I have in mind now. I'm creating LazyBigIntValue to store required information to calculate BigInts properly. A LazyJSValue(NewBigInt) can have KnowValue or other LazyBigIntValue as operands. This enables us fold cascaded constants. The Folding is being done during Strengthreduction, following String rules as well.
Comment 3 Caio Lima 2019-01-28 05:27:03 PST
(In reply to Caio Lima from comment #1)
> What I have in mind to make it possible is to follow what we do with Strings
> right now. The idea is to use LazyJSValue, since we can only allocate heap
> objects after compilation is finished. In the case of LazyJaValues of
> BigInts, the plan is to record following information:
> 
> 1. lhs and rhs operands;
> 2. Type of operation;
> 
> To have a robust implementation and fold constants properly, lhs and rhs
> should be LazyJSValues that also can be computed on further steps.
> We need to change JSBigInt API to support arithmetic operations that can't
> fail due OOM.
> Also, we need to guarantee when constant fold happens that we won't overflow
> BigInt::maxSize.

I think we also can have a special case when BigInts are proven to be 64-bit.
Comment 4 Saam Barati 2019-01-31 00:04:22 PST
Sounds good to me