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

Intl.NumberFormat: Add latest options, fix previous library discrepancies #56902

Merged
merged 23 commits into from
Mar 1, 2024

Conversation

Renegade334
Copy link
Contributor

@Renegade334 Renegade334 commented Dec 30, 2023

Fixes #56269
Fixes #52072
Fixes #43336

  • A few historic deviations from the relevant versions of the Intl specification have been addressed.
  • The latest changes are based on ECMA-402 10.0, which accompanied the ECMAScript 2023 language specification. Accordingly, I've created a new es2023.intl to house them. The declarations currently residing in esnext.intl were also from the same version of the spec, so I've moved these across as well.
  • Properties originally typed as string, but defined in the spec as a union of string literals, have been narrowed accordingly. Where the range of acceptable values for a string literal type have been expanded in subsequent versions of the spec, the types are now defined as keyof <RegistryInterface> in order to make them extensible, as per precedent. This is technically breaking, and will likely need to be tested against high-exposure libraries for side-effects.
  • useGrouping is a bit of a mess, as the property's primitive type was changed in version 10. The inclusion of "true" and "false" as acceptable values in the es2023 implementation is intentional, as per the specification.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Dec 30, 2023
@Renegade334 Renegade334 changed the title Intl numberformat Intl.NumberFormat: Add latest options, fix previous library discrepancies Dec 30, 2023
src/lib/es5.d.ts Outdated Show resolved Hide resolved
@Renegade334
Copy link
Contributor Author

This should be ready for review.

Context for some less-obvious changes:

  • lib.es5
    • NumberFormatOptionsUseGrouping and ResolvedNumberFormatOptionsUseGrouping are typed conditionally. This is to satisfy the following change in the v10 spec:
      type NumberFormatOptionsUseGrouping =
      /* es5    */ boolean;
      /* es2023 */ keyof NumberFormatOptionsUseGroupingRegistry | "true" | "false" | boolean;
      type ResolvedNumberFormatOptionsUseGrouping =
      /* es5    */ boolean;
      /* es2023 */ keyof NumberFormatOptionsUseGroupingRegistry | false;
      Tests under conformance/es2023 confirm these to be working appropriately.
  • lib.es2018.intl
    • The values "code", "symbol" and "name" were previously erroneously included in NumberFormatPartTypes; this was likely a misreading of the specification.
  • lib.es2020.intl
    • Changing the notation and signDisplay properties of ResolvedNumberFormatOptions from optional to required is an intentional change.
  • tests
    • The tests included in formatToPartsBigInt were already included under bigIntWithLib, hence its removal.
    • DateTimeFormatAndNumberFormatES2021 tested for NumberFormat methods that didn't exist in ES2021, and the baseline for this test contained errors accordingly. The test scope has been narrowed to DateTimeFormat and moved to conformance/es2021, while testing NumberFormat#formatRange has been moved to conformance/es2023.

I'd be grateful if someone could run top100/dt when convenient.

@Renegade334 Renegade334 marked this pull request as ready for review January 2, 2024 11:04
@typescript-bot
Copy link
Collaborator

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@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
@typescript-bot
Copy link
Collaborator

typescript-bot commented Jan 4, 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/159246/artifacts?artifactName=tgz&fileId=576D53D334DC37587E8C3B2DF7A4DA90B4DE69F90ABC032E783942C033EC773D02&fileName=/typescript-5.4.0-insiders.20240104.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.4.0-pr-56902-8".;

@typescript-bot
Copy link
Collaborator

