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

Don't propagate partial union/intersection properties between caches #58083

Merged
merged 3 commits into from Apr 9, 2024

Conversation

ahejlsberg
Copy link
Member

There's currently no repro in this PR since it is really hard to reproduce the conditions in a stand-alone manner.

Fixes #58050.

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Apr 4, 2024
@ahejlsberg
Copy link
Member Author

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 4, 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

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

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the user tests comparing main and refs/pull/58083/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

@ahejlsberg
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
Angular - node (v18.15.0, x64)
Memory used 295,683k (± 0.00%) 295,645k (± 0.02%) ~ 295,574k 295,713k p=0.298 n=6
Parse Time 3.92s (± 0.42%) 3.92s (± 0.47%) ~ 3.89s 3.94s p=0.870 n=6
Bind Time 1.23s (± 0.80%) 1.22s (± 1.12%) ~ 1.20s 1.24s p=0.933 n=6
Check Time 12.05s (± 0.46%) 12.01s (± 0.36%) ~ 11.96s 12.07s p=0.229 n=6
Emit Time 10.47s (± 0.47%) 10.47s (± 0.75%) ~ 10.41s 10.62s p=0.422 n=6
Total Time 27.68s (± 0.34%) 27.62s (± 0.33%) ~ 27.52s 27.77s p=0.297 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 192,177k (± 0.06%) 193,304k (± 0.93%) ~ 192,115k 195,652k p=0.521 n=6
Parse Time 2.02s (± 1.07%) 2.02s (± 0.68%) ~ 2.01s 2.04s p=0.681 n=6
Bind Time 1.08s (± 0.96%) 1.08s (± 0.95%) ~ 1.07s 1.10s p=0.273 n=6
Check Time 13.94s (± 0.50%) 13.95s (± 0.88%) ~ 13.81s 14.17s p=0.873 n=6
Emit Time 3.87s (± 0.64%) 3.85s (± 0.60%) ~ 3.82s 3.88s p=0.223 n=6
Total Time 20.90s (± 0.22%) 20.91s (± 0.65%) ~ 20.74s 21.14s p=0.936 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,535k (± 0.00%) 347,542k (± 0.00%) ~ 347,520k 347,559k p=0.378 n=6
Parse Time 3.68s (± 1.43%) 3.70s (± 0.69%) ~ 3.67s 3.73s p=0.517 n=6
Bind Time 1.40s (± 2.19%) 1.37s (± 0.75%) -0.03s (- 2.26%) 1.35s 1.38s p=0.046 n=6
Check Time 10.18s (± 0.26%) 10.16s (± 0.40%) ~ 10.10s 10.21s p=0.421 n=6
Emit Time 6.02s (± 0.38%) 6.02s (± 0.54%) ~ 5.98s 6.07s p=1.000 n=6
Total Time 21.28s (± 0.27%) 21.25s (± 0.18%) ~ 21.21s 21.30s p=0.259 n=6
TFS - node (v18.15.0, x64)
Memory used 302,812k (± 0.01%) 302,838k (± 0.01%) ~ 302,788k 302,857k p=0.173 n=6
Parse Time 2.93s (± 0.95%) 2.96s (± 0.39%) ~ 2.94s 2.97s p=0.106 n=6
Bind Time 1.47s (± 0.56%) 1.47s (± 0.28%) ~ 1.46s 1.47s p=1.000 n=6
Check Time 9.27s (± 0.17%) 9.24s (± 0.42%) ~ 9.20s 9.31s p=0.089 n=6
Emit Time 5.29s (± 0.95%) 5.28s (± 0.69%) ~ 5.25s 5.33s p=0.421 n=6
Total Time 18.97s (± 0.30%) 18.95s (± 0.23%) ~ 18.90s 19.00s p=0.519 n=6
material-ui - node (v18.15.0, x64)
Memory used 510,199k (± 0.01%) 510,237k (± 0.01%) ~ 510,175k 510,317k p=0.298 n=6
Parse Time 3.94s (± 0.27%) 3.95s (± 0.59%) ~ 3.93s 3.99s p=0.210 n=6
Bind Time 1.47s (± 0.61%) 1.46s (± 1.03%) ~ 1.44s 1.48s p=0.557 n=6
Check Time 25.42s (± 0.48%) 25.42s (± 0.68%) ~ 25.19s 25.63s p=0.936 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 30.83s (± 0.38%) 30.83s (± 0.52%) ~ 30.60s 31.02s p=1.000 n=6
mui-docs - node (v18.15.0, x64)
Memory used 1,744,939k (± 0.00%) 1,744,698k (± 0.00%) -241k (- 0.01%) 1,744,655k 1,744,745k p=0.005 n=6
Parse Time 9.63s (± 0.83%) 9.63s (± 0.79%) ~ 9.53s 9.75s p=0.810 n=6
Bind Time 3.48s (± 0.72%) 3.48s (± 0.60%) ~ 3.45s 3.50s p=0.627 n=6
Check Time 81.98s (± 0.50%) 82.16s (± 0.56%) ~ 81.66s 82.86s p=1.000 n=6
Emit Time 0.19s (± 2.67%) 0.19s (± 2.81%) ~ 0.19s 0.20s p=0.640 n=6
Total Time 95.28s (± 0.45%) 95.46s (± 0.50%) ~ 94.93s 96.22s p=0.689 n=6
self-build-src - node (v18.15.0, x64)
Memory used 2,296,762k (± 0.03%) 2,296,696k (± 0.01%) ~ 2,296,525k 2,296,935k p=0.471 n=6
Parse Time 7.47s (± 1.06%) 7.49s (± 0.62%) ~ 7.42s 7.53s p=0.936 n=6
Bind Time 2.79s (± 0.97%) 2.79s (± 1.05%) ~ 2.76s 2.84s p=1.000 n=6
Check Time 49.36s (± 0.35%) 49.45s (± 0.17%) ~ 49.31s 49.56s p=0.298 n=6
Emit Time 3.94s (± 1.05%) 3.94s (± 2.29%) ~ 3.85s 4.05s p=1.000 n=6
Total Time 63.57s (± 0.39%) 63.69s (± 0.28%) ~ 63.47s 63.89s p=0.378 n=6
self-build-src-public-api - node (v18.15.0, x64)
Memory used 2,258,890k (± 0.03%) 2,258,853k (± 0.04%) ~ 2,257,367k 2,259,606k p=1.000 n=6
Parse Time 7.57s (± 0.79%) 7.56s (± 1.34%) ~ 7.44s 7.69s p=1.000 n=6
Bind Time 2.63s (± 1.31%) 2.64s (± 0.57%) ~ 2.61s 2.65s p=0.629 n=6
Check Time 53.02s (± 0.29%) 52.88s (± 0.33%) ~ 52.63s 53.09s p=0.230 n=6
Emit Time 4.24s (± 2.95%) 4.22s (± 2.70%) ~ 4.04s 4.34s p=0.810 n=6
Total Time 67.47s (± 0.32%) 67.31s (± 0.13%) ~ 67.21s 67.44s p=0.228 n=6
self-compiler - node (v18.15.0, x64)
Memory used 419,487k (± 0.01%) 419,456k (± 0.01%) ~ 419,412k 419,505k p=0.128 n=6
Parse Time 2.75s (± 0.48%) 2.74s (± 0.43%) ~ 2.72s 2.75s p=0.491 n=6
Bind Time 1.07s (± 1.15%) 1.07s (± 1.02%) ~ 1.05s 1.08s p=0.487 n=6
Check Time 15.48s (± 0.22%) 15.45s (± 0.51%) ~ 15.32s 15.53s p=0.872 n=6
Emit Time 1.14s (± 1.06%) 1.15s (± 1.95%) ~ 1.13s 1.19s p=0.567 n=6
Total Time 20.43s (± 0.17%) 20.41s (± 0.36%) ~ 20.27s 20.48s p=1.000 n=6
vscode - node (v18.15.0, x64)
Memory used 2,908,094k (± 0.00%) 2,907,961k (± 0.00%) -133k (- 0.00%) 2,907,777k 2,908,075k p=0.030 n=6
Parse Time 15.89s (± 0.32%) 15.95s (± 0.57%) ~ 15.87s 16.08s p=0.373 n=6
Bind Time 5.07s (± 0.18%) 5.08s (± 0.27%) ~ 5.06s 5.09s p=0.562 n=6
Check Time 87.71s (± 0.29%) 87.98s (± 0.47%) ~ 87.34s 88.43s p=0.298 n=6
Emit Time 23.65s (± 0.68%) 25.15s (± 9.62%) ~ 23.49s 28.42s p=0.689 n=6
Total Time 132.31s (± 0.26%) 134.16s (± 2.12%) ~ 131.90s 137.93s p=0.336 n=6
webpack - node (v18.15.0, x64)
Memory used 409,092k (± 0.02%) 408,967k (± 0.02%) -125k (- 0.03%) 408,883k 409,057k p=0.031 n=6
Parse Time 4.79s (± 0.39%) 4.79s (± 0.66%) ~ 4.75s 4.84s p=0.517 n=6
Bind Time 2.06s (± 0.43%) 2.05s (± 0.79%) ~ 2.03s 2.07s p=0.563 n=6
Check Time 20.91s (± 0.21%) 20.82s (± 0.31%) -0.09s (- 0.44%) 20.73s 20.92s p=0.030 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 27.76s (± 0.22%) 27.66s (± 0.36%) -0.10s (- 0.37%) 27.57s 27.83s p=0.037 n=6
xstate - node (v18.15.0, x64)
Memory used 513,626k (± 0.02%) 513,535k (± 0.01%) ~ 513,469k 513,622k p=0.128 n=6
Parse Time 4.89s (± 0.57%) 4.90s (± 0.40%) ~ 4.88s 4.93s p=0.373 n=6
Bind Time 2.30s (± 0.64%) 2.32s (± 0.63%) ~ 2.29s 2.33s p=0.161 n=6
Check Time 4.31s (± 0.19%) 4.29s (± 0.54%) ~ 4.26s 4.32s p=0.089 n=6
Emit Time 0.11s (± 0.00%) 0.11s (± 0.00%) ~ 0.11s 0.11s p=1.000 n=6
Total Time 11.61s (± 0.14%) 11.62s (± 0.27%) ~ 11.59s 11.66s p=0.624 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)
  • 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)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the top 400 repos comparing main and refs/pull/58083/merge:

