Skip to content

Commit

Permalink
Add missing refinement of dynamic/0 into dynamic/1
Browse files Browse the repository at this point in the history
Summary:
Leverage `dynamic/1` to refine `dynamic/0` in occurrence typing. This effectively solves the issue where the types of all parameters are not refined if one of them is `dynamic()`.

The introduction of new `dynamic/1`'s causes an issue with an existing optimization in `subtype` where we checked for the syntactic presence of a type alias before unfolding it (needed for very large aliases). Fix it by adding `BoundedDynamicType` to this check.

Reviewed By: ilya-klyuchnikov

Differential Revision: D68207950

fbshipit-source-id: f9704adb46cc804297df0c6c19c794721af0a7dc
  • Loading branch information
VLanvin authored and facebook-github-bot committed Jan 15, 2025
1 parent 1a69edd commit bd21cef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,8 @@ final class Occurrence(pipelineContext: PipelineContext) {
restrict(body, t2)
case (BoundedDynamicType(t), s) =>
BoundedDynamicType(restrict(t, s))
case (DynamicType, s) =>
BoundedDynamicType(s)
case (OpaqueType(_, _), _) =>
t1
case (_, _) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class Subtype(pipelineContext: PipelineContext) {
subTypePol(t1, bound, seen)
case (RemoteType(rid, args), _) =>
val body = util.getTypeDeclBody(rid, args)
containsType(t1, t2) || subTypePol(body, t2, seen + ((t1, v1) -> (t2, v2)))
containsType(t1, t2, v2) || subTypePol(body, t2, seen + ((t1, v1) -> (t2, v2)))
case (_, RemoteType(rid, args)) =>
val body = util.getTypeDeclBody(rid, args)
subTypePol(t1, body, seen + ((t1, v1) -> (t2, v2)))
Expand Down Expand Up @@ -259,12 +259,14 @@ class Subtype(pipelineContext: PipelineContext) {
false
})

private def containsType(t1: Type, t2: Type): Boolean = {
private def containsType(t1: Type, t2: Type, v2: Variance): Boolean = {
t2 match {
case AnyType => true
case _ if t1 == t2 => true
case UnionType(tys) =>
tys.exists(containsType(t1, _))
tys.exists(containsType(t1, _, v2))
case BoundedDynamicType(bound) if v2 == + =>
containsType(t1, bound, v2)
case _ => false
}
}
Expand Down

0 comments on commit bd21cef

Please sign in to comment.