Skip to content

Cleanup parmatch#3

Closed
gasche wants to merge 36 commits intogasche:trunkfrom
trefis:cleanup-parmatch
Closed

Cleanup parmatch#3
gasche wants to merge 36 commits intogasche:trunkfrom
trefis:cleanup-parmatch

Conversation

@gasche
Copy link
Owner

@gasche gasche commented Jul 15, 2017

I'm creating this PR to discuss @trefis' efforts to understand and clarify the parmatch code.

@trefis trefis force-pushed the cleanup-parmatch branch from 9889dce to 907a5bd Compare July 17, 2017 11:10
Copy link

@maranget maranget left a comment

Choose a reason for hiding this comment

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

Coucou

trefis and others added 28 commits July 24, 2017 13:36
Added a test checking that the result of [check_partial_all] is unchanged (on
the particular example being tested)
We avoid doing some redundant work in the process.
We avoid doing some redundant work in the process.
The other option was to simply use [option].
The tests still pass so I expect that there was indeed no semantic change as a
result of this factorization. [1]
However I might have have *unreasonably* degraded performances in the simple
case. Please have a look.

Also, I'd like to rename [satisfiables] to something more meaningful,
[list_satisfying_vectors] is only partially convincing, suggestions welcomed.

Note:
[1]: in my first implementation I had forgotten to guard one of the calls to
[set_args] with the [if only_care_about_existence] check. As a result "make
world" succeeded, so did the tests typing-warnings/, but "make world.opt" failed
with a fatal error in [read_args].
Guarding none of the calls to [set_args] or all of them does fix the problem.
I chose to guard all of them, but that might actually have a negative impact on
performance in general.
trefis and others added 7 commits July 24, 2017 13:36
@gasche: you were involved in https://caml.inria.fr/mantis/view.php?id=6437 and
might have a better understanding than me of what's going on here.
If you're unsure, let's ask Jacques.
The same issue that was reported for typecore.ml in PR#6394 did occur in
fragile pattern-matching detection code. Fix is similar: accept the fact that
in presence of recursive module some incoherence may happen.
@trefis trefis force-pushed the cleanup-parmatch branch from 464b29a to fe2a2aa Compare July 24, 2017 12:38
@trefis
Copy link
Collaborator

trefis commented Jul 24, 2017

Hum @gasche , I rebased my branch and pushed...
If you update trunk on this repo to rev c427e58 the commit list should become reasonable again.
Sorry.

@gasche gasche changed the base branch from trunk to 4.05-Changes July 24, 2017 17:34
@gasche gasche changed the base branch from 4.05-Changes to trunk July 24, 2017 17:34
@gasche
Copy link
Owner Author

gasche commented Jul 24, 2017

I had to change base twice to get github to update the PR as expected (looks like they only monitor the pull-from branch...), but it worked. On the other hand, I'm in holidays right now, so don't expect fast reactions :-)

@trefis
Copy link
Collaborator

trefis commented Jul 25, 2017

As a consequence of the rebase, all the comments are "lost" (i.e. they are on commits not referenced on this PR anymore).
I reproduced them on the relevant new commits.

Sorry for the email spam this must have generated.
I'll refrain from rebasing this branch from now on.

simplify_head_pat r p1 ps varsets (simplify_head_pat r p2 ps varsets k)
| _ ->
(p, { row = ps; varsets = r :: varsets; }) :: k
and simplify_head_pat head_bound_variables p ps varsets k =
Copy link
Collaborator

Choose a reason for hiding this comment

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

@gasche said

We could also use head_variables (of course they are bounds in pattern, I'd say) or head_varset if we want something shorter.

To which I answered:

Your choice. I personally don't mind the long name.

@gasche
Copy link
Owner Author

gasche commented Jul 25, 2017

As a consequence of the rebase, all the comments are "lost" (i.e. they are on commits not referenced on this PR anymore).

I think this is my fault for commenting before I created the PR. If I comment on the PR now, github should be able to track comments across rebases.

@gasche
Copy link
Owner Author

gasche commented Jul 24, 2018

This PR has been superseded by ocaml#1488 and ocaml#1560, both merged now. Thanks!

@gasche gasche closed this Jul 24, 2018
gasche pushed a commit that referenced this pull request Jul 13, 2024
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 <[email protected]>
Signed-off-by: Edwin Török <[email protected]>
gasche added a commit that referenced this pull request Jul 30, 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 <[email protected]>

Signed-off-by: Edwin Török <[email protected]>
Co-authored-by: Edwin Török <[email protected]>
gasche pushed a commit that referenced this pull request Sep 23, 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.

4 participants