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

Simplify for loops in fourslash.ts #11894

Merged
2 commits merged into from
Oct 27, 2016
Merged

Simplify for loops in fourslash.ts #11894

2 commits merged into from
Oct 27, 2016

Conversation

ghost
Copy link

@ghost ghost commented Oct 27, 2016

No description provided.

@@ -1273,8 +1252,8 @@ namespace FourSlash {
if (emitOutput.emitSkipped) {
resultString += "Diagnostics:" + Harness.IO.newLine();
const diagnostics = ts.getPreEmitDiagnostics(this.languageService.getProgram());
for (let i = 0, n = diagnostics.length; i < n; i++) {
resultString += " " + diagnostics[0].messageText + Harness.IO.newLine();
Copy link
Author

Choose a reason for hiding this comment

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

Assuming this should have been diagnostics[i] before.

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

One name change request and I'm not sure whether we're supposed to be using ES5 map.

@@ -124,6 +124,13 @@ namespace ts {
return undefined;
}

export function zip<T, U>(arrayA: T[], arrayB: U[], callback: (a: T, b: U, index: number) => void): void {
Copy link
Member

Choose a reason for hiding this comment

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

lodash and ramda call this zipWith, and have zip with the type (t: T[], u: U[]) => [T,U][] (as do underscore, F#, Python and Haskell). I'd call it zipWith


this.raiseError("Member list is not empty at Caret: " + errorMsg);

this.raiseError(`Member list is not empty at Caret:\nMember List contains: ${stringify(members.entries.map(e => e.name))}`);
Copy link
Member

Choose a reason for hiding this comment

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

are we using ES5's Array.map now?


this.raiseError("Completion list is not empty at caret at position " + this.activeFile.fileName + " " + this.currentCaretPosition + errorMsg);
this.raiseError(`Completion list is not empty at caret at position ${this.activeFile.fileName} ${this.currentCaretPosition}\n` +
`Completion List contains: ${stringify(completions.entries.map(e => e.name))}`);
Copy link
Member

Choose a reason for hiding this comment

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

same here. Are we using Array.map now?

Copy link
Member

Choose a reason for hiding this comment

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

I think it should be fine since fourslash only runs when testing the compiler, not when actually compiling.

Copy link
Author

Choose a reason for hiding this comment

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

We can use Array.map now. We haven't been ES3-compatible for a while.

@ghost ghost merged commit aad663c into master Oct 27, 2016
@ghost ghost deleted the for_loops branch October 27, 2016 19:22
@mihailik
Copy link
Contributor

mihailik commented Nov 2, 2016

Majority of changes replace for with zip with comparable LOC, slightly worse readability, potentially worse performance (due to closure allocations on heap).

It would make sense to run perf comparisons on various platforms — this change might be suboptimal for the reasons above.

@ghost
Copy link
Author

ghost commented Nov 2, 2016

This is test code -- it won't affect the time running the typescript compiler or services.

@mihailik
Copy link
Contributor

mihailik commented Nov 2, 2016

Tests take a considerable time to run too.
And given that complexity didn't improve noticeably (arguably even gone up), what's the upside?

@sandersn
Copy link
Member

sandersn commented Nov 2, 2016

  1. Fourslash tests are slow because they do a lot of work -- probably too much. Micro-optimisations are unlikely to make a difference. Especially since only one or two of the changed functions is called more than a handful of times.
  2. Readability is subjective, and the people who have to look at the fourslash code the most (@andy-ms and me, at least) find zip easier to read than for+indexing.
  3. Tests take about 30 seconds to run on my machine. Compiling takes at least that long. I think the next build improvement should be compile time, not test time. That difference is largely because tests are parallel, so that's probably the best way forward for compiling too.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants