Skip to content

Bail on 0- and 1-length lists in removeSubtypes to avoid spurious circularity problems - #46981

Merged
Ryan Cavanaugh (RyanCavanaugh) merged 4 commits into
microsoft:mainfrom
RyanCavanaugh:fix46939
Mar 8, 2022
Merged

Bail on 0- and 1-length lists in removeSubtypes to avoid spurious circularity problems#46981
Ryan Cavanaugh (RyanCavanaugh) merged 4 commits into
microsoft:mainfrom
RyanCavanaugh:fix46939

Conversation

@RyanCavanaugh

@RyanCavanaughRyan Cavanaugh (RyanCavanaugh) commented Dec 1, 2021

Copy link
Copy Markdown
Member

Creates a reasonable workaround for #46939

Another example for illustration:

typeBox={content?: Foo};declareconstb: Box;classFoo{getfoo(){return{content: thisasFoo,
...b};}}

When resolving the type of Foo#foo, we need to compute the type of the object literal in the return position. This has two parts: the content from the content: property (type Foo), and the content property from type Box (which is Foo | missing).

We want the type of content here to be subtype-reduced when creating the union of the two possible constituents, Foo and Foo. That list gets deduped in getUnionType to just [Foo], then passed to removeSubTypes, which computes this value ahead of the while loop below it which in reality runs zero iterations:

consthasEmptyObject=hasObjectTypes&&some(types,t=>!!(t.flags&TypeFlags.Object)&&!isGenericMappedType(t)&&isEmptyResolvedType(resolveStructuredTypeMembers(tasObjectType)));

That call to resolveStructuredTypeMembers attempts to resolve the type of Foo#foo, triggering a circularity even though none actually exists.

Instead we can just bail out earlier in the function, saving time (I hope?) and avoiding this computation until later when doing so won't introduce a circularity.

@typescript-botTypeScript Bot (typescript-bot) added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Dec 1, 2021
@RyanCavanaughRyan Cavanaugh (RyanCavanaugh) changed the title Bail on 1-length lists in removeSubtypes to avoid spurious circularity problemsBail on 0- and 1-length lists in removeSubtypes to avoid spurious circularity problemsDec 1, 2021
Ryan Cavanaugh (RyanCavanaugh) added a commit to RyanCavanaugh/lens that referenced this pull request Dec 1, 2021
This code has a type circularity that previously went undetected. Adding an `as Wizard` assertion here removes the circularity.
See microsoft/TypeScript#46939 / microsoft/TypeScript#46981
@RyanCavanaugh

Copy link
Copy Markdown
MemberAuthor

TypeScript Bot (@typescript-bot) perf test this

@typescript-bot

TypeScript Bot (typescript-bot) commented Dec 1, 2021

Copy link
Copy Markdown
Contributor

Heya Ryan Cavanaugh (@RyanCavanaugh), I've started to run the perf test suite on this PR at dd91ab7. You can monitor the build here.

Update: The results are in!

@typescript-bot

Copy link
Copy Markdown
Contributor

Ryan Cavanaugh (@RyanCavanaugh)
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..46981

