rec_check.ml: fix a bug in recursive class declarations check.#1915
rec_check.ml: fix a bug in recursive class declarations check.#1915gasche merged 1 commit intoocaml:trunkfrom
Conversation
Cemoixerestre
commented
Jul 18, 2018
|
I'll try to take a look at this next week. |
|
@yallop no problem, thanks for the notice. Note: I think the fix, if approved, should go in the maintenance 4.07 branch -- the Changes entry is placed there. |
yallop
left a comment
There was a problem hiding this comment.
There's one typo in a comment, but I'm otherwise happy.
typing/rec_check.ml
Outdated
| | Tcl_let (rec_flag, valbinds, _, ce) -> | ||
| let _, ty = value_bindings rec_flag env valbinds in | ||
| Use.join ty (class_expr env ce) | ||
| (* This rule looks like the `Texp_rule` in the expression function, |
There was a problem hiding this comment.
The comment should read "… like the Texp_let rule …"
typing/rec_check.ml
Outdated
| Use.join ty (class_expr env ce) | ||
| (* This rule looks like the `Texp_rule` in the expression function, | ||
| but is more restrictive. Maybe we should add `Use.discard` to | ||
| make this rule more similar. *) |
There was a problem hiding this comment.
Maybe we should addUse.discardto make this rule more similar.
Since Use.discard won't perform any useful function here, I think it's best to leave it out.
Here's my reasoning for why Use.discard would do nothing: the only way to use a class name in a computation is via new, which counts as an inspection; inspection turns everything into dereferencing; any further surrounding contexts can only turn Dereferenced into Dereferenced or Guarded, both of which are left unchanged by guarded.
|
Yes, I agree with the reasoning for why Thanks for the review! I will fix the typo and rebase the PR. |
|
I rebased the PR, and added a precise comment on the lack of |
# class a = let x() = new a in let y = x() in object end;;
Warning 26: unused variable y.
Segmentation fault (core dumped)
rec_check.ml: fix a bug in recursive class declarations check. (cherry picked from commit 9e45a79)
|
When I cherry-picked in 4.07 ( 8e043eb ) I realized that there are two occurrences of |
This work was conducted by Alban Reynaud during an internship at INRIA Saclay, with the help and under the supervision of Gabriel Scherer in the Parsifal team. A summary is included below. For more details, see https://github.com/Cemoixerestre/Internship-2018-ocaml-recursive-value or the comments in the code itself, which has evolved a bit from Alban's internship report above. Summary: -------- Rec_check is based on the idea of assigning "access modes" to variables m ::= Dereference (* full access and inspection of the value *) | Unguarded (* the value result is directly returned *) | Guard (* the value is stored under a data constructor *) | Delayed (* the value is not needed at definition time *) Before this patchset, the implementation (contributed by Jeremy Yallop) was formulated as a type-checker manipulating "uses", which are mappings from free variables to modes u ::= (x : m)* and contexts Γ mapping variables to uses Γ ::= (x : u)* The check relied on a judgment of the form Γ ⊢ e : u where, in the typing algorithm, `Γ` and `e` are the inputs, and `u` is the output — this could be written `-Γ ⊢ e : +u`. After this patchset, the implementation uses a simpler notion of context mapping variables to mods Γ ::= (x : m)* and the judgment has the simpler structure Γ ⊢ e : m but now `m` is an input to the judgment, indicating in which usage context `e` is checked, and `Γ` is the output: `+Γ ⊢ e : -m`. Other fixes: ------------ This patchset also fixes a soundness bug around `{ foo with ... }` which is already present in 4.06 and 4.07. Another soundness bug found during this work was submitted and fixed independently as GPR ocaml#1915. This work also led to the refactoring of GPR ocaml#1922, and the refactoring of the testsuite in GPR ocaml#1937.
This work was conducted by Alban Reynaud during an internship at INRIA Saclay, with the help and under the supervision of Gabriel Scherer in the Parsifal team. A summary is included below. For more details, see https://github.com/Cemoixerestre/Internship-2018-ocaml-recursive-value or the comments in the code itself, which has evolved a bit from Alban's internship report above. Summary: -------- Rec_check is based on the idea of assigning "access modes" to variables m ::= Dereference (* full access and inspection of the value *) | Unguarded (* the value result is directly returned *) | Guard (* the value is stored under a data constructor *) | Delayed (* the value is not needed at definition time *) Before this patchset, the implementation (contributed by Jeremy Yallop) was formulated as a type-checker manipulating "uses", which are mappings from free variables to modes u ::= (x : m)* and contexts Γ mapping variables to uses Γ ::= (x : u)* The check relied on a judgment of the form Γ ⊢ e : u where, in the typing algorithm, `Γ` and `e` are the inputs, and `u` is the output — this could be written `-Γ ⊢ e : +u`. After this patchset, the implementation uses a simpler notion of context mapping variables to mods Γ ::= (x : m)* and the judgment has the simpler structure Γ ⊢ e : m but now `m` is an input to the judgment, indicating in which usage context `e` is checked, and `Γ` is the output: `+Γ ⊢ e : -m`. Other fixes: ------------ This patchset also fixes a soundness bug around `{ foo with ... }` which is already present in 4.06 and 4.07. Another soundness bug found during this work was submitted and fixed independently as GPR ocaml#1915. This work also led to the refactoring of GPR ocaml#1922, and the refactoring of the testsuite in GPR ocaml#1937.
This work was conducted by Alban Reynaud during an internship at INRIA Saclay, with the help and under the supervision of Gabriel Scherer in the Parsifal team. A summary is included below. For more details, see https://github.com/Cemoixerestre/Internship-2018-ocaml-recursive-value or the comments in the code itself, which has evolved a bit from Alban's internship report above. Summary: -------- Rec_check is based on the idea of assigning "access modes" to variables m ::= Dereference (* full access and inspection of the value *) | Unguarded (* the value result is directly returned *) | Guard (* the value is stored under a data constructor *) | Delayed (* the value is not needed at definition time *) Before this patchset, the implementation (contributed by Jeremy Yallop) was formulated as a type-checker manipulating "uses", which are mappings from free variables to modes u ::= (x : m)* and contexts Γ mapping variables to uses Γ ::= (x : u)* The check relied on a judgment of the form Γ ⊢ e : u where, in the typing algorithm, `Γ` and `e` are the inputs, and `u` is the output — this could be written `-Γ ⊢ e : +u`. After this patchset, the implementation uses a simpler notion of context mapping variables to mods Γ ::= (x : m)* and the judgment has the simpler structure Γ ⊢ e : m but now `m` is an input to the judgment, indicating in which usage context `e` is checked, and `Γ` is the output: `+Γ ⊢ e : -m`. Other fixes: ------------ This patchset also fixes a soundness bug around `{ foo with ... }` which is already present in 4.06 and 4.07. Another soundness bug found during this work was submitted and fixed independently as GPR ocaml#1915. This work also led to the refactoring of GPR ocaml#1922, and the refactoring of the testsuite in GPR ocaml#1937.
This work was conducted by Alban Reynaud during an internship at INRIA Saclay, with the help and under the supervision of Gabriel Scherer in the Parsifal team. A summary is included below. For more details, see https://github.com/Cemoixerestre/Internship-2018-ocaml-recursive-value or the comments in the code itself, which has evolved a bit from Alban's internship report above. Summary: -------- Rec_check is based on the idea of assigning "access modes" to variables m ::= Dereference (* full access and inspection of the value *) | Unguarded (* the value result is directly returned *) | Guard (* the value is stored under a data constructor *) | Delayed (* the value is not needed at definition time *) Before this patchset, the implementation (contributed by Jeremy Yallop) was formulated as a type-checker manipulating "uses", which are mappings from free variables to modes u ::= (x : m)* and contexts Γ mapping variables to uses Γ ::= (x : u)* The check relied on a judgment of the form Γ ⊢ e : u where, in the typing algorithm, `Γ` and `e` are the inputs, and `u` is the output — this could be written `-Γ ⊢ e : +u`. After this patchset, the implementation uses a simpler notion of context mapping variables to mods Γ ::= (x : m)* and the judgment has the simpler structure Γ ⊢ e : m but now `m` is an input to the judgment, indicating in which usage context `e` is checked, and `Γ` is the output: `+Γ ⊢ e : -m`. Other fixes: ------------ This patchset also fixes a soundness bug around `{ foo with ... }` which is already present in 4.06 and 4.07. Another soundness bug found during this work was submitted and fixed independently as GPR ocaml#1915. This work also led to the refactoring of GPR ocaml#1922, and the refactoring of the testsuite in GPR ocaml#1937.
This work was conducted by Alban Reynaud during an internship at INRIA Saclay, with the help and under the supervision of Gabriel Scherer in the Parsifal team. A summary is included below. For more details, see https://github.com/Cemoixerestre/Internship-2018-ocaml-recursive-value or the comments in the code itself, which has evolved a bit from Alban's internship report above. Summary: -------- Rec_check is based on the idea of assigning "access modes" to variables m ::= Dereference (* full access and inspection of the value *) | Unguarded (* the value result is directly returned *) | Guard (* the value is stored under a data constructor *) | Delayed (* the value is not needed at definition time *) Before this patchset, the implementation (contributed by Jeremy Yallop) was formulated as a type-checker manipulating "uses", which are mappings from free variables to modes u ::= (x : m)* and contexts Γ mapping variables to uses Γ ::= (x : u)* The check relied on a judgment of the form Γ ⊢ e : u where, in the typing algorithm, `Γ` and `e` are the inputs, and `u` is the output — this could be written `-Γ ⊢ e : +u`. After this patchset, the implementation uses a simpler notion of context mapping variables to mods Γ ::= (x : m)* and the judgment has the simpler structure Γ ⊢ e : m but now `m` is an input to the judgment, indicating in which usage context `e` is checked, and `Γ` is the output: `+Γ ⊢ e : -m`. Other fixes: ------------ This patchset also fixes a soundness bug around `{ foo with ... }` which is already present in 4.06 and 4.07. Another soundness bug found during this work was submitted and fixed independently as GPR ocaml#1915. This work also led to the refactoring of GPR ocaml#1922, and the refactoring of the testsuite in GPR ocaml#1937.
This work was conducted by Alban Reynaud during an internship at INRIA Saclay, with the help and under the supervision of Gabriel Scherer in the Parsifal team. A summary is included below. For more details, see https://github.com/Cemoixerestre/Internship-2018-ocaml-recursive-value or the comments in the code itself, which has evolved a bit from Alban's internship report above. Summary: -------- Rec_check is based on the idea of assigning "access modes" to variables m ::= Dereference (* full access and inspection of the value *) | Unguarded (* the value result is directly returned *) | Guard (* the value is stored under a data constructor *) | Delayed (* the value is not needed at definition time *) Before this patchset, the implementation (contributed by Jeremy Yallop) was formulated as a type-checker manipulating "uses", which are mappings from free variables to modes u ::= (x : m)* and contexts Γ mapping variables to uses Γ ::= (x : u)* The check relied on a judgment of the form Γ ⊢ e : u where, in the typing algorithm, `Γ` and `e` are the inputs, and `u` is the output — this could be written `-Γ ⊢ e : +u`. After this patchset, the implementation uses a simpler notion of context mapping variables to mods Γ ::= (x : m)* and the judgment has the simpler structure Γ ⊢ e : m but now `m` is an input to the judgment, indicating in which usage context `e` is checked, and `Γ` is the output: `+Γ ⊢ e : -m`. Other fixes: ------------ This patchset also fixes a soundness bug around `{ foo with ... }` which is already present in 4.06 and 4.07. Another soundness bug found during this work was submitted and fixed independently as GPR ocaml#1915. This work also led to the refactoring of GPR ocaml#1922, and the refactoring of the testsuite in GPR ocaml#1937.
This work was conducted by Alban Reynaud during an internship at INRIA Saclay, with the help and under the supervision of Gabriel Scherer in the Parsifal team. A summary is included below. For more details, see https://github.com/Cemoixerestre/Internship-2018-ocaml-recursive-value or the comments in the code itself, which has evolved a bit from Alban's internship report above. Summary: -------- Rec_check is based on the idea of assigning "access modes" to variables m ::= Dereference (* full access and inspection of the value *) | Unguarded (* the value result is directly returned *) | Guard (* the value is stored under a data constructor *) | Delayed (* the value is not needed at definition time *) | Unused (* the value is not used at all *) Before this patchset, the implementation (contributed by Jeremy Yallop) was formulated as a type-checker manipulating "uses", which are mappings from free variables to modes u ::= (x : m)* and contexts Γ mapping variables to uses Γ ::= (x : u)* The check relied on a judgment of the form Γ ⊢ e : u where, in the typing algorithm, `Γ` and `e` are the inputs, and `u` is the output — this could be written `-Γ ⊢ e : +u`. After this patchset, the implementation uses a simpler notion of context mapping variables to mods Γ ::= (x : m)* and the judgment has the simpler structure Γ ⊢ e : m but now `m` is an input to the judgment, indicating in which usage context `e` is checked, and `Γ` is the output: `+Γ ⊢ e : -m`. Other fixes: ------------ This patchset also fixes a soundness bug around `{ foo with ... }` which is already present in 4.06 and 4.07. Another soundness bug found during this work was submitted and fixed independently as GPR ocaml#1915. This work also led to the refactoring of GPR ocaml#1922, and the refactoring of the testsuite in GPR ocaml#1937.
This work was conducted by Alban Reynaud during an internship at INRIA Saclay, with the help and under the supervision of Gabriel Scherer in the Parsifal team. A summary is included below. For more details, see https://github.com/Cemoixerestre/Internship-2018-ocaml-recursive-value or the comments in the code itself, which has evolved a bit from Alban's internship report above. Summary: -------- Rec_check is based on the idea of assigning "access modes" to variables m ::= Dereference (* full access and inspection of the value *) | Unguarded (* the value result is directly returned *) | Guard (* the value is stored under a data constructor *) | Delayed (* the value is not needed at definition time *) | Unused (* the value is not used at all *) Before this patchset, the implementation (contributed by Jeremy Yallop) was formulated as a type-checker manipulating "uses", which are mappings from free variables to modes u ::= (x : m)* and contexts Γ mapping variables to uses Γ ::= (x : u)* The check relied on a judgment of the form Γ ⊢ e : u where, in the typing algorithm, `Γ` and `e` are the inputs, and `u` is the output — this could be written `-Γ ⊢ e : +u`. After this patchset, the implementation uses a simpler notion of context mapping variables to mods Γ ::= (x : m)* and the judgment has the simpler structure Γ ⊢ e : m but now `m` is an input to the judgment, indicating in which usage context `e` is checked, and `Γ` is the output: `+Γ ⊢ e : -m`. Other fixes: ------------ This patchset also fixes a soundness bug around `{ foo with ... }` which is already present in 4.06 and 4.07. Another soundness bug found during this work was submitted and fixed independently as GPR ocaml#1915. This work also led to the refactoring of GPR ocaml#1922, and the refactoring of the testsuite in GPR ocaml#1937.
This work was conducted by Alban Reynaud during an internship at INRIA Saclay, with the help and under the supervision of Gabriel Scherer in the Parsifal team. A summary is included below. For more details, see https://github.com/Cemoixerestre/Internship-2018-ocaml-recursive-value or the comments in the code itself, which has evolved a bit from Alban's internship report above. Summary: -------- Rec_check is based on the idea of assigning "access modes" to variables m ::= Dereference (* full access and inspection of the value *) | Unguarded (* the value result is directly returned *) | Guard (* the value is stored under a data constructor *) | Delayed (* the value is not needed at definition time *) | Unused (* the value is not used at all *) Before this patchset, the implementation (contributed by Jeremy Yallop) was formulated as a type-checker manipulating "uses", which are mappings from free variables to modes u ::= (x : m)* and contexts Γ mapping variables to uses Γ ::= (x : u)* The check relied on a judgment of the form Γ ⊢ e : u where, in the typing algorithm, `Γ` and `e` are the inputs, and `u` is the output — this could be written `-Γ ⊢ e : +u`. After this patchset, the implementation uses a simpler notion of context mapping variables to mods Γ ::= (x : m)* and the judgment has the simpler structure Γ ⊢ e : m but now `m` is an input to the judgment, indicating in which usage context `e` is checked, and `Γ` is the output: `+Γ ⊢ e : -m`. Other fixes: ------------ This patchset also fixes a soundness bug around `{ foo with ... }` which is already present in 4.06 and 4.07. Another soundness bug found during this work was submitted and fixed independently as GPR ocaml#1915. This work also led to the refactoring of GPR ocaml#1922, and the refactoring of the testsuite in GPR ocaml#1937.
|
@Cemoixerestre @yallop, any comment on @gasche's tweak described above? |
|
@damiendoligez: the tweak may be overzealous, but it appears to be harmless. |
Co-authored-by: cuihtlauac <cuihtlauac@users.noreply.github.com>