@jakebailey
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,465k (± 0.02%) 295,506k (± 0.01%) ~ 295,445k 295,563k p=0.173 n=6
Parse Time 2.65s (± 0.21%) 2.65s (± 0.15%) ~ 2.64s 2.65s p=0.282 n=6
Bind Time 0.82s (± 0.50%) 0.82s (± 0.50%) ~ 0.81s 0.82s p=0.218 n=6
Check Time 8.17s (± 0.34%) 8.15s (± 0.51%) ~ 8.11s 8.22s p=0.171 n=6
Emit Time 7.11s (± 0.41%) 7.10s (± 0.33%) ~ 7.07s 7.14s p=0.517 n=6
Total Time 18.75s (± 0.29%) 18.71s (± 0.29%) ~ 18.66s 18.78s p=0.195 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 193,494k (± 1.57%) 193,498k (± 1.56%) ~ 191,490k 197,407k p=0.471 n=6
Parse Time 1.34s (± 0.87%) 1.35s (± 0.94%) ~ 1.33s 1.37s p=0.245 n=6
Bind Time 0.72s (± 0.00%) 0.72s (± 0.00%) ~ 0.72s 0.72s p=1.000 n=6
Check Time 9.26s (± 0.33%) 9.26s (± 0.48%) ~ 9.19s 9.30s p=1.000 n=6
Emit Time 2.61s (± 0.29%) 2.61s (± 0.40%) ~ 2.60s 2.63s p=0.611 n=6
Total Time 13.93s (± 0.20%) 13.95s (± 0.27%) ~ 13.90s 13.98s p=0.517 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,406k (± 0.00%) 347,400k (± 0.01%) ~ 347,362k 347,425k p=0.936 n=6
Parse Time 2.46s (± 0.48%) 2.46s (± 0.51%) ~ 2.44s 2.47s p=0.801 n=6
Bind Time 0.92s (± 0.59%) 0.93s (± 0.44%) ~ 0.92s 0.93s p=0.282 n=6
Check Time 6.87s (± 0.36%) 6.89s (± 0.38%) ~ 6.87s 6.94s p=0.286 n=6
Emit Time 4.06s (± 0.39%) 4.06s (± 0.30%) ~ 4.04s 4.07s p=0.803 n=6
Total Time 14.31s (± 0.23%) 14.33s (± 0.14%) ~ 14.31s 14.36s p=0.220 n=6
TFS - node (v18.15.0, x64)
Memory used 302,730k (± 0.00%) 302,733k (± 0.01%) ~ 302,704k 302,754k p=0.936 n=6
Parse Time 1.99s (± 0.84%) 2.01s (± 1.16%) ~ 1.98s 2.04s p=0.118 n=6
Bind Time 1.00s (± 0.41%) 1.00s (± 1.17%) ~ 0.99s 1.02s p=0.584 n=6
Check Time 6.32s (± 0.29%) 6.29s (± 0.50%) ~ 6.26s 6.33s p=0.140 n=6
Emit Time 3.58s (± 0.42%) 3.59s (± 0.45%) ~ 3.57s 3.61s p=0.934 n=6
Total Time 12.89s (± 0.14%) 12.89s (± 0.14%) ~ 12.86s 12.91s p=0.685 n=6
material-ui - node (v18.15.0, x64)
Memory used 506,833k (± 0.01%) 506,830k (± 0.01%) ~ 506,800k 506,872k p=0.936 n=6
Parse Time 2.58s (± 0.45%) 2.58s (± 0.32%) ~ 2.58s 2.60s p=0.547 n=6
Bind Time 1.00s (± 0.84%) 0.99s (± 0.76%) ~ 0.98s 1.00s p=0.209 n=6
Check Time 16.97s (± 0.51%) 16.95s (± 0.48%) ~ 16.83s 17.03s 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 20.55s (± 0.39%) 20.52s (± 0.39%) ~ 20.42s 20.60s p=0.872 n=6
xstate - node (v18.15.0, x64)
Memory used 512,867k (± 0.01%) 512,971k (± 0.01%) +104k (+ 0.02%) 512,925k 513,053k p=0.013 n=6
Parse Time 3.27s (± 0.30%) 3.28s (± 0.31%) ~ 3.26s 3.29s p=0.203 n=6
Bind Time 1.54s (± 0.36%) 1.54s (± 0.27%) ~ 1.53s 1.54s p=0.282 n=6
Check Time 2.81s (± 1.20%) 2.84s (± 0.35%) ~ 2.83s 2.85s p=0.102 n=6
Emit Time 0.07s (± 0.00%) 0.07s (± 5.69%) ~ 0.07s 0.08s p=0.405 n=6
Total Time 7.70s (± 0.37%) 7.73s (± 0.17%) ~ 7.71s 7.75s p=0.062 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,348ms (± 0.66%) 2,344ms (± 0.74%) ~ 2,319ms 2,367ms p=0.936 n=6
Req 2 - geterr 5,393ms (± 0.57%) 5,410ms (± 1.16%) ~ 5,364ms 5,531ms p=1.000 n=6
Req 3 - references 324ms (± 1.14%) 324ms (± 1.15%) ~ 320ms 329ms p=0.746 n=6
Req 4 - navto 277ms (± 0.42%) 275ms (± 1.01%) ~ 270ms 277ms p=0.079 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 86ms (± 3.20%) 86ms (± 6.81%) ~ 79ms 94ms p=0.864 n=6
CompilerTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,471ms (± 0.98%) 2,489ms (± 1.11%) ~ 2,445ms 2,523ms p=0.230 n=6
Req 2 - geterr 4,183ms (± 2.02%) 4,166ms (± 2.15%) ~ 4,079ms 4,262ms p=0.575 n=6
Req 3 - references 335ms (± 1.13%) 337ms (± 1.17%) ~ 332ms 343ms p=0.293 n=6
Req 4 - navto 286ms (± 1.14%) 284ms (± 0.52%) ~ 282ms 286ms p=0.807 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 81ms (± 7.36%) 84ms (± 7.55%) ~ 75ms 90ms p=0.520 n=6
xstateTSServer - node (v18.15.0, x64)
Req 1 - updateOpen 2,602ms (± 0.93%) 2,592ms (± 0.75%) ~ 2,564ms 2,610ms p=0.261 n=6
Req 2 - geterr 1,726ms (± 1.87%) 1,707ms (± 2.15%) ~ 1,672ms 1,763ms p=0.575 n=6
Req 3 - references 106ms (± 7.58%) 109ms (± 9.53%) ~ 101ms 123ms p=0.868 n=6
Req 4 - navto 364ms (± 1.02%) 366ms (± 0.14%) ~ 365ms 366ms p=0.070 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.72%) 305ms (± 1.83%) ~ 296ms 312ms p=0.170 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.69ms (± 0.21%) 153.59ms (± 0.20%) -0.10ms (- 0.07%) 152.45ms 156.75ms p=0.005 n=600
tsserver-startup - node (v18.15.0, x64)
Execution time 228.69ms (± 0.16%) 228.46ms (± 0.15%) -0.23ms (- 0.10%) 227.05ms 231.45ms p=0.000 n=600
tsserverlibrary-startup - node (v18.15.0, x64)
Execution time 230.23ms (± 0.18%) 230.33ms (± 0.19%) +0.11ms (+ 0.05%) 228.41ms 233.50ms p=0.024 n=600
typescript-startup - node (v18.15.0, x64)
Execution time 230.60ms (± 0.19%) 230.49ms (± 0.18%) -0.10ms (- 0.04%) 228.91ms 234.79ms p=0.011 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

