-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
[Merged by Bors] - Implement Classes #1976
Conversation
Too many passed tests for github comments... VM implementation
Fixed tests (6766):Broken tests (71):
|
Codecov Report
@@ Coverage Diff @@
## main #1976 +/- ##
==========================================
- Coverage 45.90% 43.87% -2.04%
==========================================
Files 206 211 +5
Lines 17148 18662 +1514
==========================================
+ Hits 7872 8188 +316
- Misses 9276 10474 +1198
Continue to review full report at Codecov.
|
Benchmark for aeb6891Click to view benchmark
|
ed9b9ae
to
4ee3490
Compare
Benchmark for 9ec374eClick to view benchmark
|
Benchmark for 7ac4292Click to view benchmark
|
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.
Great work!! It looks very good. I have stuff to review, but I already have some comments.
Benchmark for 43ff007Click to view benchmark
|
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.
Looks very good from my side :) I added some improvements that could be done. Especially in the parser.
The bytecompiler
module is getting very out of hand... but not related to the PR. Almost 3k lines... We really need #1808 and #1608 to be implemented asap, since this is a huge issue for being able to contribute to the compiler.
It would be good to document how the idea behind each opcode is thought of. The order of the operands in the stack, how is the implementation... But maybe can be done in PRs to fix those two issues.
let _timer = Profiler::global().start_event("ClassExpression", "Parsing"); | ||
let strict = cursor.strict_mode(); | ||
cursor.set_strict_mode(true); | ||
|
||
let token = cursor.peek(0, interner)?.ok_or(ParseError::AbruptEnd)?; |
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.
Looking at the spec, the first token of this parser should be the class
keyword, right? I guess this should "expect" that keyword.
I guess it's not here because the parser that calls it consumes it before calling it, but I think that should be changed.
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.
Yeah that is exactly it. I will open a issue for this, because it will mean replacing next
with peek
in multiple places and as a result multiple parsers need to be changed. We have this behaviour in lot's of parsers, so doing this in a dedicated issue seems like the best idea.
TokenKind::Keyword(Keyword::Class) => { | ||
ClassExpression::new(self.name, false, false).parse(cursor, interner) | ||
} |
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.
I guess the "TODO" a bit higher is the issue. I guess this could be fixed in a future PR.
{ | ||
type Output = Class; | ||
|
||
fn parse( |
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.
This parser is way too big, and it's not clear how to follow the spec. It seems that this parser should be pretty simple: just check if the extends
keyword exists, and if so, call the ClassHeritage
parser, and then, expect the {
, call the ClassBody
parser, then expect the }
.
Then, we could have all the different parsers defined (well, ClassBody
would be a type alias for ClassElementList
, for example). Dividing this parser into multiple smaller parsers should make things more maintainable (and reusable, if any of them gets referenced anywhere else in the future).
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.
I refactored the parser to match the spec better. I think it got a bit better for sure. Some syntax error handling is now consolidated instead of spread throughout hundreds of lines.
The ClassElement
parser is still ~700 lines long. We maybe can get the line count down with some helpers, but I think it is mostly the natural complexity of the parser. I guess this is probably one of the most complex parsers in spec, because we have fields, methods of all kinds, all of that in static, constructors, static blocks and all of that with private identifiers.
Benchmark for 5c84d48Click to view benchmark
|
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.
Great work @raskad !
I did a light review of the PR, I intend to do a more in depth review :)
f163dc8
to
c71bffe
Compare
Rebased |
Benchmark for 66bc9d5Click to view benchmark
|
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.
Looks good from my side :)
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.
This looks very good now! LGTM!
bors r+ |
This Pull Request fixes/closes #337. It changes the following: - Implement class declaration parsing. - Implement class expression parsing. - Implement class execution. There are still some features like `super` missing and there are some early errors that are not implemented yet. But I think it makes sense to merge this, as we can branch out the missing features from here.
Pull request successfully merged into main. Build succeeded: |
This Pull Request fixes/closes #337. It changes the following: - Implement class declaration parsing. - Implement class expression parsing. - Implement class execution. There are still some features like `super` missing and there are some early errors that are not implemented yet. But I think it makes sense to merge this, as we can branch out the missing features from here.
This Pull Request fixes/closes #337.
It changes the following:
There are still some features like
super
missing and there are some early errors that are not implemented yet. But I think it makes sense to merge this, as we can branch out the missing features from here.