Commit Graph

950 Commits

Author SHA1 Message Date
Jake Leahy
1e52423774 Fix getting custom pragma from generic object (#20481)
* Merge devel

Add another test case

* Fix test

Use getCustomPragmaVal instead of hasCustomPragma

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
2023-01-11 20:44:33 -05:00
ringabout
a55604a3d8 fixes #21232; highlite.getNextToken() returns gtOperator for '/' in C (#21234) 2023-01-08 15:40:27 +01:00
Andrey Makarov
2620da9bf9 docgen: implement cross-document links (#20990)
* docgen: implement cross-document links

Fully implements https://github.com/nim-lang/RFCs/issues/125
Follow-up of: https://github.com/nim-lang/Nim/pull/18642 (for internal links)
and https://github.com/nim-lang/Nim/issues/20127.

Overview
--------

Explicit import-like directive is required, called `.. importdoc::`.
(the syntax is % RST, Markdown will use it for a while).

Then one can reference any symbols/headings/anchors, as if they
were in the local file (but they will be prefixed with a module name
or markup document in link text).
It's possible to reference anything from anywhere (any direction
in `.nim`/`.md`/`.rst` files).

See `doc/docgen.md` for full description.

Working is based on `.idx` files, hence one needs to generate
all `.idx` beforehand. A dedicated option `--index:only` is introduced
(and a separate stage for `--index:only` is added to `kochdocs.nim`).

Performance note
----------------

Full run for `./koch docs` now takes 185% of the time before this PR.
(After: 315 s, before: 170 s on my PC).
All the time seems to be spent on `--index:only` run, which takes
almost as much (85%) of normal doc run -- it seems that most time
is spent on file parsing, turning off HTML generation phase has not
helped much.
(One could avoid it by specifying list of files that can be referenced
and pre-processing only them. But it can become error-prone and I assume
that these linke will be **everywhere** in the repository anyway,
especially considering https://github.com/nim-lang/RFCs/issues/478.
So every `.nim`/`.md` file is processed for `.idx` first).

But that's all without significant part of repository converted to
cross-module auto links. To estimate impact I checked the time for
`doc`ing a few files (after all indexes have been generated), and
everywhere difference was **negligible**.
E.g. for `lib/std/private/osfiles.nim` that `importdoc`s large
`os.idx` and hence should have been a case with relatively large
performance impact, but:

* After: 0.59 s.
* Before: 0.59 s.

So Nim compiler works so slow that doc part basically does not matter :-)

Testing
-------

1) added `extlinks` test to `nimdoc/`
2) checked that `theindex.html` is still correct
2) fixed broken auto-links for modules that were derived from `os.nim`
   by adding appropriate ``importdoc``

Implementation note
-------------------

Parsing and formating of `.idx` entries is moved into a dedicated
`rstidx.nim` module from `rstgen.nim`.

`.idx` file format changed:

* fields are not escaped in most cases because we need original
  strings for referencing, not HTML ones
  (the exception is linkTitle for titles and headings).
  Escaping happens later -- on the stage of `rstgen` buildIndex, etc.
* all lines have fixed number of columns 6
* added discriminator tag as a first column,
  it always allows distinguish Nim/markup entries, titles/headings, etc.
  `rstgen` does not rely any more (in most cases) on ad-hoc logic
  to determine what type each entry is.
