Skip to content

Commit

Permalink
Pass the value to stop after rather than calling each time
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Aug 1, 2023
1 parent c31d069 commit 42d68cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
7 changes: 3 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21303,13 +21303,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (result === Ternary.True || result === Ternary.Maybe) {
// If result is definitely true, record all maybe keys as having succeeded. Also, record Ternary.Maybe
// results as having succeeded once we reach depth 0, but never record Ternary.Unknown results.
maybeKeys.popAll(v => {
maybeKeys.popUntilInclusive(id, v => {
relation.set(v, RelationComparisonResult.Succeeded | propagatingVarianceFlags);
return v === id;
});
}
else {
maybeKeys.popAll(v => v === id);
maybeKeys.popUntilInclusive(id);
}
}
// Note: it's intentional that we don't pop in the else case;
Expand All @@ -21320,7 +21319,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// A false result goes straight into global cache (when something is false under
// assumptions it will also be false without assumptions)
relation.set(id, (reportErrors ? RelationComparisonResult.Reported : 0) | RelationComparisonResult.Failed | propagatingVarianceFlags);
maybeKeys.popAll(v => v === id);
maybeKeys.popUntilInclusive(id);
}
return result;
}
Expand Down
20 changes: 10 additions & 10 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2885,7 +2885,7 @@ export function isNodeLikeSystem(): boolean {


/** @internal */
export interface StackSet<T extends {}> {
export interface StackSet<T> {
/**
* Returns true if the value has already been pushed.
*/
Expand All @@ -2895,17 +2895,16 @@ export interface StackSet<T extends {}> {
*/
push(value: T): void;
/**
* This pops from the stack until the callback returns true.
* This pops from the stack, stopping iteration after v is found.
*
* Note that a value is popped, _then_ the callback is evaluated, meaning
* that if you return true to stop iteration, the value that the callback
* returned true for will still have been popped.
* Note that the callback is evaluated _after_ the item is popped, meaning
* the callback will execute for v and it will not remain on the stack.
*/
popAll(callback: (v: T) => boolean): void;
popUntilInclusive(v: T, callback?: (v: T) => void): void;
}

/** @internal */
export function createStackSet<T extends {}>(): StackSet<T> {
export function createStackSet<T>(): StackSet<T> {
// Why var? It avoids TDZ checks in the runtime which can be costly.
// See: https://github.com/microsoft/TypeScript/issues/52924
/* eslint-disable no-var */
Expand All @@ -2924,13 +2923,14 @@ export function createStackSet<T extends {}>(): StackSet<T> {
stack[end] = value;
end++;
},
popAll(callback) {
popUntilInclusive(v, callback) {
while (end > 0) {
end--;
const value = stack[end];
set.delete(value);
if (callback(value)) {
break;
callback?.(value);
if (value === v) {
return;
}
}
},
Expand Down

0 comments on commit 42d68cb

Please sign in to comment.