Metricmain46981DeltaBestWorst
Angular - node (v10.16.3, x64)
Memory used354,508k (± 0.02%)354,636k (± 0.03%)+128k (+ 0.04%)354,369k354,800k
Parse Time1.95s (± 0.32%)1.95s (± 0.49%)-0.00s (- 0.21%)1.92s1.96s
Bind Time0.84s (± 0.89%)0.85s (± 0.58%)+0.00s (+ 0.36%)0.84s0.86s
Check Time5.47s (± 0.45%)5.50s (± 0.55%)+0.03s (+ 0.51%)5.43s5.56s
Emit Time5.86s (± 0.33%)5.90s (± 0.70%)+0.04s (+ 0.67%)5.80s6.00s
Total Time14.12s (± 0.26%)14.19s (± 0.41%)+0.07s (+ 0.47%)14.07s14.35s
Compiler-Unions - node (v10.16.3, x64)
Memory used204,059k (± 0.03%)203,902k (± 0.03%)-157k (- 0.08%)203,766k204,051k
Parse Time0.78s (± 0.87%)0.79s (± 1.01%)+0.01s (+ 1.02%)0.77s0.81s
Bind Time0.52s (± 1.11%)0.52s (± 1.39%)+0.00s (+ 0.38%)0.50s0.53s
Check Time7.81s (± 0.50%)7.86s (± 0.71%)+0.05s (+ 0.65%)7.76s8.05s
Emit Time2.46s (± 0.78%)2.47s (± 0.65%)+0.01s (+ 0.41%)2.42s2.50s
Total Time11.56s (± 0.33%)11.64s (± 0.47%)+0.07s (+ 0.65%)11.53s11.83s
Monaco - node (v10.16.3, x64)
Memory used342,426k (± 0.02%)342,357k (± 0.03%)-69k (- 0.02%)342,202k342,613k
Parse Time1.48s (± 0.44%)1.48s (± 0.50%)+0.00s (+ 0.34%)1.47s1.50s
Bind Time0.74s (± 0.66%)0.75s (± 0.49%)+0.00s (+ 0.27%)0.74s0.75s
Check Time5.47s (± 0.70%)5.46s (± 0.61%)-0.01s (- 0.15%)5.38s5.55s
Emit Time3.19s (± 0.69%)3.24s (± 0.90%)+0.06s (+ 1.82%)3.19s3.32s
Total Time10.88s (± 0.22%)10.94s (± 0.23%)+0.06s (+ 0.52%)10.88s11.01s
TFS - node (v10.16.3, x64)
Memory used305,439k (± 0.03%)305,469k (± 0.02%)+29k (+ 0.01%)305,331k305,647k
Parse Time1.20s (± 0.46%)1.20s (± 0.50%)+0.01s (+ 0.58%)1.19s1.22s
Bind Time0.71s (± 0.66%)0.71s (± 0.69%)+0.00s (+ 0.56%)0.71s0.73s
Check Time5.03s (± 0.43%)5.05s (± 0.67%)+0.02s (+ 0.50%)4.98s5.14s
Emit Time3.34s (± 0.93%)3.41s (± 1.50%)+0.07s (+ 2.06%)3.28s3.56s
Total Time10.28s (± 0.35%)10.38s (± 0.66%)+0.10s (+ 1.01%)10.17s10.52s
material-ui - node (v10.16.3, x64)
Memory used471,310k (± 0.01%)471,246k (± 0.02%)-64k (- 0.01%)471,065k471,434k
Parse Time1.77s (± 0.40%)1.78s (± 0.36%)+0.01s (+ 0.40%)1.76s1.79s
Bind Time0.65s (± 0.52%)0.65s (± 0.89%)0.00s ( 0.00%)0.64s0.66s
Check Time14.17s (± 0.38%)14.30s (± 0.72%)+0.14s (+ 0.96%)14.08s14.47s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time16.59s (± 0.34%)16.73s (± 0.65%)+0.14s (+ 0.85%)16.50s16.90s
xstate - node (v10.16.3, x64)
Memory used568,998k (± 0.02%)569,074k (± 0.02%)+76k (+ 0.01%)568,800k569,363k
Parse Time2.55s (± 0.30%)2.55s (± 0.49%)+0.01s (+ 0.31%)2.53s2.59s
Bind Time1.00s (± 0.55%)1.01s (± 0.61%)+0.01s (+ 0.70%)1.00s1.02s
Check Time1.49s (± 0.50%)1.50s (± 0.97%)+0.00s (+ 0.27%)1.47s1.54s
Emit Time0.07s (± 0.00%)0.07s (± 0.00%)0.00s ( 0.00%)0.07s0.07s
Total Time5.11s (± 0.19%)5.13s (± 0.39%)+0.02s (+ 0.43%)5.09s5.18s
Angular - node (v12.1.0, x64)
Memory used332,458k (± 0.02%)332,452k (± 0.02%)-6k (- 0.00%)332,298k332,582k
Parse Time1.94s (± 0.56%)1.96s (± 1.08%)+0.02s (+ 1.08%)1.92s2.02s
Bind Time0.82s (± 0.91%)0.82s (± 0.79%)+0.00s (+ 0.24%)0.81s0.83s
Check Time5.30s (± 0.30%)5.37s (± 1.28%)+0.06s (+ 1.19%)5.29s5.62s
Emit Time6.15s (± 0.96%)6.18s (± 0.55%)+0.04s (+ 0.62%)6.11s6.27s
Total Time14.21s (± 0.47%)14.33s (± 0.68%)+0.12s (+ 0.84%)14.13s14.61s
Compiler-Unions - node (v12.1.0, x64)
Memory used191,602k (± 0.03%)191,358k (± 0.05%)-245k (- 0.13%)191,007k191,497k
Parse Time0.78s (± 0.61%)0.79s (± 0.96%)+0.00s (+ 0.38%)0.77s0.80s
Bind Time0.53s (± 0.89%)0.53s (± 1.16%)-0.00s (- 0.38%)0.52s0.55s
Check Time7.28s (± 0.39%)7.32s (± 0.32%)+0.05s (+ 0.63%)7.28s7.39s
Emit Time2.47s (± 0.81%)2.47s (± 0.72%)-0.00s (- 0.20%)2.43s2.50s
Total Time11.07s (± 0.38%)11.11s (± 0.40%)+0.04s (+ 0.39%)11.03s11.22s
Monaco - node (v12.1.0, x64)
Memory used325,493k (± 0.04%)325,399k (± 0.02%)-95k (- 0.03%)325,306k325,542k
Parse Time1.46s (± 0.72%)1.47s (± 0.56%)+0.01s (+ 0.62%)1.45s1.49s
Bind Time0.73s (± 0.61%)0.73s (± 0.79%)+0.00s (+ 0.27%)0.72s0.74s
Check Time5.34s (± 0.48%)5.37s (± 0.50%)+0.03s (+ 0.49%)5.31s5.43s
Emit Time3.21s (± 0.55%)3.23s (± 0.47%)+0.02s (+ 0.50%)3.20s3.26s
Total Time10.74s (± 0.36%)10.79s (± 0.32%)+0.05s (+ 0.50%)10.73s10.87s
TFS - node (v12.1.0, x64)
Memory used290,301k (± 0.03%)290,263k (± 0.02%)-39k (- 0.01%)290,177k290,354k
Parse Time1.21s (± 0.48%)1.22s (± 0.53%)+0.01s (+ 0.74%)1.21s1.24s
Bind Time0.68s (± 0.54%)0.69s (± 0.75%)+0.00s (+ 0.58%)0.68s0.70s
Check Time4.94s (± 0.47%)4.95s (± 0.80%)+0.01s (+ 0.22%)4.88s5.07s
Emit Time3.40s (± 1.27%)3.40s (± 0.65%)+0.00s (+ 0.03%)3.33s3.43s
Total Time10.23s (± 0.63%)10.25s (± 0.47%)+0.03s (+ 0.25%)10.15s10.40s
material-ui - node (v12.1.0, x64)
Memory used450,083k (± 0.02%)449,965k (± 0.05%)-119k (- 0.03%)449,028k450,214k
Parse Time1.78s (± 0.33%)1.78s (± 0.66%)+0.01s (+ 0.28%)1.76s1.81s
Bind Time0.64s (± 1.14%)0.64s (± 1.27%)+0.01s (+ 0.78%)0.62s0.66s
Check Time12.69s (± 0.40%)12.75s (± 0.55%)+0.07s (+ 0.52%)12.64s12.92s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.10s (± 0.33%)15.18s (± 0.45%)+0.07s (+ 0.49%)15.05s15.31s
xstate - node (v12.1.0, x64)
Memory used535,055k (± 0.02%)535,067k (± 0.01%)+12k (+ 0.00%)534,872k535,205k
Parse Time2.48s (± 0.47%)2.49s (± 0.65%)+0.02s (+ 0.65%)2.46s2.53s
Bind Time1.04s (± 0.75%)1.04s (± 0.71%)+0.00s (+ 0.10%)1.03s1.06s
Check Time1.43s (± 0.56%)1.44s (± 0.67%)+0.01s (+ 0.91%)1.42s1.46s
Emit Time0.07s (± 0.00%)0.07s (± 0.00%)0.00s ( 0.00%)0.07s0.07s
Total Time5.02s (± 0.27%)5.04s (± 0.32%)+0.03s (+ 0.60%)5.01s5.08s
Angular - node (v14.15.1, x64)
Memory used330,820k (± 0.01%)330,848k (± 0.01%)+27k (+ 0.01%)330,785k330,950k
Parse Time1.94s (± 0.53%)1.95s (± 0.74%)+0.01s (+ 0.72%)1.92s1.99s
Bind Time0.86s (± 0.55%)0.86s (± 0.42%)+0.00s (+ 0.47%)0.86s0.87s
Check Time5.38s (± 0.48%)5.40s (± 0.27%)+0.02s (+ 0.33%)5.36s5.43s
Emit Time6.15s (± 0.33%)6.23s (± 0.92%)+0.08s (+ 1.38%)6.11s6.41s
Total Time14.32s (± 0.26%)14.44s (± 0.42%)+0.12s (+ 0.87%)14.31s14.62s
Compiler-Unions - node (v14.15.1, x64)
Memory used192,757k (± 0.49%)191,700k (± 0.63%)-1,057k (- 0.55%)190,018k193,379k
Parse Time0.81s (± 1.01%)0.81s (± 0.59%)0.00s ( 0.00%)0.80s0.82s
Bind Time0.55s (± 0.73%)0.55s (± 0.40%)0.00s ( 0.00%)0.55s0.56s
Check Time7.34s (± 0.34%)7.41s (± 0.64%)+0.08s (+ 1.02%)7.32s7.49s
Emit Time2.48s (± 0.90%)2.49s (± 0.87%)+0.01s (+ 0.28%)2.44s2.54s
Total Time11.18s (± 0.30%)11.26s (± 0.45%)+0.08s (+ 0.73%)11.14s11.35s
Monaco - node (v14.15.1, x64)
Memory used324,294k (± 0.00%)324,178k (± 0.00%)-115k (- 0.04%)324,157k324,211k
Parse Time1.50s (± 0.56%)1.51s (± 0.48%)+0.01s (+ 0.47%)1.49s1.53s
Bind Time0.76s (± 0.59%)0.76s (± 0.66%)-0.00s (- 0.40%)0.75s0.77s
Check Time5.29s (± 0.43%)5.30s (± 0.41%)+0.01s (+ 0.15%)5.24s5.34s
Emit Time3.25s (± 0.78%)3.27s (± 0.63%)+0.03s (+ 0.80%)3.22s3.32s
Total Time10.80s (± 0.35%)10.83s (± 0.29%)+0.04s (+ 0.33%)10.76s10.91s
TFS - node (v14.15.1, x64)
Memory used289,141k (± 0.00%)289,115k (± 0.01%)-26k (- 0.01%)289,058k289,159k
Parse Time1.22s (± 0.82%)1.23s (± 0.81%)+0.01s (+ 0.82%)1.22s1.26s
Bind Time0.73s (± 0.55%)0.73s (± 0.99%)+0.00s (+ 0.14%)0.72s0.75s
Check Time4.91s (± 0.33%)4.94s (± 0.62%)+0.03s (+ 0.65%)4.88s5.03s
Emit Time3.51s (± 0.53%)3.51s (± 0.68%)+0.01s (+ 0.20%)3.45s3.58s
Total Time10.38s (± 0.26%)10.42s (± 0.51%)+0.05s (+ 0.44%)10.29s10.53s
material-ui - node (v14.15.1, x64)
Memory used448,276k (± 0.01%)448,182k (± 0.05%)-95k (- 0.02%)447,218k448,332k
Parse Time1.82s (± 0.34%)1.84s (± 0.44%)+0.02s (+ 0.99%)1.81s1.85s
Bind Time0.67s (± 0.54%)0.68s (± 0.50%)+0.00s (+ 0.45%)0.67s0.68s
Check Time12.77s (± 0.39%)12.88s (± 0.85%)+0.11s (+ 0.88%)12.64s13.15s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time15.26s (± 0.33%)15.39s (± 0.73%)+0.13s (+ 0.88%)15.15s15.67s
xstate - node (v14.15.1, x64)
Memory used532,756k (± 0.01%)532,777k (± 0.01%)+22k (+ 0.00%)532,713k532,869k
Parse Time2.55s (± 0.63%)2.55s (± 0.37%)-0.00s (- 0.04%)2.53s2.57s
Bind Time1.15s (± 1.10%)1.15s (± 0.86%)+0.00s (+ 0.26%)1.14s1.18s
Check Time1.48s (± 0.52%)1.48s (± 0.63%)+0.01s (+ 0.47%)1.46s1.50s
Emit Time0.07s (± 0.00%)0.07s (± 3.14%)+0.00s (+ 1.43%)0.07s0.08s
Total Time5.25s (± 0.50%)5.26s (± 0.24%)+0.01s (+ 0.21%)5.24s5.30s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory10 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v10.16.3, x64)
  • xstate - node (v12.1.0, x64)
  • xstate - node (v14.15.1, x64)
BenchmarkNameIterations
Current4698110
Baselinemain10

Developer Information:

Download Benchmark

@weswigham

Wesley Wigham (weswigham) commented Mar 5, 2022

Copy link
Copy Markdown
Member

I'm want to merge this, because I think the early bail is fine to have regardless of anything else, however I think there's another underlying issue that probably needs fixing, so it'd be nice if we had a tweaked example that still triggered an issue and an issue to track fixing it. Likely something like

typeBox={content?: Foo|Box};declareconstb: Box;classFoo{getfoo(){return{content: thisasFoo|Box,
...b};}}

will continue to trigger a new-ish circularity error.

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

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants

@RyanCavanaugh@typescript-bot@weswigham@sandersn