* there is now always a title entry added at the first line.
* add a line number as 6th column
* linkTitle (4th) column has a different format: before it was like
  `module: funcName()`, now it's `proc funcName()`.
  (This format is also propagated to `theindex.html` and search results,
  I kept it that way since I like it more though it's discussible.)
  This column is what used for Nim symbols resolution.
* also changed details on column format for headings and titles:
  "keyword" is original, "linkTitle" is HTML one

* fix paths on Windows + more clear code

* Update compiler/docgen.nim

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>

* Handle .md and .nim paths uniformly in findRefFile

* handle titles better + more comments

* don't allow markup overwrite index title for .nim files

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-01-04 15:19:01 -05:00
ringabout
9ba07edb2e build the documentation of official packages (#20986)
* remove db stuffs

* remove punycode

* remove

* fixes script

* add cloner

* patches

* disable

* patch

* fixes external packages

* disable two packages

* preview documentation build

* try again

* fixes URL

* fixes a bug

* simplify

* fixes documentaion

* fixes

* Apply suggestions from code review
2022-12-06 22:37:16 +08:00
ringabout
8266750497 [unittest] remove unnecessay export for testing (#20868) 2022-12-01 14:31:48 -05:00
Chavdar Ivanov
8f728ace35 Update tssl.nim (#20973)
This test hangs also under NetBSD and prevents the rest of the tests to carry over to the end.
2022-11-30 07:21:47 +08:00
Anna
b5a008bac8 Allow some tests to run without network (#20955)
* thttpclient.nim: respect NIM_TESTAMENT_REMOTE_NETWORKING

* tnetconnect.nim: respect NIM_TESTAMENT_REMOTE_NETWORKING
2022-11-29 06:40:28 +01:00
ringabout
27a38a9fce fix #13790; ptr char (+friends) should not implicitly convert to cstring (#20761)
* fix =#13790 ptr char (+friends) should not implicitly convert to cstring

* Apply suggestions from code review

* first round; compiles on windows

* nimPreviewSlimSystem

* conversion is unsafe, cast needed

* fixes more tests

* fixes asyncnet

* another try another error

* last one

* true

* one more

* why bugs didn't show at once

* add `nimPreviewCstringConversion` switch

* typo

Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
2022-11-24 07:49:23 +01:00
metagn
5adfaa2a92 render post expr blocks better (#20871)
* render post expr blocks

* remove pointless diff

* fix PR split mistake
2022-11-22 20:40:05 +01:00
ringabout
0448f30fd9 fixes #20026; marks system procs which can raise defects (#20864)
* marks system procs which can raise defects

* add tests

* add more systemRaisesDefect

* add comment
2022-11-22 20:07:00 +01:00
ringabout
e03a178bff rename std/threads to std/typedthreads (#20850)
* rename `std/threads` to `std/oldthreads`

* fixes tests

* rename to `typedthreads`

* changelog
2022-11-16 16:35:20 +01:00
ringabout
06cd15663d fixes ptr to cstring warnings[backport] (#20848)
* fix =#13790 ptr char (+friends) should not implicitly convert to cstring

* Apply suggestions from code review

* first round; compiles on windows

* nimPreviewSlimSystem

* conversion is unsafe, cast needed

* fixes more tests

* fixes asyncnet

* another try another error

* last one

* true

* one more

* why bugs didn't show at once

* add `nimPreviewCstringConversion` switch

* typo

* fixes ptr to cstring warnings[backport]

* add fixes

Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
2022-11-16 10:22:51 +01:00
ringabout
cfab08d985 fixes tests and add notes (#20830) 2022-11-13 05:52:21 +01:00
ringabout
15bffc20ed fixes tests for quit (#20813)
Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
2022-11-11 12:01:35 +01:00
Vindaar
cc2b0f0172 [sugar] handle HiddenDeref in capture, error at CT if unsupported nnk (#20680)
* [sugar] handle HiddenDeref in capture, error at CT if unsupported nnk

Instead of running into trouble of the `.strVal` access failing, it's
better to error at CT.

* [tests] remove unnecessary import in test case

* improve ident extraction & extend test cases

* [tests] improve tests for `capture` of different types & act. check
2022-11-10 15:42:53 -05:00
Bung
10e7f18d01 remove compiler/strutils2.nim (#20748)
* use std strutils toLowerAscii char

* avoid additional call and assign

* remove compiler/strutils2.nim

* canonical
2022-11-05 12:22:45 +01:00
n5m
51bef9b4a8 fix posix.mq_receive compilation with cpp backend (#20710)
* fix posix.mq_receive compilation with cpp backend

* only enable runnableExample on posix

* linux, not posix

* simplify example

* add test

* mqueue.h does not exist on MacOS

* place test case in own block

* drop runnableExamples
2022-11-05 06:31:19 +01:00
n5m
52166e3546 allow deferred close of nil stream (#20706)
* allow deferred close of nil stream

* improve example
2022-10-31 11:20:06 +01:00
ringabout
e1ddd2d524 put std/threads under the umbrella of nimPreviewSlimSystem (#20711)
* put `std/threads` under the umbrella of `nimPreviewSlimSystem`

* add changelog

* fixes tests

* fixes tests again

* fixes tests
2022-10-31 06:36:50 +01:00
Andrey Makarov
779b1cc5be Fix #20628 for Windows (#20667)
* Fix #20628 for Windows

* Move isRegular - !isSpecial and onlyRegular - skipSpecial

* Forgot to change it in 1 more place
2022-10-28 10:01:28 +02:00
Andrey Makarov
8ed2431db0 Implement Unix file regularity check (#20448) (#20628)
* Implement Unix file regularity check

* update std/dirs also
2022-10-25 07:42:47 +02:00
Jason Beetham
ea0e45e62f Added 'openArray[char]' overloads to 'std/parseutils' (#20527)
* Added 'openarray[char]' overloads to 'std/parseutils'

* Removed redundant `start` and `last` params from slice using procs

* Fixed type for parseIdent overload

* fixed one by off with 'substr'

* removed missed start parameters for procedures

* Added 'openarray[char]' overloads to 'std/parseutils'

* Removed redundant `start` and `last` params from slice using procs

* Fixed type for parseIdent overload

* fixed one by off with 'substr'

* removed missed start parameters for procedures

* Fixed VM op to work with new 'opcSlice'

* Corrected captureBetween's logic to work with openarray

* js sys's parsefloat logic now uses openarray

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
2022-10-24 14:50:54 -04:00
ringabout
7c2aa53e44 fixes #19278; make privateAccess work with generic ref object (#20640)
* fixes #19278; make `privateAccess` work with generic ref object

* fixes
2022-10-24 15:24:51 +02:00
Jake Leahy
d261135c5c Fix tuple size check in std/jsonutils (#20637)
* Add test for tuple being invalid size

* Test tuple size before accessing fields

* Fix formatting for import

* Fix not being able to build from csources_v1

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2022-10-24 17:17:14 +08:00
Jake Leahy
69cb671d8d Pass json options to hooks (#20638)
* Added tests

* Fix expected string

* Allow hooks to take an optional parameter that is the current options

* Add options to hooks for other generic types

* Fix doc links
2022-10-24 08:14:17 +02:00
ringabout
9361938ccd add std/appdirs (#20618) 2022-10-22 13:42:46 +02:00
ringabout
3c12b72168 add typesafe std/paths, std/files, std/dirs, std/symlinks (#20582)
* split std/os; add typesafe std/paths
* add more files, dirs, paths
* add documentation
* add testcase
* remove tryRemoveFile
* clean up
* Delete test.nim
* apply changes
* add `add` and fixes
2022-10-21 21:53:44 +02:00
ringabout
b07526b2c7 refactor envvars, oserrors; register vmops (#20592)
* refactor envvars, oserrors; register vmops

* remove type definitions
2022-10-18 19:44:26 +02:00
ringabout
1e15f975b8 fixes #19162; enable strictEffects for v2 (#19380)
* enable stricteffects
* add gcsafe
* fix tests
* use func
* fixes pegs tests
* explicitly mark repr related procs with noSideEffect
* add nimLegacyEffects
* change URL
* fixes docopt
* add `raises: []` to repr
* fixes weave
* fixes nimyaml
* fixes glob
* fixes parsetoml
* Apply suggestions from code review
* Update testament/important_packages.nim
* add legacy:laxEffects
2022-10-15 14:07:40 +02:00
ringabout
13b3ea71da oids sticks to 24 length strings; fixes breaking changes (#20546)
oids sticks 24 length strings
2022-10-12 15:15:21 +02:00
ringabout
5602183234 'lock levels' are deprecated, now a noop (#20539)
* 'lock levels' are deprecated, now a noop

* fixes tests
2022-10-11 09:17:09 +02:00
ringabout
e290b028ab Make rstgen work with gcsafe (#20534)
* Make rstgen work with gcsafe

Co-authored-by: Danil Yarantsev <tiberiumk12@gmail.com>

* add tests and fixes

* if nimHasWarningAsError

Co-authored-by: Danil Yarantsev <tiberiumk12@gmail.com>
2022-10-10 18:56:01 +02:00
ringabout
5e4dd571d4 fixes #20516; system.create doesn't work with bitfield objects (#20518)
* Revert "fixes #19000 (#19032)"

This reverts commit 2bda4a30a6.

* fixes #20516; add testcase
2022-10-08 17:38:22 +02:00
ringabout
723a71bd22 follow up #20109; remove shallow seqs/strings for ORC (#20502)
* remove `shallow` seqs/strings for ORC

* add a changelog item

* change url of DelaunayNim
2022-10-06 07:16:50 +02:00
Andrey Makarov
6505bd347d Markdown indented code blocks (#20473)
* Implement Markdown indented code blocks

Additional indentation of 4 spaces makes a block an "indented code block"
(monospaced text without syntax highlighting).
Also `::` RST syntax for code blocks is disabled.

So instead of
```rst
see::

  Some code
```

the code block should be written as
```markdown
see:

    Some code
```

* Migrate RST literal blocks :: to Markdown's ones
2022-10-05 14:03:10 -04:00
ee7
10355cb48a strutils, rstgen: avoid deprecated strutils.delete (#20488)
The strutils `delete` func with signature

    func delete*(s: var string, first, last: int)

was deprecated in adba5eb45e, in favor of one with signature

    func delete*(s: var string, slice: Slice[int])

However, a few procedures still used the deprecated form. This commit
updates them, resolving these deprecation warnings:

    rstgen.nim(766, 12) Warning: use `delete(s, first..last)`; delete is deprecated [Deprecated]
    strutils.nim(1651, 19) Warning: use `delete(s, first..last)`; delete is deprecated [Deprecated]
    strutils.nim(1679, 7) Warning: use `delete(s, first..last)`; delete is deprecated [Deprecated]
    strutils.nim(2472, 7) Warning: use `delete(s, first..last)`; delete is deprecated [Deprecated]

Before this commit:

- `trimZeros` called `s.delete(i+1, i)` for an input that lacks a
  trailing zero (like "1.23").

- `removePrefix*(s: var string, prefix: string)` called
  `s.delete(0, -1)` when the prefix was the empty string.

which did not modify `s`, nor raise an error. But the newer slice
`delete` raises an `IndexDefect` when the start of the slice is greater
than the end, so we avoid calling the new `delete` for such a case.

Recall that exceptions inheriting from `system.Defect` are not tracked
with the `.raises: []` exception tracking mechanism [1], so this commit
does not break existing code like:

    proc foo {.raises: [].} =
      var s = "abc1.20"
      s.removePrefix("abc")
      s.trimZeros()
      doAssert s == "1.2"

The `strutils.delete` deprecation was motivated by a problem with
`system.delete` [2][3]:

    `system.delete` had surprising behavior when the index passed to it
    was out of bounds (it would delete the last entry then). Compile
    with `-d:nimStrictDelete` so that an index error is produced
    instead.

    Be aware however that your code might depend on this quirky behavior
    so a review process is required on your part before you can use
    `-d:nimStrictDelete`. To make this review easier, use the
    `-d:nimAuditDelete` switch, which pretends that `system.delete` is
    deprecated so that it is easier to see where it was used in your
    code.

    `-d:nimStrictDelete` will become the default in upcoming versions.

A similar deprecation happened with `sequtils.delete` [4], but that
deprecated form is already not used in this repo.

[1] https://github.com/nim-lang/Nim/blob/2dec69fe5aa6/doc/manual.md#exception-tracking
[2] https://github.com/nim-lang/Nim/blob/2dec69fe5aa6/changelogs/changelog_1_6_0.md#system
[3] https://github.com/nim-lang/Nim/commit/92cb76571432
[4] https://github.com/nim-lang/Nim/commit/1d6863a7899f
2022-10-05 13:57:17 -04:00
ringabout
f89ba2c951 add default field support for object in ARC/ORC (#20480)
* fresh start

* add cpp target

* add result support

* add nimPreviewRangeDefault

* reduce

* use orc

* refactor common parts

* add tuple support

* add testcase for tuple

* cleanup; fixes nimsuggest tests

* there is something wrong with cpp

* remove

* add support for seqs

* fixes style

* addd initial distinct support

* remove links

* typo

* fixes tuple defaults

* add rangedefault

* add cpp support

* fixes one more bugs

* add more hasDefaults

* fixes ordinal types

* add testcase for #16744

* add testcase for #3608

* fixes docgen

* small fix

* recursive

* fixes

* cleanup and remove tuple support

* fixes nimsuggest

* fixes generics procs

* refactor

* increases timeout

* refactor hasDefault

* zero default; disable i386

* add tuples back

* fixes bugs

* fixes tuple

* add more tests

* fix one more bug regarding tuples

* more tests and cleanup

* remove messy distinct types which must be initialized by original types

* add tests

* fixes zero default

* fixes grammar

* fixes tests

* fixes tests

* fixes tests

* fixes comments

* fixes and add testcase

* undo default values for results

Co-authored-by: flywind <43030857+xflywind@users.noreply.github.com>
2022-10-04 12:45:10 +02:00
metagn
0b1650576c move widestrs out of system (#20462)
* move widestrs out of system

* fix osproc
2022-10-01 22:35:09 +02:00
Juan Carlos
1e635bb539 Undeprecate isvalidfilename (#19643)
* Remove deprecated isvalidfilename
* https://github.com/nim-lang/Nim/pull/19643#issuecomment-1235102314
* https://github.com/nim-lang/Nim/pull/19643#issuecomment-1235102314
* https://github.com/nim-lang/Nim/pull/19643#issuecomment-1235102314
* Add unittests
* Add more

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2022-09-29 12:22:29 +02:00
ringabout
f56085f21e refactor dbFormat (#19746)
* refactor dbFormat

* add simple tests
2022-09-29 12:16:42 +02:00
Andreas Rumpf
77a65d3c33 fixed tstrimpl (#20452) 2022-09-29 09:41:00 +02:00
ringabout
65c2518d5c fix #19500; remove find optimization [backport: 1.6] (#19714)
* remove find optimization

close #19500

* save find to std

* add simple tests

* Apply suggestions from code review

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

Co-authored-by: sandytypical <43030857+xflywind@users.noreply.github.com>
Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
2022-09-28 16:05:41 -04:00
metagn
919a889ba8 moderate system cleanup & refactor (#20355)
* system refactor, move out 600 lines

* compilation, slice, backwardsindex, misc_num moved out of system
* some procs/types moved into arithmetics, basic_types
* system no longer depends on syncio
* some procs moved around to fit with their surroundings

* make exceptions an import, old ops to misc_num

* move instantiationInfo back

* move back nim version, fix windows echo

* include compilation

* better docs for imported modules, fix unsigned ops

also remove ze, ze64, toU8, toU16, toU32 with nimPreviewSlimSystem

* fix terminal

* workaround IC test & weird csize bug, changelog

* move NimMajor etc back to compilation, rebase for CI

* try ic fix

* form single `indices`, slim out TaintedString, try fix IC

* fix CI, update changelog, addQuitProc

* fix CI

* try fix CI

* actually fix CI finally hopefully

* Update lib/system/compilation.nim

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>

* update kochdocs

* hopefully fix csize uses for slimsystem

* fix tquit

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2022-09-28 15:28:45 -04:00
ringabout
3d2f0e2c7c make more standard libraries work with nimPreviewSlimSystem (#20343)
* make more standard libraries work with `nimPreviewSlimSystem`

* typo

* part two

* Delete specutils.nim

* fixes more tests

* more fixes

* fixes tests

* fixes three more tests

* add formatfloat import

* fix

* last
2022-09-27 20:06:23 +02:00
n5m
6b4ea88734 use almostEqual in tstats.nim (#20431)
prefer math.almostEqual
2022-09-26 15:42:26 -04:00
n5m
9ca88a1889 fix #18128 rfind on empty needle returns rightmost index (#20430)
rfind on empty needle returns haystack len
2022-09-26 15:39:22 -04:00
ringabout
7739e23420 defaults to ORC (#19972)
* defaults to Orc

* bootstrap using refc

* use gc

* init orc defines

* unregister orc

* fix gc

* fix commands

* add prepareMutation for orc

* enable deepcopy for orc

* prepareMutation

* more fixes

* some cases

* bug #20081

* partial fixes

* partial fixes

* fixes command line

* more fixes

* build Nim with refc

* use gc

* more fixes

* rstore

* orc doesn't support threadpool

* more shallowCopy

* more fixes

* fixes unsafeNew

* workarounds

* small

* more fixes

* fixes some megatest

* tcodegenbugs1 refc

* fxies megatest

* build nimble with refc

* workaround tensordsl tests

* replace shallowCopy with move

* fixes action

* workaround

* add todo

* fixes important packages

* unpublic unregisterArcOrc

* fixes cpp

* enable windows

Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
2022-09-23 13:05:05 +02:00
ringabout
db8a62d480 fixes #20285; prevent oid time overflow at year 2038 (#20338)
* Revert "fixes  #20285; prevent oid time overflow at year 2038"

This reverts commit dfcdb6ec2a.

* increase time to 64 bits and clean up

* add testcase

* inline consts

* add a changelog

* fixes  #20285; prevent oid time overflow at year 2038
2022-09-22 21:15:27 +08:00
ringabout
de70128fcc follow up #19968; add more tests (#20396) 2022-09-20 16:14:01 -04:00
ringabout
cd9290818a add testcase for #19020 (#20363) 2022-09-15 23:18:14 +08:00