Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Using values of Smtml #128

Merged
merged 30 commits into from
Jun 25, 2024
Merged

Refactor: Using values of Smtml #128

merged 30 commits into from
Jun 25, 2024

Conversation

julianayang777
Copy link
Collaborator

Changes

  1. Operators exp, random, typeof and tuple related operators were removed from syntax and became external functions.
  2. The values used by ECMA-SL (Val.ml) were changed to the values of Smtml. In the next code snippet, you can see how it was converted:
type t =
  | Null (* -> App "null" [] *)
  | Void (* -> App "void" [] *)
  | Int of int (* -> Int *)
  | Flt of (float[@unboxed]) (* -> Real *)
  | Str of string  (* -> Str *)
  | Bool of bool  (* -> True | False *)
  | Symbol of string (* -> App "symbol" [Str s] *)
  | Loc of Lo. c.t (* -> App "loc" [Int l] *)
  | Arr of t array (* int (pointer to array) *)
  | List of t list (* -> List l *)
  | Tuple of t list (* -> List l *)
  | Byte of int (* Int *)
  | Type of Type.t  
    (* -> App t [] *) 
    (* t := "NullType" | "IntType"    | "RealType" | "StrType" 
          | "BoolType" | "SymbolType" | "LocType"  | "ListType" 
          | "TupleType"| "CurryType" *)
  | Curry of string * t list  (* -> App fn fvs *)
  1. When converting bitwise operators, I already take into consideration issue Bitwise operations should not be defined over floats #93. That means that the bitwise operators is already defined over integers.
  2. I moved the custom pp function that was defined in Val.ml to EExpr.ml so that I could delete Val.ml. (But this might be the best approach😕).

Concrete Interpreter

In the concrete execution, all the tests passed using the command dune runtest. However, for the test262 suite, some tests are still failing. To fix it, we might change the ecmaref. (for instance, some of the tests failed due to change 3)

Symbolic Interpreter

In the symbolic execution, the tests are not passing, which might be due to the way we have defined the symbol undefined. And the way of handling error in symbolic_value.ml can be improved, because for now I have just put failwith.

@julianayang777 julianayang777 requested review from filipeom and andreffnascimento and removed request for filipeom and andreffnascimento June 19, 2024 13:19
@julianayang777
Copy link
Collaborator Author

cc @andreffnascimento

Copy link
Member

@filipeom filipeom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen everything. But the more I see. The more I think we should use Smtml.Expr.Ptr for locations. I'm going to fix Ptr so that we can apply it here more easily.

I'll review more during the day

ECMA-SL/semantics/core/concrete/eval_op.ml Outdated Show resolved Hide resolved
julianayang777 added a commit that referenced this pull request Jun 22, 2024
Copy link
Member

@filipeom filipeom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More reviews, could you also change the smtml pin to commit ff3c34ad926f7b4329fe7412fe31d270c7b2220b?

ECMA-SL/semantics/core/functorial/symbolic_extern.ml Outdated Show resolved Hide resolved
ECMA-SL/semantics/core/functorial/symbolic_extern.ml Outdated Show resolved Hide resolved
ECMA-SL/semantics/core/functorial/symbolic_extern.ml Outdated Show resolved Hide resolved
ECMA-SL/semantics/core/functorial/symbolic_extern.ml Outdated Show resolved Hide resolved
ECMA-SL/semantics/core/functorial/symbolic_extern.ml Outdated Show resolved Hide resolved