Everything looks good!

@Andarist
Copy link
Contributor

Andarist commented Apr 5, 2024

minimal repro case

interface ComponentOptions<Props> {
  setup?: (props: Props) => void;
  name?: string;
}

interface FunctionalComponent<P> {
  (props: P): void;
}

type ConcreteComponent<Props> =
  | ComponentOptions<Props>
  | FunctionalComponent<Props>;

type Component<Props = {}> = ConcreteComponent<Props>;

type WithInstallPlugin = { _prefix?: string };

export function withInstall<C extends Component, T extends WithInstallPlugin>(
  component: C | C[],
  target?: T,
): string {
  const componentWithInstall = (target ?? component) as T;
  const components = Array.isArray(component) ? component : [component];

  const { name } = components[0];
  if (name) {
    return name;
  }

  return "";
}

@ahejlsberg
Copy link
Member Author

@Andarist It is quite odd. Your example reproduces with the command-line compiler, but not in the IDE (VS Code). Meanwhile, this even shorter example reproduces in the IDE, but not with the command-line compiler:

type Foo = { x: number } | { toString: string | undefined };

function gg<T extends Foo>(x: T & { toString(): string | undefined }, foo: Foo) {
  foo.toString;  // Error, Property 'toString' does not exist on type 'Foo'
}

