Skip to content

Missing "rec" hint: v2#1720

Merged
gasche merged 10 commits intoocaml:trunkfrom
Armael:improved-error-letrec-v2
May 6, 2018
Merged

Missing "rec" hint: v2#1720
gasche merged 10 commits intoocaml:trunkfrom
Armael:improved-error-letrec-v2

Conversation

@Armael
Copy link
Copy Markdown
Member

@Armael Armael commented Apr 11, 2018

This is a second iteration of #1472, following up on #1678 . Compared to the first iteration, this additionally includes:

@Armael Armael force-pushed the improved-error-letrec-v2 branch from 904a970 to b911893 Compare April 11, 2018 20:33
Copy link
Copy Markdown
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

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

Looks nice to me.

if is_recursive then new_env
else if not is_recursive then begin
(* add ghost bindings to help detecting missing "rec" keywords *)
else if not is_recursive && List.for_all sexp_is_fun spat_sexp_list
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we want List.for_all or List.exists? I would be content with a let .. and .., one of them being a function.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I do not have a strong opinion either way. I guess it should be relatively safe to use List.exists since let .. and .. is rarely used to define something else than recursive functions.

let value2 = value2 (* typo: should be value1 *) + 1 in
^^^^^^
Error: Unbound value value2
Hint: Did you mean value1?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

At this point in the patch series, there is no heuristic to disable the missing-rec handling for non-functions (added in the next commit 92ff83e ). How come there is no recursive-definition here, does the spellchecking hint override it naturally?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, it appears I just messed up the tests while rebasing. This should be fixed now.

@Armael Armael force-pushed the improved-error-letrec-v2 branch from b911893 to 457da87 Compare April 11, 2018 22:29
@gasche
Copy link
Copy Markdown
Member

gasche commented Apr 12, 2018

This looks good to merge in trunk to me, but I would be interested in feedback from the flambda people, @xclerc or @mshinwell or @lpw25 for example.

let (_, line, _) = Location.get_pos_info loc.Location.loc_start in
fprintf ppf
"@.@[%s %i@]"
"Hint: If this is a recursive definition, you should add a 'rec' keyword on line"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This line seems to be a bit long, and the resulting
user-facing message is larger than what is usually
output by the Format module. It might be worthwhile
to both split the line and insert a breakable space.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

See also Format.pp_print_text : formatter -> string -> unit which turns all spaces into breakable spaces; here it could be used by turning %s into%a.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(Actually, I am not certain we want to blindly turn all spaces
into breakable ones. Given the shape of the message, there
is a possibility that the break would occur right before the line
number, which is not very nice.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well this particular space is not part of the string literal so it actually wouldn't be made breakable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, I am wondering if it would be possible to avoid "@." by opening a vectical box :

fprintf ppf
        "@[<v>@[Unbound value %a@]" longident lid;
      spellcheck ppf fold_values env lid;
      let (_, line, _) = Location.get_pos_info loc.Location.loc_start in
      fprintf ppf
        "@,@[%s %i@]@]"
        "Hint: If this is a recursive definition, you should add a 'rec' keyword on line"

since the behavior of @. tends to mask problems with the formatting.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@gasche sure, but we can get a break before the word "line";
in the surrounding code, breakable spaces are explicitly placed
at strategic points.

@gasche
Copy link
Copy Markdown
Member

gasche commented Apr 16, 2018

Another thing we could do is disable the hint if the let-binding is "ghost" code -- automatically generated.

@Armael Armael force-pushed the improved-error-letrec-v2 branch from 831e7a4 to 1e0e6f0 Compare April 23, 2018 09:36
@Armael
Copy link
Copy Markdown
Member Author

Armael commented Apr 23, 2018

I just made the following changes:

  • the hint message has been split, using a breakable space, as adviced by @xclerc;
  • the hint is now disabled for ghost code as suggested by @gasche.

@Armael Armael force-pushed the improved-error-letrec-v2 branch 2 times, most recently from 7e8b309 to 3d0f0fa Compare April 26, 2018 12:10
@Armael
Copy link
Copy Markdown
Member Author

Armael commented Apr 26, 2018

I just rebased on top of trunk (this was required after @trefis refactoring in #1735).

Any other comments on this?

@xclerc
Copy link
Copy Markdown
Contributor

xclerc commented Apr 26, 2018

I just noticed a small inconsistency in the comments:
the comment about the fold_values function in
typing/typetexp.ml here uses "phantom" while
"ghost" is used everywhere.

(I am quite probably the one to blame for introducing
the inconsistency, but cannot edit the PR.)

@Armael Armael force-pushed the improved-error-letrec-v2 branch from 3d0f0fa to 61528b9 Compare April 26, 2018 13:12
@Armael
Copy link
Copy Markdown
Member Author

Armael commented Apr 26, 2018

Good catch, thanks.

@Armael
Copy link
Copy Markdown
Member Author

Armael commented May 5, 2018

Anything else I can do about this PR?

@gasche
Copy link
Copy Markdown
Member

gasche commented May 5, 2018

@xclerc, @mshinwell, @lpw25: is there a better way to know if your concerns with the previous version are addressed in this new PR than to merge in trunk and let you see for yourself over time?

@xclerc
Copy link
Copy Markdown
Contributor

xclerc commented May 5, 2018

Even if the conditions triggering the warning need to be
refined at some point, the current PR looks like a significant
and welcomed improvement. I think it should be merged.

@gasche
Copy link
Copy Markdown
Member

gasche commented May 5, 2018

@Armael could you move the Changes entry to be in the development version rather than 4.07?

@Armael Armael force-pushed the improved-error-letrec-v2 branch from 61528b9 to 465a5f7 Compare May 6, 2018 08:01
@Armael Armael force-pushed the improved-error-letrec-v2 branch from 465a5f7 to acfd378 Compare May 6, 2018 08:08
@Armael
Copy link
Copy Markdown
Member Author

Armael commented May 6, 2018

@gasche done and rebased on trunk

@gasche gasche merged commit 4a456d3 into ocaml:trunk May 6, 2018
@vicuna vicuna mentioned this pull request Mar 14, 2019
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.

4 participants