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

Specify null safety subtyping #3515

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

eernstg
Copy link
Member

@eernstg eernstg commented Dec 14, 2023

This PR contains the null-safety updates from #2605 (the overall null-safety PR) that are concerned with subtyping. The intention is that we process and land this PR, and #2605 will then be made smaller when it is rebased over this one, thus allowing us to deal with the null-safety update in smaller portions.

@eernstg eernstg force-pushed the specify_null_safety_subtyping_dec23 branch from 082c391 to a9f4886 Compare December 18, 2023 13:27
Copy link
Member

@lrhn lrhn left a comment

Choose a reason for hiding this comment

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

Can't really review this as source.
Do we still have a way to generate a rendering showing the changes?

which means that this seemingly expensive step can be confined to some extent.%
}
\commentary{%
Note that this rule is admissible, and can be safely elided if desired.%
Copy link
Member

Choose a reason for hiding this comment

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

Define "admissible". It's a term of art not used elsewhere in the specification, so we cannot assume the reader to be familiar with it.

@eernstg eernstg force-pushed the specify_null_safety_subtyping_dec23 branch from a9f4886 to 0fd9980 Compare February 9, 2024 13:53
@eernstg eernstg force-pushed the specify_null_safety_subtyping_dec23 branch from 0fd9980 to 84e6d38 Compare August 13, 2024 17:18
@eernstg eernstg force-pushed the specify_null_safety_subtyping_dec23 branch from 84e6d38 to 4fcf76e Compare September 2, 2024 16:13
@eernstg eernstg force-pushed the specify_null_safety_subtyping_dec23 branch from 4fcf76e to b7cdb30 Compare September 23, 2024 09:56
@eernstg eernstg force-pushed the specify_null_safety_subtyping_dec23 branch from b7cdb30 to bf98431 Compare October 11, 2024 13:38
@eernstg
Copy link
Member Author

eernstg commented Oct 17, 2024

dartLangSpec-3515.pdf

@eernstg
Copy link
Member Author

eernstg commented Oct 18, 2024

Based on the output from git diff main..., here is an overview of the changes:

Front matter

Only comments.

@@ -21633,128 +21631,188 @@

Section 'Subtypes': Now mentions intersection types.

Figure 'Subtype rules': Changed a lot.

Subsection 'Meta-Variables': Slightly changes presentation of
metavariables.

Subsection 'Subtype Rules': Introduces the 'canonical syntax' of a
type. Controversial! An alternative could be to say that subtype rules
are not applicable to syntax, they are applicable to semantic
entities that are normalized in the same way as canonical syntax does
it. Extensively rewritten.

Subsection 'Being a Subtype': Extensively rewritten.

Subsubsection 'Informal subtype rule descriptions': Rewritten extensively.

Subsection 'Additional Subtyping Concepts': Extensively rewritten.

Section 'Function Types': Last paragraph modified.

Section 'Type Function': Rewritten.

@@ -22482,7 +22498,7 @@

Just the title of section 'Type dynamic' was adjusted, for consistency
(that is: titles do not use non-standard fonts).

Section 'Type FutureOr': Just adding missing \Error{} on static
errors, and updating Object to Object? in an example.

Section 'Type void': Removed commentary that reiterated an obsolete
definition of Type equality. Removed the item that enabled await expressionOfTypeVoid, because that rule that enabled this usage has
been removed from the language. Example at the end is updated.

Subsection 'Void Soundness': Example updated, plus body text about the
example.

@@ -23324,156 +23324,238 @@

Section 'Appendix: Algorithmic Subtyping': Updated to use the
NNBD-updated presentation of the subtype rules.

if $T_1$ is \code{FutureOr<$S$>} for some $S$,
then the query is true if{}f \SubtypeNE{\code{Null}}{S}.
\item
if $T_1$ is \code{$S$?} for some $S$ then the query is true.
Copy link
Member Author

Choose a reason for hiding this comment

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

The case where $T_1$ is \code{Null} is already handled by reflexivity.

\item
\textbf{Left Top:}
if $T_0$ is \DYNAMIC{} or \VOID{}
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{\code{Object?}}{T_1}.
Copy link
Member Author

Choose a reason for hiding this comment

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

I think it should be 'iff' rather than 'if', so I changed it.

It could be implied that it works the same with 'if' because it was already stated that it is never necessary to try subsequent cases when a syntactic match has been determined, but many rules further down use 'iff' so it seems consistent to do it here as well.

\item
\textbf{Left Promoted Variable:}
If $T_0$ is a promoted type variable \code{$X_0$\,\&\,$S_0$}
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{S_0}{T_1}.
Copy link
Member Author

Choose a reason for hiding this comment

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

In 'subtyping.md' there is no 'If', and the second line is just 'and S0 <: T1'. However, that seems to make it less obvious that if T0 is a promoted type variable X0 & S0 but S0 <: T1 cannot be proven, then we do have a known false outcome, rather than a non-matching rule.

\item
\textbf{Left Type Variable Bound:}
$T_0$ is a type variable $X_0$ with bound $B_0$
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{B_0}{T_1}.
Copy link
Member Author

Choose a reason for hiding this comment

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

Similar to the previous rule. A few more rules below got the same treatment.

$T_0$ is a function type and $T_1$ is \FUNCTION.
\item
\textbf{Record Type/Record:}
$T_0$ is a record type and $T_1$ is \RECORD.
Copy link
Member Author

Choose a reason for hiding this comment

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

This one is far into the future (that is, it comes with a version which is much higher than 2.13), so perhaps we should omit it (comment it out)?

Note that records are only mentioned here in the appendix, they do not occur in the subtype rules figure.

\item
If $T_0$ is \code{($V_0$, \ldots, $V_n$, \{$V_{n+1} d_{n+1}$, \ldots, $V_m d_m$\})}
and $T_1$ is \code{($S_0$, \ldots, $S_n$, \{$S_{n+1} d_{n+1}$, \ldots, $S_m d_m$\})}
then \SubtypeNE{T_0}{T_1} if{}f \SubtypeNE{V_i}{S_i} for each $i \in 0 .. m$.
Copy link
Member Author

Choose a reason for hiding this comment

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

Again a record type: Could be commented out for now.

then the subtyping does not hold
(\commentary{%
i.e., the result of the subtyping query is known to be false%
}).
Copy link
Member Author

Choose a reason for hiding this comment

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

Like a few other rules, I believe 'Right Object' is admissible, but not required.

@eernstg
Copy link
Member Author

eernstg commented Oct 21, 2024

I tried to use latexdiff to generate a PDF that shows the differences, but it doesn't handle "non-standard" LaTeX (which seems to be difficult to avoid). I can generate a PDF that shows some differences and stops at page 232, but it would take some more experimentation to produce something that shows the differences in a way that can be relied upon.

@eernstg
Copy link
Member Author

eernstg commented Nov 1, 2024

I added a section about 'being the same type', and adjusted the text such that the thing previously known as 'canonical syntax' (now renamed to 'explicitly resolved syntax') is encapsulated in this section. Also, alpha equivalence has been made part of this 'being the same type' section.

@eernstg eernstg force-pushed the specify_null_safety_subtyping_dec23 branch from f28e000 to 54323ec Compare November 25, 2024 09:51
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