-
Notifications
You must be signed in to change notification settings - Fork 23
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
new {.disabled.} pragma #213
Comments
Can you elaborate on this point
As I understand the RFC the error messages would be incomprehensible with |
This is interesting:
One thing that I would add is that when defined(cuda) or defined(nimdoc) or defined(nimsuggest):
import ./tensor_cuda
export tensor_cuda
when defined(opencl) or defined(nimdoc) or defined(nimsuggest):
import ./tensor_opencl
export tensor_opencl Additionally, a disable message "This feature is disabled unless you explicitly compile with -d:cuda. Please refer to documentation at https///abc.efg" might also help library authors develop experimental features and making sure to point people at direct documentation (or bug report). Furthermore, when managing a library function lifetime, we could smoothly transition from "live function -> deprecated -> function -> disabled function -> undeclared identifier". With the deprecated and disabled steps directly linking to the relevant changelog or mentioning the alternative. |
Why? with {.disabled.} in the case of sigmatch/lookup error, can show the same information as {.error.} (which used to be super cryptic until nim-lang/Nim#13833 where I added where the symbol was declared); with symbol location, it should be easy for user to figure out why it was disabled (identical effort compared to {.error.}) with {.push disabled}, it would work the same; you'd get symbol location, and potentially (as enhancement) we could also report in errmsg the location of the enclosing {.push disabled}, but even without that it shouldn't be hard to grok. Note that os.nim doesn't push but uses pragma pragma so it's not relevant for current os.nim. example1: {.disabled.}# module foo
proc fun0*() = discard
proc fun1*() {.disabled.} = discard
example2: {.push disabled.}# module foo2
when defined js: {push("label_js_disable"): disabled.} # just to illustrate push/pop with labels
proc fun0*() = discard
proc fun1*() {.disabled.} = discard
{.pop("label_js_disable").}
example3: non-nested labeled push/pop
{.push bar.}
lots of code
{.push foo.}
lots of code
{.pop.} # which push did I pop ? (especially since pop is optional) @mratsim
that's implied by the
of course; {.disabled.} can take an optional msg argument
great point! good idea; and at the {.disabled.} stage we can get rid of proc body, so code is already simplified |
Sophistry. You can also use |
summary:
{.disabled}
disables a symbol; unlike {.error.}, the symbol doesn't participate in overload resolution/lookup (which causes issues like import os + use of existsDir/dirExists/existsFile/fileExists/findExe in config.nims causes "ambiguous call' error Nim#14142); but provides a useful error message when overload resolution/lookup fails instead of "undefined symbol" (see [superseded] fix #14142: no more clash with: import os + use of existsDir/dirExists/existsFile/fileExists/findExe in config.nims Nim#14143 (comment))semantics of
proc foo {.disabled.} = ...
declared(foo)
should return false (unlessdeclared(foo)
was already true because of another symbol with same name); consequently,nim doc
won't generate a corresponding entry, but maybe nimsuggest could list it as candidate showing it's disabledfoo {.disabled.}
should not participate symbol lookup nor in overload resolution unless there is an error; in particular, it cannot cause aredefinition
errorThe only semantic difference between
proc foo {.disabled.} = ...
andwhen false: proc foo = ...
is that it gives better error messages when lookup/sigmatch fails:"foo"
fails, instead ofError: undeclared identifier: 'foo'
we show:Error: usage of 'foo' is {.disabled.} at mymodule.nim(12,1)
"foo"
fails, we add to the list of candidates inexpected one of ...
list the disabled symbol (and show the {.disabled.} pragma)other use cases of {.disabled}
replace {.error.} by {.disabled.} in code disabled for for custom targets (js,nimscript), so we avoid import os + use of existsDir/dirExists/existsFile/fileExists/findExe in config.nims causes "ambiguous call' error Nim#14142 while keeping informative errors
use it inside the {.since: (1, 3).} pragma for nicer error messages without changing semantics of
since
; so now you'll get more informative errors like:`newSymbolX` is available starting 1.3.1, not 1.2.0
with
when cond: {.push disabled}
, we can conditionally disable all the remainder of the code in the same scope without having to re-indent underwhen not cond
; this somewhat related to D's__EOF__
special token except it's during semantic, and is more useful (eg: scoped)in particular, when used at module-level, this allows conditionally disabling all remainder of a module, which is needed for an RFC I'm preparing that will allow introducing user defined self-contained module metadata, and reduce the need for separate foo.nims files, magic testament spec blocks, magic exclusions in kochdocs, magic comments indicating this is only an include file etc. More on this soon.
(optional feature): disabled inside push/pop section
this reduces the need for having to re-indent a whole section, eg:
implementation
why not use {.error.} instead for that?
semantics are different, {.error} procs participate in overload resolution and declared(foo) is true
why not change semantics of {.error.} to be like disabled instead?
that'd be a breaking change (eg:
declared(foo)
would turn from true to false), and IMO {.error} fullfils a different role than {.disabled}why not use
template disabled(body): untyped = discard
instead?invalid pragma
for var pragmas inside templates timotheecour/Nim#89{.push disabled}
section and it may not be obvious at 1st glance that a symbol was disabledThe text was updated successfully, but these errors were encountered: