Skip to content
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

Fix docgen snippet numbering #13507

Merged
merged 1 commit into from
Mar 3, 2020
Merged

Fix docgen snippet numbering #13507

merged 1 commit into from
Mar 3, 2020

Conversation

genotrance
Copy link
Contributor

  • Fix snippet file name - everything was 101 - also print snippet if error
  • Reduce noise in snippet and example compilation
  • Reduce specific warnings, hints in koch docs

@@ -159,6 +159,7 @@ proc getOutFile2(conf: ConfigRef; filename: RelativeFile,
else:
result = getOutFile(conf, filename, ext)

var gIdx = 101
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces global state and I don't understand why it's needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

rawMessage(conf, hintExecuting, c2)
if execShellCmd(c2) != status:
echo importStmt & content
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the compiler doesn't use echo for error reporting and this PR is about making the compiler less noisy, not moreso.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea was to print the snippet code that failed, makes it easier to debug the problematic snippet instead of having to search the snippet numerically in source file.

Removed for now.

@@ -5,7 +5,7 @@ import os, strutils, osproc, sets
const
gaCode* = " --doc.googleAnalytics:UA-48159761-1"
# --warning[LockLevel]:off pending #13218
nimArgs = "--warning[LockLevel]:off --hint[Conf]:off --hint[Path]:off --hint[Processing]:off -d:boot --putenv:nimversion=$#" % system.NimVersion
nimArgs = "--warning[LockLevel]:off --warning[Deprecated]:off --warning[UnusedImport]:off --warning[RedefinitionOfLabel]:off --hint[Conf]:off --hint[Path]:off --hint[Processing]:off --hint[XDeclaredButNotUsed]:off -d:boot --putenv:nimversion=$#" % system.NimVersion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line seems to be the only necessary line to accomplish what your PR title says.

@@ -211,7 +211,8 @@ proc newDocumentor*(filename: AbsoluteFile; cache: IdentCache; conf: ConfigRef,
writeFile(outp, importStmt & content)
let c = if cmd.startsWith("nim "): os.getAppFilename() & cmd.substr(3)
else: cmd
let c2 = c % quoteShell(outp)
let subst = if "-r" in c: "-r" else: "$1"
let c2 = c.replace(subst, "--verbosity:0 --hints:off " & subst) % quoteShell(outp)
Copy link
Member

@Araq Araq Feb 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not let c2 = (c & "--verbosity:0 --hints:off") % quoteShell(outp)"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't put flags after the filename.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but let subst = if "-r" in c: "-r" else: "$1" is suspicious. Why does -r lack the $1 part?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all tests are run so -r isn't common. But when it is, these flags have to go before it, hence looking for both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-r seems fragile, eg would trigger for --rangeChecks:on
a more robust solution would identify the position right before the filename in nim cmd -flag1 -flag2 filename arg, ideally by reusing same code compiler uses instead of duplicating logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open to ideas but like I said, these params have to go before -r. How about " -r "?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these params have to go before -r

anything between nim binary and filename can go anywhere:

nim c --rangeChecks:on -r main
nim c  -r --rangeChecks:on main
nim --rangeChecks:on -r c main

How about " -r "

not robust to things like:

nim c -r -d:mystr:"foo -r bar" main

(there are more such cases, eg --passC, --passL etc)

sure, these may be rare/edge cases, but I think it's just better to reuse (not re-implement) the logic nim compiler itself uses

Copy link
Member

@timotheecour timotheecour Mar 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about instead adding --verbosity:0 --hints:off to here:
tools/kochdocs.nim:235:27: commands[i] = nim & " rst2html $# --git.url:$# -o:$# --index:on $#" %

=> see comment below for a better idea

@genotrance
Copy link
Contributor Author

Only freebsd is failing in unrelated test.

@timotheecour
Copy link
Member

timotheecour commented Mar 1, 2020

I like the spirit of this PR but not the current implementation.

  • Some of the warnings are legit and we should fix the code instead of masking the warnings, eg:
/Users/timothee/git_clone/nim/Nim_prs/lib/system/channels.nim(154, 22) Warning: pragma before generic parameter list is deprecated [Deprecated]
    Channel* {.gcsafe.}[TMsg] = RawChannel ## a channel for thread communication
/Users/timothee/git_clone/nim/Nim_prs/lib/system/channels.nim(269, 37) Warning: Number of spaces around '*%' is not consistent [Spacing]
                  cast[pointer](s +% i*% mt.base.size), mt.base, t, mode)
  • we need to identify which warnings don't make sense for a compiler target, eg: for rst2html RedefinitionOfLabel does not make sense so we should fix it at the compiler level:

compiler/main.nim:

  of "rst2html":
    conf.notes.excl warnRedefinitionOfLabel # similar to issue #13218

here's all the warnings produced:

https://gist.github.com/timotheecour/397948fa2017e147e62e1b4044561060

we can do analysis on this eg:

cat $logsmisc_D/kochdocs.log | grep Warning: | grep -v RedefinitionOfLabel| sort | uniq
cat $logsmisc_D/kochdocs.log | grep Warning: | grep -v RedefinitionOfLabel| sort | uniq | wc -l

=> see #13550 which addresses at the compiler level some of those irrelevant warnings; IMO it's a better approach, eg it doesn't suppress UnusedImport from $nim_prs_D/doc/docgen_sample.nim unlike this PR (which does --warning[UnusedImport]:off), but it does suppress them from things like nimrtl (because of --app:lib); ditto with other flags

@genotrance
Copy link
Contributor Author

I'm fine if this can be fixed in compiler as well as by fixing the actual warnings, there's too many though. Fact is that nim doc warnings are not really attended to, nim doc isn't run in the main CI so there's too many warnings flooding the logs. Nightlies are already a long process.

I can trim this PR to just fixing the snippet numbering.

@timotheecour
Copy link
Member

I'm fine if this can be fixed in compiler as well as by fixing the actual warnings, there's too many though.

#13550 will fix a lot of these; subsequent PRs to fix remaining ones are welcome

Fact is that nim doc warnings are not really attended to, nim doc isn't run in the main CI so there's too many warnings flooding the logs. Nightlies are already a long process.

out of sight, out of mind; they're much more likely to be attended to if we surface them. Indeed, many tests are only run via nim doc (eg runnableExamples), and simply gagging warnings (including relevant ones) will make it really hard to fix those.

I can trim this PR to just fixing the snippet numbering.

you mean inc(gen.id) ? ya, after reading your whole PR, I think that's the best approach; we can followup after #13550 with more warning slayings as needed.

template since(version, body: untyped) {.dirty, used.} =,

maybe that one might be ok, I don't care either way for that specific one

@genotrance genotrance changed the title Reduce noise in koch docs Fix docgen snippet numbering Mar 3, 2020
@genotrance
Copy link
Contributor Author

I've cleaned up this PR to just fix the docgen snippet numbering.

@Araq Araq merged commit f817568 into nim-lang:devel Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants