Comments (9)
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.
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.
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.
Oof, sorry for forgetting about this!
from ocaml.
from ocaml.
# 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.
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.
@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)
- Ground coercion is not composable HOT 1
- Regression with default GC settings between `4.14.2` and `5.1.1` HOT 7
- Doc typo in `Printexc` HOT 2
- Abnormal exit after upgrading to OCaml 5 HOT 4
- Restore native armv7 support for NetBSD 10.0 HOT 7
- Support parameter constraints in module signature type equalities HOT 5
- Update the effect handlers manual page to use syntax HOT 3
- Simplify effect handler closure and reperform by dropping the `last_fiber` argument
- Module type substitutions in signature of recursive modules are not checked for cyclicity
- Sub-module identities inside an applicative functor are actually generative, leading to invalid signatures
- Strange error message with trunk HOT 5
- "β t is less general than ∀α. α t" with trunk HOT 14
- Please provide guidance whether the static linking exception applies to distributions like DkML HOT 12
- Semantics of toplevel let-bindings in classes HOT 12
- Make extensible variants more efficient and mashalable. HOT 4
- Library archive name change in OCaml 5 (e.g libunix.a -> libunixbyt.a & libunixnat.a) HOT 3
- Type-level module alias for functor parameter accepted HOT 1
- Signal handler doesn't run if signal received at the wrong time
- Stdlib: `Dynarray.insert` procedure HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ocaml.