Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect sites names against reserved keywords #4219

Closed
Lelio-Brun opened this issue Feb 12, 2021 · 7 comments
Closed

Protect sites names against reserved keywords #4219

Lelio-Brun opened this issue Feb 12, 2021 · 7 comments

Comments

@Lelio-Brun
Copy link

Expected Behavior

Compilation success.

Actual Behavior

Compilation error.

Reproduction

  1. define a site whose name is a reserved Ocaml keyword, eg.,
    dune-project:
    (package
     (name my-package)
     (sites (lib include))
    
    dune:
    (generate_sites_module
     (module sites)
     (sites my-package))
    ...
    
  2. dune build generates and tries to build the following Sites.ml:
    module Sites = struct
        let include = Dune_site.Private_.Helpers.site
          ~package:"my-package"
          ~section:Dune_section.Lib
          ~suffix:"include"
          ~encoded:(Sys.opaque_identity "%%DUNE_PLACEHOLDER:...%%")
    end
  3. Compilation obviously fails with a syntax error.

Specifications

  • Version of dune (output of dune --version): 2.8.2
  • Version of ocaml (output of ocamlc --version): 4.11.1
  • Operating system (distribution and version): Ubuntu 20.04.2
@bobot
Copy link
Collaborator

bobot commented Feb 19, 2021

Thank you a lot for the report.

I don't know how to accept those name for sites, and have a predictable value name in the generated module. We can add an underscore at the end: include_. But it could clash if someone defines a site named include_ and include. However I would like to accept a site named include because it is a very sensible name.

So possible Fix1:

  • Accept OCaml keyword, but the are suffixed by _ in the OCaml module.
  • Forbid to define sites named as an OCaml keyword suffixed by _.

NTS list of OCaml keywords

@Lelio-Brun
Copy link
Author

Lelio-Brun commented Feb 19, 2021

What about suffixing all sites variable by eg., _site ?
It would be a breaking change though.

@rgrinberg
Copy link
Member

What about changing the api to be:

val get : string -> site

and the generated code to be:

let sites =
  [ "name", Dune_site.Private_.Helpers.site ..
  ; ..
  ]

You can keep aliases for site names that are valid identifiers for backwards compatibility as well.

@Lelio-Brun
Copy link
Author

Seems good!

@bobot
Copy link
Collaborator

bobot commented Feb 19, 2021

By doing so we replace a compile-time error into an error at execution if the site doesn't exists.

It would be a breaking change though.

It is not a problem, site is an experimental feature and 3.0 is coming.

What about suffixing all sites variable by eg., _site ?

I prefer that. Another possibility is that module name have less limitations (no keyword capitalized). So Sites.Foo.path is possible and let us extend later with some other values if we need.

@Lelio-Brun
Copy link
Author

By doing so we replace a compile-time error into an error at execution if the site doesn't exists.

Ah yes, that's right.

@aalekseyev
Copy link
Collaborator

One could also have a rule like this:
If the original name is a keyword followed by any number of underscores, then it's extended by one underscore.

So

"foo" => "foo"
"include" => "include_"
"include_" => "include__"

the advantages are that it is injective while continuing the pattern @bobot proposed in FIX1.
The reason that pattern is worth continuing is that that's the de-facto idiom I've seen people use.

Underscore at the beginning has an additional meaning of "suppress unused variable warning", so I slightly prefer if that's avoided. One could consider unconditionally adding "_site" at the end if we're looking for a user-friendly uniform mapping.

(please take all that with a grain of salt because I know nothing about sites and how their names are to be used)

bobot added a commit to bobot/jbuilder that referenced this issue May 21, 2021
        a name matching "$ocaml_keyword_*" is converted into name^"_"

        Fixes ocaml#4219
bobot added a commit to bobot/jbuilder that referenced this issue May 21, 2021
        a name matching "$ocaml_keyword_*" is converted into name^"_"

        Fixes ocaml#4219
bobot added a commit to bobot/jbuilder that referenced this issue May 25, 2021
        a name matching "$ocaml_keyword_*" is converted into name^"_"

        Fixes ocaml#4219
bobot added a commit to bobot/jbuilder that referenced this issue May 25, 2021
        a name matching "$ocaml_keyword_*" is converted into name^"_"

        Fixes ocaml#4219
bobot added a commit to bobot/jbuilder that referenced this issue May 25, 2021
        a name matching "$ocaml_keyword_*" is converted into name^"_"

        Fixes ocaml#4219

Signed-off-by: François Bobot <francois.bobot@cea.fr>
bobot added a commit to bobot/jbuilder that referenced this issue May 27, 2021
        a name matching "$ocaml_keyword_*" is converted into name^"_"

        Fixes ocaml#4219

Signed-off-by: François Bobot <francois.bobot@cea.fr>
bobot added a commit to bobot/jbuilder that referenced this issue May 28, 2021
        a name matching "$ocaml_keyword_*" is converted into name^"_"

        Fixes ocaml#4219

Signed-off-by: François Bobot <francois.bobot@cea.fr>
bobot added a commit that referenced this issue Jun 9, 2021
        a name matching "$ocaml_keyword_*" is converted into name^"_"

        Fixes #4219

Signed-off-by: François Bobot <francois.bobot@cea.fr>
bobot added a commit to bobot/jbuilder that referenced this issue Jun 14, 2021
        a name matching "$ocaml_keyword_*" is converted into name^"_"

        Fixes ocaml#4219

Signed-off-by: François Bobot <francois.bobot@cea.fr>
bobot added a commit to bobot/jbuilder that referenced this issue Jun 14, 2021
        a name matching "$ocaml_keyword_*" is converted into name^"_"

        Fixes ocaml#4219

Signed-off-by: François Bobot <francois.bobot@cea.fr>
bobot added a commit to bobot/jbuilder that referenced this issue Jun 15, 2021
        a name matching "$ocaml_keyword_*" is converted into name^"_"

        Fixes ocaml#4219

Signed-off-by: François Bobot <francois.bobot@cea.fr>
bobot added a commit to bobot/jbuilder that referenced this issue Jun 24, 2021
        a name matching "$ocaml_keyword_*" is converted into name^"_"

        Fixes ocaml#4219

Signed-off-by: François Bobot <francois.bobot@cea.fr>
@bobot bobot closed this as completed in 9b4595f Jun 24, 2021
ejgallego added a commit to ejgallego/opam-repository that referenced this issue Jun 29, 2021
…ator, dune-private-libs, dune and dune-build-info (2.9.0)

CHANGES:

- Add `(enabled_if ...)` to `(mdx ...)` (ocaml/dune#4434, @emillon)

- Add support for instrumentation dependencies (ocaml/dune#4210, fixes ocaml/dune#3983, @nojb)

- Add the possibility to use `locks` with the cram tests stanza (ocaml/dune#4480, @voodoos)

- Allow to set up merlin in a variant of the default context
  (ocaml/dune#4145, @TheLortex, @voodoos)

- Add `(package ...)` to `(mdx ...)` (ocaml/dune#4691, fixes ocaml/dune#3756, @emillon)

- Handle renaming of `coq.kernel` library to `coq-core.kernel` in Coq 8.14 (ocaml/dune#4713, @proux01)

- Fix generation of merlin configuration when using `(include_subdirs
  unqualified)` on Windows (ocaml/dune#4745, @nojb)

- Fix bug for the install of Coq native files when using `(include_subdirs qualified)`
  (ocaml/dune#4753, @ejgallego)

- Allow users to specify install target directories for `doc` and
  `etc` sections. We add new options `--docdir` and `--etcdir` to both
  Dune's configure and `dune install` command. (ocaml/dune#4744, fixes ocaml/dune#4723,
  @ejgallego, thanks to @JasonGross for reporting this issue)

- Fix issue where Dune would ignore `(env ... (coq (flags ...)))`
  declarations appearing in `dune` files (ocaml/dune#4749, fixes ocaml/dune#4566, @ejgallego @rgrinberg)

- Disable some warnings on Coq 8.14 and `(lang coq (>= 0.3))` due to
  the rework of the Coq "native" compilation system (ocaml/dune#4760, @ejgallego)

- Fix a bug where instrumentation flags would be added even if the
  instrumentatation was disabled (@nojb, ocaml/dune#4770)

- Fix ocaml/dune#4682: option `-p` takes now precedence on environement variable
  `DUNE_PROFILE` (ocaml/dune#4730, ocaml/dune#4774, @bobot, reported by @dra27 ocaml/dune#4632)

- Fix installation with opam of package with dune sites. The `.install` file is
  now produced by a local `dune install` during the build phase (ocaml/dune#4730, ocaml/dune#4645,
  @bobot, reported by @kit-ty-kate ocaml/dune#4198)

- Fix multiple issues in the sites feature (ocaml/dune#4730, ocaml/dune#4645 @bobot, reported by @Lelio-Brun
  ocaml/dune#4219, by @Kakadu ocaml/dune#4325, by @toots ocaml/dune#4415)
ejgallego added a commit to ejgallego/opam-repository that referenced this issue Jul 1, 2021
…ator, dune-private-libs, dune and dune-build-info (2.9.0)

CHANGES:

- Add `(enabled_if ...)` to `(mdx ...)` (ocaml/dune#4434, @emillon)

- Add support for instrumentation dependencies (ocaml/dune#4210, fixes ocaml/dune#3983, @nojb)

- Add the possibility to use `locks` with the cram tests stanza (ocaml/dune#4480, @voodoos)

- Allow to set up merlin in a variant of the default context
  (ocaml/dune#4145, @TheLortex, @voodoos)

- Add `(package ...)` to `(mdx ...)` (ocaml/dune#4691, fixes ocaml/dune#3756, @emillon)

- Handle renaming of `coq.kernel` library to `coq-core.kernel` in Coq 8.14 (ocaml/dune#4713, @proux01)

- Fix generation of merlin configuration when using `(include_subdirs
  unqualified)` on Windows (ocaml/dune#4745, @nojb)

- Fix bug for the install of Coq native files when using `(include_subdirs qualified)`
  (ocaml/dune#4753, @ejgallego)

- Allow users to specify install target directories for `doc` and
  `etc` sections. We add new options `--docdir` and `--etcdir` to both
  Dune's configure and `dune install` command. (ocaml/dune#4744, fixes ocaml/dune#4723,
  @ejgallego, thanks to @JasonGross for reporting this issue)

- Fix issue where Dune would ignore `(env ... (coq (flags ...)))`
  declarations appearing in `dune` files (ocaml/dune#4749, fixes ocaml/dune#4566, @ejgallego @rgrinberg)

- Disable some warnings on Coq 8.14 and `(lang coq (>= 0.3))` due to
  the rework of the Coq "native" compilation system (ocaml/dune#4760, @ejgallego)

- Fix a bug where instrumentation flags would be added even if the
  instrumentatation was disabled (@nojb, ocaml/dune#4770)

- Fix ocaml/dune#4682: option `-p` takes now precedence on environement variable
  `DUNE_PROFILE` (ocaml/dune#4730, ocaml/dune#4774, @bobot, reported by @dra27 ocaml/dune#4632)

- Fix installation with opam of package with dune sites. The `.install` file is
  now produced by a local `dune install` during the build phase (ocaml/dune#4730, ocaml/dune#4645,
  @bobot, reported by @kit-ty-kate ocaml/dune#4198)

- Fix multiple issues in the sites feature (ocaml/dune#4730, ocaml/dune#4645 @bobot, reported by @Lelio-Brun
  ocaml/dune#4219, by @Kakadu ocaml/dune#4325, by @toots ocaml/dune#4415)
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

No branches or pull requests

4 participants