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

Split up the type checker file into multiple files #40937

Closed
5 tasks done
RDambrosio016 opened this issue Oct 4, 2020 · 7 comments
Closed
5 tasks done

Split up the type checker file into multiple files #40937

RDambrosio016 opened this issue Oct 4, 2020 · 7 comments
Labels
Duplicate An existing issue was already created

Comments

@RDambrosio016
Copy link

Search Terms

Split, TypeChecker, Checker

Suggestion

I would love to see the type checker file be split up into multiple files, as it is it is unreadable, and understanding what is going on is nearly impossible.

Use Cases

The typescript type checker is a very interesting tool, however, it is nearly unreadable, because:

  • it is 40281 lines in total
  • it cannot be looked at in github
  • it lags vsc (for me at least)

I would love to learn more about it, and eventually make a custom implementation for a tool i am making, but the fact that the checker is a single file makes it nearly impossible to understand.

Examples

Type checking consists of distinct goals and steps, and it is possible to split up those steps, for example, splitting up checking functions, loops, binary expressions, unary expressions, generics, scope analysis, etc.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

This is purely a formatting feature, it has zero impact on the end user.

Relevant issues

#17861 seems to be somewhat relevant and it mentions this:

For better typescript future I think checker.ts should be separated into multiple files/classes, and this is the first step. This code is not merge ready. Of course we should think about methods to be provided to public api, and may be unsafe access for people who do really complicated transformations.

but it is not further discussed

@andrewbranch
Copy link
Member

andrewbranch commented Oct 6, 2020

The main reason we haven't done this is performance, as shown in #17861. I felt this way when I first joined the team, but my view has softened as I’ve learned to approach the checker differently. I still think certain parts, like the node builder, would be better suited in their own module, but I would probably not split up the checking of different kinds of syntactic constructs, as suggested. Performance in VS Code isn’t a huge problem for me, but I run a pretty powerful computer, and I would love if we could view the file on GitHub. But of course, we cannot reduce the amount of code or its conceptual complexity by splitting it into different files, so I don’t believe such a change would make it significantly easier to understand. In my opinion, the only way to begin to understand the checker is by debugging. While fairly high-level and not specific to the checker, I wrote a blog post on some debugging tips specific to this codebase. I would also suggest @orta’s typescript-notes and @sandersn’s manual as good learning resources that you won’t find in official documentation. Aside from that, you can look at the good first issue and help wanted labels and learn by contributing to the compiler. Depending on your level of familiarity with TypeScript and compilers in general, you may find some that can ease you into understanding the checker bit by bit. For housekeeping purposes, I’m going to call this a duplicate of #17861.

@andrewbranch andrewbranch added the Duplicate An existing issue was already created label Oct 6, 2020
@RDambrosio016
Copy link
Author

I see, my main issue is just finding things in the type checker, like if i wanted to find the entry point or where statements are checked its pretty hard. I would love a dev guide which explains some of the concepts around it and how it works. I have some typechecking experience but tsc seems to have some very specific things.

@andrewbranch
Copy link
Member

The syntactic entrypoints typically have predictable names in the format of check{SyntaxKind}. checkSourceElementWorker is the one that fans out into all those syntax-specific ones. In VS Code I frequently use ⌘⇧O (go to symbol) to find those.

@RDambrosio016
Copy link
Author

Yeah it works for expressions but checkStmt and checkStatement do not seem to work, which is why i am confused 😄

@andrewbranch
Copy link
Member

🤔

image

@RDambrosio016
Copy link
Author

Haha i was checking for checkStmt alone

@RDambrosio016
Copy link
Author

Ill go ahead and close this as it seems this wont happen soon because of perf reasons 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants