Safety for system running parallel threads of Prettier #1392
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In this comment I was made aware that prettier can be run asynchronously.
When parsing, we recollect data from our AST tree, that if run in parallel jobs, will generate errors in formatting.
Right now our parsing is not
asyncso there shouldn't be any issue. but if at any pointslangorprettierdecide that their API should be asynchronous, we must address this.This solution changes the signature of the constructor of nodes, making it necessary the passing of Prettier's
optionsobject which is unique per job.The important changes happen in
src/slang-nodes/SlangNode.ts(where we collect the data),src/slangSolidityParser.ts(where we used to clear the data for the next run), andsrc/types.d.ts(where we define the type that will contain the data). Everywhere else the changes are just to modify the constructor signature and initiate each new node with theoptionsobject.I didn't want to complicate the signatures of the nodes'
constructorand already half of the nodes receive the Prettieroptionsobject. Using an_prettier_solidity_to prepend the names of the attributes seemed like a good enough solution but I'm willing to revisit this if we decide is safer in another way.