Skip to content

Conversation

@Anukriti12
Copy link

First PR: try_depth yet to be removed

@lthls
Copy link
Owner

lthls commented Jun 2, 2020

(There's a huge number of commits in the diff because I forgot to keep my trunk branch in sync with the upstream one, sorry about that)

@Anukriti12
Copy link
Author

(There's a huge number of commits in the diff because I forgot to keep my trunk branch in sync with the upstream one, sorry about that)

I was figuring out whether there is pass by reference but was informed later through IRC channel that there isn't anything like pointers in OCaml. Will do more changes soon

@lthls
Copy link
Owner

lthls commented Jun 2, 2020

Can you explain why you put Ident.Map.empty in some places instead of the depth argument from the caller ?

Apart from that, this looks like you've correctly added a new parameter to the count and count_default functions. The next step is to use this new parameter to carry the value that would otherwise be stored in try_depth.

I would suggest temporarily replacing the line let rec count depth = function with the two following lines:

let rec count depth lam =
  assert (depth = !try_depth);
  match lam with

which means that you will get an error during compilation if at some point the value for the new parameter and the old value kept in the reference disagree.

@lthls
Copy link
Owner

lthls commented Jun 2, 2020

(It will also force the depth argument to have the same type as the contents of the try_depth reference, which should help getting rid of the extra Ident.Map.empty)

@Anukriti1999
Copy link

Ohh this seems to be a nice approach, will add this. I added Ident.Map.empty for some debugging purpose while beginning but forgot to replace it.

gasche and others added 20 commits June 2, 2020 17:22
More partial application warnings
This PR fixes an old bug in the interaction between [merge_constraint]
and [Typedecl.transl_with_constraint], where
variance (and now separability) are recomputed in an invalid type
environment. See ocaml#9624 and the new tests.
(suggested by Leo White and Jacques Garrigue)
fix an environment problem in merge_constraint
Also: better explain how to encapsulate naked pointers in Abstract blocks.
Following review comments.

Also: fix the assertion in the third val_of_typtr function.
gasche and others added 16 commits June 8, 2020 15:39
We want to start allowing more information in the payload of
[@tailcall] attributes (currently no payload is supported), for
example we could consider using [@tailcall false] to ask the code
generator to disable a tail call.

A first required step in this direction is to use a custom datatype to
represent the tail-call attribute, instead of a boolean. This is
consistent with the other application-site
attributes (inline_attribute, specialise_attribute, local_attribute),
so it makes the code more regular -- but the change itself is
boilerplate-y.
Eliminate MKEXE_ANSI from build system
matching: refactor the local control flow of the Unused exception
[minor] refactoring the datatype for the [@tailcall] attribute
…port

ocamldoc: remove debugging facility
--enable-warn-error configure option
* Memprof: disable sampling when memprof is suspended.

* Changes.
This patch removes casts between struct skiplist * and struct skipcell *, and removes the "layout compatibility" fields in skiplist that were there to enable these casts.

The only algorithmic difference is that caml_skiplist_find is now "stop-at" (see discussion here), as this was slightly easier to write in the no-cast style.
* Remove temporary hack related to the Num library

This is a follow-up to commit 3de0115

* Also do some cleanup in stdlib/Makefiile
* Introducing codefrag: a new runtime module to work with code fragments

This module collects all the operations on code fragments performed in
various places of the runtime systems.  Applies both to bytecode and
to native code.

The implementation is based on skiplists, so that "lookup fragment by
PC" and "lookup fragment by number" are efficient (logarithmic in the
number of code fragments).  "Lookup fragment by digest" remains
linear-time.

The new module also improves the handling of digests: now it is
possible to mark a code fragment as "no digest" i.e. not marshal-able.

* Use the new "codefrag" runtime module for marshaling and for the
  debugger interface

Replace the previous handling of code fragments with calls to the
functions provided by the "codefrag" runtime module.
@lthls
Copy link
Owner

lthls commented Jun 12, 2020

The functional part of the task is done, good job.
I'll make a number of style comments that will help making the code easier to review for other people, but the first thing we want to do is to choose a name that is closer to the original try_depth name. The original name meant "depth of nested try...with expressions", and the "try" part is important.
One possibility is to reuse the original try_depth name. Now that the original reference has been removed, there is no ambiguity left, and it will make it very clear that it's used for the same purpose as the old reference.
I'll make a number of small inline comments about comments, white space, and stuff like that too.

Copy link
Owner

@lthls lthls left a comment

Choose a reason for hiding this comment

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

I've pointed out all the places where I think some cleanup should be done. I think once you've done that we should think of submitting back the PR to the main repository, but that's not urgent.


let try_depth = ref 0 in
(*
let try_depth = ref 0 in *)
Copy link
Owner

Choose a reason for hiding this comment

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

Comment should be removed for the final version.

let rec count depth = function
(* let rec count depth lam =
assert (depth = !try_depth);
match lam with *)
Copy link
Owner

Choose a reason for hiding this comment

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

Comment should be removed for the final version.

| (Lvar _| Lconst _) -> ()
| Lapply ap -> count ap.ap_func; List.iter count ap.ap_args
| Lfunction {body} -> count body
| Lapply ap -> (count depth) ap.ap_func; List.iter (count depth) ap.ap_args
Copy link
Owner

Choose a reason for hiding this comment

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

The first pair of parentheses is not needed.

| _ -> count depth d; count depth d (* default will get replicated *)
end
| Lstaticraise (i,ls) -> incr_exit i 1 !try_depth; List.iter count ls

Copy link
Owner

Choose a reason for hiding this comment

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

There's an extra empty line here, that you should remove for consistency.

in
count lam;
assert(!try_depth = 0);

Copy link
Owner

Choose a reason for hiding this comment

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

Extra empty line, might be better to remove it.

let subst = Hashtbl.create 17 in

let rec simplif = function
Copy link
Owner

Choose a reason for hiding this comment

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

There are two extra spaces on this line, most likely added by your editor; you should remove them (and keep the empty line).

| Lapply ap ->
Lapply{ap with ap_func = simplif ap.ap_func;
ap_args = List.map simplif ap.ap_args}
Lapply{ap with ap_func = (simplif depth) ap.ap_func;
Copy link
Owner

Choose a reason for hiding this comment

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

These parentheses are not needed, I would suggest removing them.

| Lsequence(l1, l2) -> Lsequence(simplif l1, simplif l2)
| Lwhile(l1, l2) -> Lwhile(simplif l1, simplif l2)
let depth1 = depth +1 in
let l1 = simplif depth1 l1 in
Copy link
Owner

Choose a reason for hiding this comment

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

Using simplif (depth + 1) l1 and removing the depth1 let-binding above probably better here.

@Anukriti12 Anukriti12 force-pushed the trunk branch 2 times, most recently from 5ba64b8 to 537920a Compare June 15, 2020 00:21
@lthls
Copy link
Owner

lthls commented Jun 15, 2020

I think we can now make a pull request on the main repository with your changes.
There's no guarantee that it will be merged, because it doesn't fix any bug or add any feature, but it could give you an idea of what kind of feedback to expect.
My own advice would be to submit a pull request but not spend too much time on it (in particular, you don't have to reply to every comment immediately), but I'll leave the choice to you.
I could also submit the PR on your behalf, if you prefer it this way.

@Anukriti1999
Copy link

No, that's not a concern for me. I will be making the first PR today itself.

lthls pushed a commit that referenced this pull request Aug 13, 2024
…l#13294)

The toplevel printer detects cycles by keeping a hashtable of values
that it has already traversed.

However, some OCaml runtime types (at least bigarrays) may be
partially uninitialized, and hashing them at arbitrary program points
may read uninitialized memory. In particular, the OCaml testsuite
fails when running with a memory-sanitizer enabled, as bigarray
printing results in reads to uninitialized memory:

```
==133712==WARNING: MemorySanitizer: use-of-uninitialized-value
    #0 0x4e6d11 in caml_ba_hash /var/home/edwin/git/ocaml/runtime/bigarray.c:486:45
    #1 0x52474a in caml_hash /var/home/edwin/git/ocaml/runtime/hash.c:251:35
    #2 0x599ebf in caml_interprete /var/home/edwin/git/ocaml/runtime/interp.c:1065:14
    #3 0x5a909a in caml_main /var/home/edwin/git/ocaml/runtime/startup_byt.c:575:9
    #4 0x540ccb in main /var/home/edwin/git/ocaml/runtime/main.c:37:3
    #5 0x7f0910abb087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: 8f53abaad945a669f2bdcd25f471d80e077568ef)
    #6 0x7f0910abb14a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a14a) (BuildId: 8f53abaad945a669f2bdcd25f471d80e077568ef)
    #7 0x441804 in _start (/var/home/edwin/git/ocaml/runtime/ocamlrun+0x441804) (BuildId: 7a60eef57e1c2baf770bc38d10d6c227e60ead37)

  Uninitialized value was created by a heap allocation
    #0 0x47d306 in malloc (/var/home/edwin/git/ocaml/runtime/ocamlrun+0x47d306) (BuildId: 7a60eef57e1c2baf770bc38d10d6c227e60ead37)
    #1 0x4e7960 in caml_ba_alloc /var/home/edwin/git/ocaml/runtime/bigarray.c:246:12
    #2 0x4e801f in caml_ba_create /var/home/edwin/git/ocaml/runtime/bigarray.c:673:10
    #3 0x59b8fc in caml_interprete /var/home/edwin/git/ocaml/runtime/interp.c:1058:14
    #4 0x5a909a in caml_main /var/home/edwin/git/ocaml/runtime/startup_byt.c:575:9
    #5 0x540ccb in main /var/home/edwin/git/ocaml/runtime/main.c:37:3
    #6 0x7f0910abb087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: 8f53abaad945a669f2bdcd25f471d80e077568ef)
    #7 0x7f0910abb14a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a14a) (BuildId: 8f53abaad945a669f2bdcd25f471d80e077568ef)
    #8 0x441804 in _start (/var/home/edwin/git/ocaml/runtime/ocamlrun+0x441804) (BuildId: 7a60eef57e1c2baf770bc38d10d6c227e60ead37)

SUMMARY: MemorySanitizer: use-of-uninitialized-value /var/home/edwin/git/ocaml/runtime/bigarray.c:486:45 in caml_ba_hash
```

The only use of hashing in genprintval is to avoid cycles, that is, it
is only useful for OCaml values that contain other OCaml values
(including possibly themselves). Bigarrays cannot introduce cycles,
and they are always printed as "<abstr>" anyway.

The present commit proposes to be more conservative in which values
are hashed by the cycle detector to avoid this issue: we skip hashing
any value with tag above No_scan_tag -- which may not contain any
OCaml values.

Suggested-by: Gabriel Scherer <gabriel.scherer@gmail.com>

Signed-off-by: Edwin Török <edwin.torok@cloud.com>
Co-authored-by: Edwin Török <edwin.torok@cloud.com>
lthls pushed a commit that referenced this pull request Oct 11, 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.