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

SourceText collection & toString() for fns and methods #4038

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Nikita-str
Copy link
Contributor

This Pull Request closes #3780

In current approach all SourceText collected (because mostly a script consist of function codes and classes) and LinearSpan used to retrieve it when needed (to be fair toString() not often called); Gc::<SourceText> used for storage and therefore it can be deallocated only when we have access to no function from a source anymore.

It actually solve some tests from test262, but there is implementation for checking toString() correctness that take any [native code] as correct, without regard to whether it should accept in concrete case or not (assertToStringOrNativeFunction).

Also I don't sure about derive(arbitrary::Arbitrary) for core\ast\src\source.rs::Script & LinearSpan, just derive is ok here?

TODO: find out is `derive(arbitrary::Arbitrary)` in `core\ast\src\source.rs::Script` correct?
TODO: also find out correctness of `derive(arbitrary::Arbitrary)` for `LinearSpan`, `LinearPosition`
Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 81.19469% with 85 lines in your changes missing coverage. Please review.

Project coverage is 53.68%. Comparing base (6ddc2b4) to head (f000cfa).
Report is 287 commits behind head on main.

Files with missing lines Patch % Lines
core/parser/src/parser/statement/if_stm/mod.rs 0.00% 15 Missing ⚠️
core/engine/src/bytecompiler/mod.rs 56.66% 13 Missing ⚠️
core/ast/src/source_text.rs 73.91% 6 Missing ⚠️
core/parser/src/lexer/identifier.rs 16.66% 5 Missing ⚠️
.../statement/declaration/hoistable/class_decl/mod.rs 64.28% 5 Missing ⚠️
core/engine/src/spanned_source_text.rs 66.66% 4 Missing ⚠️
core/parser/src/lexer/mod.rs 91.11% 4 Missing ⚠️
core/ast/src/position.rs 93.47% 3 Missing ⚠️
core/parser/src/lexer/private_identifier.rs 50.00% 3 Missing ⚠️
...rser/expression/assignment/async_arrow_function.rs 75.00% 2 Missing ⚠️
... and 21 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4038      +/-   ##
==========================================
+ Coverage   47.24%   53.68%   +6.43%     
==========================================
  Files         476      485       +9     
  Lines       46892    47270     +378     
==========================================
+ Hits        22154    25376    +3222     
+ Misses      24738    21894    -2844     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@raskad
Copy link
Member

raskad commented Nov 15, 2024

I have not done an in depth review yet, just an initial question. As far as I see, the positions you used for the function start and end (LinearSpan and LinearPosition) only contain the start and end line of the function, correct?

I think that would not work in cases where other stuff is in the same line, e.g.:

let a = 1; function f() {return a + 1}; let b = 3;

In this case f.toString() should only be function f() {return a + 1} but it would return the complete line, right?

@Nikita-str
Copy link
Contributor Author

@raskad
No, it contains linear position, in source code, not line. It is position(and span) in representation of source code as ~vector of code points.
so f.toString() will return function f() {return a + 1}.

in details:

let a = 1; function f() {return a + 1}; let b = 3;
//         ↑                         ↑ 
//     span.start                span.end

here is tests
and in particular it tests that:

        ia1 = (b) => b * 2    ;
        // \\ // \\ // \\ // \\ // \\ // \\ // \\
        A    =    ia1 . toString(    );

A will be exactly (b) => b * 2

@Nikita-str
Copy link
Contributor Author

also you can read the issue where it was accepted to collect the source code(it should slow down parse stage performance)

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.

Function.prototyp.toString only returns a fixed [native code] string
2 participants