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 local extends constraints of infer type parameters when they can contain type variables #60345

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

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Oct 26, 2024

fixes #60299

this reverts a good chunk of #57362 but it also makes some modifications to the code that was removed there

cc @weswigham

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Oct 26, 2024
@Andarist Andarist force-pushed the fix/infer-type-params-with-instantiatable-extends-constraints branch from 659c426 to 7cf0d7c Compare October 26, 2024 19:36
Comment on lines +19227 to +19229
function maybeCloneInferTypeParameter(p: TypeParameter) {
return getConstraintDeclaration(p) && couldContainTypeVariables(getConstraintFromTypeParameter(p)!) ? cloneTypeParameter(p) : p;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this only clones type parameters with "local" constraints (the ones added by infer R extends C syntax)

It could do the same with all constraints, using this patch:

git diff
diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index a8803f5823..52f44bcebe 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -19117,9 +19117,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
                     }
                 }
                 const context = createInferenceContext(freshParams, /*signature*/ undefined, InferenceFlags.None);
-                if (mapper) {
-                    context.nonFixingMapper = combineTypeMappers(context.nonFixingMapper, mapper);
-                }
                 if (!checkTypeDeferred) {
                     // We don't want inferences from constraints as they may cause us to eagerly resolve the
                     // conditional type instead of deferring resolution. Also, we always want strict function
@@ -19220,7 +19217,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
     }
 
     function maybeCloneInferTypeParameter(p: TypeParameter) {
-        return getConstraintDeclaration(p) && couldContainTypeVariables(getConstraintFromTypeParameter(p)!) ? cloneTypeParameter(p) : p;
+        const constraint = getConstraintFromTypeParameter(p);
+        return constraint && couldContainTypeVariables(constraint) ? cloneTypeParameter(p) : p;
     }
 
     function getTrueTypeFromConditionalType(type: ConditionalType) {
diff --git a/tests/baselines/reference/inferTypes1.types b/tests/baselines/reference/inferTypes1.types
index edc97a2ea1..f6018d54a3 100644
--- a/tests/baselines/reference/inferTypes1.types
+++ b/tests/baselines/reference/inferTypes1.types
@@ -1,5 +1,8 @@
 //// [tests/cases/conformance/types/conditional/inferTypes1.ts] ////
 
+=== Performance Stats ===
+Instantiation count: 1,000
+
 === inferTypes1.ts ===
 type Unpacked<T> =
 >Unpacked : Unpacked<T>

As we can see, we could drop the context.nonFixingMapper manipulation and simplify the logic here - but that would create more type parameter clones and that's even caught by this diff (Instantiation count was reported by one of the tests when using this patch)

@zedryas
Copy link

zedryas commented Oct 28, 2024

thank you very much @Andarist, how long do you reckon before this might be merged ?

@Andarist
Copy link
Contributor Author

@zedryas that's not up to me, we have to wait for the review and merge by one of the TS team members

@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 28, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started ✅ Results
user test this ✅ Started ✅ Results
run dt ✅ Started ✅ Results
perf test this faster ✅ Started 👀 Results

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user tests with tsc comparing main and refs/pull/60345/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

@jakebailey
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 31 31 ~ ~ ~ p=1.000 n=6
Symbols 62,340 62,340 ~ ~ ~ p=1.000 n=6
Types 50,379 50,379 ~ ~ ~ p=1.000 n=6
Memory used 193,467k (± 0.76%) 192,851k (± 0.07%) ~ 192,763k 193,126k p=0.471 n=6
Parse Time 1.31s (± 0.80%) 1.31s (± 1.12%) ~ 1.29s 1.32s p=0.557 n=6
Bind Time 0.72s 0.72s ~ ~ ~ p=1.000 n=6
Check Time 9.75s (± 0.46%) 9.74s (± 0.22%) ~ 9.72s 9.77s p=0.870 n=6
Emit Time 2.72s (± 1.56%) 2.71s (± 1.51%) ~ 2.63s 2.74s p=0.373 n=6
Total Time 14.50s (± 0.39%) 14.48s (± 0.30%) ~ 14.41s 14.53s p=0.810 n=6
angular-1 - node (v18.15.0, x64)
Errors 33 33 ~ ~ ~ p=1.000 n=6
Symbols 947,886 947,886 ~ ~ ~ p=1.000 n=6
Types 410,840 410,840 ~ ~ ~ p=1.000 n=6
Memory used 1,224,823k (± 0.01%) 1,224,845k (± 0.01%) ~ 1,224,779k 1,224,926k p=0.575 n=6
Parse Time 8.10s (± 0.83%) 8.08s (± 0.77%) ~ 8.01s 8.17s p=0.630 n=6
Bind Time 2.28s (± 0.66%) 2.27s (± 0.82%) ~ 2.25s 2.29s p=0.365 n=6
Check Time 37.86s (± 0.28%) 37.93s (± 0.59%) ~ 37.65s 38.32s p=0.689 n=6
Emit Time 18.30s (± 0.55%) 18.27s (± 0.47%) ~ 18.16s 18.40s p=0.748 n=6
Total Time 66.54s (± 0.20%) 66.55s (± 0.41%) ~ 66.23s 66.96s p=0.936 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,494,603 2,494,603 ~ ~ ~ p=1.000 n=6
Types 908,300 908,300 ~ ~ ~ p=1.000 n=6
Memory used 2,307,228k (± 0.00%) 2,307,217k (± 0.00%) ~ 2,307,176k 2,307,258k p=0.810 n=6
Parse Time 9.32s (± 0.18%) 9.34s (± 0.16%) +0.02s (+ 0.27%) 9.32s 9.36s p=0.036 n=6
Bind Time 2.14s (± 0.46%) 2.14s (± 0.75%) ~ 2.11s 2.15s p=0.720 n=6
Check Time 74.77s (± 0.13%) 74.96s (± 0.32%) ~ 74.60s 75.21s p=0.173 n=6
Emit Time 0.28s (± 3.53%) 0.29s (± 2.85%) ~ 0.27s 0.29s p=0.144 n=6
Total Time 86.51s (± 0.13%) 86.73s (± 0.29%) ~ 86.36s 87.01s p=0.128 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,258,044 1,258,052 +8 (+ 0.00%) ~ ~ p=0.001 n=6
Types 266,229 266,231 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,422,962k (± 0.04%) 2,422,861k (± 0.01%) ~ 2,422,473k 2,423,341k p=1.000 n=6
Parse Time 5.22s (± 0.63%) 5.22s (± 0.62%) ~ 5.19s 5.27s p=0.872 n=6
Bind Time 1.93s (± 0.28%) 1.93s (± 0.60%) ~ 1.91s 1.94s p=0.152 n=6
Check Time 35.49s (± 0.23%) 35.53s (± 0.25%) ~ 35.40s 35.65s p=0.521 n=6
Emit Time 3.09s (± 2.54%) 3.02s (± 1.82%) ~ 2.93s 3.08s p=0.173 n=6
Total Time 45.73s (± 0.35%) 45.71s (± 0.30%) ~ 45.49s 45.85s p=0.689 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,258,044 1,258,052 +8 (+ 0.00%) ~ ~ p=0.001 n=6
Types 266,229 266,231 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,766,242k (±12.86%) 2,619,337k (±11.21%) ~ 2,497,875k 3,219,236k p=0.689 n=6
Parse Time 6.65s (± 2.47%) 6.57s (± 1.56%) ~ 6.47s 6.74s p=0.521 n=6
Bind Time 2.15s (± 1.74%) 2.18s (± 2.76%) ~ 2.14s 2.30s p=0.226 n=6
Check Time 43.15s (± 0.50%) 43.11s (± 0.31%) ~ 42.93s 43.26s p=0.575 n=6
Emit Time 3.54s (± 2.87%) 3.63s (± 5.83%) ~ 3.42s 4.02s p=0.471 n=6
Total Time 55.49s (± 0.51%) 55.49s (± 0.39%) ~ 55.28s 55.85s p=0.810 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 261,754 261,762 +8 (+ 0.00%) ~ ~ p=0.001 n=6
Types 106,477 106,479 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 438,571k (± 0.01%) 438,587k (± 0.02%) ~ 438,515k 438,671k p=0.936 n=6
Parse Time 2.89s (± 0.61%) 2.89s (± 0.58%) ~ 2.86s 2.90s p=0.507 n=6
Bind Time 1.10s 1.10s (± 0.37%) ~ 1.10s 1.11s p=0.405 n=6
Check Time 15.73s (± 0.12%) 15.76s (± 0.19%) ~ 15.72s 15.80s p=0.105 n=6
Emit Time 1.30s (± 1.57%) 1.30s (± 1.16%) ~ 1.28s 1.32s p=0.804 n=6
Total Time 21.01s (± 0.11%) 21.05s (± 0.13%) +0.04s (+ 0.17%) 21.03s 21.10s p=0.028 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 68 68 ~ ~ ~ p=1.000 n=6
Symbols 225,919 225,919 ~ ~ ~ p=1.000 n=6
Types 94,415 94,415 ~ ~ ~ p=1.000 n=6
Memory used 371,139k (± 0.01%) 371,095k (± 0.01%) ~ 371,047k 371,150k p=0.230 n=6
Parse Time 2.91s (± 0.92%) 2.92s (± 1.61%) ~ 2.88s 3.01s p=0.936 n=6
Bind Time 1.60s (± 1.33%) 1.59s (± 1.34%) ~ 1.57s 1.62s p=0.256 n=6
Check Time 16.39s (± 0.46%) 16.37s (± 0.40%) ~ 16.31s 16.49s p=0.808 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.89s (± 0.33%) 20.88s (± 0.44%) ~ 20.80s 21.03s p=0.809 n=6
vscode - node (v18.15.0, x64)
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 3,127,909 3,127,909 ~ ~ ~ p=1.000 n=6
Types 1,078,188 1,078,188 ~ ~ ~ p=1.000 n=6
Memory used 3,220,310k (± 0.01%) 3,220,233k (± 0.01%) ~ 3,219,375k 3,220,477k p=0.936 n=6
Parse Time 17.41s (± 0.65%) 17.31s (± 0.36%) ~ 17.19s 17.38s p=0.297 n=6
Bind Time 5.50s (± 2.51%) 5.45s (± 2.12%) ~ 5.36s 5.68s p=0.575 n=6
Check Time 104.79s (± 2.91%) 105.55s (± 3.00%) ~ 102.85s 110.96s p=0.575 n=6
Emit Time 32.19s (± 6.17%) 32.18s (± 6.87%) ~ 27.68s 33.42s p=0.689 n=6
Total Time 159.89s (± 1.11%) 160.48s (± 1.07%) ~ 158.42s 162.42s p=0.575 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 286,866 286,866 ~ ~ ~ p=1.000 n=6
Types 116,245 116,245 ~ ~ ~ p=1.000 n=6
Memory used 437,860k (± 0.03%) 437,716k (± 0.06%) ~ 437,374k 437,993k p=0.298 n=6
Parse Time 4.02s (± 0.73%) 4.03s (± 0.92%) ~ 3.98s 4.07s p=0.685 n=6
Bind Time 1.74s (± 0.43%) 1.74s (± 1.23%) ~ 1.71s 1.76s p=1.000 n=6
Check Time 18.50s (± 0.69%) 18.81s (± 2.35%) ~ 18.42s 19.38s p=0.298 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.26s (± 0.53%) 24.58s (± 1.72%) ~ 24.19s 25.15s p=0.199 n=6
xstate-main - node (v18.15.0, x64)
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 543,130 543,130 ~ ~ ~ p=1.000 n=6
Types 181,889 181,889 ~ ~ ~ p=1.000 n=6
Memory used 485,557k (± 0.01%) 485,577k (± 0.01%) ~ 485,518k 485,636k p=0.575 n=6
Parse Time 4.18s (± 0.47%) 4.19s (± 0.58%) ~ 4.15s 4.22s p=0.803 n=6
Bind Time 1.47s (± 0.82%) 1.47s (± 0.70%) ~ 1.45s 1.48s p=0.408 n=6
Check Time 23.78s (± 0.24%) 23.80s (± 0.36%) ~ 23.63s 23.86s p=0.289 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 29.44s (± 0.22%) 29.45s (± 0.37%) ~ 29.24s 29.54s p=0.422 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top 400 repos with tsc comparing main and refs/pull/60345/merge:

Everything looks good!

@zedryas
Copy link

zedryas commented Dec 13, 2024

Any update on this merge request? cc @weswigham (i do tag because you were the reviewer on #57362 )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

Can extends [any, any] but not generic which is exactly [any, any] (woks till 5.3.3 breaks from 5.4.5)
4 participants