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

Use faster, stricter prop type comparison when merging props in union prop creation #43696

Merged
merged 4 commits into from
Apr 19, 2021

Conversation

weswigham
Copy link
Member

Fixes #43690

@weswigham weswigham requested a review from sandersn April 15, 2021 21:06
@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Apr 15, 2021
@weswigham
Copy link
Member Author

@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 15, 2021

Heya @weswigham, I've started to run the parallelized Definitely Typed test suite on this PR at 1035416. You can monitor the build here.

@weswigham weswigham force-pushed the fix-backbone-stackout branch from 1035416 to 586bb7b Compare April 15, 2021 21:19
@weswigham weswigham marked this pull request as draft April 15, 2021 21:24
@weswigham weswigham marked this pull request as ready for review April 15, 2021 23:25
@weswigham
Copy link
Member Author

@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 15, 2021

Heya @weswigham, I've started to run the parallelized Definitely Typed test suite on this PR at 488ed1f. You can monitor the build here.

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.

I also don't understand what is wrong with isPropertyIdenticalTo that compareProperties fixes.

typeParameters = (target.objectFlags & ObjectFlags.Reference || target.symbol.flags & SymbolFlags.TypeLiteral) && !target.aliasTypeArguments ?
filter(typeParameters, tp => isTypeParameterPossiblyReferenced(tp, declaration)) :
typeParameters = (target.objectFlags & ObjectFlags.Reference || target.symbol.flags & SymbolFlags.Method || target.symbol.flags & SymbolFlags.TypeLiteral) && !target.aliasTypeArguments ?
filter(typeParameters, tp => isTypeParameterPossiblyReferenced(tp, declaration) || !(type.objectFlags & ObjectFlags.Reference) && some(type.symbol.declarations, d => isTypeParameterPossiblyReferenced(tp, d))) :
Copy link
Member

Choose a reason for hiding this comment

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

why skip object references here? are references really the only object types that won't work?

I'd suggest instead declaring

const allDeclarations = type.objectFlags & ObjectFlags.Reference ? [(<TypeReference>type).node!] : type.symbol.declarations! just below declarations, then:

Suggested change
filter(typeParameters, tp => isTypeParameterPossiblyReferenced(tp, declaration) || !(type.objectFlags & ObjectFlags.Reference) && some(type.symbol.declarations, d => isTypeParameterPossiblyReferenced(tp, d))) :
filter(typeParameters, tp => some(allDeclarations, d => isTypeParameterPossiblyReferenced(tp, d)) :

Copy link
Member Author

Choose a reason for hiding this comment

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

Because References use their .node to track their content, not their declarations. Because reasons.

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 I'd still prefer
const allDeclarations = type.objectFlags & ObjectFlags.Reference ? [] : type.symbol.declarations!
then

src/compiler/checker.ts Show resolved Hide resolved
@weswigham weswigham requested a review from sandersn April 19, 2021 20:28
@weswigham
Copy link
Member Author

@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 19, 2021

Heya @weswigham, I've started to run the parallelized Definitely Typed test suite on this PR at 252b34b. You can monitor the build here.

@@ -15930,6 +15931,9 @@ namespace ts {
getTypeFromTypeNodeWorker(<TypeNode>node) === tp; // use worker because we're looking for === equality
case SyntaxKind.TypeQuery:
return true;
case SyntaxKind.MethodDeclaration:
case SyntaxKind.MethodSignature:
return (!(node as FunctionLikeDeclaration).type && !!(node as FunctionLikeDeclaration).body) || !!forEachChild(node, containsReference);
Copy link
Member

Choose a reason for hiding this comment

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

@weswigham I'm fixing #44292 which was indirectly caused by the changes in this PR. Now I'm looking at this code and I'm not really sure why you return true if there's no type annotation but a function body, but otherwise you visit every node in the function body.

Copy link
Member

Choose a reason for hiding this comment

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

Before your changes in this PR, we'd only call isTypeParameterPossiblyReferenced on something that is a type. Now we can end up crawling through method bodies which this code wasn't intended to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stack overflow on DT after #43560
4 participants