Skip to content

Propagate the error any type in union and intersection construction - #58610

Merged
Wesley Wigham (weswigham) merged 3 commits into
microsoft:mainfrom
weswigham:propagate-error-type
May 23, 2024
Merged

Propagate the error any type in union and intersection construction#58610
Wesley Wigham (weswigham) merged 3 commits into
microsoft:mainfrom
weswigham:propagate-error-type

Conversation

@weswigham

Copy link
Copy Markdown
Member

You might not think this is the obvious fix for the issue, but it is! Type parameter constraints, when they see a non-error any, remap it to unknown (there are historical reasons for this). So by swallowing the error-any (and replacing it with a normal any), union and intersection construction resulted in the constraint calculation logic not witnessing the error type, and thus remapping the constraint (and, thus, making the constraint from the type node not match the cached constraint on the type parameter itself!)

This should also just behave a bit better with respect to follow on errors in some other cases, too.

Fixes#58598

@jakebailey

Copy link
Copy Markdown
Member

Is this at all related to #56429?

@weswigham

Copy link
Copy Markdown
MemberAuthor

It's related insofar as better error-type propagation often creates better behaviors for follow-on locations for us.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, some quibbles with formatting. And we should see how DT/top400 tests look.

includes & TypeFlags.IncludesWildcard ? wildcardType : anyType :
includes & TypeFlags.IncludesWildcard ? wildcardType :
includes & TypeFlags.IncludesError ? errorType : anyType :
unknownType;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These ternaries are officially off the chain now.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

🤷‍♀️ I just write the ternaries, I let the formatter figure out how it wants to indent them.

}
if (includes & TypeFlags.Any) {
return includes & TypeFlags.IncludesWildcard ? wildcardType : anyType;
return includes & TypeFlags.IncludesWildcard ? wildcardType : includes & TypeFlags.IncludesError ? errorType : anyType;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it would be nice to have multiple lines here

Comment threadsrc/compiler/types.ts
/** @internal */
Reserved1 = 1 << 29, // Used by union/intersection type construction
/** @internal */
Reserved2 = 1 << 30, // Used by union/intersection type construction

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

remind me, do we have 31 bits available?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In modern Node, yep, we do.

@jakebailey

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) test it

@typescript-bot

TypeScript Bot (typescript-bot) commented May 22, 2024

Copy link
Copy Markdown
Contributor

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

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

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey) Here are the results of running the user tests comparing main and refs/pull/58610/merge:

Something interesting changed - please have a look.

Details

effect

tsconfig.json

tsconfig.base.json

puppeteer

test/tsconfig.json

@typescript-bot