@jakebailey Here are the results of running the user test suite comparing main and refs/pull/56902/merge:

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Package install failed"

Otherwise...

Something interesting changed - please have a look.

Details

puppeteer

packages/browsers/test/src/tsconfig.json

@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 Here are the results of running the top-repos suite comparing main and refs/pull/56902/merge:

Everything looks good!

@sandersn sandersn self-requested a review January 24, 2024 21:57
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

I think this is good to go, although I'd like to wait until after the beta.

The only question I have is about any as the property type for registries. Everything else is notes for myself about the combined members of registries.

src/lib/es2018.intl.d.ts Outdated Show resolved Hide resolved
@@ -37,10 +37,22 @@ declare namespace Intl {

const PluralRules: PluralRulesConstructor;

// We can only have one definition for 'type' in TypeScript, and so you can learn where the keys come from here:
type ES2018NumberFormatPartType = "literal" | "nan" | "infinity" | "percent" | "integer" | "group" | "decimal" | "fraction" | "plusSign" | "minusSign" | "percentSign" | "currency" | "code" | "symbol" | "name";
Copy link
Member

Choose a reason for hiding this comment

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

NumberFormatPartTypeRegistry

ES2018

  • literal
  • nan
  • infinity
  • percent
  • integer
  • group
  • decimal
  • fraction
  • plusSign
  • minusSign
  • percentSign
  • currency

ES2020

  • compact
  • exponentInteger
  • exponentMinusSign
  • exponentSeparator
  • unit
  • unknown

@@ -705,6 +705,5 @@ interface DataView {
declare namespace Intl {
interface NumberFormat {
format(value: number | bigint): string;
resolvedOptions(): ResolvedNumberFormatOptions;
Copy link
Member

Choose a reason for hiding this comment

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

duplicated with entry in es5, doesn't need to be here

exceptZero: any;
}

type NumberFormatOptionsSignDisplay = keyof NumberFormatOptionsSignDisplayRegistry;
Copy link
Member

Choose a reason for hiding this comment

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

ES2020

  • auto
  • never
  • always
  • exceptZero

ES2023

  • negative

currency: any;
}

type NumberFormatOptionsStyle = keyof NumberFormatOptionsStyleRegistry;
Copy link
Member

Choose a reason for hiding this comment

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

ES5

  • decimal
  • percent
  • currency

ES2020

  • unit

name: any;
}

type NumberFormatOptionsCurrencyDisplay = keyof NumberFormatOptionsCurrencyDisplayRegistry;
Copy link
Member

Choose a reason for hiding this comment

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

ES5

  • code
  • symbol
  • name

ES2020

  • narrowSymbol


type NumberFormatOptionsCurrencyDisplay = keyof NumberFormatOptionsCurrencyDisplayRegistry;

interface NumberFormatOptionsUseGroupingRegistry {}
Copy link
Member

Choose a reason for hiding this comment

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

ES2023

  • min2
  • auto
  • always

@sandersn sandersn self-assigned this Feb 1, 2024
@Renegade334
Copy link
Contributor Author

Renegade334 commented Feb 2, 2024

Updated the registry interfaces as discussed.

I've also included one other minor change. The defined behaviour of the resolved options {minimum,maximum}FractionDigits changed subtly in v10: whereas these properties were always included under ResolvedNumberFormatOptions in previous versions, they're now omitted under certain circumstances. For simplicity, these are now typed as optional throughout. Although unlikely to break anything, this probably warrants re-running the test suite.

@sandersn
Copy link
Member

@typescript-bot test top200
@typescript-bot user test this
@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 16, 2024

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 16, 2024

Heya @sandersn, I've started to run the diff-based user code test suite on this PR at 254a8ce. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 16, 2024

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@sandersn Here are the results of running the user test suite comparing main and refs/pull/56902/merge:

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Package install failed"

Otherwise...

Something interesting changed - please have a look.

Details

puppeteer

packages/browsers/test/src/tsconfig.json

@typescript-bot
Copy link
Collaborator

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

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@felixfbecker
Copy link
Contributor

Can't wait for this to land!

@sandersn sandersn merged commit 877d9d3 into microsoft:main Mar 1, 2024
19 checks passed
sandersn added a commit to sandersn/TypeScript that referenced this pull request Mar 1, 2024
I forgot to check whether CI had run recently when I merged, and this PR
adds a new section to every resolution trace baseline.
sandersn added a commit that referenced this pull request Mar 1, 2024
@Renegade334 Renegade334 deleted the intl-numberformat branch March 2, 2024 18:31
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
5 participants