-
-
Notifications
You must be signed in to change notification settings - Fork 413
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
base: main
Are you sure you want to change the base?
Conversation
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`
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4038 +/- ##
==========================================
+ Coverage 47.24% 54.92% +7.67%
==========================================
Files 476 487 +11
Lines 46892 48747 +1855
==========================================
+ Hits 22154 26774 +4620
+ Misses 24738 21973 -2765 ☔ View full report in Codecov by Sentry. |
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 ( 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 |
@raskad in details:
here is tests
|
also you can read the issue where it was accepted to collect the source code(it should slow down parse stage performance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for letting you wait so long for the full review. First of all thank you for the great contribution! Really nice work!
I added some specific comments, but I have one more general one. I would be in favor of Removing all the Option
s for the various SourceText
fields. In principle, everytime we parse, compile and execute code, we must have the source text and a span. I did a quick check an I'm 99% sure the Option
s can be removed in all places.
In addition to the Script
struct, the Module
struct would also need the source text.
In some cases (e.g. the "dummy" use of the Bytecompiler
for syntetic modules) there is really no source text, but there it is also never used. In those cases we can just use the default (empty vec).
Regarding Arbitrary
, I think it should be a manual implementation that is just an empty source text. You can check here for en example of a manual impl:
boa/core/ast/src/expression/literal/mod.rs
Lines 121 to 137 in 517ad50
#[cfg(feature = "arbitrary")] | |
impl<'a> arbitrary::Arbitrary<'a> for Literal { | |
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> { | |
let c = <u8 as arbitrary::Arbitrary<'a>>::arbitrary(u)? % 6; | |
match c { | |
0 => Ok(Self::String(<Sym as arbitrary::Arbitrary>::arbitrary(u)?)), | |
1 => Ok(Self::Num(<f64 as arbitrary::Arbitrary>::arbitrary(u)?)), | |
2 => Ok(Self::Int(<i32 as arbitrary::Arbitrary>::arbitrary(u)?)), | |
3 => Ok(Self::BigInt(Box::new( | |
<BigInt as arbitrary::Arbitrary>::arbitrary(u)?, | |
))), | |
4 => Ok(Self::Bool(<bool as arbitrary::Arbitrary>::arbitrary(u)?)), | |
5 => Ok(Self::Null), | |
_ => unreachable!(), | |
} | |
} | |
} |
If remove |
I was mostly concerned with the code in the bytecompiler being a bit easier to work with. Like you mentioned, with the |
Seems like all done. We don't always have boa/core/engine/src/spanned_source_text.rs Lines 44 to 48 in cbb2d79
In all other places Option is removed.
|
Looks really nice! Thank you for the work! Could you do a rebase, best would be after #4117 is merged, because the CI is broken without that. One very minor nitpick: I would like to rename |
39e71a0
to
782a218
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution. Great stuff. I'd be happy to merge this.
How much progress is this towards errors with backtraces? Haven't looked at it yet, I'm just curious if this would be another step forward or if we would have to essentially rewrite everything when we have nicer errors |
Sorry, I actually don't sure what is needed for backtraced errors. |
If we just need to increasingly add |
This Pull Request closes #3780
In current approach all
SourceText
collected (because mostly a script consist of function codes and classes) andLinearSpan
used to retrieve it when needed (to be fairtoString()
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 checkingtoString()
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)
forcore\ast\src\source.rs::Script
&LinearSpan
, just derive is ok here?