Copy link
Copy Markdown
Contributor

Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey)
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Compiler-Unions - node (v18.15.0, x64)
Errors3030~~~p=1.000 n=6
Symbols62,15462,154~~~p=1.000 n=6
Types50,24850,248~~~p=1.000 n=6
Memory used194,058k (± 1.03%)192,252k (± 0.03%)~192,187k192,365kp=0.230 n=6
Parse Time1.29s (± 1.27%)1.30s (± 1.26%)~1.27s1.31sp=0.321 n=6
Bind Time0.72s0.72s~~~p=1.000 n=6
Check Time9.55s (± 0.37%)9.57s (± 0.21%)~9.55s9.59sp=0.374 n=6
Emit Time2.63s (± 0.46%)2.63s (± 0.46%)~2.61s2.64sp=0.406 n=6
Total Time14.20s (± 0.30%)14.21s (± 0.28%)~14.16s14.26sp=0.468 n=6
angular-1 - node (v18.15.0, x64)
Errors55~~~p=1.000 n=6
Symbols944,110944,110~~~p=1.000 n=6
Types407,140407,140~~~p=1.000 n=6
Memory used1,222,050k (± 0.00%)1,222,075k (± 0.00%)~1,221,989k1,222,120kp=0.575 n=6
Parse Time6.79s (± 0.74%)6.82s (± 0.26%)~6.80s6.85sp=0.171 n=6
Bind Time1.88s (± 0.62%)1.88s (± 0.52%)~1.87s1.89sp=0.555 n=6
Check Time31.25s (± 0.25%)31.32s (± 0.49%)~31.11s31.50sp=0.471 n=6
Emit Time14.71s (± 0.38%)14.76s (± 0.33%)~14.71s14.83sp=0.296 n=6
Total Time54.64s (± 0.23%)54.78s (± 0.35%)~54.54s54.98sp=0.173 n=6
mui-docs - node (v18.15.0, x64)
Errors55~~~p=1.000 n=6
Symbols1,978,4041,978,450+46 (+ 0.00%)~~p=0.001 n=6
Types882,046882,062+16 (+ 0.00%)~~p=0.001 n=6
Memory used1,884,924k (± 0.00%)1,884,982k (± 0.00%)+58k (+ 0.00%)1,884,962k1,885,013kp=0.030 n=6
Parse Time6.77s (± 0.33%)6.76s (± 0.20%)~6.74s6.78sp=0.163 n=6
Bind Time2.29s (± 0.18%)2.24s (± 5.67%)~1.98s2.30sp=0.929 n=6
Check Time60.37s (± 0.60%)60.40s (± 0.24%)~60.21s60.59sp=0.336 n=6
Emit Time0.14s (± 2.88%)0.15s (± 3.52%)~0.14s0.15sp=0.112 n=6
Total Time69.57s (± 0.52%)69.53s (± 0.29%)~69.25s69.78sp=0.873 n=6
self-build-src - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,223,2621,223,286+24 (+ 0.00%)~~p=0.001 n=6
Types260,177260,185+8 (+ 0.00%)~~p=0.001 n=6
Memory used2,339,410k (± 0.03%)2,339,735k (± 0.04%)~2,338,837k2,341,091kp=0.630 n=6
Parse Time5.01s (± 1.07%)4.98s (± 0.78%)~4.93s5.04sp=0.261 n=6
Bind Time1.90s (± 0.80%)1.89s (± 1.09%)~1.86s1.91sp=0.511 n=6
Check Time33.86s (± 0.27%)33.84s (± 0.25%)~33.73s33.97sp=0.689 n=6
Emit Time2.68s (± 2.22%)2.65s (± 1.27%)~2.59s2.69sp=0.296 n=6
Total Time43.46s (± 0.27%)43.37s (± 0.30%)~43.21s43.53sp=0.298 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols1,223,2621,223,286+24 (+ 0.00%)~~p=0.001 n=6
Types260,177260,185+8 (+ 0.00%)~~p=0.001 n=6
Memory used2,415,130k (± 0.05%)2,440,419k (± 2.49%)~2,414,014k2,564,802kp=0.378 n=6
Parse Time6.29s (± 0.79%)6.23s (± 0.98%)~6.16s6.34sp=0.173 n=6
Bind Time2.05s (± 1.37%)2.05s (± 1.94%)~2.01s2.10sp=0.936 n=6
Check Time40.24s (± 0.27%)40.37s (± 0.47%)~40.13s40.62sp=0.298 n=6
Emit Time3.26s (± 3.08%)3.19s (± 1.64%)~3.13s3.26sp=0.229 n=6
Total Time51.83s (± 0.21%)51.86s (± 0.27%)~51.69s52.05sp=1.000 n=6
self-compiler - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols257,714257,716+2 (+ 0.00%)~~p=0.001 n=6
Types104,904104,906+2 (+ 0.00%)~~p=0.001 n=6
Memory used426,487k (± 0.01%)426,460k (± 0.01%)~426,412k426,522kp=0.229 n=6
Parse Time3.35s (± 0.70%)3.36s (± 0.64%)~3.33s3.39sp=0.803 n=6
Bind Time1.33s (± 0.39%)1.32s (± 0.48%)~1.31s1.33sp=0.091 n=6
Check Time17.93s (± 0.24%)17.95s (± 0.21%)~17.90s17.99sp=0.470 n=6
Emit Time1.36s (± 1.20%)1.37s (± 0.97%)~1.36s1.39sp=0.676 n=6
Total Time23.98s (± 0.16%)24.00s (± 0.19%)~23.93s24.05sp=0.520 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors3535~~~p=1.000 n=6
Symbols224,575224,575~~~p=1.000 n=6
Types93,78593,785~~~p=1.000 n=6
Memory used369,852k (± 0.03%)369,928k (± 0.02%)~369,822k370,036kp=0.173 n=6
Parse Time3.51s (± 0.95%)3.50s (± 1.09%)~3.47s3.56sp=0.687 n=6
Bind Time1.94s (± 0.65%)1.94s (± 0.73%)~1.92s1.96sp=1.000 n=6
Check Time19.35s (± 0.31%)19.35s (± 0.28%)~19.30s19.45sp=0.936 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time24.80s (± 0.30%)24.79s (± 0.39%)~24.69s24.94sp=0.810 n=6
vscode - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols2,834,8182,834,818~~~p=1.000 n=6
Types960,647960,647~~~p=1.000 n=6
Memory used3,006,755k (± 0.00%)3,006,791k (± 0.00%)~3,006,729k3,006,862kp=0.336 n=6
Parse Time13.82s (± 0.21%)13.81s (± 0.21%)~13.77s13.85sp=0.808 n=6
Bind Time4.17s (± 0.38%)4.26s (± 2.71%)~4.14s4.38sp=0.625 n=6
Check Time76.46s (± 1.99%)75.26s (± 2.95%)~73.10s77.62sp=0.575 n=6
Emit Time20.21s (± 7.55%)21.62s (± 9.75%)~19.56s23.81sp=0.092 n=6
Total Time114.66s (± 0.07%)114.95s (± 0.26%)+0.29s (+ 0.26%)114.61s115.47sp=0.045 n=6
webpack - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols266,087266,087~~~p=1.000 n=6
Types108,518108,518~~~p=1.000 n=6
Memory used410,844k (± 0.01%)410,861k (± 0.03%)~410,770k411,095kp=0.810 n=6
Parse Time3.84s (± 0.92%)3.83s (± 0.71%)~3.79s3.86sp=0.871 n=6
Bind Time1.66s (± 1.30%)1.66s (± 0.89%)~1.64s1.68sp=0.684 n=6
Check Time16.89s (± 0.35%)16.94s (± 0.29%)~16.87s16.99sp=0.107 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time22.39s (± 0.30%)22.44s (± 0.20%)~22.36s22.49sp=0.298 n=6
xstate-main - node (v18.15.0, x64)
Errors00~~~p=1.000 n=6
Symbols524,654524,654~~~p=1.000 n=6
Types178,920178,920~~~p=1.000 n=6
Memory used462,683k (± 0.01%)462,685k (± 0.02%)~462,582k462,891kp=0.810 n=6
Parse Time3.88s (± 0.53%)3.89s (± 0.68%)~3.86s3.92sp=0.870 n=6
Bind Time1.44s (± 1.16%)1.44s (± 1.13%)~1.42s1.46sp=0.743 n=6
Check Time22.54s (± 0.77%)22.44s (± 0.70%)~22.23s22.60sp=0.226 n=6
Emit Time0.00s0.00s~~~p=1.000 n=6
Total Time27.87s (± 0.59%)27.77s (± 0.45%)~27.60s27.92sp=0.173 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)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

