+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

Conversation

leops
Copy link
Contributor

@leops leops commented Sep 23, 2022

Summary

This PR changes the type of diagnostics code / categories from plain strings to the new Category type. I tried to make use of statically checked categories (using the category! macro) as much as possible, and one particular area of interest for these are the analyzer rules:

Since some rules never emit any diagnostic (mainly assist rules such as flipBinExp or inlineVariable) this check needs to happen only for rules that actually end up creating a diagnostic. The solution I came up with is to have the declare_rule! macro emit a new rule_category! macro in the module context that expands to the category for the rule if it is correctly registered (or a compilation error if it's not). This macro is used by lint rules to create diagnostics with the correct category, and most importantly assist rules never use the macro and consequently never cause the compile error to be emitted in the expanded code.

One downside of this approach is that the analyzer infrastructure is no longer responsible for injecting the category corresponding to a rule into the diagnostics it emits, and individual rules could possible emit diagnostics with a different category, but they would still be restricted to existing categories, and this may in fact turn out to be useful to implement syntax rules that would emit diagnostics with the "parse" error category instead of "lint"

Test Plan

I changed a number of error categories to re-use the name they had in Rome JS, this has caused some parser and CLI snapshots to change again. For the rest as I mentioned earlier I used static verification as much as possible, so this guarantees that the categories used in the code are valid if it builds correctly.

@netlify
Copy link

netlify bot commented Sep 23, 2022

Deploy Preview for rometools canceled.

Name Link
🔨 Latest commit b479602
🔍 Latest deploy log https://app.netlify.com/sites/rometools/deploys/633473cc5826ee00081fb924

@leops leops force-pushed the refactor/diagnostics-categories branch from f40c9f2 to 10d3272 Compare September 23, 2022 13:27
@leops leops temporarily deployed to netlify-playground September 23, 2022 13:27 Inactive
@github-actions
Copy link

Parser conformance results on ubuntu-latest

js/262

Test result main count This PR count Difference
Total 45879 45879 0
Passed 44939 44939 0
Failed 940 940 0
Panics 0 0 0
Coverage 97.95% 97.95% 0.00%

jsx/babel

Test result main count This PR count Difference
Total 39 39 0
Passed 36 36 0
Failed 3 3 0
Panics 0 0 0
Coverage 92.31% 92.31% 0.00%

symbols/microsoft

Test result main count This PR count Difference
Total 5946 5946 0
Passed 1621 1621 0
Failed 4325 4325 0
Panics 0 0 0
Coverage 27.26% 27.26% 0.00%

ts/babel

Test result main count This PR count Difference
Total 588 588 0
Passed 519 519 0
Failed 69 69 0
Panics 0 0 0
Coverage 88.27% 88.27% 0.00%

ts/microsoft

Test result main count This PR count Difference
Total 16257 16257 0
Passed 12395 12395 0
Failed 3862 3862 0
Panics 0 0 0
Coverage 76.24% 76.24% 0.00%

@github-actions
Copy link

github-actions bot commented Sep 23, 2022

@leops leops force-pushed the refactor/diagnostics-categories branch from 10d3272 to c41a0d8 Compare September 23, 2022 14:09
@leops leops temporarily deployed to netlify-playground September 23, 2022 14:09 Inactive
@leops leops marked this pull request as ready for review September 23, 2022 14:20
@leops leops requested a review from a team September 23, 2022 14:20
Copy link
Contributor

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

The use of rule_category!() should be documented somewhere, probably here and add its link in the contribution document

Comment on lines 62 to 65
"io/skippedFile",
"io/unhandledFile",
"parse",
"suppressions/unknownGroup",
Copy link
Contributor

@ematipico ematipico Sep 23, 2022

Choose a reason for hiding this comment

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

Is io beginner friendly? (it's also an acronym right?) Would it make sense to call it fileSystem?

Also (sorry I caught this only now), I think args is not beginner friendly. A junior developer might not undestand what it means, it's really technical. To be honest, I also struggle to understand what it means, because there's fileNotFound later... which something related to the file system. I would suggest an alternative but I would need a clarification of the category first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried to reword some of these codes, but I/O errors are not necessarily caused by the filesystem as they can also be related to the domain socket or named pipe used by the daemon process to communicate for instance. So I think we still need a generic internalError/io category when a low-level error happens.

For the args/fileNotFound category it's something I reused from Rome JS along with flags/invalid, but I haven't put much thought into it since at the moment those two are only used in examples and tests to re-implement the equivalent diagnostic from the JS version.

"internalError/panic",
"io/skippedFile",
"io/unhandledFile",
"parse",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the parse category shared between all parsers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The parse category is highly generic and is shared between all syntax error diagnostics in the lexer, parser and potentially future rule in the syntax category in the analyzer

@ematipico ematipico added the A-Diagnostic Area: errors and diagnostics label Sep 26, 2022
@leops leops force-pushed the refactor/diagnostics-categories branch from c41a0d8 to 059453e Compare September 27, 2022 10:12
@leops leops temporarily deployed to netlify-playground September 27, 2022 10:12 Inactive
@calibre-analytics
Copy link

calibre-analytics bot commented Sep 27, 2022

Comparing refactor(rome_diagnostics): refactor diagnostics to use static categories Snapshot #6 to median since last deploy of rome.tools.

LCP? CLS? TBT?
Overall
Median across all pages and test profiles
2.01s
from 563ms
0.0
no change
211ms
from 44ms
Chrome Desktop
Chrome Desktop • Cable
2.01s
from 592ms
0.0
no change
384ms
from 238ms
iPhone, 4G LTE
iPhone 12 • 4G LTE
1.01s
from 220ms
0.0
no change
0ms
no change
Motorola Moto G Power, 3G connection
Motorola Moto G Power • Regular 3G
13.7s
from 563ms
0.0
no change
211ms
from 44ms

1 page tested

 Home

Browser previews

Chrome Desktop iPhone, 4G LTE Motorola Moto G Power, 3G connection
Chrome Desktop iPhone, 4G LTE Motorola Moto G Power, 3G connection

Most significant changes

Value Budget
JS Parse & Compile
Motorola Moto G Power, 3G connection
1.81s
from 29ms
Total JavaScript Size in Bytes
Chrome Desktop
4.29 MB
from 86.8 KB
Total JavaScript Size in Bytes
iPhone, 4G LTE
4.29 MB
from 86.8 KB
Total JavaScript Size in Bytes
Motorola Moto G Power, 3G connection
4.29 MB
from 86.8 KB
JS Parse & Compile
iPhone, 4G LTE
381ms
from 8ms

28 other significant changes: JS Parse & Compile on Chrome Desktop, First Contentful Paint on Motorola Moto G Power, 3G connection, Largest Contentful Paint on Motorola Moto G Power, 3G connection, Speed Index on Motorola Moto G Power, 3G connection, Total Page Size in Bytes on Chrome Desktop, Total Page Size in Bytes on iPhone, 4G LTE, Total Page Size in Bytes on Motorola Moto G Power, 3G connection, Number of Requests on Motorola Moto G Power, 3G connection, Number of Requests on Chrome Desktop, Number of Requests on iPhone, 4G LTE, Time to Interactive on Motorola Moto G Power, 3G connection, First Contentful Paint on Chrome Desktop, First Contentful Paint on iPhone, 4G LTE, Time to Interactive on Chrome Desktop, Total Blocking Time on Motorola Moto G Power, 3G connection, Speed Index on iPhone, 4G LTE, Speed Index on Chrome Desktop, Largest Contentful Paint on iPhone, 4G LTE, Time to Interactive on iPhone, 4G LTE, Largest Contentful Paint on Chrome Desktop, Total Image Size in Bytes on Chrome Desktop, Total Image Size in Bytes on iPhone, 4G LTE, Total Image Size in Bytes on Motorola Moto G Power, 3G connection, Total HTML Size in Bytes on Chrome Desktop, Total HTML Size in Bytes on iPhone, 4G LTE, Total HTML Size in Bytes on Motorola Moto G Power, 3G connection, Lighthouse Performance Score on Motorola Moto G Power, 3G connection, Lighthouse Performance Score on Chrome Desktop

Calibre: Site dashboard | View this PR | Edit settings | View documentation

@leops leops force-pushed the refactor/diagnostics-categories branch from 059453e to 320d33b Compare September 28, 2022 16:04
@leops leops temporarily deployed to netlify-playground September 28, 2022 16:04 Inactive
@leops leops force-pushed the refactor/diagnostics-categories branch from 320d33b to b479602 Compare September 28, 2022 16:18
@leops leops temporarily deployed to netlify-playground September 28, 2022 16:18 Inactive
@leops leops merged commit 6ad6ea9 into main Sep 28, 2022
@leops leops deleted the refactor/diagnostics-categories branch September 28, 2022 16:30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

A-Diagnostic Area: errors and diagnostics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载