-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
{.used: symbol}
: fixes lots of issues with UnusedImport, XDeclaredButNotUsed, etc; fix #13185, #17511, #17510, #14246
#17938
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
985b610
{.used: symbol}
timotheecour ac3e2d4
add tests
timotheecour 2f42905
fix tests with --import
timotheecour 98ec125
--import works without giving spurious unused warnings
timotheecour f4eee1d
new warning warnDuplicateModuleImport for `import foo; import foo`
timotheecour 46d51cc
fix test, add resolveModuleAlias, use proper line info for module ali…
timotheecour b235191
fix spurious warnings
timotheecour fcb2cca
fix deprecation msg for deprecated modules even with `import foo as bar`
timotheecour 6f116fb
disable a test for i386 pending sorting XDeclaredButNotUsed errors
timotheecour f6afeae
UnusedImport now works with re-exported symbols
timotheecour 414b3b2
fix typo [skip ci]
timotheecour 9428b31
ic support
timotheecour 621b2d9
add genPNode to allow writing PNode-based compiler code similarly to …
timotheecour 4808772
fix DuplicateModuleImport warning
timotheecour File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import | |
intsets, ast, astalgo, msgs, options, idents, lookups, | ||
semdata, modulepaths, sigmatch, lineinfos, sets, | ||
modulegraphs, wordrecg | ||
from strutils import `%` | ||
|
||
proc readExceptSet*(c: PContext, n: PNode): IntSet = | ||
assert n.kind in {nkImportExceptStmt, nkExportExceptStmt} | ||
|
@@ -224,19 +225,21 @@ proc importForwarded(c: PContext, n: PNode, exceptSet: IntSet; fromMod: PSym; im | |
|
||
proc importModuleAs(c: PContext; n: PNode, realModule: PSym, importHidden: bool): PSym = | ||
result = realModule | ||
c.unusedImports.add((realModule, n.info)) | ||
template createModuleAliasImpl(ident): untyped = | ||
createModuleAlias(realModule, nextSymId c.idgen, ident, realModule.info, c.config.options) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
createModuleAlias(realModule, nextSymId c.idgen, ident, n.info, c.config.options) | ||
if n.kind != nkImportAs: discard | ||
elif n.len != 2 or n[1].kind != nkIdent: | ||
localError(c.config, n.info, "module alias must be an identifier") | ||
elif n[1].ident.id != realModule.name.id: | ||
# some misguided guy will write 'import abc.foo as foo' ... | ||
result = createModuleAliasImpl(n[1].ident) | ||
if result == realModule: | ||
# avoids modifying `realModule`, see D20201209T194412 for `import {.all.}` | ||
# and also for `import foo; {.used: foo.}` | ||
result = createModuleAliasImpl(realModule.name) | ||
if importHidden: | ||
if result == realModule: # avoids modifying `realModule`, see D20201209T194412. | ||
result = createModuleAliasImpl(realModule.name) | ||
result.options.incl optImportHidden | ||
c.unusedImports.add((result, n.info)) | ||
|
||
proc transformImportAs(c: PContext; n: PNode): tuple[node: PNode, importHidden: bool] = | ||
var ret: typeof(result) | ||
|
@@ -281,16 +284,15 @@ proc myImportModule(c: PContext, n: var PNode, importStmtResult: PNode): PSym = | |
#echo "set back to ", L | ||
c.graph.importStack.setLen(L) | ||
# we cannot perform this check reliably because of | ||
# test: modules/import_in_config) | ||
when true: | ||
if result.info.fileIndex == c.module.info.fileIndex and | ||
result.info.fileIndex == n.info.fileIndex: | ||
localError(c.config, n.info, "A module cannot import itself") | ||
if sfDeprecated in result.flags: | ||
if result.constraint != nil: | ||
message(c.config, n.info, warnDeprecated, result.constraint.strVal & "; " & result.name.s & " is deprecated") | ||
# test: modules/import_in_config) # xxx is that still true? | ||
let realModule = result.resolveModuleAlias | ||
if realModule == c.module: | ||
localError(c.config, n.info, "module '$1' cannot import itself" % c.module.name.s) | ||
if sfDeprecated in realModule.flags: | ||
if realModule.constraint != nil: | ||
message(c.config, n.info, warnDeprecated, realModule.constraint.strVal & "; " & realModule.name.s & " is deprecated") | ||
else: | ||
message(c.config, n.info, warnDeprecated, result.name.s & " is deprecated") | ||
message(c.config, n.info, warnDeprecated, realModule.name.s & " is deprecated") | ||
suggestSym(c.graph, n.info, result, c.graph.usageSym, false) | ||
importStmtResult.add newSymNode(result, n.info) | ||
#newStrNode(toFullPath(c.config, f), n.info) | ||
|
@@ -303,6 +305,9 @@ proc impMod(c: PContext; it: PNode; importStmtResult: PNode) = | |
addDecl(c, m, it.info) # add symbol to symbol table of module | ||
importAllSymbols(c, m) | ||
#importForwarded(c, m.ast, emptySet, m) | ||
for s in allSyms(c.graph, m): # fixes bug #17510, for re-exported symbols | ||
if s.owner != m.resolveModuleAlias: | ||
c.exportIndirections.incl((m.id, s.id)) | ||
|
||
proc evalImport*(c: PContext, n: PNode): PNode = | ||
result = newNodeI(nkImportStmt, n.info) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need IC support?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, but untestable beyond the existing ic tests (that still do pass) because of pre-existing issue with ic+export: #17943; new tests can be added in future work.
Also, manually serializing/deserializing the AST/symbols/various compiler structures as in done in packed_ast is IMO the wrong approach, it duplicates logic and adds significant complexity, and on top of that in my experience using ic makes compilation slower that a full recompilation. We should really explore alternatives:
nim secret
despite using c backendwe should probably discuss this elsewhere though, separate topic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well since you bring it up:
Well if IC is already too slow, a more generic solution won't make it faster... Furthermore I regard the .rod file format as the future for Nim's tooling and it enforces us to be honest about phase ordering issues (no more unprincipled mutations possible). A compiler server accomplishes nothing comparable. We already have nimsuggest, it eats gigabytes of RAM and occasionally 100% CPU...
The "loopy structures" are harmful and cause many many bugs; don't write tooling to hide them, avoid them.