Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Don't inferFromIndexTypes() twice#34501

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sandersn merged 2 commits intomicrosoft:masterfromjablko:patch-19
Mar 4, 2020
Merged

Conversation

@jablko
Copy link
Contributor

@jablkojablko commentedOct 15, 2019
edited
Loading

Fixes#33559
Fixes#33752
Fixes#34924
Fixes#34925
Fixes#34937
Fixes#35136
Fixes#35258

interfaceI<T>{}declarefunctionf1<T1,T2>(values:[I<T1>,I<T2>]):T1;declarefunctionf2<T1,T2>(values:readonly[I<T1>,I<T2>]):T1;declareconstvalues:[I<1>,I<number>];letone:1;one=f1(values);// ✓ 1one=f2(values);// ✗ number

Currentlyf2(values) isnumber whilef1(values) is1.

There are three cases ininferFromProperties()

  1. Source and target are both tuples: infers types element-wise
  2. Target is an array: callsinferFromIndexTypes()
  3. Otherwise: iterates over properties

But theninferFromObjectTypesWorker() callsinferFromIndexTypes() again, in all cases

if(!typesDefinitelyUnrelated(source,target)){inferFromProperties(source,target);inferFromSignatures(source,target,SignatureKind.Call);inferFromSignatures(source,target,SignatureKind.Construct);inferFromIndexTypes(source,target);}

This PR moves that call frominferFromObjectTypesWorker() to the third case. Consequently

  1. inferFromIndexTypes() isn't called twice in the second (array) case
  2. it isn't called at all in the first (tuple) case, sof2(values) is1 likef1(values)

FYIf1(values) is currently1 unlikef2(values) because parameter and argument are the same generic type (tuple) and handled by

if(getObjectFlags(source)&ObjectFlags.Reference&&getObjectFlags(target)&ObjectFlags.Reference&&((<TypeReference>source).target===(<TypeReference>target).target||isArrayType(source)&&isArrayType(target))&&!((<TypeReference>source).node&&(<TypeReference>target).node)){// If source and target are references to the same generic type, infer from type argumentsinferFromTypeArguments(getTypeArguments(<TypeReference>source),getTypeArguments(<TypeReference>target),getVariances((<TypeReference>source).target));}

whereasf2(values) parameter (readonly tuple) and argument (tuple) aren't.

capaj, rktuxyn, ThomasBower, guzzur, dicotomy, Eduardogbg, BubbleBear, davishooly, Kobzol, Nividica, and AZaviruha reacted with heart emojiAnyhowStep, stephank, lambda-fairy, buu700, falkenhawk, nmchaves, tonivj5, Gaubee, rafaelpinabew, gomesalexandre, and 2 more reacted with rocket emoji
@jablko
Copy link
ContributorAuthor

@typescript-bot user test this

@RyanCavanaugh
Copy link
Member

@typescript-bot user test this
@typescript-bot test this

jablko reacted with thumbs up emoji

@typescript-bot
Copy link
Collaborator

typescript-bot commentedOct 15, 2019
edited
Loading

Heya@RyanCavanaugh, I've started to run the parallelized community code test suite on this PR ate427f3f. You can monitor the buildhere. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

typescript-bot commentedOct 15, 2019
edited
Loading

Heya@RyanCavanaugh, I've started to run the extended test suite on this PR ate427f3f. You can monitor the buildhere. It should now contribute to this PR's status checks.

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished andfailed. I've opened aPR with the baseline diff from master.

@jablkojablkoforce-pushed thepatch-19 branch 2 times, most recently fromdea9d72 tod045c4cCompareOctober 17, 2019 16:59
@jablkojablkoforce-pushed thepatch-19 branch 3 times, most recently fromd37394a to82d6ad7CompareNovember 18, 2019 14:18
@jablkojablkoforce-pushed thepatch-19 branch 2 times, most recently from4765642 to8af1dcaCompareNovember 25, 2019 20:24
@weswigham
Copy link
Member

@jablko rather than the other changes inchecker.ts, could you just delete

if(isArrayType(target)){inferFromIndexTypes(source,target);return;}

frominferFromProperties? That way the single unconditionalinferFromIndexTypes is still easy to track.

@jablko
Copy link
ContributorAuthor

@weswigham Thanks a lot for taking a look at this! What you describe would callinferFromIndexTypes() just once, however it would still call it in the tuple case, so I assume it wouldn't resolve the test case included in this issue: Inferring an array type instead of a tuple type.

inferFromProperties() infers a tuple type element-wise, but theninferFromObjectTypesWorker() callsinferFromIndexTypes() which re-infers an array type. ❌

@jablkojablkoforce-pushed thepatch-19 branch 2 times, most recently from1a56348 to84baa5cCompareNovember 27, 2019 19:40
@weswigham
Copy link
Member

however it would still call it in the tuple case, so I assume it wouldn't resolve the test case included in this issue: Inferring an array type instead of a tuple type

Hm, if that's the case, can we copy the tuple check into theinferFromObjectTypesWorker instead of shiftinginferFromIndexSignatures intoinferFromProperties? I don't like the implicit linkage of index inference to property inference caused by the current layering.

@jablko
Copy link
ContributorAuthor

✔️ Yup, that works. Done.

@jablkojablkoforce-pushed thepatch-19 branch 3 times, most recently from9c6fe7d to2cfb902CompareJanuary 29, 2020 01:06
@sandersnsandersn added the For Milestone BugPRs that fix a bug with a specific milestone labelFeb 1, 2020
@jablkojablkoforce-pushed thepatch-19 branch 5 times, most recently fromc248e7f tof85c83fCompareFebruary 9, 2020 17:19
@jablkojablkoforce-pushed thepatch-19 branch 5 times, most recently from012cbda to3f15d40CompareFebruary 13, 2020 15:42
@sandersn
Copy link
Member

@weswigham are you happy with this change now? It's been a while, but the inference code hasn't changed much in the last few months.

Copy link
Member

@weswighamweswigham left a comment
edited
Loading

Choose a reason for hiding this comment

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

Yeah, I think this is fine now (it just moves a chunk of code out of a call and into the (only) caller), I just wanted@ahejlsberg to look at it briefly before it got in, which is why he's assigned iirc.

@sandersnsandersn merged commit061338e intomicrosoft:masterMar 4, 2020
Copy link

@StefanXhungaStefanXhunga left a comment

Choose a reason for hiding this comment

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

Thank you for your assistance, please change the nesessery scedares!

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@weswighamweswighamweswigham approved these changes

@ahejlsbergahejlsbergahejlsberg approved these changes

+1 more reviewer

@StefanXhungaStefanXhungaStefanXhunga left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

@ahejlsbergahejlsberg

Labels

For Milestone BugPRs that fix a bug with a specific milestone

Projects

Archived in project

Milestone

No milestone

7 participants

@jablko@RyanCavanaugh@typescript-bot@weswigham@sandersn@ahejlsberg@StefanXhunga

[8]ページ先頭

©2009-2025 Movatter.jp