-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Update to dprint 0.18.0 and latest swc #5509
Update to dprint 0.18.0 and latest swc #5509
Conversation
@@ -69,6 +69,21 @@ impl Into<TsTypeDef> for &TsLitType { | |||
boolean: None, | |||
}, | |||
), | |||
TsLit::Tpl(tpl) => { | |||
// A template literal in a type is not allowed to have | |||
// expressions, so there will only be one quasi. |
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'm not sure if quasi is the singular form of quasis... I'm not so familiar with the word quasis other than seeing it in the babel ast and in swc.
|
||
let param_def = match param { | ||
Pat(pat) => pat_to_param_def(pat), | ||
Param(param) => pat_to_param_def(¶m.pat), |
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 changed to support decorators on parameters.
My test suite in dprint had lots of failing tests after this change because a lot of code was looking for a Pat
instead of Param
, so hopefully my tests suite is thorough enough... still want to eventually add many repos to format in a test suite to find regressions.
@@ -25,7 +25,7 @@ pub fn function_to_function_def( | |||
let mut params = vec![]; | |||
|
|||
for param in &function.params { | |||
let param_def = pat_to_param_def(param); | |||
let param_def = pat_to_param_def(¶m.pat); |
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.
+1 for the ParamDef and similar abstractions 🙂
I have a problem with this which is that it causes stack overflows in debug builds (windows). To reproduce:
Edit: It seems that this is actually happing with the swc 0.21.10: https://gist.github.com/piscisaureus/ae0d8a287d0a74ab80c459265c24cfb9#file-stack_overflow_swc-0-21-10-txt Also with swc 0.22.0: https://gist.github.com/piscisaureus/ae0d8a287d0a74ab80c459265c24cfb9#file-stack_overflow_swc-0-22-0-txt |
@piscisaureus I have the same problem on Windows in debug builds. This issue is probably related, but in the case you mentioned it starts parsing with more in the stack: swc-project/swc#716 |
SWC still fills pretty much the entire stack (925kb out of 1mb) though...
|
Wow, seems a little excessive... it's such a small file too. Perhaps @kdy1 would know. I just tried profiling myself in visual studio, but it keeps failing with a non-helpful error message. |
I made a list of all the stack frames ordered by size. Maybe it'll help identify the cause of the issue. https://gist.github.com/piscisaureus/ae0d8a287d0a74ab80c459265c24cfb9#file-stack_frames_by_size-txt |
@piscisaureus I started investigating it. Thank you for the details. |
The issue will be fixed by swc-project/swc#776. @piscisaureus Btw, how can I get a stack usage report? |
Well... IDK what the right way is... What I did is debug the failing test with vscode + lldb plugin (vadimcn.vscode-lldb). Then when the program hits the stack overflow, I enter this in the debugger console:
Followed by:
That produces a list with stack frames prefixed with their stack pointer. let prev_sp;
let lines = require("fs")
.readFileSync("stack.txt", "utf8")
.split(/\r?\n/)
.map(l => l.replace(/^[\* ]+/, ""))
.map(l => /^0x([0-9a-zA-Z]+) (.*)$/.exec(l))
.filter(Boolean)
.map(([, sp, rest]) => {
sp = parseInt(sp, 16);
let delta = sp - (prev_sp ?? sp);
prev_sp = sp;
return `+${String(delta).padStart(7)} ${rest}`;
})
.sort()
.reverse();
console.log(lines.join("\n")); So ... it's a bit of work, and there might very well be an easier way that I don't know about. |
@piscisaureus Wow, thanks! |
@kdy1 I just upgraded and unfortunately the stack still overflows, but it's good to know we at least fixed the issue with the diagnostic. I got the output of the bundle text that's failing to parse here: https://gist.github.com/dsherret/6d126bb543501894bf017dd58d5dc325 |
@dsherret Well, I forgot publishing swc_common. |
@kdy1 that was it! I didn't notice the change was in swc_common. Works perfectly now. Thanks! 🙂 |
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.
Testing locally, I can also confirm that the the stack overflow has been fixed. |
Closes #5180.
Also fixes swc parsing and formatting for template literals in types (ex.
export type Permission = `test`;
).