-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Reintroduce definitelyAssignableRelation and use with conditional types #39577
Conversation
@typescript-bot test this |
Heya @ahejlsberg, I've started to run the extended test suite on this PR at 854229a. You can monitor the build here. |
Heya @ahejlsberg, I've started to run the parallelized community code test suite on this PR at 854229a. You can monitor the build here. |
Heya @ahejlsberg, I've started to run the perf test suite on this PR at 854229a. You can monitor the build here. Update: The results are in! |
Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 854229a. You can monitor the build here. |
@ahejlsberg Here they are:Comparison Report - master..39577
System
Hosts
Scenarios
|
Tests are clean (failures are all preexisting conditions). Except for |
src/compiler/checker.ts
Outdated
if (source.flags & TypeFlags.Index) { | ||
if (result = isRelatedTo(targetType, (<IndexType>source).type, /*reportErrors*/ false)) { | ||
return result; | ||
if (relation !== definitelyAssignableRelation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the definite assignment relation skip over relating keyof S
and keyof T
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have two keyof
types, then S
and T
are distinct generic types. Since they're not the same type and generic types have no constraints under this relationship, seems there's no point in further exploration. Also, if I change to include this check we get circularity errors in the circularlySimplifyingConditionalTypesNoCrash.ts
test plus error baseline changes in two other similar tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we're relating keyof S
to keyof substitute(S, S & T)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even keyof S
to keyof Q[T]
where the value of Q[T]
is only ever S
(eg, because every property in a concrete Q
is of type S
)?
A lot of type relationships are subsets or supersets of others (i.e. identitical ≤ subtype of ≤ assignable to ≤ comparable to). It's not clear to me that that's the case with the definitelyAssignable relationship - maybe it's a subset of assignable to? Either way, I experimented with a layered cache check that leveraged that a few years back, but saw no real difference on the codebase. You might see it in a stress test like material-ui though. |
It's a subset of the assignable-to relation in the sense that when assignable-to is false then definitely-assignable-to is also false. It's possible we might save time in our determination of whether to defer conditional types by first checking for assignable-to and, only when that's true, then checking for definitely-assignable-to. But of course were then doing even more work in the true case. |
Latest commit is an experiment to see the effects of checking assignable-to before definitely-assignable-to. Note that there are baseline changes because the more aggressive constraint explorations of assignable-to cause circularity errors. |
@typescript-bot perf test this |
Heya @ahejlsberg, I've started to run the perf test suite on this PR at 289ba80. You can monitor the build here. Update: The results are in! |
@ahejlsberg Here they are:Comparison Report - master..39577
System
Hosts
Scenarios
|
This doesn't feel like a "Pay 1% perf penalty to fix it" bug given that this is our first report in 9 versions of shipping it. Are there other positive impacts in favor of it? |
I don't necessarily mean requesting that work - I mean just checking whether that work has already been done before in other caches before starting any work. Check whether something is |
No positive effect from performance experiment, so reverting that. |
# Conflicts: # src/compiler/checker.ts
@DanielRosenwasser I did a few experiments with your idea, specifically, if we have cached a true for definitely-assignable-to then assignable-to is also true, and if we have cached a false for assignable-to then definitely-assignable-to is also false. Unfortunately, it doesn't seem to have any effect. @RyanCavanaugh Yes, a 2.5% performance definitely doesn't seem worth it for this rather obscure corner case. But, material-ui is an outlier and generally I wouldn't expect any measurable difference. In terms of other positive impacts of the change, it's simpler because we can get rid of the restrictive instantiation and its associated cache. But probably not a big deal. |
# Conflicts: # src/compiler/checker.ts
@ahejlsberg is it worth it to keep this open; would you want to merge it for 4.2 after the 4.1 RC is out? |
@DanielRosenwasser Let's discuss in a design meeting before we make a final call. |
My vote is early 4.2 (i.e. merge on Monday) if we decide to take it. |
@typescript-bot perf test this |
Heya @ahejlsberg, I've started to run the perf test suite on this PR at d2e3a35. You can monitor the build here. Update: The results are in! |
@ahejlsberg Here they are:Comparison Report - master..39577
System
Hosts
Scenarios
|
The 10/30/2020 notes still don't show whether we decided to take this PR. @DanielRosenwasser or @ahejlsberg do either of you remember? Do we need to discuss this again? |
I'm going to close this PR for now to reduce clutter. We can re-open it if there's demand for it. |
Fixes #39364.