Giter Site home page Giter Site logo

Comments (9)

gasche avatar gasche commented on June 2, 2024

In general it is a known usability issue that the compiler has an "open world" approach to attributes: any attribute we see may have been meant for a preprocessor instead of us, so we ignore them silently instead of assuming that they are incorrect -- even when they are typos, or misplaced compiler-supported attributes. The Jane Street fork has improvements in this direction, relying on assumptions about the preprocessor (they use the ppxlib strategy of removing the attributes they handle): ocaml-flambda/ocaml-jst#44 . I believe that they ( @goldfirere, @ccasin ) would be interested in help upstreaming this work.

In the specific case that you mention (adding [@@unboxed] to a type that does not support unboxing), there should be an error. Do you have an example?

from ocaml.

Octachron avatar Octachron commented on June 2, 2024

This work has already upstreamed in #12451: we don't have an open world approach for builtin compiler attributes anymore.

Instead, we record all known compilers attributes during parsing, and we mark them whenever they are used. The misplaced warning is then emitted if there were compiler attributes without consumers. This is not 100% exact yet, because for some attributes (mostly alerts) it is not that clear to decide when an attribute is consumed.

@shindere , do you have a precise example of missing warning for an unused attribute?

A possibility that is occuring to me now is that the reworked misplaced-attribute warning 57 doesn't trigger in the toplevel. Did you test in a toplevel?

from ocaml.

ccasin avatar ccasin commented on June 2, 2024

I do think there is a bug where the warning doesn't trigger in the top level. We just noticed this internally last week. I meant to take a look at fixing, which is probably just one line, but have been swamped - soon!

from ocaml.

gasche avatar gasche commented on June 2, 2024

Oof, sorry for forgetting about this!

from ocaml.

shindere avatar shindere commented on June 2, 2024

from ocaml.

tmcgilchrist avatar tmcgilchrist commented on June 2, 2024
# Using unboxed attribute on an Effect
$ echo 'type _ Effect.t += Foo : int -> int Effect.t [@@unboxed]' > test.ml
$ opam exec --switch="5.2.0" -- ocamlc -c test.ml
File "test.ml", line 1, characters 48-55:
1 | type _ Effect.t += Foo : int -> int Effect.t [@@unboxed]
                                                    ^^^^^^^
Warning 53 [misplaced-attribute]: the "unboxed" attribute cannot appear in this context
$ opam exec --switch="5.1.1" -- ocamlc -c test.ml 
# No Warning

# Using spelling mistake unbxed
$ echo 'type _ Effect.t += Foo : int -> int Effect.t [@@unbxed]' > test_2.ml
$ opam exec --switch="5.2.0" -- ocamlc -c test_2.ml
# No warning
$ opam exec --switch="5.1.1" -- ocamlc -c test_2.ml
# No warning

from ocaml.

ccasin avatar ccasin commented on June 2, 2024

thanks a lot! If you provide a fix, will you please also add a test tomake sure the fix does work and prevent regressions?

Indeed - I'll be sure to add a test. I have a local version of the fix, but it will need to wait until after #13170 (because there are many attributes in tests that incorrectly give warning 53 once I fix this issue, if that one isn't fixed first).

from ocaml.

ccasin avatar ccasin commented on June 2, 2024

@tmcgilchrist Both of your examples look expected to me. [@unboxed] does not work on extensible variants, and warning 53 cannot detect spelling mistakes (because the attribute may be intended for an external tool like a ppx - we can only warn about attributes known to the compiler but in the wrong place).

from ocaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.