Skip to content

Commit e0e893c

Browse files
zwadejakebailey
andauthored
Re-introduce preemptive caching of CouldContainTypeVariables (#612)
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
1 parent 1cce30e commit e0e893c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

internal/checker/checker.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20451,6 +20451,20 @@ func (c *Checker) getObjectTypeInstantiation(t *Type, m *TypeMapper, alias *Type
2045120451
result = c.instantiateAnonymousType(target, newMapper, newAlias)
2045220452
}
2045320453
data.instantiations[key] = result
20454+
if result.flags&TypeFlagsObjectFlagsType != 0 && result.objectFlags&ObjectFlagsCouldContainTypeVariablesComputed == 0 {
20455+
// if `result` is one of the object types we tried to make (it may not be, due to how `instantiateMappedType` works), we can carry forward the type variable containment check from the input type arguments
20456+
resultCouldContainObjectFlags := core.Some(typeArguments, c.couldContainTypeVariables)
20457+
if result.objectFlags&ObjectFlagsCouldContainTypeVariablesComputed == 0 {
20458+
if result.objectFlags&(ObjectFlagsMapped|ObjectFlagsAnonymous|ObjectFlagsReference) != 0 {
20459+
result.objectFlags |= ObjectFlagsCouldContainTypeVariablesComputed | core.IfElse(resultCouldContainObjectFlags, ObjectFlagsCouldContainTypeVariables, 0)
20460+
} else {
20461+
// If none of the type arguments for the outer type parameters contain type variables, it follows
20462+
// that the instantiated type doesn't reference type variables.
20463+
// Intrinsics have `CouldContainTypeVariablesComputed` pre-set, so this should only cover unions and intersections resulting from `instantiateMappedType`
20464+
result.objectFlags |= core.IfElse(!resultCouldContainObjectFlags, ObjectFlagsCouldContainTypeVariablesComputed, 0)
20465+
}
20466+
}
20467+
}
2045420468
}
2045520469
return result
2045620470
}

0 commit comments

Comments
 (0)