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 enforce export/declare overload modifier consistency across module augmentations #59416

Merged
merged 4 commits into from
Jul 29, 2024

Conversation

andrewbranch
Copy link
Member

@andrewbranch andrewbranch commented Jul 24, 2024

Fixes #58756

These rules are only there because it looks confusing to have overload declarations like

// what does this mean??
declare function foo(): any;
function foo(s: number): string;
export declare function foo(s: string): number;

But if the overloads came from a module augmentation, it's reasonable for them to have different modifiers (see code comment and tests for the differences that are allowed).

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Jul 24, 2024
@andrewbranch
Copy link
Member Author

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 25, 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 @andrewbranch, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@gabritto
Copy link
Member

I feel like I don't have a good understanding of the old behavior to be able to assess the new one. Why was the old behavior in place? What are the bad scenarios we're trying to avoid, exactly?

@typescript-bot
Copy link
Collaborator

@andrewbranch
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 30 30 ~ ~ ~ p=1.000 n=6
Symbols 62,153 62,153 ~ ~ ~ p=1.000 n=6
Types 50,242 50,242 ~ ~ ~ p=1.000 n=6
Memory used 193,638k (± 0.92%) 192,326k (± 0.01%) -1,313k (- 0.68%) 192,305k 192,353k p=0.037 n=6
Parse Time 1.30s (± 1.33%) 1.31s (± 0.62%) ~ 1.30s 1.32s p=0.402 n=6
Bind Time 0.71s 0.71s ~ ~ ~ p=1.000 n=6
Check Time 9.56s (± 0.33%) 9.58s (± 0.35%) ~ 9.52s 9.62s p=0.421 n=6
Emit Time 2.74s (± 0.64%) 2.73s (± 0.43%) ~ 2.72s 2.75s p=0.164 n=6
Total Time 14.31s (± 0.26%) 14.32s (± 0.22%) ~ 14.27s 14.35s p=0.520 n=6
angular-1 - node (v18.15.0, x64)
Errors 7 7 ~ ~ ~ p=1.000 n=6
Symbols 945,532 945,532 ~ ~ ~ p=1.000 n=6
Types 409,507 409,507 ~ ~ ~ p=1.000 n=6
Memory used 1,221,148k (± 0.00%) 1,221,137k (± 0.00%) ~ 1,221,086k 1,221,174k p=0.689 n=6
Parse Time 6.60s (± 0.83%) 6.60s (± 0.49%) ~ 6.56s 6.64s p=0.936 n=6
Bind Time 1.86s (± 0.44%) 1.86s (± 0.45%) ~ 1.84s 1.86s p=0.673 n=6
Check Time 31.08s (± 0.34%) 31.15s (± 0.26%) ~ 31.04s 31.24s p=0.230 n=6
Emit Time 15.03s (± 0.90%) 15.03s (± 0.41%) ~ 14.96s 15.11s p=0.688 n=6
Total Time 54.56s (± 0.42%) 54.63s (± 0.20%) ~ 54.49s 54.77s p=0.336 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,433,165 2,433,165 ~ ~ ~ p=1.000 n=6
Types 1,002,715 1,002,715 ~ ~ ~ p=1.000 n=6
Memory used 2,424,292k (± 0.00%) 2,424,237k (± 0.00%) ~ 2,424,184k 2,424,307k p=0.065 n=6
Parse Time 8.43s (± 0.33%) 8.43s (± 0.28%) ~ 8.40s 8.46s p=0.807 n=6
Bind Time 2.09s (± 0.36%) 2.08s (± 0.47%) ~ 2.07s 2.09s p=0.300 n=6
Check Time 74.64s (± 0.56%) 74.52s (± 0.44%) ~ 74.10s 74.91s p=0.688 n=6
Emit Time 0.28s (± 1.47%) 0.28s (± 1.99%) ~ 0.27s 0.28s p=0.282 n=6
Total Time 85.43s (± 0.47%) 85.30s (± 0.37%) ~ 84.89s 85.68s p=0.688 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,230,046 1,230,085 +39 (+ 0.00%) ~ ~ p=0.001 n=6
Types 265,645 265,653 +8 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,347,399k (± 0.01%) 2,347,135k (± 0.01%) ~ 2,346,802k 2,347,640k p=0.173 n=6
Parse Time 5.02s (± 0.60%) 4.99s (± 0.87%) ~ 4.94s 5.04s p=0.336 n=6
Bind Time 1.90s (± 0.21%) 1.89s (± 0.54%) ~ 1.88s 1.90s p=0.114 n=6
Check Time 34.70s (± 0.14%) 34.71s (± 0.25%) ~ 34.61s 34.82s p=0.936 n=6
Emit Time 3.31s (± 0.47%) 3.29s (± 0.95%) ~ 3.25s 3.33s p=0.261 n=6
Total Time 44.93s (± 0.18%) 44.90s (± 0.29%) ~ 44.76s 45.11s p=0.378 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,230,046 1,230,085 +39 (+ 0.00%) ~ ~ p=0.001 n=6
Types 265,645 265,653 +8 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,422,113k (± 0.03%) 2,421,618k (± 0.03%) ~ 2,420,523k 2,422,469k p=0.378 n=6
Parse Time 6.21s (± 0.67%) 6.22s (± 0.94%) ~ 6.14s 6.29s p=0.575 n=6
Bind Time 2.05s (± 0.60%) 2.04s (± 0.48%) ~ 2.03s 2.05s p=0.286 n=6
Check Time 41.41s (± 0.29%) 41.46s (± 0.33%) ~ 41.34s 41.72s p=0.575 n=6
Emit Time 4.00s (± 1.42%) 4.04s (± 0.92%) ~ 3.98s 4.07s p=0.298 n=6
Total Time 53.70s (± 0.34%) 53.78s (± 0.32%) ~ 53.61s 54.09s p=0.470 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 258,471 258,510 +39 (+ 0.02%) ~ ~ p=0.001 n=6
Types 105,534 105,542 +8 (+ 0.01%) ~ ~ p=0.001 n=6
Memory used 429,159k (± 0.03%) 429,096k (± 0.01%) ~ 429,057k 429,126k p=0.575 n=6
Parse Time 4.16s (± 0.62%) 4.16s (± 0.47%) ~ 4.14s 4.19s p=1.000 n=6
Bind Time 1.64s (± 1.00%) 1.63s (± 1.29%) ~ 1.61s 1.66s p=0.516 n=6
Check Time 22.27s (± 0.55%) 22.27s (± 0.30%) ~ 22.16s 22.35s p=0.471 n=6
Emit Time 2.01s (± 0.81%) 2.01s (± 1.31%) ~ 1.97s 2.04s p=1.000 n=6
Total Time 30.08s (± 0.53%) 30.07s (± 0.27%) ~ 29.93s 30.15s p=0.630 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 35 35 ~ ~ ~ p=1.000 n=6
Symbols 224,931 224,931 ~ ~ ~ p=1.000 n=6
Types 94,146 94,146 ~ ~ ~ p=1.000 n=6
Memory used 369,957k (± 0.01%) 370,039k (± 0.03%) ~ 369,895k 370,134k p=0.230 n=6
Parse Time 2.77s (± 0.87%) 2.78s (± 0.54%) ~ 2.76s 2.79s p=0.511 n=6
Bind Time 1.60s (± 1.00%) 1.59s (± 0.86%) ~ 1.57s 1.61s p=0.251 n=6
Check Time 15.64s (± 0.36%) 15.71s (± 0.24%) ~ 15.66s 15.76s p=0.054 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.01s (± 0.32%) 20.07s (± 0.18%) ~ 20.01s 20.11s p=0.077 n=6
vscode - node (v18.15.0, x64)
Errors 11 11 ~ ~ ~ p=1.000 n=6
Symbols 2,986,389 2,986,389 ~ ~ ~ p=1.000 n=6
Types 1,027,251 1,027,251 ~ ~ ~ p=1.000 n=6
Memory used 3,110,393k (± 0.00%) 3,110,447k (± 0.00%) ~ 3,110,409k 3,110,493k p=0.066 n=6
Parse Time 13.83s (± 0.29%) 13.84s (± 0.14%) ~ 13.81s 13.86s p=0.871 n=6
Bind Time 4.29s (± 2.34%) 4.37s (± 2.61%) ~ 4.25s 4.48s p=0.250 n=6
Check Time 78.84s (± 0.55%) 78.51s (± 0.37%) ~ 78.08s 78.88s p=0.173 n=6
Emit Time 20.39s (± 0.49%) 20.41s (± 0.42%) ~ 20.30s 20.51s p=0.747 n=6
Total Time 117.35s (± 0.44%) 117.12s (± 0.20%) ~ 116.85s 117.44s p=0.575 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 267,560 267,560 ~ ~ ~ p=1.000 n=6
Types 109,076 109,076 ~ ~ ~ p=1.000 n=6
Memory used 412,428k (± 0.02%) 412,405k (± 0.01%) ~ 412,381k 412,435k p=0.575 n=6
Parse Time 3.82s (± 0.52%) 3.82s (± 0.49%) ~ 3.79s 3.84s p=0.684 n=6
Bind Time 1.71s (± 0.30%) 1.71s (± 0.37%) ~ 1.70s 1.72s p=0.386 n=6
Check Time 16.88s (± 0.21%) 16.83s (± 0.25%) ~ 16.77s 16.88s p=0.089 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 22.41s (± 0.19%) 22.36s (± 0.19%) ~ 22.30s 22.43s p=0.126 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 511,803 511,803 ~ ~ ~ p=1.000 n=6
Types 162,088 162,088 ~ ~ ~ p=1.000 n=6
Memory used 449,272k (± 0.07%) 448,989k (± 0.08%) ~ 448,627k 449,384k p=0.128 n=6
Parse Time 3.90s (± 0.53%) 3.90s (± 0.72%) ~ 3.87s 3.94s p=1.000 n=6
Bind Time 1.44s (± 1.11%) 1.44s (± 0.95%) ~ 1.42s 1.46s p=1.000 n=6
Check Time 21.21s (± 0.37%) 21.28s (± 0.43%) ~ 21.20s 21.41s p=0.226 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 26.55s (± 0.22%) 26.62s (± 0.29%) ~ 26.53s 26.69s p=0.090 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

@andrewbranch
Copy link
Member Author

Stating my understanding, but I might have some of the details wrong. AFAIK, overloads are additional declarations of the same method/function symbol. Since there’s ultimately only one merged symbol, all these modifiers necessarily apply uniformly to the symbol. We don’t really have mechanisms in place to reason about what it would mean for some signatures to be exported while others aren’t. And the presence or absence of declare on an overload signature doesn’t really have any meaning at all, since overloads aren’t a runtime/emitting construct anyway. So I think the rules are in place because the mixing of modifiers like

export function foo(x: T1): T2;
export function foo(x: T3): T4;
       function foo(x: T5): T6;
export function foo(x: any): any {
  // ...
}

looks like it might make the third overload file-local, but there’s actually nothing in place to make that happen, so we want to enforce consistency in the modifiers.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@andrewbranch andrewbranch merged commit 9405f21 into microsoft:main Jul 29, 2024
32 checks passed
@andrewbranch andrewbranch deleted the bug/58756 branch July 29, 2024 16:20
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
Status: Done
Development

Successfully merging this pull request may close these issues.

Can't augment function overload is function is exported via export {}
3 participants