@weswigham

Copy link
Copy Markdown
MemberAuthor

TypeScript Bot (@typescript-bot) pack this

@typescript-bot

TypeScript Bot (typescript-bot) commented May 22, 2024

Copy link
Copy Markdown
Contributor

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

CommandStatusResults
pack this✅ Started✅ Results

@typescript-bot

TypeScript Bot (typescript-bot) commented May 22, 2024

Copy link
Copy Markdown
Contributor

Hey Wesley Wigham (@weswigham), 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/161864/artifacts?artifactName=tgz&fileId=BF2ED1BFDABF4FEABBEC62B88D698F99B6AF1D9CAF9649FC65736C9D6381C1D002&fileName=/typescript-5.5.0-insiders.20240522.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-58610-9".;

@typescript-bot

Copy link
Copy Markdown
Contributor

Jake Bailey (@jakebailey) Here are the results of running the top 400 repos comparing main and refs/pull/58610/merge:

Something interesting changed - please have a look.

Details

nextauthjs/next-auth

18 of 40 projects failed to build with the old tsc and were ignored

docs/tsconfig.json

@weswigham

Wesley Wigham (weswigham) commented May 22, 2024

Copy link
Copy Markdown
MemberAuthor

TypeScript Bot (@typescript-bot) user test this

@typescript-bot

