Repository navigation
Checker rewrite R5a design turn 2: R5a-2 built once - #436
Conversation
…ariable half
src/tc/r5a2_tests.rs: the acceptance tests of aliases, universal
variables, globalize, transl_simple_type, transl_type_scheme and
unify_params, ignored until the slice is built, beside pins of today's
checker on every program they judge (ten aliases, twelve record fields
with a polymorphic type, five object programs, eight annotations over
types whose parameters share a variable or are constrained). Six step
tests relate 1,000 and 10,000 elements. All of them ran against a
throw-away prototype that is not committed.
src/tc/walk/typetexp.rs, skeleton only: TypeVars gains univar_heads and
global_level; TypeVars::reset takes the current level; Annot gains
univar, declared and add_declared (todo!("R5a-2")); the doc comments of
unify_params, globalize, transl_simple_type and transl_type_scheme say
what the prototype showed they do.
Co-authored-by: Jaap Frolich <jfrolich@gmail.com>
Session: https://os.submodule.nl/session/bks-70623c69-2944-7bf2-a162-c8f0b9ef7aeb
Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
|
It is ONE diff against commit 947fad3 of this branch WITH the prototype of R5a-1 applied first (comment 7255791970 of pull request 430, The prototype is not to be applied by the builder; it need not meet the engineering standard. // R5A-PROTOTYPE R5a-2
diff --git a/compiler-rust/src/tc/walk/typetexp.rs b/compiler-rust/src/tc/walk/typetexp.rs
--- a/compiler-rust/src/tc/walk/typetexp.rs
+++ b/compiler-rust/src/tc/walk/typetexp.rs
@@ -10,6 +10,7 @@
//! order, and its [`CoreTypeRow`] is written when it is left.
use super::super::graph::{ARROW, CONSTR, GENERIC, NONE, Node, Param, TUPLE, Ty, VAR};
+use super::super::segment::{EXTENDED, ExtraDescriptor};
use super::super::scope::{BinderKind, Key, Namespace, Resolved, ResolvedKind, USED};
use super::super::expand::PLAIN_PARAMS;
use super::super::{Declined, Stop};
@@ -148,7 +149,25 @@
/// the graph's current level. O(variables of the item). No
/// allocation. (R5a-2)
pub fn reset(&mut self, level: u32) {
- todo!("R5a-2")
+ // R5A-PROTOTYPE R5a-2
+ for row in 0..self.declared.len() {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let name = self.declared[row].name;
+ self.declared_heads[name.0 as usize] = NONE;
+ }
+ self.declared.clear();
+ self.forget_used();
+ self.drop_univars();
+ self.global_level = level + 1;
+ }
+
+ fn drop_univars(&mut self) {
+ for row in 0..self.univars.len() {
+ let name = self.univars[row].name;
+ self.univar_heads[name.0 as usize] = NONE;
+ }
+ self.univars.clear();
}
}
@@ -303,10 +322,13 @@
/// nested in another. No recursion: an annotation 10,000 deep uses the two
/// stacks. No allocation beyond the growth of the pools. (R5a-1)
pub fn transl_type(&mut self, root: CoreTypeIdx, policy: Policy) -> Result<Ty, Stop> {
+ let level = self.c.g.level;
let result = self.run(root, policy);
if result.is_err() {
self.st.frames.clear();
self.st.values.clear();
+ self.c.g.level = level;
+ self.st.vars.drop_univars();
}
result
}
@@ -371,7 +393,42 @@
/// the unifications. No allocation beyond the growth of the pools.
/// (R5a-2)
pub fn unify_params(&mut self, type_index: u32, args: u32, node: Ty) -> Result<(), Stop> {
- todo!("R5a-2")
+ let arity = u32::from(self.c.types.info(type_index).arity);
+ let start = match self.st.params_of.get(type_index as usize) {
+ Some(&start) if start != NONE => start,
+ _ => return Err(Stop::Declined(Declined::NotBuilt)),
+ };
+ let mark = self.st.values.len();
+ // `instance_list decl.type_params`, then `unify_var` an argument.
+ self.instance_list(start, arity);
+ for at in 0..arity as usize {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let param = self.st.values[mark + at];
+ let arg = self.st.values[args as usize + at];
+ if self.c.unify_var(param, arg).is_err() {
+ self.st.values.truncate(mark);
+ return Err(Stop::Error);
+ }
+ }
+ self.st.values.truncate(mark);
+ // `enforce_constraints` (ctype.ml:1333-1342): `subst` at the
+ // node's level with a new body.
+ let level = std::mem::replace(&mut self.c.g.level, self.c.g.nodes[node.0 as usize].level);
+ self.instance_list(start, arity);
+ self.c.g.level = level;
+ for at in 0..arity as usize {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let param = self.st.values[mark + at];
+ let arg = self.st.values[args as usize + at];
+ if self.c.unify(param, arg).is_err() {
+ self.st.values.truncate(mark);
+ return Err(Stop::Error);
+ }
+ }
+ self.st.values.truncate(mark);
+ Ok(())
}
/// `globalize_used_variables env fixed` (compiler/ml/typetexp.ml:
@@ -406,7 +463,45 @@
/// allocation: the second half reads the rows the first sorted.
/// (R5a-2)
pub fn globalize(&mut self, fixed: bool) -> Result<(), Stop> {
- todo!("R5a-2")
+ if self.st.vars.used.len() > 1 {
+ let names = &self.scopes.names;
+ self.st
+ .vars
+ .used
+ .sort_unstable_by(|l, r| names.text(l.name).as_bytes().cmp(names.text(r.name).as_bytes()));
+ }
+ let global = self.st.vars.global_level;
+ for row in 0..self.st.vars.used.len() {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let used = self.st.vars.used[row];
+ let v = self.var_at(NONE, global);
+ let token = self.c.g.speculate();
+ if self.c.unify(v, used.ty).is_err() {
+ self.c.restore(token);
+ return Err(Stop::Declined(Declined::PolyType));
+ }
+ self.c.g.keep(token);
+ if self.declared(used.name).0 == NONE {
+ let repr = self.c.g.repr(used.ty);
+ if fixed && self.c.g.nodes[repr.0 as usize].tag() == VAR {
+ return Err(Stop::Error);
+ }
+ let v2 = self.var_at(NONE, global);
+ self.add_declared(used.name, v2, used.loc);
+ }
+ }
+ for row in (0..self.st.vars.used.len()).rev() {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let used = self.st.vars.used[row];
+ let v2 = self.declared(used.name);
+ if self.c.unify(used.ty, v2).is_err() {
+ return Err(Stop::Error);
+ }
+ }
+ self.st.vars.forget_used();
+ Ok(())
}
/// `transl_simple_type env fixed styp` (compiler/ml/typetexp.ml:
@@ -418,7 +513,11 @@
/// nothing is done for it before R6b. O(1) plus
/// [`Annot::transl_type`] and [`Annot::globalize`]. (R5a-2)
pub fn transl_simple_type(&mut self, root: CoreTypeIdx, fixed: bool) -> Result<Ty, Stop> {
- todo!("R5a-2")
+ self.st.vars.drop_univars();
+ self.st.vars.forget_used();
+ let ty = self.transl_type(root, if fixed { Policy::Fixed } else { Policy::Extensible })?;
+ self.globalize(fixed)?;
+ Ok(ty)
}
/// `transl_type_scheme env styp` (compiler/ml/typetexp.ml:751-756):
@@ -428,7 +527,13 @@
/// `Err` too. O(1) plus [`Annot::transl_simple_type`] and
/// `Checker::generalize`. (R5a-2)
pub fn transl_type_scheme(&mut self, root: CoreTypeIdx) -> Result<Ty, Stop> {
- todo!("R5a-2")
+ self.st.vars.reset(self.c.g.level);
+ self.c.g.begin_def();
+ let result = self.transl_simple_type(root, false);
+ self.c.g.end_def();
+ let ty = result?;
+ self.c.generalize(ty);
+ Ok(ty)
}
/// `List.assoc name !(univars ())` (compiler/ml/typetexp.ml:308,
@@ -438,7 +543,14 @@
/// two loads. (R5a-2)
#[inline]
pub fn univar(&self, name: Name) -> Ty {
- todo!("R5a-2")
+ let vars = &self.st.vars;
+ if vars.univars.is_empty() {
+ return Ty(NONE);
+ }
+ match vars.univar_heads.get(name.0 as usize) {
+ Some(&row) if row != NONE => vars.univars[row as usize].ty,
+ _ => Ty(NONE),
+ }
}
/// `Tbl.find name !(type_variables ())` (compiler/ml/typetexp.ml:
@@ -448,7 +560,11 @@
/// (R5a-2)
#[inline]
pub fn declared(&self, name: Name) -> Ty {
- todo!("R5a-2")
+ let vars = &self.st.vars;
+ match vars.declared_heads.get(name.0 as usize) {
+ Some(&row) if row != NONE => vars.declared[row as usize].ty,
+ _ => Ty(NONE),
+ }
}
/// `type_variables () := Tbl.add name v` (compiler/ml/typetexp.ml:
@@ -458,7 +574,13 @@
/// `Already_bound` first, 250-251; R5a-3 tests it with
/// [`Annot::declared`]). (R5a-2)
pub fn add_declared(&mut self, name: Name, ty: Ty, loc: u32) {
- todo!("R5a-2")
+ let vars = &mut self.st.vars;
+ let at = name.0 as usize;
+ if at >= vars.declared_heads.len() {
+ vars.declared_heads.resize(at + 1, NONE);
+ }
+ vars.declared_heads[at] = vars.declared.len() as u32;
+ vars.declared.push(UsedVar { name, ty, loc });
}
}
@@ -502,8 +624,41 @@
}
fn var(&mut self, name: u32) -> Ty {
- let serial = self.c.g.nodes.len() as u32;
let level = self.c.g.level;
+ self.var_at(name, level)
+ }
+
+ /// `instance env t` of a used variable's node.
+ fn instance(&mut self, ty: Ty) -> Ty {
+ let repr = self.c.g.repr(ty);
+ if self.c.g.nodes[repr.0 as usize].level == GENERIC {
+ self.c.copy(ty)
+ } else {
+ ty
+ }
+ }
+
+ /// `instance_list` of `arity` parameters from `start`: pushed on
+ /// `values`.
+ fn instance_list(&mut self, start: u32, arity: u32) {
+ let first = self.c.g.nodes.len();
+ self.c.g.copy_begin();
+ for at in 0..arity {
+ let param = self.st.params[(start + at) as usize];
+ let copy = self.c.g.copy_ref(param);
+ self.st.values.push(copy);
+ }
+ self.c.g.copy_drain();
+ let cells = !self.c.extras.descriptors.is_empty();
+ if self.c.memo.live != 0 || cells {
+ self.c.extras.copying = true;
+ self.c.link_memorized(first, NONE, cells);
+ self.c.extras.copying = false;
+ }
+ }
+
+ fn var_at(&mut self, name: u32, level: u32) -> Ty {
+ let serial = self.c.g.nodes.len() as u32;
self.c.g.push(Node {
head: VAR,
level,
@@ -532,7 +687,8 @@
return Err(Stop::Error);
}
let name = self.st.strs.name(arena, &mut self.scopes.names, *text);
- let used = self.st.vars.used(name);
+ let universal = self.univar(name);
+ let used = if universal.0 != NONE { universal } else { self.st.vars.used(name) };
if used.0 == NONE {
// `validate_name` (typetexp.ml:224-231).
let first = arena.get_string(*text).as_bytes().first().copied();
@@ -564,9 +720,6 @@
if !repeated && args.len() as u32 != arity {
return Err(Stop::Error);
}
- if info.reserved & PLAIN_PARAMS == 0 {
- return Err(Stop::Declined(Declined::NotBuilt));
- }
self.set_row(node, CoreTypeRow { ty: Ty(NONE), resolved });
self.push_frame(node);
return Ok(());
@@ -577,9 +730,58 @@
return Ok(());
}
CoreTypeDesc::Ptyp_object(_) => return Err(Stop::Declined(Declined::ObjectType)),
- CoreTypeDesc::Ptyp_alias(_) => return Err(Stop::Declined(Declined::AliasType)),
+ CoreTypeDesc::Ptyp_alias(inner) => {
+ // typetexp.ml:394-428, before the aliased type.
+ let name = self.scopes.names.intern(&inner.1);
+ let mut t = self.univar(name);
+ let mut new = false;
+ if t.0 == NONE {
+ let used = self.st.vars.used(name);
+ if used.0 == NONE {
+ t = self.var(NONE);
+ self.st.vars.add_used(name, t, core.ptyp_loc.0);
+ new = true;
+ } else {
+ t = self.instance(used);
+ }
+ }
+ self.set_row(node, NO_ROW);
+ self.push_frame(node);
+ // Below the aliased type's result: the variable, and for
+ // a new one the alias's name (a `Name` in a slot).
+ self.st.values.push(t);
+ if new {
+ self.st.values.push(Ty(name.0));
+ }
+ return Ok(());
+ }
CoreTypeDesc::Ptyp_variant(_) => return Err(Stop::Declined(Declined::PolyVariantType)),
- CoreTypeDesc::Ptyp_poly(_) => return Err(Stop::Declined(Declined::PolyType)),
+ CoreTypeDesc::Ptyp_poly(inner) => {
+ // typetexp.ml:545-549.
+ self.c.g.begin_def();
+ let first = self.st.vars.univars.len();
+ for var in &inner.0 {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let name = self.st.strs.name(arena, &mut self.scopes.names, var.txt);
+ let first_byte = arena.get_string(var.txt).as_bytes().first().copied();
+ let named = first_byte.is_some_and(|c| c == b'_' || c.is_ascii_alphabetic());
+ let ty = self.var(if named { name.0 } else { NONE });
+ self.st.vars.univars.push(UsedVar { name, ty, loc: NONE });
+ }
+ let vars = &mut self.st.vars;
+ for row in (first..vars.univars.len()).rev() {
+ let at = vars.univars[row].name.0 as usize;
+ if at >= vars.univar_heads.len() {
+ vars.univar_heads.resize(at + 1, NONE);
+ }
+ vars.univars[row].loc = vars.univar_heads[at];
+ vars.univar_heads[at] = row as u32;
+ }
+ self.set_row(node, NO_ROW);
+ self.push_frame(node);
+ return Ok(());
+ }
CoreTypeDesc::Ptyp_package(_) => return Err(Stop::Declined(Declined::PackageType)),
CoreTypeDesc::Ptyp_extension(_) => return Err(Stop::Declined(Declined::ExtensionType)),
};
@@ -607,6 +809,8 @@
let arena = self.arena;
let next = frame.next as usize;
Ok(match &arena.get_core_type(CoreTypeIdx(frame.node)).ptyp_desc {
+ CoreTypeDesc::Ptyp_alias(inner) => (next == 0).then_some(inner.0),
+ CoreTypeDesc::Ptyp_poly(inner) => (next == 0).then_some(inner.1),
CoreTypeDesc::Ptyp_tuple(list) => arena.type_list(*list).get(next).copied(),
CoreTypeDesc::Ptyp_constr((_, list)) => {
let args = arena.type_list(*list);
@@ -658,21 +862,28 @@
}
CoreTypeDesc::Ptyp_constr(_) => {
let type_index = self.type_index(frame.node)?;
- for at in base..base + count {
- let arg = self.st.values[at];
- if self.c.lower(arg, level).is_err() {
- return Err(Stop::Error);
+ let plain = self.c.types.info(type_index).reserved & PLAIN_PARAMS != 0;
+ if plain {
+ for at in base..base + count {
+ let arg = self.st.values[at];
+ if self.c.lower(arg, level).is_err() {
+ return Err(Stop::Error);
+ }
}
}
let b = self.c.g.lists.len() as u32;
self.c.g.lists.push(Ty(NONE));
self.c.g.lists.extend_from_slice(&self.st.values[base..]);
- self.c.g.push(Node {
+ let constr = self.c.g.push(Node {
head: CONSTR | (count as u32) << 8,
level,
a: type_index,
b,
- })
+ });
+ if !plain {
+ self.unify_params(type_index, base as u32, constr)?;
+ }
+ constr
}
CoreTypeDesc::Ptyp_arrow(inner) => {
let (arg, _, _) = &**inner;
@@ -712,6 +923,87 @@
b,
})
}
+ CoreTypeDesc::Ptyp_alias(_) => {
+ // typetexp.ml:402-427, after the aliased type.
+ let t = self.st.values[base];
+ let ty = self.st.values[base + count - 1];
+ if self.c.unify_var(t, ty).is_err() {
+ return Err(Stop::Error);
+ }
+ if count == 2 {
+ ty
+ } else {
+ let name = self.st.values[base + 1].0;
+ let t = self.instance(t);
+ let proxy = self.c.g.repr(t);
+ let found = self.c.g.nodes[proxy.0 as usize];
+ if found.tag() == VAR && found.a == NONE {
+ self.c.g.write(proxy, Node { a: name, ..found });
+ }
+ t
+ }
+ }
+ CoreTypeDesc::Ptyp_poly(inner) => {
+ // typetexp.ml:550-571.
+ let body = self.st.values[base];
+ let first = self.st.vars.univars.len() - inner.0.len();
+ let vars = &mut self.st.vars;
+ for row in first..vars.univars.len() {
+ let at = vars.univars[row].name.0 as usize;
+ vars.univar_heads[at] = vars.univars[row].loc;
+ }
+ self.c.g.end_def();
+ self.c.generalize(body);
+ // `deep_occur v ty` for every variable of the list: one walk.
+ let generation = self.c.fresh_marks();
+ self.c.g.work.clear();
+ self.c.g.work.push(body);
+ while let Some(ty) = self.c.g.work.pop() {
+ let ty = self.c.g.repr(ty);
+ if self.c.marks[ty.0 as usize] == generation {
+ continue;
+ }
+ #[cfg(test)]
+ super::super::steps::tick();
+ self.c.marks[ty.0 as usize] = generation;
+ let reached = self.c.g.nodes[ty.0 as usize];
+ self.c.g.children(reached, false);
+ }
+ let b = self.c.g.lists.len() as u32;
+ self.c.g.lists.push(body);
+ let mut bound = 0;
+ for row in first..self.st.vars.univars.len() {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let v = self.c.g.repr(self.st.vars.univars[row].ty);
+ if self.c.marks[v.0 as usize] != generation {
+ continue;
+ }
+ let found = self.c.g.nodes[v.0 as usize];
+ if found.tag() != VAR || found.level != GENERIC {
+ return Err(Stop::Error);
+ }
+ let a = self.c.extras.univar(found.a);
+ self.c.g.write(v, Node { head: TUPLE | EXTENDED, level: GENERIC, a, b: 0 });
+ self.c.g.lists.push(v);
+ bound += 1;
+ }
+ self.st.vars.univars.truncate(first);
+ let a = self.c.extras.descriptors.len() as u32;
+ self.c.extras.descriptors.push(ExtraDescriptor::Poly);
+ let poly = self.c.g.push(Node {
+ head: TUPLE | EXTENDED | (bound + 1) << 8,
+ level: GENERIC,
+ a,
+ b,
+ });
+ // `unify_var env (newvar ()) ty'` (571).
+ let level = self.c.g.level;
+ if self.c.lower(poly, level).is_err() {
+ return Err(Stop::Error);
+ }
+ poly
+ }
_ => return Err(NOT_A_FRAME),
})
} |
…prompt CHECKER_REWRITE.md 10.12: decisions 13 to 21 (the cut of R5a-2 in two, the alias arm beside typetexp.ml 394-428, who decides a self-alias, the decline in place of the silent skip of globalize, globalize as two loops, universal variables and the polymorphic arm beside 545-571, unify_params and enforce_constraints, what an error leaves), the skeleton changes with their reasons, measured costs, what R5a-1's tests pin that this slice removes, the second half on paper, and the table of programs with what OCaml and today's checker answer. 10.10 gains the prompt of R5a-2a; 10.7 its two rows; item 4 of 10.11 its State line. r5a2_tests.rs: one more ignored test, the global level of a globalized variable and the used variables emptied first. Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/bks-70623c69-2944-7bf2-a162-c8f0b9ef7aeb Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
Trunk gained the corrected alias arm of today's checker (pull request 433). Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/bks-70623c69-2944-7bf2-a162-c8f0b9ef7aeb Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
…the breaks seen to fail r5a2_tests.rs: after the merge of trunk today's checker refuses the six self-aliases and prints the two lines the new checker's tests expect for an alias through an identity and a phantom abbreviation; one test that runs today pins that. CHECKER_REWRITE.md: decision 15 and the programs table say so; 10.10 gains the table of 35 changes to the prototype each seen to fail a test, the four no test catches, and what was not run. Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/bks-70623c69-2944-7bf2-a162-c8f0b9ef7aeb Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
Trunk gained the build of R5a-1 (pull request 435). Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/bks-70623c69-2944-7bf2-a162-c8f0b9ef7aeb Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
|
With it applied on def93a8, The builder does not apply it. // R5A-PROTOTYPE R5a-2, second
diff --git a/compiler-rust/src/tc/walk/typetexp.rs b/compiler-rust/src/tc/walk/typetexp.rs
index 5dde1aed3..018cea321 100644
--- a/compiler-rust/src/tc/walk/typetexp.rs
+++ b/compiler-rust/src/tc/walk/typetexp.rs
@@ -13,6 +13,7 @@ use super::super::expand::PLAIN_PARAMS;
use super::super::graph::{ARROW, CONSTR, GENERIC, NONE, Node, Param, TUPLE, Ty, VAR};
use super::super::name_table::{Name, NameTable};
use super::super::scope::{BinderKind, Key, Namespace, Resolved, ResolvedKind, Scopes, USED};
+use super::super::segment::{EXTENDED, ExtraDescriptor};
use super::super::unify::Checker;
use super::super::{Declined, Stop};
use crate::intern::StrIdx;
@@ -147,7 +148,25 @@ impl TypeVars {
/// the graph's current level. O(variables of the item). No
/// allocation. (R5a-2)
pub fn reset(&mut self, level: u32) {
- todo!("R5a-2")
+ // R5A-PROTOTYPE R5a-2
+ for row in 0..self.declared.len() {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let name = self.declared[row].name;
+ self.declared_heads[name.0 as usize] = NONE;
+ }
+ self.declared.clear();
+ self.forget_used();
+ self.drop_univars();
+ self.global_level = level + 1;
+ }
+
+ fn drop_univars(&mut self) {
+ for row in 0..self.univars.len() {
+ let name = self.univars[row].name;
+ self.univar_heads[name.0 as usize] = NONE;
+ }
+ self.univars.clear();
}
}
@@ -302,10 +321,14 @@ impl Annot<'_> {
/// nested in another. No recursion: an annotation 10,000 deep uses the two
/// stacks. No allocation beyond the growth of the pools. (R5a-1)
pub fn transl_type(&mut self, root: CoreTypeIdx, policy: Policy) -> Result<Ty, Stop> {
+ // R5A-PROTOTYPE R5a-2
+ let level = self.c.g.level;
let result = self.walk(root, policy);
if result.is_err() {
self.st.frames.clear();
self.st.values.clear();
+ self.c.g.level = level;
+ self.st.vars.drop_univars();
}
result
}
@@ -372,7 +395,42 @@ impl Annot<'_> {
/// the unifications. No allocation beyond the growth of the pools.
/// (R5a-2)
pub fn unify_params(&mut self, type_index: u32, args: u32, node: Ty) -> Result<(), Stop> {
- todo!("R5a-2")
+ let arity = u32::from(self.c.types.info(type_index).arity);
+ let start = match self.st.params_of.get(type_index as usize) {
+ Some(&start) if start != NONE => start,
+ _ => return Err(Stop::Declined(Declined::NotBuilt)),
+ };
+ let mark = self.st.values.len();
+ // `instance_list decl.type_params`, then `unify_var` an argument.
+ self.instance_list(start, arity);
+ for at in 0..arity as usize {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let param = self.st.values[mark + at];
+ let arg = self.st.values[args as usize + at];
+ if self.c.unify_var(param, arg).is_err() {
+ self.st.values.truncate(mark);
+ return Err(Stop::Error);
+ }
+ }
+ self.st.values.truncate(mark);
+ // `enforce_constraints` (ctype.ml:1333-1342): `subst` at the
+ // node's level with a new body.
+ let level = std::mem::replace(&mut self.c.g.level, self.c.g.nodes[node.0 as usize].level);
+ self.instance_list(start, arity);
+ self.c.g.level = level;
+ for at in 0..arity as usize {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let param = self.st.values[mark + at];
+ let arg = self.st.values[args as usize + at];
+ if self.c.unify(param, arg).is_err() {
+ self.st.values.truncate(mark);
+ return Err(Stop::Error);
+ }
+ }
+ self.st.values.truncate(mark);
+ Ok(())
}
/// `globalize_used_variables env fixed` (compiler/ml/typetexp.ml:
@@ -407,7 +465,45 @@ impl Annot<'_> {
/// allocation: the second half reads the rows the first sorted.
/// (R5a-2)
pub fn globalize(&mut self, fixed: bool) -> Result<(), Stop> {
- todo!("R5a-2")
+ if self.st.vars.used.len() > 1 {
+ let names = &self.scopes.names;
+ self.st
+ .vars
+ .used
+ .sort_unstable_by(|l, r| names.text(l.name).as_bytes().cmp(names.text(r.name).as_bytes()));
+ }
+ let global = self.st.vars.global_level;
+ for row in 0..self.st.vars.used.len() {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let used = self.st.vars.used[row];
+ let v = self.var_at(NONE, global);
+ let token = self.c.g.speculate();
+ if self.c.unify(v, used.ty).is_err() {
+ self.c.restore(token);
+ return Err(Stop::Declined(Declined::PolyType));
+ }
+ self.c.g.keep(token);
+ if self.declared(used.name).0 == NONE {
+ let repr = self.c.g.repr(used.ty);
+ if fixed && self.c.g.nodes[repr.0 as usize].tag() == VAR {
+ return Err(Stop::Error);
+ }
+ let v2 = self.var_at(NONE, global);
+ self.add_declared(used.name, v2, used.loc);
+ }
+ }
+ for row in (0..self.st.vars.used.len()).rev() {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let used = self.st.vars.used[row];
+ let v2 = self.declared(used.name);
+ if self.c.unify(used.ty, v2).is_err() {
+ return Err(Stop::Error);
+ }
+ }
+ self.st.vars.forget_used();
+ Ok(())
}
/// `transl_simple_type env fixed styp` (compiler/ml/typetexp.ml:
@@ -419,7 +515,11 @@ impl Annot<'_> {
/// nothing is done for it before R6b. O(1) plus
/// [`Annot::transl_type`] and [`Annot::globalize`]. (R5a-2)
pub fn transl_simple_type(&mut self, root: CoreTypeIdx, fixed: bool) -> Result<Ty, Stop> {
- todo!("R5a-2")
+ self.st.vars.drop_univars();
+ self.st.vars.forget_used();
+ let ty = self.transl_type(root, if fixed { Policy::Fixed } else { Policy::Extensible })?;
+ self.globalize(fixed)?;
+ Ok(ty)
}
/// `transl_type_scheme env styp` (compiler/ml/typetexp.ml:751-756):
@@ -429,7 +529,13 @@ impl Annot<'_> {
/// `Err` too. O(1) plus [`Annot::transl_simple_type`] and
/// `Checker::generalize`. (R5a-2)
pub fn transl_type_scheme(&mut self, root: CoreTypeIdx) -> Result<Ty, Stop> {
- todo!("R5a-2")
+ self.st.vars.reset(self.c.g.level);
+ self.c.g.begin_def();
+ let result = self.transl_simple_type(root, false);
+ self.c.g.end_def();
+ let ty = result?;
+ self.c.generalize(ty);
+ Ok(ty)
}
/// `List.assoc name !(univars ())` (compiler/ml/typetexp.ml:308,
@@ -439,7 +545,14 @@ impl Annot<'_> {
/// two loads. (R5a-2)
#[inline]
pub fn univar(&self, name: Name) -> Ty {
- todo!("R5a-2")
+ let vars = &self.st.vars;
+ if vars.univars.is_empty() {
+ return Ty(NONE);
+ }
+ match vars.univar_heads.get(name.0 as usize) {
+ Some(&row) if row != NONE => vars.univars[row as usize].ty,
+ _ => Ty(NONE),
+ }
}
/// `Tbl.find name !(type_variables ())` (compiler/ml/typetexp.ml:
@@ -449,7 +562,11 @@ impl Annot<'_> {
/// (R5a-2)
#[inline]
pub fn declared(&self, name: Name) -> Ty {
- todo!("R5a-2")
+ let vars = &self.st.vars;
+ match vars.declared_heads.get(name.0 as usize) {
+ Some(&row) if row != NONE => vars.declared[row as usize].ty,
+ _ => Ty(NONE),
+ }
}
/// `type_variables () := Tbl.add name v` (compiler/ml/typetexp.ml:
@@ -459,7 +576,13 @@ impl Annot<'_> {
/// `Already_bound` first, 250-251; R5a-3 tests it with
/// [`Annot::declared`]). (R5a-2)
pub fn add_declared(&mut self, name: Name, ty: Ty, loc: u32) {
- todo!("R5a-2")
+ let vars = &mut self.st.vars;
+ let at = name.0 as usize;
+ if at >= vars.declared_heads.len() {
+ vars.declared_heads.resize(at + 1, NONE);
+ }
+ vars.declared_heads[at] = vars.declared.len() as u32;
+ vars.declared.push(UsedVar { name, ty, loc });
}
}
@@ -525,8 +648,41 @@ impl Annot<'_> {
/// the current level whose serial is its index, named by the [`Name`]
/// in `name` or by none ([`NONE`]). O(1): one node.
fn new_var(&mut self, name: u32) -> Ty {
- let serial = self.c.g.nodes.len() as u32;
let level = self.c.g.level;
+ self.var_at(name, level)
+ }
+
+ /// `instance env t` of a used variable's node.
+ fn instance(&mut self, ty: Ty) -> Ty {
+ let repr = self.c.g.repr(ty);
+ if self.c.g.nodes[repr.0 as usize].level == GENERIC {
+ self.c.copy(ty)
+ } else {
+ ty
+ }
+ }
+
+ /// `instance_list` of `arity` parameters from `start`: pushed on
+ /// `values`.
+ fn instance_list(&mut self, start: u32, arity: u32) {
+ let first = self.c.g.nodes.len();
+ self.c.g.copy_begin();
+ for at in 0..arity {
+ let param = self.st.params[(start + at) as usize];
+ let copy = self.c.g.copy_ref(param);
+ self.st.values.push(copy);
+ }
+ self.c.g.copy_drain();
+ let cells = !self.c.extras.descriptors.is_empty();
+ if self.c.memo.live != 0 || cells {
+ self.c.extras.copying = true;
+ self.c.link_memorized(first, NONE, cells);
+ self.c.extras.copying = false;
+ }
+ }
+
+ fn var_at(&mut self, name: u32, level: u32) -> Ty {
+ let serial = self.c.g.nodes.len() as u32;
self.c.g.push(Node {
head: VAR,
level,
@@ -580,7 +736,8 @@ impl Annot<'_> {
return Err(Stop::Error);
}
let name = self.st.strs.name(arena, &mut self.scopes.names, *text);
- let used = self.st.vars.used(name);
+ let universal = self.univar(name);
+ let used = if universal.0 != NONE { universal } else { self.st.vars.used(name) };
if used.0 != NONE {
// `instance env`: a node that is not generic is
// itself (`copy`, compiler/ml/ctype.ml:744-797).
@@ -619,9 +776,6 @@ impl Annot<'_> {
}
// CHECKER_REWRITE 10.2, decision 5: without the bit the
// road is `Annot::unify_params` (R5a-2).
- if info.reserved & PLAIN_PARAMS == 0 {
- return Err(Stop::Declined(Declined::NotBuilt));
- }
self.set_row(node, CoreTypeRow { ty: Ty(NONE), resolved });
self.push_frame(node);
return Ok(());
@@ -632,9 +786,58 @@ impl Annot<'_> {
return Ok(());
}
CoreTypeDesc::Ptyp_object(_) => return Err(Stop::Declined(Declined::ObjectType)),
- CoreTypeDesc::Ptyp_alias(_) => return Err(Stop::Declined(Declined::AliasType)),
+ CoreTypeDesc::Ptyp_alias(inner) => {
+ // typetexp.ml:394-428, before the aliased type.
+ let name = self.scopes.names.intern(&inner.1);
+ let mut t = self.univar(name);
+ let mut new = false;
+ if t.0 == NONE {
+ let used = self.st.vars.used(name);
+ if used.0 == NONE {
+ t = self.new_var(NONE);
+ self.st.vars.add_used(name, t, core.ptyp_loc.0);
+ new = true;
+ } else {
+ t = self.instance(used);
+ }
+ }
+ self.set_row(node, NO_ROW);
+ self.push_frame(node);
+ // Below the aliased type's result: the variable, and for
+ // a new one the alias's name (a `Name` in a slot).
+ self.st.values.push(t);
+ if new {
+ self.st.values.push(Ty(name.0));
+ }
+ return Ok(());
+ }
CoreTypeDesc::Ptyp_variant(_) => return Err(Stop::Declined(Declined::PolyVariantType)),
- CoreTypeDesc::Ptyp_poly(_) => return Err(Stop::Declined(Declined::PolyType)),
+ CoreTypeDesc::Ptyp_poly(inner) => {
+ // typetexp.ml:545-549.
+ self.c.g.begin_def();
+ let first = self.st.vars.univars.len();
+ for var in &inner.0 {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let name = self.st.strs.name(arena, &mut self.scopes.names, var.txt);
+ let first_byte = arena.get_string(var.txt).as_bytes().first().copied();
+ let named = first_byte.is_some_and(|c| c == b'_' || c.is_ascii_alphabetic());
+ let ty = self.new_var(if named { name.0 } else { NONE });
+ self.st.vars.univars.push(UsedVar { name, ty, loc: NONE });
+ }
+ let vars = &mut self.st.vars;
+ for row in (first..vars.univars.len()).rev() {
+ let at = vars.univars[row].name.0 as usize;
+ if at >= vars.univar_heads.len() {
+ vars.univar_heads.resize(at + 1, NONE);
+ }
+ vars.univars[row].loc = vars.univar_heads[at];
+ vars.univar_heads[at] = row as u32;
+ }
+ self.set_row(node, NO_ROW);
+ self.push_frame(node);
+ return Ok(());
+ }
CoreTypeDesc::Ptyp_package(_) => return Err(Stop::Declined(Declined::PackageType)),
CoreTypeDesc::Ptyp_extension(_) => return Err(Stop::Declined(Declined::ExtensionType)),
};
@@ -665,6 +868,8 @@ impl Annot<'_> {
let arena = self.arena;
let next = frame.next as usize;
Ok(match &arena.get_core_type(CoreTypeIdx(frame.node)).ptyp_desc {
+ CoreTypeDesc::Ptyp_alias(inner) => (next == 0).then_some(inner.0),
+ CoreTypeDesc::Ptyp_poly(inner) => (next == 0).then_some(inner.1),
CoreTypeDesc::Ptyp_tuple(list) => arena.type_list(*list).get(next).copied(),
CoreTypeDesc::Ptyp_constr((_, list)) => match arena.type_list(*list) {
// One `_`: as many times as the type has parameters (the
@@ -736,19 +941,26 @@ impl Annot<'_> {
// for the instance (CHECKER_REWRITE 10.2, decision 5).
CoreTypeDesc::Ptyp_constr(_) => {
let type_index = self.type_index(frame.node)?;
- for at in base..self.st.values.len() {
- let arg = self.st.values[at];
- self.c.lower(arg, level).map_err(|_clash| Stop::Error)?;
+ let plain = self.c.types.info(type_index).reserved & PLAIN_PARAMS != 0;
+ if plain {
+ for at in base..self.st.values.len() {
+ let arg = self.st.values[at];
+ self.c.lower(arg, level).map_err(|_clash| Stop::Error)?;
+ }
}
let b = self.c.g.lists.len() as u32;
self.c.g.lists.push(Ty(NONE));
self.c.g.lists.extend_from_slice(&self.st.values[base..]);
- self.c.g.push(Node {
+ let constr = self.c.g.push(Node {
head: CONSTR | count << 8,
level,
a: type_index,
b,
- })
+ });
+ if !plain {
+ self.unify_params(type_index, base as u32, constr)?;
+ }
+ constr
}
CoreTypeDesc::Ptyp_arrow(arrow) => {
let (first, _, _) = &**arrow;
@@ -786,6 +998,87 @@ impl Annot<'_> {
b,
})
}
+ CoreTypeDesc::Ptyp_alias(_) => {
+ // typetexp.ml:402-427, after the aliased type.
+ let t = self.st.values[base];
+ let ty = self.st.values[base + count as usize - 1];
+ if self.c.unify_var(t, ty).is_err() {
+ return Err(Stop::Error);
+ }
+ if count == 2 {
+ ty
+ } else {
+ let name = self.st.values[base + 1].0;
+ let t = self.instance(t);
+ let proxy = self.c.g.repr(t);
+ let found = self.c.g.nodes[proxy.0 as usize];
+ if found.tag() == VAR && found.a == NONE {
+ self.c.g.write(proxy, Node { a: name, ..found });
+ }
+ t
+ }
+ }
+ CoreTypeDesc::Ptyp_poly(inner) => {
+ // typetexp.ml:550-571.
+ let body = self.st.values[base];
+ let first = self.st.vars.univars.len() - inner.0.len();
+ let vars = &mut self.st.vars;
+ for row in first..vars.univars.len() {
+ let at = vars.univars[row].name.0 as usize;
+ vars.univar_heads[at] = vars.univars[row].loc;
+ }
+ self.c.g.end_def();
+ self.c.generalize(body);
+ // `deep_occur v ty` for every variable of the list: one walk.
+ let generation = self.c.fresh_marks();
+ self.c.g.work.clear();
+ self.c.g.work.push(body);
+ while let Some(ty) = self.c.g.work.pop() {
+ let ty = self.c.g.repr(ty);
+ if self.c.marks[ty.0 as usize] == generation {
+ continue;
+ }
+ #[cfg(test)]
+ super::super::steps::tick();
+ self.c.marks[ty.0 as usize] = generation;
+ let reached = self.c.g.nodes[ty.0 as usize];
+ self.c.g.children(reached, false);
+ }
+ let b = self.c.g.lists.len() as u32;
+ self.c.g.lists.push(body);
+ let mut bound = 0;
+ for row in first..self.st.vars.univars.len() {
+ #[cfg(test)]
+ super::super::steps::tick();
+ let v = self.c.g.repr(self.st.vars.univars[row].ty);
+ if self.c.marks[v.0 as usize] != generation {
+ continue;
+ }
+ let found = self.c.g.nodes[v.0 as usize];
+ if found.tag() != VAR || found.level != GENERIC {
+ return Err(Stop::Error);
+ }
+ let a = self.c.extras.univar(found.a);
+ self.c.g.write(v, Node { head: TUPLE | EXTENDED, level: GENERIC, a, b: 0 });
+ self.c.g.lists.push(v);
+ bound += 1;
+ }
+ self.st.vars.univars.truncate(first);
+ let a = self.c.extras.descriptors.len() as u32;
+ self.c.extras.descriptors.push(ExtraDescriptor::Poly);
+ let poly = self.c.g.push(Node {
+ head: TUPLE | EXTENDED | (bound + 1) << 8,
+ level: GENERIC,
+ a,
+ b,
+ });
+ // `unify_var env (newvar ()) ty'` (571).
+ let level = self.c.g.level;
+ if self.c.lower(poly, level).is_err() {
+ return Err(Stop::Error);
+ }
+ poly
+ }
_ => return Err(NOT_A_FRAME),
})
} |
The prototype was rebuilt on trunk's bodies of R5a-1 and posted again; the prompt names the functions of that build its code meets, and its searches give what they print on a head that holds it. Co-authored-by: Jaap Frolich <jfrolich@gmail.com> Session: https://os.submodule.nl/session/bks-70623c69-2944-7bf2-a162-c8f0b9ef7aeb Signed-off-by: open-session-submodule[bot] <341020755+open-session-submodule[bot]@users.noreply.github.com>
|
First-pass checklist review at 39a933e (a checklist for the final reviewer, not an approval). First-pass review (checklist, not an approval): Setup: 1. Scope — PASS
2. Default path — PASS
3. Engineering standard — PASS for the diff; notes on the prototypeGreps were run over the
4. Tests and oracles — PASSNo existing test, expectation, fixture, ratchet or script is touched. The diff has 5 files (section 1), and r5a_tests.rs is not among them. Weakenings come later, by the prompt: it lets the builder delete 5. New scripts and fixtures — PASSNone. The new test file is in 6. Privacy — PASS
7. Changelog — PASS
8. Numbers — UNCLEAR
9. Focused tests — not run (host review)10. Where I would look hardest
11. Files — PASS(a) The diff touches no body that R5a-1 built: (b) The two new fields of
(c) Signatures and doc comments, against the body's "Skeleton changes":
(d) mod.rs gains one item, written as two lines (the 12. The alias arm (decisions 14, 15) — PASS, kernel side partly UNCLEARtypetexp.ml:394-428:
The name is interned once in Decision 15, OCaml side, by reading 2748-2765, 2240-2242 and occur_rec 1384-1408 (unify2/unify3 were not pasted):
Kernel side: Walks without marks on a node that names itself:
Objects: 13. The polymorphic arm (decision 18) — PASSIn order:
Duplicate binder names, Aliased binders, Marks: Nested binder, by reading only: the inner 14.
|
|
Coordinator review, final, at 39a933e (the author did not write this review). It follows the first-pass checklist review above (7258428653), which read the OCaml source line by line beside the design and the prototype; I did not repeat that reading and say below what I checked myself. What this pull request puts on trunk. The design of R5a-2 (CHECKER_REWRITE 10.12, decisions 13 to 21), cut in two; for the first half, R5a-2a (aliases, universal variables and the polymorphic arm, Checked by me.
Decisions. 13 (the cut: R5a-3 needs R5a-2a only), 14, 17, 18, 20 and 21: confirmed by the first pass's reading. 16 (a used variable whose globalization fails declines the unit where OCaml skips it silently): accepted; a decline sends the unit to today's checker and is never wrong, and it is taken with the speculation closed. 15 (a phantom self-alias is held as a type that names itself): accepted for annotations; R5a-9 declines such a scheme unless its design shows capture and publication on one. 19: accepted with the correction above. Owed, and to whom.
CI on 39a933e: 23 of 23 (read by the first pass: Not rerun or not read by me: any cargo command; the prototype (applied by the first pass, not by me); the skeleton diff of Merging. R5a-2a is built next, by a builder that writes the bodies reading the prototype. |
Second design turn of slice R5a of the type checker rewrite (
compiler-rust/docs/CHECKER_REWRITE.md, section 10). Slice R5a-2, the rest of type annotations, is decided, cut in two, and its first half is tested and built once as a prototype. No body of a slice is committed: the committed tree keeps itstodo!bodies and its ignored tests, and nothing of a default build changes.What is in it
State:line; 10.10 has the prompt "Task R5a-2a".src/tc/r5a2_tests.rs: 23 acceptance tests ignored until the slice is built, 5 pins of today's checker that run today, and the check that every ignored test names its slice.src/tc/walk/typetexp.rs, skeleton only (listed below).// R5A-PROTOTYPE R5a-2, second): one diff against commit def93a8, the merge of trunk after R5a-1 was built (pull request 435), applied alone; it stands on the BUILT bodies of R5a-1. Fetched back,git apply --checkpasses on def93a8 and on the head. The first, comment 7257203319, was built on commit 947fad3 with the second prototype of R5a-1 (comment 7255791970 of pull request 430) applied first; both applied in order there. The bodies of the eight R5a-2 functions are the same text in both.Which deliverables are complete
The cut
The prototype of everything but paths changes 336 lines (314 added, 22 removed). Paths and types of other units were not built: a type of another unit needs a row in the unit's own type table, and
TypeTable::from_segmentmakes a whole table from one segment. That needs a design turn that builds that row first (10.12.5). So: R5a-2a (aliases, universal variables,globalize,transl_simple_type,transl_type_scheme,unify_params) has tests, a prototype and a prompt; R5a-2b (paths, other units) has neither. R5a-3 needs only R5a-2a.Decisions a review should confirm
validate_name; oneinternan alias.unify_var, unchanged; a phantom self-alias (ph<'b> as 'b) is HELD as a node that names itself, not declined.Declined::PolyType), where OCaml skips it silently and can leave a universal variable outside its binder.globalizeis two loops over the used rows with no list between them; the second runs from the last row to the first; one speculation a variable, closed before the decline.deep_occurfor a binder's list is ONE marking walk of the body; the last line of the arm isChecker::lower.unify_paramsalways callsunify_var;enforce_constraintsis kept as a second copy session.Policy::Univarshas no caller in OCaml and keeps declining.Err,transl_typeputs the level back and drops the universal variables.Lines of OCaml read, and not read
Read, every line:
compiler/ml/typetexp.ml63-136, 205-428, 545-588, 677-756;compiler/ml/ctype.ml120-162, 509-520, 879-894, 1333-1342, 1384-1408, 1723-1776, 2216-2247, 2726-2733, 2748-2767.NOT read:
occur_univar,subst,update_level,unify2/unify3in OCaml (the kernel's functions were run instead); typetexp.ml 431-544 and 572-586 beyond the first lines (they decline);compiler/ml/env.ml; the port of the alias and polymorphic arms insrc/types/typecore.rs(today's checker was run on every program instead); the body ofTypeTable::from_segment.Tests run, with counts
--lib tc::r5a_tests -- --include-ignored--lib tc::--lib tc::r5a -- --include-ignored--lib tc::r5a2_tests -- --include-ignored--lib tc::r5a--lib tc::r5a -- --include-ignoredThe 2 failures are tests of R5a-1 that pin a decline this slice removes (
a_type_without_plain_parameters_is_declined, and the rowint as 'aofunbuilt_annotations_decline); the prompt tells the builder to delete the first and that one row (10.12.4). The other 20 tests of R5a-1 pass with both prototypes.NOT run: the whole
tc::filter on the head after the two merges of trunk (CI shows the number); the 39 breaks against the second prototype (they ran against the first);cargo clippyandcargo doclocally (CI'scompiler-warningspassed on cc6758a); the five commits of the prompt each built alone (their order was checked by reading what each test calls, and the prompt says so).Every acceptance test
All 23 ignored tests passed against the prototype. Three passed only after a change:
a_polymorphic_type_binds_the_variables_that_occur: the PROTOTYPE was wrong (it lowered the finished type to the binder's own level); corrected, then passed.polymorphic_fields_agree_with_todays_checker,the_fixed_policy_refuses_a_variable_that_is_not_declared,parameters_without_plain_params_agree_with_todays_checker,ten_thousand_uses_of_one_alias: expectations written on paper were wrong and were replaced by what today's checker shows (a record field without a binder is not wrapped in a polymorphic type;sh<int, int>has its twointnodes linked).large <= 11 * small,small >= 1,000was not changed.Arms no test reaches: a binder inside a binder (the parser or today's checker refuses every source form tried); the
Tunivar Nonehalf of the proxy naming;Cannot_quantifyfor a variable lowered below its binder.Wrong bodies
39 breaks of the prototype were run, one at a time, against
--lib tc::r5a2_tests -- --include-ignored; 35 failed at least one test. The table is in 10.10 of the document; by function:a_self_alias_is_refused_as_in_ocamland 8 moreunify_varan_alias_bound_to_two_types_is_an_errorand 7 morealiases_agree_with_todays_checkera_polymorphic_type_binds_the_variables_that_occurdeep_occuronce a variableten_thousand_universal_variablesend_def; nogeneralize; heads not put backpolymorphic_fields_agree_with_todays_checker,ten_thousand_universal_variablesunivara_universal_variable_hides_a_used_variable_inside_its_binderglobalizeused_variables_are_globalized_in_the_order_of_their_namesglobalizepolymorphic_fields_agree_with_todays_checkerglobalizethe_fixed_policy_refuses_a_variable_that_is_not_declared,a_name_bound_to_two_types_by_two_annotations_is_an_error,globalized_variables_are_at_the_global_leveltransl_simple_typeglobalize; used not emptied; always extensibleglobalized_variables_are_at_the_global_level;polymorphic_fields_agree_with_todays_checkertransl_type_schemegeneralize; no reset; level kept on an errora_scheme_is_generalizedunify_paramsparameters_without_plain_params_agree_with_todays_checkerunify_paramsthe_declared_parameters_are_instantiated_not_boundTypeVars::resetlevel + 1reset_forgets_the_declared_variablesdeclaredtransl_typeonErran_error_inside_a_binder_leaves_no_binderNo test catches (each named in the prompt or argued in the document):
enforce_constraintsleft out; a binder's heads written in source order; the instances ofunify_paramsleft on the value stack (the driver cuts them);Checker::copywithout the generic test (the same node). Not run as breaks because steps do not count them: aunivarthat scans, an alias interned twice, a sort that allocates; all three are in the prompt's failure list.Step tests seen to fail on a body that walks more: only
ten_thousand_universal_variables(ondeep_occuronce a variable). The other five were NOT broken with a body that walks twice.Today's checker against the OCaml texts
On the trunk this turn began from, today's checker accepted every refused self-alias and printed
id<'a> => intforid<'b> as 'b. Pull request 433 corrected it; this branch merged trunk, andold_checker_self_aliases_are_pinnednow observes agreement on all of them. No other program of the coordinator's list differs.Programs whose OCaml answer this turn could not know
Each is a file to run alone; the test follows today's checker.
Skeleton changes (signatures, costs, doc comments)
TypeVars::reset(&mut self)isreset(&mut self, level: u32).TypeVars::univar_headsandTypeVars::global_level; the doc ofunivarssays what a row'slocholds. These two field lines are in the struct, not "aftertransl_type_scheme": atodo!body must be able to read them and the tests name them. They sit beside the fields marked R5a-2, away from every line R5a-1's builder writes; the R5a-1 prototype still applies.Annot::univar,Annot::declared,Annot::add_declared, bodiestodo!("R5a-2"), aftertransl_type_scheme.unify_params,globalize,transl_simple_type,transl_type_scheme.src/tc/mod.rs: one line,mod r5a2_tests;with thecfgofr5a_tests.r5a_tests.rsis not touched.Attributes added:
#[inline]onAnnot::univarandAnnot::declared(one bounds test and two loads, called once a variable node, asTypeVars::usedhas it).Checks changed on trunk: none. Added:
r5a2_tests::ignored_tests_name_the_slices_they_reach, the check ofr5a_testsrepeated for the new file; it pins no number. That every ignored test names only its own slice and earlier ones was checked by that test, which runs today.No reader was added on the side of today's checker. No hash map, no new struct or enum.
Open questions, each with a recommended answer
'a. (.. as 'b)before R5c if in doubt.enforce_constraints(decision 19)? Recommended: keep until program 14 is answered by OCaml's source or a run; then delete the second loop.Graph::captureand the published text on one.r5a_tests.rsmoves.Asked by the coordinator during the turn, and not done
Paramlocation taken from the type,resolvedleft empty for a constructor without arguments, the fixed policy skipped for a repeated_, a non-ASCII letter keeping its name, the wrongDeclinedvariant, a decline by counting parameters, only the first argument lowered, amarkon a binder that is not a type): none was added. One of them touches this slice directly and is in the prompt: the rule ofvalidate_nameon trunk tests only for an ASCII letter behind a refusal of_, and a binder's variable has no such refusal, so the builder is told to share one helper with the whole rule.charas distinct fromint.Gates
Nothing of a default build calls the new code:
Instruction countcannot move, and no measurement was taken. CI is the gate for clippy,cargo docand the parity checks.Started by Jaap Frolich in this Assistant session