let equal (e1 : value) (e2 : value) : bool = E.equal e1 e2 [@@inline]
let hash (e : value) = E.hash e [@@inline]
let compare (e1 : value) (e2 : value) = compare (hash e1) (hash e2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compare should probably be defined in Smtml and we just use that

ECMA-SL/semantics/core/functorial/symbolic_value.ml Outdated Show resolved Hide resolved
ECMA-SL/semantics/core/functorial/symbolic_value.ml Outdated Show resolved Hide resolved
ECMA-SL/semantics/core/functorial/symbolic_value.ml Outdated Show resolved Hide resolved
ECMA-SL/semantics/core/parser/parser.mly Outdated Show resolved Hide resolved
julianayang777 added a commit that referenced this pull request Jun 24, 2024
@@ -327,11 +327,11 @@ function NumberPrototypeToFixedAlt(global, this, strict, items) {
z := "";
counter := 0;
while (!(counter <= (f - k))) {
z := s_concat(z, "0");
z := s_concat[z, "0"];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s_concat receives a list as parameter?

Suggested change
z := s_concat[z, "0"];
z := s_concat [z, "0"];

I know for parsing it's all the same, but adding a space would make this look better

Copy link
Collaborator Author

@julianayang777 julianayang777 Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s_concat receives a list as parameter?

Yes, I think s_concat already received a list as parameter before the change.
Maybe, in this case it was receiving a tuple instead of a list? Because I didn't change the semantics of the s_concat, it is still an unary operator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it might have been receiving a tuple. I don't know how this worked. But it was on ecmaref5 which supposedly we're not going to maintain?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it might have been receiving a tuple. I don't know how this worked. But it was on ecmaref5 which supposedly we're not going to maintain?

The idea is to stop maintaining the ECMARef5, yes

Copy link
Member

@filipeom filipeom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you run dune fmt just to verify that everything is well formatted? Otherwise, I think I'm done.

@filipeom
Copy link
Member

filipeom commented Jun 24, 2024

@andreffnascimento This will probably break some tests for test262. But I'd rather not wait long to merge this as it is a monster PR 😅 and I want to catch the bugs earlier rather than later. If you can also just see if there is anything you'd like to change before we merge.

@julianayang777 Could you rebase on main and add the description of changes you provided here to CHANGES.md?

@julianayang777
Copy link
Collaborator Author

Can you run dune fmt just to verify that everything is well formatted? Otherwise, I think I'm done.

Ok, maybe it's better to do it after André has done the review.

Copy link
Contributor

@andreffnascimento andreffnascimento left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm done with my review. I'm going to approve this, so that you can merge this soon, but first take I look at my comments/proposals. I'm not going to merge #129 until this is done to avoid introducing extra merge conflicts. Also, I can run the entire Test262 to see how we are doing, but only after we are passing the CI. Btw, here is a link with the previous test results

ECMA-SL/semantics/core/concrete/eval_op.ml Outdated Show resolved Hide resolved
ECMA-SL/syntax/extended/eExpr.ml Outdated Show resolved Hide resolved
Comment on lines +36 to +39
if (el = "R") { return "Reference" }
elif (el = "C") { return "Completion" }
elif (el = "P") { return "PropertyIdentifier" }
else { return "List" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filipeom how sure are we that this is not going to break?? 😅
If we evaluate a list where the first element matches one of these cases, we will not get the correct type right? This used to be fine since tuples were only used internally, never in the JS AST, now I'm not sure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filipeom how sure are we that this is not going to break?? 😅

I'm confident it will break at some point 😅

If we evaluate a list where the first element matches one of these cases, we will not get the correct type right? This used to be fine since tuples were only used internally, never in the JS AST, now I'm not sure

Exactly. That's why I believe the completions and objects we return in lists should be something else. Since they are never extended, we could use esl arrays, which are simply OCaml arrays. Besides allowing O(1) read/write operations, they would also be more memory efficient. We could use this efficiency to add metadata in the initial element of the array, such as a unique location to a global object used only when building these completion arrays.

For example, in this function, we would know exactly what we have instead of hoping the list is as expected. I asked Juliana to open an issue about this here: #132. I think we can implement this without compromising the similarity of ecmaref to the standard.

Comment on lines +358 to +370
| t = dtype_target; { Value.App (`Op t, []) }

let dtype_target :=
| DTYPE_NULL; { Type.NullType }
| DTYPE_INT; { Type.IntType }
| DTYPE_FLT; { Type.FltType }
| DTYPE_STR; { Type.StrType }
| DTYPE_BOOL; { Type.BoolType }
| DTYPE_SYMBOL; { Type.SymbolType }
| DTYPE_LOC; { Type.LocType }
| DTYPE_LIST; { Type.ListType }
| DTYPE_TUPLE; { Type.TupleType }
| DTYPE_CURRY; { Type.CurryType }
| DTYPE_NULL; { "NullType" }
| DTYPE_INT; { "IntType" }
| DTYPE_FLT; { "FltType" }
| DTYPE_STR; { "StrType" }
| DTYPE_BOOL; { "BoolType" }
| DTYPE_SYMBOL; { "SymbolType" }
| DTYPE_LOC; { "LocType" }
| DTYPE_LIST; { "ListType" }
| DTYPE_TUPLE; { "TupleType" }
| DTYPE_CURRY; { "CurryType" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a very strong opinion on this, so we can leave it as it is (specially because this may break things / slow things down). But shouldn't these types be stored as: Value.App (`Op "type", ["null"]. I mean, it looks more consistent, but I'm not sure it is worth it. Opinions @filipeom @julianayang777

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it looks more consistent, but yes, in both cases we will break things.

Copy link
Member

@filipeom filipeom Jun 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it looks more consistent. It also might help in pattern matching situations? For the solver it's all the same. Value applications are unitary so the strings in the list will be concatenated with the string in Op to make an uninterpreted symbol.

So we can probably do it and optimize later

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will not change now because I am not sure if it will influence my other branch merge. However, I will make the change in the next PR for branch merge.

@@ -327,11 +327,11 @@ function NumberPrototypeToFixedAlt(global, this, strict, items) {
z := "";
counter := 0;
while (!(counter <= (f - k))) {
z := s_concat(z, "0");
z := s_concat[z, "0"];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, it might have been receiving a tuple. I don't know how this worked. But it was on ecmaref5 which supposedly we're not going to maintain?

The idea is to stop maintaining the ECMARef5, yes

@filipeom
Copy link
Member

I can run the entire Test262 to see how we are doing, but only after we are passing the CI.

@julianayang777 I'll just make dune runtest ignore symbolic tests for now. Its better to have the CI catch other failing tests and not be polluted by se related failures that are know to not be working

filipeom added 3 commits June 25, 2024 15:44
This will reduce the number of rules dune
produces from 750k to 10k. Will not make compilation
faster but it does make dune more responsive.
@andreffnascimento
Copy link
Contributor

Can we merge this?

@julianayang777
Copy link
Collaborator Author

Can we merge this?

For me, yes

@filipeom filipeom merged commit 3492447 into main Jun 25, 2024
2 checks passed
filipeom pushed a commit that referenced this pull request Jun 25, 2024
filipeom pushed a commit that referenced this pull request Jun 25, 2024
filipeom pushed a commit that referenced this pull request Jun 25, 2024
@filipeom filipeom deleted the refactor-symbval branch June 25, 2024 16:41
filipeom pushed a commit that referenced this pull request Dec 27, 2024
filipeom pushed a commit that referenced this pull request Dec 27, 2024
filipeom pushed a commit that referenced this pull request Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants