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 apparent type of homomorphic mapped type with non-homomorphic instantiation #56727

Merged
merged 2 commits into from
Jan 9, 2024

Conversation

Andarist
Copy link
Contributor

fixes #56726

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Dec 10, 2023
const modifiersConstraint = getConstraintOfType(getModifiersTypeFromMappedType(type));
if (modifiersConstraint) {
homomorphicMappedTypeApparentTypeStack.push(type);
constraint = getApparentType(modifiersConstraint);
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 not super sure if I should be calling getApparentType here but then... we get to this place from getApparentType so it feels like it's OK to do right now.

if (typeVariable && !mappedType.declaration.nameType) {
let constraint: Type | undefined;
if (!type.target) {
constraint = getConstraintOfTypeParameter(typeVariable);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other branch is now using getApparentType. If that's the correct thing to do then I feel like this probably should call that too. This would fix issues like this one:

declare function func2<A extends readonly any[], B extends A>(
  arr: A,
  fields: [
    // A rest element type must be an array type.(2574)
    ...{
      [K in keyof B]: { v: B[K] };
    },
  ],
): [A, B];

declare const tuple: [number | string, number | boolean, number | bigint];

const result = func2(tuple, [{ v: "foo" }, { v: true }, { v: 6 }]);

Copy link
Member

Choose a reason for hiding this comment

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

You probably could... or you could move the apparent type check forward and replace everyType(constraint, isArrayOrTupleType) with something like everyType(constraint, isApparentArrayOrTupleType), provided it's not critical the instantiation here be with the apparent types (and I don't think the instantiation using an apparent constraint is the important part, since mapped types have lazy apparent type members). It's possible changing the should-this-be-a-mapped-array check we use everywhere to something that looks into the apparent types of the members of the constraint could be prudent.

@typescript-bot typescript-bot added For Backlog Bug PRs that fix a backlog bug and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jan 2, 2024
Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

This looks OK to me - calling getApparentType on part of a type while resolving an apparent type is fairly normal behavior (mapped types can just be circular, which you guard against), and using that information to see if the apparent mapped type should be array or tuple like seems reasonable to me. Still, I'd like to let @ahejlsberg get a chance to review this if he'd like, too, so once the extended tests come back (presumably clean), I'll hold off on merging this for a little bit.

@weswigham
Copy link
Member

@typescript-bot test this
@typescript-bot run dt
@typescript-bot test top100
@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 3, 2024

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 3, 2024

Heya @weswigham, I've started to run the regular perf test suite on this PR at d762b80. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 3, 2024

Heya @weswigham, I've started to run the diff-based top-repos suite on this PR at d762b80. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Compiler

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Angular - node (v18.15.0, x64)
Memory used 295,428k (± 0.01%) 295,464k (± 0.01%) ~ 295,411k 295,499k p=0.128 n=6
Parse Time 2.64s (± 0.46%) 2.65s (± 0.15%) ~ 2.64s 2.65s p=0.473 n=6
Bind Time 0.82s (± 0.50%) 0.82s (± 0.99%) ~ 0.82s 0.84s p=1.000 n=6
Check Time 8.16s (± 0.40%) 8.15s (± 0.39%) ~ 8.11s 8.20s p=0.572 n=6
Emit Time 7.10s (± 0.11%) 7.10s (± 0.36%) ~ 7.07s 7.14s p=1.000 n=6
Total Time 18.72s (± 0.21%) 18.72s (± 0.18%) ~ 18.67s 18.77s p=1.000 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 191,541k (± 0.02%) 194,475k (± 1.64%) ~ 191,528k 197,527k p=0.093 n=6
Parse Time 1.35s (± 1.66%) 1.35s (± 1.01%) ~ 1.34s 1.38s p=0.549 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=1.000 n=6
Check Time 9.29s (± 0.54%) 9.26s (± 0.21%) ~ 9.23s 9.28s p=0.467 n=6
Emit Time 2.63s (± 0.56%) 2.63s (± 0.89%) ~ 2.59s 2.66s p=0.868 n=6
Total Time 13.99s (± 0.32%) 13.96s (± 0.20%) ~ 13.93s 13.99s p=0.195 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,405k (± 0.00%) 347,407k (± 0.00%) ~ 347,385k 347,418k p=0.748 n=6
Parse Time 2.47s (± 0.43%) 2.46s (± 0.33%) ~ 2.45s 2.47s p=0.181 n=6
Bind Time 0.93s (± 0.56%) 0.92s (± 0.44%) ~ 0.92s 0.93s p=0.112 n=6
Check Time 6.87s (± 0.42%) 6.91s (± 0.42%) ~ 6.88s 6.95s p=0.126 n=6
Emit Time 4.06s (± 0.34%) 4.05s (± 0.43%) ~ 4.02s 4.07s p=0.801 n=6
Total Time 14.32s (± 0.22%) 14.34s (± 0.24%) ~ 14.31s 14.39s p=0.258 n=6
TFS - node (v18.15.0, x64)
Memory used 302,713k (± 0.01%) 302,726k (± 0.00%) ~ 302,710k 302,742k p=0.228 n=6
Parse Time 2.00s (± 0.76%) 1.99s (± 1.02%) ~ 1.97s 2.01s p=0.933 n=6
Bind Time 1.00s (± 0.41%) 1.01s (± 1.20%) ~ 0.99s 1.02s p=0.209 n=6
Check Time 6.29s (± 0.22%) 6.30s (± 0.19%) ~ 6.28s 6.31s p=0.215 n=6
Emit Time 3.58s (± 0.29%) 3.58s (± 0.38%) ~ 3.57s 3.60s p=0.360 n=6
Total Time 12.86s (± 0.21%) 12.87s (± 0.27%) ~ 12.83s 12.92s p=0.376 n=6
material-ui - node (v18.15.0, x64)
Memory used 506,822k (± 0.00%) 506,832k (± 0.00%) ~ 506,803k 506,872k p=0.471 n=6
Parse Time 2.58s (± 0.65%) 2.59s (± 0.53%) ~ 2.57s 2.61s p=0.179 n=6
Bind Time 0.99s (± 1.22%) 0.99s (± 1.38%) ~ 0.98s 1.01s p=0.867 n=6
Check Time 16.94s (± 0.24%) 16.96s (± 0.15%) ~ 16.92s 16.99s p=0.261 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.51s (± 0.25%) 20.55s (± 0.18%) ~ 20.51s 20.59s p=0.226 n=6
xstate - node (v18.15.0, x64)
Memory used 512,942k (± 0.01%) 512,898k (± 0.02%) ~ 512,820k 513,054k p=0.173 n=6
Parse Time 3.27s (± 0.32%) 3.27s (± 0.16%) ~ 3.27s 3.28s p=0.928 n=6
Bind Time 1.54s (± 0.53%) 1.54s (± 0.53%) ~ 1.53s 1.55s p=1.000 n=6
Check Time 2.82s (± 0.47%) 2.82s (± 0.41%) ~ 2.80s 2.83s p=0.514 n=6
Emit Time 0.07s (± 5.69%) 0.07s (± 5.69%) ~ 0.07s 0.08s p=1.000 n=6
Total Time 7.71s (± 0.19%) 7.70s (± 0.10%) ~ 7.69s 7.71s p=0.142 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

tsserver

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,346ms (± 0.77%) 2,345ms (± 0.56%) ~ 2,328ms 2,362ms p=0.873 n=6
Req 2 - geterr 5,441ms (± 1.32%) 5,408ms (± 1.69%) ~ 5,338ms 5,558ms p=0.173 n=6
Req 3 - references 324ms (± 1.20%) 325ms (± 1.31%) ~ 321ms 333ms p=0.572 n=6
Req 4 - navto 276ms (± 1.14%) 278ms (± 1.10%) ~ 273ms 280ms p=0.505 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 88ms (± 4.83%) 85ms (± 4.00%) ~ 82ms 89ms p=0.169 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,479ms (± 0.90%) 2,482ms (± 0.54%) ~ 2,468ms 2,502ms p=0.575 n=6
Req 2 - geterr 4,137ms (± 2.15%) 4,093ms (± 0.31%) ~ 4,079ms 4,113ms p=0.936 n=6
Req 3 - references 341ms (± 1.64%) 346ms (± 0.96%) ~ 339ms 348ms p=0.290 n=6
Req 4 - navto 285ms (± 1.03%) 285ms (± 0.59%) ~ 282ms 287ms p=0.625 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 85ms (± 7.13%) 88ms (± 4.92%) ~ 79ms 91ms p=0.532 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,606ms (± 0.42%) 2,608ms (± 0.75%) ~ 2,584ms 2,633ms p=0.810 n=6
Req 2 - geterr 1,702ms (± 2.49%) 1,744ms (± 0.88%) ~ 1,725ms 1,763ms p=0.054 n=6
Req 3 - references 114ms (± 8.71%) 112ms (± 9.75%) ~ 102ms 123ms p=0.681 n=6
Req 4 - navto 364ms (± 0.22%) 365ms (± 0.46%) ~ 363ms 368ms p=0.546 n=6
Req 5 - completionInfo count 2,073 (± 0.00%) 2,073 (± 0.00%) ~ 2,073 2,073 p=1.000 n=6
Req 5 - completionInfo 310ms (± 1.85%) 313ms (± 1.46%) ~ 307ms 320ms p=0.574 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • CompilerTSServer - node (v18.15.0, x64)
  • Compiler-UnionsTSServer - node (v18.15.0, x64)
  • xstateTSServer - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
tsc-startup - node (v18.15.0, x64)
Execution time 153.41ms (± 0.20%) 153.48ms (± 0.21%) ~ 152.18ms 156.43ms p=0.065 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 229.08ms (± 0.17%) 228.98ms (± 0.15%) -0.11ms (- 0.05%) 227.66ms 234.95ms p=0.006 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 230.05ms (± 0.18%) 230.08ms (± 0.18%) ~ 228.41ms 233.67ms p=0.693 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 230.64ms (± 0.19%) 230.62ms (± 0.20%) ~ 229.16ms 235.89ms p=0.336 n=600
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • tsc-startup - node (v18.15.0, x64)
  • tsserver-startup - node (v18.15.0, x64)
  • tsserverlibrary-startup - node (v18.15.0, x64)
  • typescript-startup - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

Hey @weswigham, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

@typescript-bot
Copy link
Collaborator

@weswigham Here are the results of running the top-repos suite comparing main and refs/pull/56727/merge:

Everything looks good!

@weswigham weswigham merged commit 424b964 into microsoft:main Jan 9, 2024
19 checks passed
@jakebailey
Copy link
Member

jakebailey commented Jan 11, 2024

This PR was missing a "user test this" and broke VS Code's compiling, though I think in a good way:

node_modules/@types/sinon/index.d.ts:47:20 - error TS2370: A rest parameter must be of an array type.

47         calledWith(...args: Partial<MatchArguments<TArgs>>): boolean;
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@types/sinon/index.d.ts:1120:13 - error TS2370: A rest parameter must be of an array type.

1120             ...args: Partial<MatchArguments<TArgs>>
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@types/sinon/index.d.ts:1127:69 - error TS2370: A rest parameter must be of an array type.

1127         alwaysCalledWith<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: Partial<MatchArguments<TArgs>>): void;
                                                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@types/sinon/index.d.ts:1133:68 - error TS2370: A rest parameter must be of an array type.

1133         neverCalledWith<TArgs extends any[]>(spy: SinonSpy<TArgs>, ...args: Partial<MatchArguments<TArgs>>): void;
                                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 4 errors in the same file, starting at: node_modules/@types/sinon/index.d.ts:47

(I believe they are just using an old version of the sinon types.)

@Andarist
Copy link
Contributor Author

It is slightly surprising to me since I wouldn't exactly expect some types to stop being spreadable with this change. Unless this is hitting some circularity case here or something. I'll reduce this to a minimal repro case later so we can assess with more confidence what happens here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Non-homomorphic instantiation of a homomorphic mapped type is not spreadable when it has an array constraint
5 participants