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

Consistently use terminology "instance implementing" and "dynamic type". #3918

Closed
wants to merge 1 commit into from

Conversation

stereotype441
Copy link
Member

In the code review discussion
#3850 (comment), we agreed to use the terminology "instance satisfying type T" to mean "instance whose runtime type is T or a subtype thereof", and I made the necessary changes to
resources/type-system/inference.md. However, after digging through dartLangSpec.tex, it appears that the terminology we were already using in the spec for this concept is "instance implementing type T". This commit modifies resources/type-system/inference.md to match the spec terminology.

It also fixes two places in the spec where we were incorrectly saying "instance of type T", but we meant "instance implementing type T".

Furthermore, the spec consistently uses the term "dynamic type of v" for the concept that we informally refer to as the "runtime type of v", so this commit updates resources/type-system/inference.md to follow the spec convention.


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

In the code review discussion
#3850 (comment),
we agreed to use the terminology "instance satisfying type T" to mean
"instance whose runtime type is T or a subtype thereof", and I made
the necessary changes to
`resources/type-system/inference.md`. However, after digging through
`dartLangSpec.tex`, it appears that the terminology we were already
using in the spec for this concept is "instance implementing type
T". This commit modifies `resources/type-system/inference.md` to
match the spec terminology.

It also fixes two places in the spec where we were incorrectly saying
"instance of type T", but we meant "instance implementing type T".

Furthermore, the spec consistently uses the term "dynamic type of `v`"
for the concept that we informally refer to as the "runtime type of
`v`", so this commit updates `resources/type-system/inference.md` to
follow the spec convention.
@lrhn
Copy link
Member

lrhn commented Jun 19, 2024

uses the term "dynamic type of v" for the concept that we informally refer to as the "runtime type of v"

(I really want to use "runtime type of v" for that. The word "dynamic" should be reserved for things relating to the type dynamic and dynamic member invocations, and "runtime' should be used for things that happen at runtime. But that doesn't have to be done now.)

type. _Instance satisfying_ is defined as follows: a value `v` is an instance
satisfying type `T` iff the runtime type of `v` is a subtype of the _extension
exception, or evaluate to a value that is an _instance implementing_ its static
type. _Instance implementing_ is defined as follows: a value `v` is an instance
Copy link
Member

@lrhn lrhn Jun 19, 2024

Choose a reason for hiding this comment

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

I think (checking ... and still think it!) that the spec uses "implements S" to mean "has S as super-interface" (or really: "is T-bounded for a T which implements S", which means having S as super-interface or is a type variable with a bound T which implements S (recurse as needed). Probably also a promoted type variable whose intersecting type implements S.)

That's different from "having as supertype" if the type is generic, so Future<int>.value(1) is an object with runtime type _Future<int> which has Future<int> as super-interface. It implements Future<int>. It does not implement Future<Object>, it just has that as a supertype.

So, (Future<int>.value(1) as Future<Object>) does not satisfy that its value's runtime type implements its static type.

For soundness, if an expression evaluates to a value, the runtime type of that value must be a subtype of the (extension-type-erased) static type of the expression. Using "implements" is likely wrong.

... there it was, in the "Superinterfaces" section:

When we say that a type $S$
\IndexCustom{implements}{type!implements a type}
another type $T$,
this means that $T$ is a superinterface of $S$,
or $S$ is $S_0$ bounded for some type $S_0$
(\ref{bindingActualsToFormals}),
and $T$ is a superinterface of $S_0$.
... snip implementing raw types ...

\commentary{%
Note that this is not the same as being a subtype.
For instance, \code{List<int>} implements \code{Iterable<int>},
but it does not implement \code{Iterable<num>}.
Similarly, \code{List<int>} implements \code{Iterable}.
Also, note that when $S$ implements $T$
where $T$ is not a subtype of \code{Null},
$S$ cannot be a subtype of \code{Null}.%
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I see what you mean. Thanks for the explanation. I'm going to go ahead and abandon this PR and stick with the terminology "instance satisfying type T" in resources/type-system/inference.md.

type erasure_ of `T`. _So, for example, every value is considered an instance
satisfying type `dynamic`, and all values except `null` are considered an
instance satisfying type `Object`._
implementing type `dynamic`, and all values except `null` are considered an
Copy link
Member

Choose a reason for hiding this comment

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

(Since dynamic is not an interface, you can't have it as super-interface, so you can't implement it. But everything is a subtype of dynamic because it's a top type.)

@@ -7759,7 +7759,7 @@ \subsection{Super-Bounded Types}
all types of the form \code{C<$S$>}
(noting that all types must be regular-bounded
when we do not have the notion of super-bounded types).
So if we wish to allow a variable to hold any instance ``of type \code{C}''
So if we wish to allow a variable to hold any instance ``implementing type \code{C}''
Copy link
Member

Choose a reason for hiding this comment

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

So this should be
"any instance whose dynamic type is a subtype of \code{C}"

@@ -22495,7 +22495,7 @@ \subsection{Type FutureOr}

\rationale{%
The \code{FutureOr<$T$>} type represents a case where an object can be
either an instance of the type $T$
either an instance implementing the type $T$
Copy link
Member

@lrhn lrhn Jun 19, 2024

Choose a reason for hiding this comment

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

an instance whose dynamic type is a subtype of $T$

stereotype441 added a commit to stereotype441/language that referenced this pull request Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants