Skip to content

Check return modes in type_argument after eliminating optionals#734

Closed
stedolan wants to merge 1 commit intooxcaml:mainfrom
stedolan:local-type-arg-fix
Closed

Check return modes in type_argument after eliminating optionals#734
stedolan wants to merge 1 commit intooxcaml:mainfrom
stedolan:local-type-arg-fix

Conversation

@stedolan
Copy link
Copy Markdown
Contributor

There is a missing mode check in type_argument, in the case where it eliminates one or more optional arguments. With the following declarations in scope:

val mklocal : ?sep:string -> local_ (string -> string)
val use : (string -> string) -> unit

then the expression use mklocal currently compiles without error, ignoring the local_ return mode. This patch makes use mklocal an error, by checking that the return mode matches the expected mode.

I suspect that this has been unsound for a while, but it is difficult to make it segfault. (Since type_argument eta-expands, the obvious approach works without error). However, the bug causes the application inside type_argument's eta-expansion to have the wrong mode, which interacts badly with the mode-specific caml_curry and caml_apply functions.

The bug became much easier to trigger after ocaml-flambda/ocaml-jst#24, and showed up in real code, from which the testsuite example is extracted. I haven't managed to construct an example that segfaults before 24, but I think one probably exists.

@stedolan
Copy link
Copy Markdown
Contributor Author

Closed in favour of the better fix in #735

@stedolan stedolan closed this Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants