Repository navigation
Share complete union and intersection property cache entries #64789
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21893,24 +21893,35 @@ func (c *Checker) getPropertyOfUnionOrIntersectionType(t *Type, name string, ski | |
| // these partial properties when identifying discriminant properties, but otherwise they are filtered out | ||
| // and do not appear to be present in the union type. | ||
| func (c *Checker) getUnionOrIntersectionProperty(t *Type, name string, skipObjectFunctionPropertyAugment bool) *ast.Symbol { | ||
| var cache ast.SymbolTable | ||
| data := t.AsUnionOrIntersectionType() | ||
| if skipObjectFunctionPropertyAugment { | ||
| cache = ast.GetSymbolTable(&t.AsUnionOrIntersectionType().propertyCacheWithoutFunctionPropertyAugment) | ||
| if prop := data.propertyCacheWithoutFunctionPropertyAugment[name]; prop != nil { | ||
| return prop | ||
| } | ||
| } else { | ||
| cache = ast.GetSymbolTable(&t.AsUnionOrIntersectionType().propertyCache) | ||
| } | ||
| if prop := cache[name]; prop != nil { | ||
| return prop | ||
| if data.propertyCache != nil { | ||
| if prop := data.propertyCache[name]; prop != nil { | ||
| return prop | ||
| } | ||
| } | ||
| // Complete non-augmented properties are also valid for augmented | ||
| // lookup. Share the entry instead of retaining it in both tables. | ||
| if prop := data.propertyCacheWithoutFunctionPropertyAugment[name]; prop != nil && prop.CheckFlags()&ast.CheckFlagsPartial == 0 { | ||
| return prop | ||
| } | ||
| } | ||
| prop := c.createUnionOrIntersectionProperty(t, name, skipObjectFunctionPropertyAugment) | ||
| if prop != nil { | ||
| cache[name] = prop | ||
| // Propagate an entry from the non-augmented cache to the augmented cache unless the property is partial. | ||
| if skipObjectFunctionPropertyAugment && prop.CheckFlags()&ast.CheckFlagsPartial == 0 { | ||
| augmentedCache := ast.GetSymbolTable(&t.AsUnionOrIntersectionType().propertyCache) | ||
| if augmentedCache[name] == nil { | ||
| augmentedCache[name] = prop | ||
| if skipObjectFunctionPropertyAugment { | ||
| ast.GetSymbolTable(&data.propertyCacheWithoutFunctionPropertyAugment)[name] = prop | ||
| if prop.CheckFlags()&ast.CheckFlagsPartial == 0 && data.propertyCache[name] == prop { | ||
| delete(data.propertyCache, name) | ||
| if len(data.propertyCache) == 0 { | ||
| data.propertyCache = nil | ||
| } | ||
|
Comment on lines
+21918
to
+21921
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not that familiar with this code path (I don't entirely know when you need one map but not the other), but I do wonder if you can hit a pathological case where you keep deleting/reallocating maps. Also, I wonder if you can save anything by having one "steal" a map from the other if the size is just 1. |
||
| } | ||
| } else { | ||
| ast.GetSymbolTable(&data.propertyCache)[name] = prop | ||
| } | ||
| } | ||
| return prop | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.