@Andarist
Copy link
Contributor

Andarist commented Apr 5, 2024

I was experiencing what I would assume to be out-of-order checking in the IDE so at some point I pasted the already slimmed down repro into the playground and continued there. Since it was a single file I could test it out quite reliably there - I didn't even run this with tsc though so I can't say how it behaved for me in this context.

Meanwhile, this even shorter example reproduces in the IDE, but not with the command-line compiler:

This is very strange 😅

@DanielRosenwasser
Copy link
Member

Maybe add each to both a compiler test and to a fourslash test?

@jakebailey
Copy link
Member

I've also had success testing these sorts of things via unit tests, e.g. src/testRunner/unittests/tsserver/inconsistentErrorInEditor.ts.

@DanielRosenwasser DanielRosenwasser added this to the TypeScript 5.4.5 milestone Apr 8, 2024
@DanielRosenwasser
Copy link
Member

I think it would be good to cherry-pick this into 5.4.5.

@jakebailey
Copy link
Member

Here's a fourslash test based on #58083 (comment) which fails before this PR but passes after:

/// <reference path="fourslash.ts" />

// @strict: true
// @lib: esnext

//// interface ComponentOptions<Props> {
////   setup?: (props: Props) => void;
////   name?: string;
//// }
//// 
//// interface FunctionalComponent<P> {
////   (props: P): void;
//// }
//// 
//// type ConcreteComponent<Props> =
////   | ComponentOptions<Props>
////   | FunctionalComponent<Props>;
//// 
//// type Component<Props = {}> = ConcreteComponent<Props>;
//// 
//// type WithInstallPlugin = { _prefix?: string };
//// 
//// 
//// /**/
//// export function withInstall<C extends Component, T extends WithInstallPlugin>(
////   component: C | C[],
////   target?: T,
//// ): string {
////   const componentWithInstall = (target ?? component) as T;
////   const components = Array.isArray(component) ? component : [component];
//// 
////   const { name } = components[0];
////   if (name) {
////     return name;
////   }
//// 
////   return "";
//// }