TypeScript Bot (typescript-bot) commented May 22, 2024

Copy link
Copy Markdown
Contributor

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

CommandStatusResults
user test this✅ Started👀 Results

@typescript-bot

Copy link
Copy Markdown
Contributor

Wesley Wigham (@weswigham) Here are the results of running the user tests comparing main and refs/pull/58610/merge:

Something interesting changed - please have a look.

Details

effect

tsconfig.json

tsconfig.base.json

puppeteer

test/tsconfig.json

@weswigham

Wesley Wigham (weswigham) commented May 22, 2024

Copy link
Copy Markdown
MemberAuthor

Something is funky with Effect-TS in the user harness - the runner shows thousands of errors in the log (Error counts for https://github.com/Effect-TS/effect/blob/e3766411b60ebb45d31e9c9d94efa099121d4d58/tsconfig.json: new = 4804, old = 4775). When you download, install, and build it locally (the same version linked in the log), even with this PR, it's not nearly that bad - 13 errors across all projects, none of them are the ones listed here.

Jake Bailey (@jakebailey) is the runner silently failing to install/link dependencies correctly for that user test or something? That's the only thing I could think of, which is why I reran the test. And it would make sense - these kinda of errors are what I'd expect to see if some intersections in class base types contained unresolved types that now get propagated out (instead of quietly any'd). Error types in class base types make the class's base types get set to nothing, rather than any.

@jakebailey

Copy link
Copy Markdown
Member

The test thing infers packages and tsconfigs and attempts to install them and run on each of them, so it's possible that it's just doing things "wrong" for that repo. We can convert it to a script test or something where it more clearly tries to run things, but we'll lose the inference of configs and such. I'm not sure I have the time to try and fix the root problem, though.

@weswigham

Wesley Wigham (weswigham) commented May 22, 2024

Copy link
Copy Markdown
MemberAuthor

The project does have one diff in the real output - a new error - but it's a follow-on caused by what I said above - a class has an error type intersected into its' base types, so all its' base types get erased now, rather than any'd (which is what should happen and would happen if the error was the single base type rather than an intersection member already). And the root error is creeping in because the project has skipLibCheck on, so isn't aware that the types for one of its' transitive deps is just straight up missing. (Specifically, packages/sql-mysql2 depends on an external mysql2, which depends on events and stream, which are presumably supposed to be provided by @types/node, but aren't because the project doesn't include @types/node!)

Big downside of using skipLibCheck - you don't get any errors for a missing environment! Though I can see why they enable it - they have a metric ton of straight up broken deps.

@weswigham

Copy link
Copy Markdown
MemberAuthor

Useful investigation regardless, even if there wasn't really much related to this issue, disabling skipLibCheck in it pointed out this regression that I've opened an issue for.

@weswigham
Wesley Wigham (weswigham) merged commit b3f3bb3 into microsoft:mainMay 23, 2024
@weswigham
Wesley Wigham (weswigham) deleted the propagate-error-type branch May 23, 2024 16:39
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: TeamFor Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[transpileDeclaration API][5.5] Self referencing generic type constraint with union gets emitted as unknown

4 participants

@weswigham@jakebailey@typescript-bot@sandersn