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

Fixed an issue with ReduceLabel flows spoiling node reachability cache #61265

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

fixes #61259

@@ -28178,7 +28192,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const target = (flow as FlowReduceLabel).node.target;
const saveAntecedents = target.antecedent;
target.antecedent = (flow as FlowReduceLabel).node.antecedents;
const result = isReachableFlowNodeWorker((flow as FlowReduceLabel).antecedent, /*noCacheCheck*/ false);
const result = isReachableFlowNodeWorker((flow as FlowReduceLabel).antecedent, FlowNodeReachableCacheFlags.None);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

as the comment in this block says:

// Cache is unreliable once we start adjusting labels

We can't let this isReachableFlowNodeWorker call here to populate the cache as that would create entries based on the temporarily antecedent(s). Anything computed below this call can't be preserved, at least not without including the id of this ReduceLabel flow in the cache key or smth.

So this disables cache writes. As later on that would be used on the same shared flow but with "correct" antecedents (and that's the only result the compiler should cache and trust).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm still considering 2 things here:

  • should this code maybe save & restore flowNodeReachable[getFlowNodeId(target)]?
  • should reads be permanently disabled here? this would make the previous consideration obsolete

I have not been able to produce a test case that would prove either to be required so far but I have only spent a little bit of time on it.

Copy link
Member

Choose a reason for hiding this comment

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

cc @ahejlsberg who has been thinking about this sort of thing recently and I believe had ideas on how to simplify the flow node logic here

@Andarist Andarist force-pushed the fix/reduce-label-spoiling-reachability-cache branch from 2a860e8 to 4552c20 Compare February 25, 2025 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

Exhaustive switch case with returns can mark a finally block as unreachable
2 participants