verify.noErrors();

goTo.marker();
edit.insert("type C = Component['name']");

verify.noErrors();

I'm observing the opposite of what @ahejlsberg is seeing, in that the above code fails in the editor for me but there's no errors when made into a compiler test. But I think it matches the original issue well enough to be a test for this PR, though.

@jakebailey
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 9, 2024

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

Command Status Results
pack this ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 9, 2024

Hey @jakebailey, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/161114/artifacts?artifactName=tgz&fileId=9B68AF666424C48FDD03893103FC608C0CE8D23B355DCBD9A3ACD1B5D60846E302&fileName=/typescript-5.5.0-insiders.20240409.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@5.5.0-pr-58083-15".;

@jakebailey
Copy link
Member

Confirmed that this test works just like the original issue in the playground; will push here since we want the patch out very shortly.

@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Apr 9, 2024
@jakebailey
Copy link
Member

@typescript-bot cherry-pick this to release-5.4

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 9, 2024

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

Command Status Results
cherry-pick this to release-5.4 ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

Hey, @jakebailey! I've created #58136 for you. This involved updating baselines; please check the diff.

@ahejlsberg ahejlsberg merged commit 53de336 into main Apr 9, 2024
25 checks passed
@ahejlsberg ahejlsberg deleted the fix58050 branch April 9, 2024 18:39
DanielRosenwasser pushed a commit that referenced this pull request Apr 9, 2024
…e-5.4 (#58136)

Co-authored-by: Anders Hejlsberg <andersh@microsoft.com>
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.

type assertions affect the type narrowing of the subsequent code
5 participants