timotheecour / Nim

Nim is a compiled, garbage-collected systems programming language with a design that focuses on efficiency, expressiveness, and elegance (in that order of priority).
http://nim-lang.org/
Other
2 stars 0 forks source link

misc cleanups #64

Open timotheecour opened 4 years ago

timotheecour commented 4 years ago
timotheecour commented 4 years ago
timotheecour commented 4 years ago
timotheecour commented 4 years ago
timotheecour commented 4 years ago
timotheecour commented 4 years ago

deprecate isNil

see also https://github.com/timotheecour/D_vs_nim/pull/36#issuecomment-610412525

Edited: nil == something doesn't work with C or JS backend sometime.

timotheecour commented 4 years ago
timotheecour commented 4 years ago
timotheecour commented 4 years ago
timotheecour commented 4 years ago

=> https://github.com/nim-lang/Nim/pull/14732

timotheecour commented 4 years ago
timotheecour commented 4 years ago
timotheecour commented 4 years ago
timotheecour commented 4 years ago
timotheecour commented 4 years ago

var ret = "foo1" ret.add fun() )

timotheecour commented 4 years ago

https://github.com/nim-lang/Nim/issues/14066#issuecomment-619824758

By the way, what is the tyOpt type that can be found next to seq in the code?
It is a builtin "opt[T]" type, it's dead code.
timotheecour commented 4 years ago

eg of big offender: lib/system.nim 87 lib/pure/strutils.nim 36 lib/pure/math.nim 31

total:

as of v1.4.0: 568
as of devel 52cf7280019c943dd7df33d0dd693931e6a116ee: 500

so it's going down... (using rg code-block: -t nim | wc -l: 500)

/cc @konsumlamm thanks for your help on this with your cleanup PR's!

timotheecour commented 4 years ago
timotheecour commented 4 years ago

https://github.com/nim-lang/Nim/pull/14413#issue-421116337

timotheecour commented 4 years ago
timotheecour commented 4 years ago

$nim_prs_D/doc/contributing.rst eg: in nimbleSubs

mentioned in https://nim-lang.github.io/Nim/manual.html#iterators-and-the-for-statement-first-class-iterators but hard to see

Caution: the body of a for loop over an inline iterator is inlined into each yield statement appearing in the iterator code, so ideally the code should be refactored to contain a single yield when possible to avoid code bloat.

timotheecour commented 4 years ago

deadcode

timotheecour commented 4 years ago

with:

##[
unstable API, internal use only for now.
candidate for merging in std/decls
]##

proc byLent*[T](a: var T): lent T =
  ## caveat: see https://github.com/nim-lang/Nim/issues/14557
  ## use case: convert a var to a lent to help with overload resolution, see
  ## https://github.com/timotheecour/Nim/issues/287
  a
timotheecour commented 4 years ago

factor vmconv.elementType with typetraits.elementType

timotheecour commented 3 years ago

targets: "c c++ js" => targets: "c cpp js"

(only a few c++, most are cpp)

=> https://github.com/nim-lang/Nim/pull/15961

timotheecour commented 3 years ago
tests/stdlib/trst.nim:9:1:import ../../lib/packages/docutils/rstgen
tests/stdlib/trst.nim:10:1:import ../../lib/packages/docutils/rst
tests/stdlib/trstgen.nim:7:1:import ../../lib/packages/docutils/rstgen
tests/stdlib/trstgen.nim:8:1:import ../../lib/packages/docutils/rst
tests/stdlib/tstrutils2.nim:1:1:import "$lib/.." / compiler/strutils2
tools/grammar_nanny.nim:6:1:import ".." / compiler / [
tools/kochdocs.nim:5:1:import "../compiler/nimpaths"
tools/nimfind.nim:33:1:import "../compiler" / [options, commands, modules, sem,
tools/winrelease.nim:7:1:import "../koch"

note:

might require: nim --prefix:PATH to set the prefix path (might be more useful than --lib:lib) · Issue #365 · timotheecour/Nim

timotheecour commented 3 years ago
timotheecour commented 3 years ago

EDIT: see https://github.com/nim-lang/Nim/pull/16486#issuecomment-751928805 for remaining assert's to change

timotheecour commented 3 years ago
Fixed “lent gives wrong results with -d:release” (#14578)
Fixed “backticks : Using reserved keywords as identifiers is not documented” (#15806)
Fixed “backticks : Using reserved keywords as identifiers is not documented” (#15806)
Fixed “backticks : Using reserved keywords as identifiers is not documented” (#15806)
Fixed “backticks : Using reserved keywords as identifiers is not documented” (#15806)
Fixed “Program SIGSEGV when using ‘–gc:orc’” (#15753)
timotheecour commented 3 years ago

and:

  exitcode: 0
timotheecour commented 3 years ago

use this:

{.pragma: lcrypto, cdecl, dynlib: DLLUtilName, importc.}

and then use this pragma everywhere relevant in this file, eg:

proc BIO_read*(b: BIO, data: cstring, length: cint): cint {.lcrypto.}

instead of:

proc BIO_read*(b: BIO, data: cstring, length: cint): cint{.cdecl,
      dynlib: DLLUtilName, importc.}

note:

this is preferable to {.push.} {.pop.} as it's more explicit (less "hidden state")

timotheecour commented 3 years ago

tcomplex.nim:

proc `=~`[T](x, y: Complex[T]): bool =
  result = abs(x.re-y.re) < 1e-6 and abs(x.im-y.im) < 1e-6

proc `=~`[T](x: Complex[T]; y: T): bool =
  result = abs(x.re-y) < 1e-6 and abs(x.im) < 1e-6
timotheecour commented 3 years ago
type
  StdMap {.importcpp: "std::map", header: "<map>".} [K, V] = object
=>
type
  StdMap [K, V] {.importcpp: "std::map", header: "<map>".} = object

https://github.com/nim-lang/Nim/pull/16497

timotheecour commented 3 years ago
timotheecour commented 3 years ago
timotheecour commented 3 years ago
timotheecour commented 3 years ago

https://github.com/nim-lang/fusion/pull/64#issuecomment-753683927

because theres stuff with broken style on Nim main repo on /lib/js/jsffi.nim and /lib/std/private/*.nim.

timotheecour commented 3 years ago

refs: https://github.com/nim-lang/fusion/pull/57#discussion_r551087943 and nim doc -b:js

=> fixed in https://github.com/nim-lang/Nim/pull/16579

timotheecour commented 3 years ago

move -d:testing to tests/config.nims so it applies to all tests even ones run via exec nim inside tests

timotheecour commented 3 years ago

rationale: nim check (or nim r --errormax:10) will otherwise show tons of (irrelevant) errors otherwise (try with: nim check lib/js/jsre.nim)

In these case, early abort is correct.

note

ditto in similar other cases, eg with cpp instead of js etc

timotheecour commented 3 years ago
ringabout commented 3 years ago

not now

timotheecour commented 3 years ago
timotheecour commented 3 years ago
timotheecour commented 3 years ago
timotheecour commented 3 years ago
timotheecour commented 3 years ago
nimArgs = "--errormax:3 --hint:Conf:off --hint:Path:off --hint:Processing:off --hint:XDeclaredButNotUsed:off --warning:UnusedImport:off -d:boot --putenv:nimversion=$#" % system.NimVersion
timotheecour commented 3 years ago
timotheecour commented 3 years ago
timotheecour commented 3 years ago

refs https://github.com/nim-lang/Nim/pull/16750#issuecomment-768529881

timotheecour commented 3 years ago

weak test, doesn't check that hash(x) == static(hash(x)) in this branch