This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [JS] fix an assertion failure caused by shrinking sources.
ClosedPublic

Authored by mprobst on Jun 7 2016, 4:56 PM.

Details

Summary

The JavaScript import sorter has a corner condition that can cause the overall
source text length to shrink. This change circumvents the issue by appending
trailing space in the line after the import blocks to match at least the
previous source code length.

This needs a better long term fix, but this fixes the immediate issue.

Diff Detail

Repository
rL LLVM

Event Timeline

mprobst updated this revision to Diff 59975.Jun 7 2016, 4:56 PM
mprobst retitled this revision from to clang-format: [JS] fix an assertion failure caused by shrinking sources..
mprobst updated this object.
mprobst added reviewers: alexeagle, djasper.
djasper accepted this revision.Jun 7 2016, 9:45 PM
djasper edited edge metadata.

I think fixing the ranges should actually not be too hard. I'll take a look soon.

lib/Format/SortJavaScriptImports.cpp
182 ↗(On Diff #59975)

nit: We call it FIXME.

This revision is now accepted and ready to land.Jun 7 2016, 9:45 PM
This revision was automatically updated to reflect the committed changes.

I think fixing the ranges should actually not be too hard. I'll take a look soon.

Yeah, I don't think it's particularly hard, but I wasn't clear on where it'd be done best, and which APIs are public. I think it might make sense to extract a "sort imports, apply the changes, update these ranges, return the code" function altogether, but not sure. Currently we have the tests and the main method follow different code paths, which seems suboptimal.

I think fixing the ranges should actually not be too hard. I'll take a look soon.

Yeah, I don't think it's particularly hard, but I wasn't clear on where it'd be done best, and which APIs are public. I think it might make sense to extract a "sort imports, apply the changes, update these ranges, return the code" function altogether, but not sure. Currently we have the tests and the main method follow different code paths, which seems suboptimal.