fixes #19795; fixes #11852; fixes #19974; remove parsing pipeline, Nim now parses the whole module at one time (#21379)
* fixes #19795; remove parse pipeline * isScript * fixes nimscriptapi * don't touch reorder * check script * fixes tests * it seems implicit imports of system cause troubles * access the first child of `nkStmtList` * ignore comments * minor messages * perhaps increases hloLoopDetector * the module is a stmtList, which changes the errors * fixes nimdoc * fixes tlinter * fixes nim secret tests * fixes arc_misc * fixes nim secret tests again * safe; fixes one more test * GlobalError is the root cause too * fixes parsing errors * put emit types to the cfsForwardTypes section * fixes #11852; `{.push checks:off}` now works in procs * disable navigator * fixes nimdoc * add tests for JS * fixes nimsuggest
This commit is contained in:
parent
fdd7520257
commit
38f876dd48
31 changed files with 227 additions and 72 deletions
25
compiler/backendpragmas.nim
Normal file
25
compiler/backendpragmas.nim
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
import pragmas, options, ast, trees
|
||||||
|
|
||||||
|
proc pushBackendOption(optionsStack: var seq[TOptions], options: var TOptions) =
|
||||||
|
optionsStack.add options
|
||||||
|
|
||||||
|
proc popBackendOption(optionsStack: var seq[TOptions], options: var TOptions) =
|
||||||
|
options = optionsStack[^1]
|
||||||
|
optionsStack.setLen(optionsStack.len-1)
|
||||||
|
|
||||||
|
proc processPushBackendOption*(optionsStack: var seq[TOptions], options: var TOptions,
|
||||||
|
n: PNode, start: int) =
|
||||||
|
pushBackendOption(optionsStack, options)
|
||||||
|
for i in start..<n.len:
|
||||||
|
let it = n[i]
|
||||||
|
if it.kind in nkPragmaCallKinds and it.len == 2 and it[1].kind == nkIntLit:
|
||||||
|
let sw = whichPragma(it[0])
|
||||||
|
let opts = pragmaToOptions(sw)
|
||||||
|
if opts != {}:
|
||||||
|
if it[1].intVal != 0:
|
||||||
|
options.incl opts
|
||||||
|
else:
|
||||||
|
options.excl opts
|
||||||
|
|
||||||
|
template processPopBackendOption*(optionsStack: var seq[TOptions], options: var TOptions) =
|
||||||
|
popBackendOption(optionsStack, options)
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
# included from cgen.nim
|
# included from cgen.nim
|
||||||
|
|
||||||
const
|
const
|
||||||
RangeExpandLimit = 256 # do not generate ranges
|
RangeExpandLimit = 256 # do not generate ranges
|
||||||
# over 'RangeExpandLimit' elements
|
# over 'RangeExpandLimit' elements
|
||||||
|
|
@ -1538,7 +1537,7 @@ proc determineSection(n: PNode): TCFileSection =
|
||||||
result = cfsProcHeaders
|
result = cfsProcHeaders
|
||||||
if n.len >= 1 and n[0].kind in {nkStrLit..nkTripleStrLit}:
|
if n.len >= 1 and n[0].kind in {nkStrLit..nkTripleStrLit}:
|
||||||
let sec = n[0].strVal
|
let sec = n[0].strVal
|
||||||
if sec.startsWith("/*TYPESECTION*/"): result = cfsTypes
|
if sec.startsWith("/*TYPESECTION*/"): result = cfsForwardTypes # TODO WORKAROUND
|
||||||
elif sec.startsWith("/*VARSECTION*/"): result = cfsVars
|
elif sec.startsWith("/*VARSECTION*/"): result = cfsVars
|
||||||
elif sec.startsWith("/*INCLUDESECTION*/"): result = cfsHeaders
|
elif sec.startsWith("/*INCLUDESECTION*/"): result = cfsHeaders
|
||||||
|
|
||||||
|
|
@ -1555,9 +1554,14 @@ proc genEmit(p: BProc, t: PNode) =
|
||||||
line(p, cpsStmts, s)
|
line(p, cpsStmts, s)
|
||||||
|
|
||||||
proc genPragma(p: BProc, n: PNode) =
|
proc genPragma(p: BProc, n: PNode) =
|
||||||
for it in n.sons:
|
for i in 0..<n.len:
|
||||||
|
let it = n[i]
|
||||||
case whichPragma(it)
|
case whichPragma(it)
|
||||||
of wEmit: genEmit(p, it)
|
of wEmit: genEmit(p, it)
|
||||||
|
of wPush:
|
||||||
|
processPushBackendOption(p.optionsStack, p.options, n, i+1)
|
||||||
|
of wPop:
|
||||||
|
processPopBackendOption(p.optionsStack, p.options)
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import
|
||||||
ccgutils, os, ropes, math, passes, wordrecg, treetab, cgmeth,
|
ccgutils, os, ropes, math, passes, wordrecg, treetab, cgmeth,
|
||||||
rodutils, renderer, cgendata, aliases,
|
rodutils, renderer, cgendata, aliases,
|
||||||
lowerings, tables, sets, ndi, lineinfos, pathutils, transf,
|
lowerings, tables, sets, ndi, lineinfos, pathutils, transf,
|
||||||
injectdestructors, astmsgs, modulepaths
|
injectdestructors, astmsgs, modulepaths, backendpragmas
|
||||||
|
|
||||||
when defined(nimPreviewSlimSystem):
|
when defined(nimPreviewSlimSystem):
|
||||||
import std/assertions
|
import std/assertions
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ type
|
||||||
options*: TOptions # options that should be used for code
|
options*: TOptions # options that should be used for code
|
||||||
# generation; this is the same as prc.options
|
# generation; this is the same as prc.options
|
||||||
# unless prc == nil
|
# unless prc == nil
|
||||||
|
optionsStack*: seq[TOptions]
|
||||||
module*: BModule # used to prevent excessive parameter passing
|
module*: BModule # used to prevent excessive parameter passing
|
||||||
withinLoop*: int # > 0 if we are within a loop
|
withinLoop*: int # > 0 if we are within a loop
|
||||||
splitDecls*: int # > 0 if we are in some context for C++ that
|
splitDecls*: int # > 0 if we are in some context for C++ that
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ import
|
||||||
nversion, msgs, idents, types,
|
nversion, msgs, idents, types,
|
||||||
ropes, passes, ccgutils, wordrecg, renderer,
|
ropes, passes, ccgutils, wordrecg, renderer,
|
||||||
cgmeth, lowerings, sighashes, modulegraphs, lineinfos, rodutils,
|
cgmeth, lowerings, sighashes, modulegraphs, lineinfos, rodutils,
|
||||||
transf, injectdestructors, sourcemap, astmsgs
|
transf, injectdestructors, sourcemap, astmsgs, backendpragmas
|
||||||
|
|
||||||
import json, sets, math, tables, intsets
|
import json, sets, math, tables, intsets
|
||||||
import strutils except addf
|
import strutils except addf
|
||||||
|
|
@ -98,6 +98,7 @@ type
|
||||||
prc: PSym
|
prc: PSym
|
||||||
globals, locals, body: Rope
|
globals, locals, body: Rope
|
||||||
options: TOptions
|
options: TOptions
|
||||||
|
optionsStack: seq[TOptions]
|
||||||
module: BModule
|
module: BModule
|
||||||
g: PGlobals
|
g: PGlobals
|
||||||
generatedParamCopies: IntSet
|
generatedParamCopies: IntSet
|
||||||
|
|
@ -2557,9 +2558,14 @@ proc genStmt(p: PProc, n: PNode) =
|
||||||
if r.res != "": lineF(p, "$#;$n", [r.res])
|
if r.res != "": lineF(p, "$#;$n", [r.res])
|
||||||
|
|
||||||
proc genPragma(p: PProc, n: PNode) =
|
proc genPragma(p: PProc, n: PNode) =
|
||||||
for it in n.sons:
|
for i in 0..<n.len:
|
||||||
|
let it = n[i]
|
||||||
case whichPragma(it)
|
case whichPragma(it)
|
||||||
of wEmit: genAsmOrEmitStmt(p, it[1])
|
of wEmit: genAsmOrEmitStmt(p, it[1])
|
||||||
|
of wPush:
|
||||||
|
processPushBackendOption(p.optionsStack, p.options, n, i+1)
|
||||||
|
of wPop:
|
||||||
|
processPopBackendOption(p.optionsStack, p.options)
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc genCast(p: PProc, n: PNode, r: var TCompRes) =
|
proc genCast(p: PProc, n: PNode, r: var TCompRes) =
|
||||||
|
|
|
||||||
|
|
@ -155,11 +155,10 @@ proc processModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator;
|
||||||
checkFirstLineIndentation(p)
|
checkFirstLineIndentation(p)
|
||||||
while true:
|
while true:
|
||||||
if graph.stopCompile(): break
|
if graph.stopCompile(): break
|
||||||
var n = parseTopLevelStmt(p)
|
var n = parseTopLevelStmt(p) # todo merge it
|
||||||
if n.kind == nkEmpty: break
|
if n.kind == nkEmpty: break
|
||||||
if (sfSystemModule notin module.flags and
|
|
||||||
({sfNoForward, sfReorder} * module.flags != {} or
|
if true:
|
||||||
codeReordering in graph.config.features)):
|
|
||||||
# read everything, no streaming possible
|
# read everything, no streaming possible
|
||||||
var sl = newNodeI(nkStmtList, n.info)
|
var sl = newNodeI(nkStmtList, n.info)
|
||||||
sl.add n
|
sl.add n
|
||||||
|
|
|
||||||
|
|
@ -364,7 +364,7 @@ proc processNote(c: PContext, n: PNode) =
|
||||||
else: invalidPragma(c, n)
|
else: invalidPragma(c, n)
|
||||||
else: invalidPragma(c, n)
|
else: invalidPragma(c, n)
|
||||||
|
|
||||||
proc pragmaToOptions(w: TSpecialWord): TOptions {.inline.} =
|
proc pragmaToOptions*(w: TSpecialWord): TOptions {.inline.} =
|
||||||
case w
|
case w
|
||||||
of wChecks: ChecksOptions
|
of wChecks: ChecksOptions
|
||||||
of wObjChecks: {optObjCheck}
|
of wObjChecks: {optObjCheck}
|
||||||
|
|
|
||||||
|
|
@ -701,6 +701,12 @@ proc myOpen(graph: ModuleGraph; module: PSym; idgen: IdGenerator): PPassContext
|
||||||
|
|
||||||
proc isImportSystemStmt(g: ModuleGraph; n: PNode): bool =
|
proc isImportSystemStmt(g: ModuleGraph; n: PNode): bool =
|
||||||
if g.systemModule == nil: return false
|
if g.systemModule == nil: return false
|
||||||
|
var n = n
|
||||||
|
if n.kind == nkStmtList:
|
||||||
|
for i in 0..<n.len-1:
|
||||||
|
if n[i].kind notin {nkCommentStmt, nkEmpty}:
|
||||||
|
n = n[i]
|
||||||
|
break
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkImportStmt:
|
of nkImportStmt:
|
||||||
for x in n:
|
for x in n:
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ nim fn2 subdir/subdir_b/utils.html#fn2,int,float proc fn2(x: int; y: float) 61
|
||||||
nim binarySearch subdir/subdir_b/utils.html#binarySearch,openArray[T],K,proc(T,K) proc binarySearch[T, K](a: openArray[T]; key: K;\n cmp: proc (x: T; y: K): int {.closure.}): int 63
|
nim binarySearch subdir/subdir_b/utils.html#binarySearch,openArray[T],K,proc(T,K) proc binarySearch[T, K](a: openArray[T]; key: K;\n cmp: proc (x: T; y: K): int {.closure.}): int 63
|
||||||
nim fn3 subdir/subdir_b/utils.html#fn3 proc fn3(): auto 66
|
nim fn3 subdir/subdir_b/utils.html#fn3 proc fn3(): auto 66
|
||||||
nim fn4 subdir/subdir_b/utils.html#fn4 proc fn4(): auto 67
|
nim fn4 subdir/subdir_b/utils.html#fn4 proc fn4(): auto 67
|
||||||
nim fn5 subdir/subdir_b/utils.html#fn5 proc fn5() 69
|
nim fn5 subdir/subdir_b/utils.html#fn5 proc fn5() 68
|
||||||
nim fn6 subdir/subdir_b/utils.html#fn6 proc fn6() 70
|
nim fn6 subdir/subdir_b/utils.html#fn6 proc fn6() 70
|
||||||
nim fn7 subdir/subdir_b/utils.html#fn7 proc fn7() 72
|
nim fn7 subdir/subdir_b/utils.html#fn7 proc fn7() 72
|
||||||
nim fn8 subdir/subdir_b/utils.html#fn8 proc fn8(): auto 75
|
nim fn8 subdir/subdir_b/utils.html#fn8 proc fn8(): auto 75
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ $nimsuggest --tester $file
|
||||||
chk;;skUnknown;;;;Hint;;???;;0;;-1;;">> (toplevel): import(dirty): tests/tchk1.nim [Processing]";;0
|
chk;;skUnknown;;;;Hint;;???;;0;;-1;;">> (toplevel): import(dirty): tests/tchk1.nim [Processing]";;0
|
||||||
chk;;skUnknown;;;;Error;;$file;;12;;0;;"identifier expected, but got \'keyword template\'";;0
|
chk;;skUnknown;;;;Error;;$file;;12;;0;;"identifier expected, but got \'keyword template\'";;0
|
||||||
chk;;skUnknown;;;;Error;;$file;;14;;0;;"nestable statement requires indentation";;0
|
chk;;skUnknown;;;;Error;;$file;;14;;0;;"nestable statement requires indentation";;0
|
||||||
chk;;skUnknown;;;;Error;;$file;;12;;0;;"implementation of \'foo\' expected";;0
|
|
||||||
chk;;skUnknown;;;;Error;;$file;;17;;0;;"invalid indentation";;0
|
chk;;skUnknown;;;;Error;;$file;;17;;0;;"invalid indentation";;0
|
||||||
|
chk;;skUnknown;;;;Error;;$file;;12;;0;;"implementation of \'foo\' expected";;0
|
||||||
chk;;skUnknown;;;;Hint;;$file;;12;;9;;"\'foo\' is declared but not used [XDeclaredButNotUsed]";;0
|
chk;;skUnknown;;;;Hint;;$file;;12;;9;;"\'foo\' is declared but not used [XDeclaredButNotUsed]";;0
|
||||||
chk;;skUnknown;;;;Hint;;$file;;14;;5;;"\'main\' is declared but not used [XDeclaredButNotUsed]";;0
|
chk;;skUnknown;;;;Hint;;$file;;14;;5;;"\'main\' is declared but not used [XDeclaredButNotUsed]";;0
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,14 @@ new line after - @['a']
|
||||||
finalizer
|
finalizer
|
||||||
aaaaa
|
aaaaa
|
||||||
hello
|
hello
|
||||||
ok
|
|
||||||
true
|
true
|
||||||
copying
|
copying
|
||||||
123
|
123
|
||||||
42
|
42
|
||||||
closed
|
ok
|
||||||
destroying variable: 20
|
destroying variable: 20
|
||||||
destroying variable: 10
|
destroying variable: 10
|
||||||
|
closed
|
||||||
'''
|
'''
|
||||||
cmd: "nim c --gc:arc --deepcopy:on -d:nimAllocPagesViaMalloc $file"
|
cmd: "nim c --gc:arc --deepcopy:on -d:nimAllocPagesViaMalloc $file"
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,12 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: "nim check --newruntime --hints:off $file"
|
cmd: "nim check --newruntime --hints:off $file"
|
||||||
nimout: '''
|
nimout: '''
|
||||||
tdont_return_unowned_from_owned.nim(36, 10) Error: cannot return an owned pointer as an unowned pointer; use 'owned(Obj)' as the return type
|
tdont_return_unowned_from_owned.nim(26, 13) Error: assignment produces a dangling ref: the unowned ref lives longer than the owned ref
|
||||||
tdont_return_unowned_from_owned.nim(39, 10) Error: cannot return an owned pointer as an unowned pointer; use 'owned(Obj)' as the return type
|
tdont_return_unowned_from_owned.nim(27, 13) Error: assignment produces a dangling ref: the unowned ref lives longer than the owned ref
|
||||||
tdont_return_unowned_from_owned.nim(42, 6) Error: type mismatch: got <Obj>
|
tdont_return_unowned_from_owned.nim(31, 10) Error: cannot return an owned pointer as an unowned pointer; use 'owned(RootRef)' as the return type
|
||||||
|
tdont_return_unowned_from_owned.nim(43, 10) Error: cannot return an owned pointer as an unowned pointer; use 'owned(Obj)' as the return type
|
||||||
|
tdont_return_unowned_from_owned.nim(46, 10) Error: cannot return an owned pointer as an unowned pointer; use 'owned(Obj)' as the return type
|
||||||
|
tdont_return_unowned_from_owned.nim(49, 6) Error: type mismatch: got <Obj>
|
||||||
but expected one of:
|
but expected one of:
|
||||||
proc new[T](a: var ref T; finalizer: proc (x: ref T) {.nimcall.})
|
proc new[T](a: var ref T; finalizer: proc (x: ref T) {.nimcall.})
|
||||||
first type mismatch at position: 2
|
first type mismatch at position: 2
|
||||||
|
|
@ -11,17 +14,21 @@ proc new[T](a: var ref T; finalizer: proc (x: ref T) {.nimcall.})
|
||||||
2 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them
|
2 other mismatching symbols have been suppressed; compile with --showAllMismatches:on to see them
|
||||||
|
|
||||||
expression: new(result)
|
expression: new(result)
|
||||||
tdont_return_unowned_from_owned.nim(42, 6) Error: illformed AST:
|
tdont_return_unowned_from_owned.nim(49, 6) Error: illformed AST:
|
||||||
tdont_return_unowned_from_owned.nim(50, 13) Error: assignment produces a dangling ref: the unowned ref lives longer than the owned ref
|
|
||||||
tdont_return_unowned_from_owned.nim(51, 13) Error: assignment produces a dangling ref: the unowned ref lives longer than the owned ref
|
|
||||||
tdont_return_unowned_from_owned.nim(55, 10) Error: cannot return an owned pointer as an unowned pointer; use 'owned(RootRef)' as the return type
|
|
||||||
'''
|
'''
|
||||||
errormsg: "cannot return an owned pointer as an unowned pointer; use 'owned(RootRef)' as the return type"
|
errormsg: "illformed AST:"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
proc testA(result: var (RootRef, RootRef)) =
|
||||||
|
let r: owned RootRef = RootRef()
|
||||||
|
result[0] = r
|
||||||
|
result[1] = RootRef()
|
||||||
|
|
||||||
|
proc testB(): RootRef =
|
||||||
|
let r: owned RootRef = RootRef()
|
||||||
|
result = r
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -39,17 +46,11 @@ proc newObjB(): Obj =
|
||||||
result = Obj()
|
result = Obj()
|
||||||
|
|
||||||
proc newObjC(): Obj =
|
proc newObjC(): Obj =
|
||||||
new(result)
|
new(result) # illFormedAst raises GlobalError,
|
||||||
|
# without pipeline parsing, it needs to placed at the end
|
||||||
|
# in case that it disturbs other errors
|
||||||
|
|
||||||
let a = newObjA()
|
let a = newObjA()
|
||||||
let b = newObjB()
|
let b = newObjB()
|
||||||
let c = newObjC()
|
let c = newObjC()
|
||||||
|
|
||||||
proc testA(result: var (RootRef, RootRef)) =
|
|
||||||
let r: owned RootRef = RootRef()
|
|
||||||
result[0] = r
|
|
||||||
result[1] = RootRef()
|
|
||||||
|
|
||||||
proc testB(): RootRef =
|
|
||||||
let r: owned RootRef = RootRef()
|
|
||||||
result = r
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
import tables
|
||||||
|
|
||||||
|
values
|
||||||
|
|
||||||
|
|
||||||
discard """
|
discard """
|
||||||
errormsg: "expression has no type: values"
|
errormsg: "expression has no type: values"
|
||||||
"""
|
"""
|
||||||
import tables
|
|
||||||
|
|
||||||
values
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
|
matrix: "--experimental:codeReordering"
|
||||||
output: "10"
|
output: "10"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -342,8 +342,8 @@ tests/newconfig/bar/mfoo.nims""".splitLines
|
||||||
when not defined(windows):
|
when not defined(windows):
|
||||||
check3 lines.len == 5
|
check3 lines.len == 5
|
||||||
check3 lines[0].isDots
|
check3 lines[0].isDots
|
||||||
check3 lines[1].dup(removePrefix(">>> ")) == "3" # prompt depends on `nimUseLinenoise`
|
# check3 lines[1].isDots # todo nim secret might use parsing pipeline
|
||||||
check3 lines[2].isDots
|
check3 lines[2].dup(removePrefix(">>> ")) == "3" # prompt depends on `nimUseLinenoise`
|
||||||
check3 lines[3] == "ab"
|
check3 lines[3] == "ab"
|
||||||
check3 lines[4] == ""
|
check3 lines[4] == ""
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
|
matrix: "--experimental:codeReordering"
|
||||||
action: compile
|
action: compile
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: "nim -d:testdef $target $file"
|
matrix: "--experimental:codeReordering -d:testdef"
|
||||||
output: '''works 34
|
output: '''works 34
|
||||||
34
|
34
|
||||||
defined
|
defined
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
|
disabled: true
|
||||||
cmd: "nim check $options --defusages:$file,12,7 $file"
|
cmd: "nim check $options --defusages:$file,12,7 $file"
|
||||||
nimout: '''def tincludefile_temp.nim(11, 10)
|
nimout: '''def tincludefile_temp.nim(11, 10)
|
||||||
usage tincludefile_temp.nim(12, 8)
|
usage tincludefile_temp.nim(12, 8)
|
||||||
|
|
@ -7,7 +8,6 @@ usage tincludefile_temp.nim(12, 8)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
proc foo(x: int) =
|
proc foo(x: int) =
|
||||||
echo x
|
echo x
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
discard """
|
discard """
|
||||||
|
disabled: true
|
||||||
cmd: "nim check $options --defusages:$file,12,7 $file"
|
cmd: "nim check $options --defusages:$file,12,7 $file"
|
||||||
nimout: '''def tnav1_temp.nim(11, 10)
|
nimout: '''def tnav1_temp.nim(11, 10)
|
||||||
usage tnav1_temp.nim(12, 8)
|
usage tnav1_temp.nim(12, 8)
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import std / [times]
|
import std / [times]
|
||||||
|
|
||||||
proc foo(x: int) =
|
proc foo(x: int) =
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ foo1
|
||||||
foo2
|
foo2
|
||||||
foo3
|
foo3
|
||||||
foo5
|
foo5
|
||||||
foo6
|
|
||||||
foo7
|
foo7
|
||||||
in examplesInTemplate1
|
in examplesInTemplate1
|
||||||
doc in outer
|
doc in outer
|
||||||
|
|
@ -15,6 +14,7 @@ doc in inner1
|
||||||
doc in inner2
|
doc in inner2
|
||||||
foo8
|
foo8
|
||||||
foo9
|
foo9
|
||||||
|
foo6
|
||||||
'''
|
'''
|
||||||
joinable: false
|
joinable: false
|
||||||
"""
|
"""
|
||||||
|
|
@ -43,7 +43,7 @@ proc fun*() =
|
||||||
proc fun*()=echo "foo5"
|
proc fun*()=echo "foo5"
|
||||||
fun()
|
fun()
|
||||||
|
|
||||||
runnableExamples:
|
runnableExamples("--experimental:codeReordering --warnings:off"):
|
||||||
# `codeReordering` only allowed at top level
|
# `codeReordering` only allowed at top level
|
||||||
{.experimental: "codeReordering".}
|
{.experimental: "codeReordering".}
|
||||||
proc fun1() = fun2()
|
proc fun1() = fun2()
|
||||||
|
|
|
||||||
82
tests/overflow/toverflow.nim
Normal file
82
tests/overflow/toverflow.nim
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
discard """
|
||||||
|
output: "ok"
|
||||||
|
matrix: "--overflowChecks:off; --overflowChecks:off --b:js"
|
||||||
|
"""
|
||||||
|
# Tests nim's ability to detect overflows
|
||||||
|
|
||||||
|
{.push overflowChecks: on.}
|
||||||
|
|
||||||
|
var
|
||||||
|
a = high(int)
|
||||||
|
b = -2
|
||||||
|
overflowDetected = false
|
||||||
|
|
||||||
|
try:
|
||||||
|
echo(b - a)
|
||||||
|
except OverflowDefect:
|
||||||
|
overflowDetected = true
|
||||||
|
|
||||||
|
{.pop.} # overflow check
|
||||||
|
|
||||||
|
doAssert(overflowDetected)
|
||||||
|
|
||||||
|
block: # Overflow checks in a proc
|
||||||
|
var
|
||||||
|
a = high(int)
|
||||||
|
b = -2
|
||||||
|
overflowDetected = false
|
||||||
|
|
||||||
|
{.push overflowChecks: on.}
|
||||||
|
proc foo() =
|
||||||
|
let c = b - a
|
||||||
|
{.pop.}
|
||||||
|
|
||||||
|
try:
|
||||||
|
foo()
|
||||||
|
except OverflowDefect:
|
||||||
|
overflowDetected = true
|
||||||
|
|
||||||
|
doAssert(overflowDetected)
|
||||||
|
|
||||||
|
block: # Overflow checks in a forward declared proc
|
||||||
|
var
|
||||||
|
a = high(int)
|
||||||
|
b = -2
|
||||||
|
overflowDetected = false
|
||||||
|
|
||||||
|
proc foo()
|
||||||
|
|
||||||
|
{.push overflowChecks: on.}
|
||||||
|
proc foo() =
|
||||||
|
let c = b - a
|
||||||
|
{.pop.}
|
||||||
|
|
||||||
|
try:
|
||||||
|
foo()
|
||||||
|
except OverflowDefect:
|
||||||
|
overflowDetected = true
|
||||||
|
|
||||||
|
doAssert(overflowDetected)
|
||||||
|
|
||||||
|
block: # Overflow checks doesn't affect fwd declaration
|
||||||
|
var
|
||||||
|
a = high(int)
|
||||||
|
b = -2
|
||||||
|
overflowDetected = false
|
||||||
|
|
||||||
|
{.push overflowChecks: on.}
|
||||||
|
proc foo()
|
||||||
|
{.pop.}
|
||||||
|
|
||||||
|
proc foo() =
|
||||||
|
let c = b - a
|
||||||
|
|
||||||
|
try:
|
||||||
|
foo()
|
||||||
|
except OverflowDefect:
|
||||||
|
overflowDetected = true
|
||||||
|
|
||||||
|
doAssert(not overflowDetected)
|
||||||
|
|
||||||
|
|
||||||
|
echo "ok"
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
{.experimental: "codeReordering".}
|
||||||
|
|
||||||
discard """
|
discard """
|
||||||
output: "ok"
|
output: "ok"
|
||||||
cmd: "nim $target --overflowChecks:off $options $file"
|
cmd: "nim $target --overflowChecks:off $options $file"
|
||||||
|
|
@ -12,7 +14,7 @@ var
|
||||||
overflowDetected = false
|
overflowDetected = false
|
||||||
|
|
||||||
try:
|
try:
|
||||||
writeLine(stdout, b - a)
|
echo b - a
|
||||||
except OverflowDefect:
|
except OverflowDefect:
|
||||||
overflowDetected = true
|
overflowDetected = true
|
||||||
|
|
||||||
|
|
@ -1,28 +1,17 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: "nim check $options --verbosity:0 $file"
|
cmd: "nim check $options --verbosity:0 --hints:off $file"
|
||||||
action: "reject"
|
action: "reject"
|
||||||
nimout: '''
|
nimout: '''
|
||||||
t20922.nim(37, 5) Error: expression expected, but found ':'
|
t20922.nim(26, 5) Error: expression expected, but found ':'
|
||||||
|
t20922.nim(34, 7) Error: expression expected, but found ':'
|
||||||
|
t20922.nim(35, 5) Error: ':' or '=' expected, but got 'keyword of'
|
||||||
Error: in expression ' '+'': identifier expected, but found ''
|
Error: in expression ' '+'': identifier expected, but found ''
|
||||||
t20922.nim(37, 7) Error: attempting to call undeclared routine: '<Error>'
|
t20922.nim(26, 7) Error: attempting to call undeclared routine: '<Error>'
|
||||||
Error: in expression ' '+'': identifier expected, but found ''
|
Error: in expression ' '+'': identifier expected, but found ''
|
||||||
t20922.nim(37, 7) Error: attempting to call undeclared routine: '<Error>'
|
t20922.nim(26, 7) Error: attempting to call undeclared routine: '<Error>'
|
||||||
t20922.nim(37, 7) Error: expression '' cannot be called
|
t20922.nim(26, 7) Error: expression '' cannot be called
|
||||||
t20922.nim(37, 7) Error: expression '' has no type (or is ambiguous)
|
t20922.nim(26, 7) Error: expression '' has no type (or is ambiguous)
|
||||||
t20922.nim(37, 7) Error: VM problem: dest register is not set
|
t20922.nim(26, 7) Error: VM problem: dest register is not set
|
||||||
t20922.nim(45, 7) Error: expression expected, but found ':'
|
|
||||||
t20922.nim(46, 5) Error: ':' or '=' expected, but got 'keyword of'
|
|
||||||
t20922.nim(45, 9) Error: undeclared identifier: 'x'
|
|
||||||
t20922.nim(45, 9) Error: expression 'x' has no type (or is ambiguous)
|
|
||||||
Error: in expression ' x': identifier expected, but found ''
|
|
||||||
t20922.nim(45, 9) Error: attempting to call undeclared routine: '<Error>'
|
|
||||||
Error: in expression ' x': identifier expected, but found ''
|
|
||||||
t20922.nim(45, 9) Error: attempting to call undeclared routine: '<Error>'
|
|
||||||
t20922.nim(45, 9) Error: expression '' cannot be called
|
|
||||||
t20922.nim(45, 9) Error: expression '' has no type (or is ambiguous)
|
|
||||||
t20922.nim(45, 9) Error: VM problem: dest register is not set
|
|
||||||
t20922.nim(33, 6) Hint: 'mapInstrToToken' is declared but not used [XDeclaredButNotUsed]
|
|
||||||
t20922.nim(43, 3) Hint: 'Foo' is declared but not used [XDeclaredButNotUsed]
|
|
||||||
'''
|
'''
|
||||||
"""
|
"""
|
||||||
# original test case issue #20922
|
# original test case issue #20922
|
||||||
|
|
|
||||||
|
|
@ -13,3 +13,15 @@ proc WarnMe() =
|
||||||
x: int
|
x: int
|
||||||
echo(x)
|
echo(x)
|
||||||
|
|
||||||
|
# bug #11852
|
||||||
|
proc foo(x: string, y: int, res: int) =
|
||||||
|
{.push checks: off}
|
||||||
|
var a: ptr char = unsafeAddr(x[y])
|
||||||
|
{.pop.}
|
||||||
|
if x.len > y:
|
||||||
|
doAssert ord(a[]) == 51
|
||||||
|
else:
|
||||||
|
doAssert x.len + 48 == res
|
||||||
|
|
||||||
|
foo("", 0, 48)
|
||||||
|
foo("abc", 40, 51)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
|
matrix: "--experimental:codeReordering"
|
||||||
output:'''0
|
output:'''0
|
||||||
1
|
1
|
||||||
2
|
2
|
||||||
|
|
|
||||||
19
tests/proc/t19795.nim
Normal file
19
tests/proc/t19795.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
discard """
|
||||||
|
matrix: "--mm:arc"
|
||||||
|
"""
|
||||||
|
|
||||||
|
# bug #19795
|
||||||
|
# bug #21085
|
||||||
|
|
||||||
|
type Vector = seq[int]
|
||||||
|
|
||||||
|
var vect: Vector = newSeq[int](5)
|
||||||
|
doAssert vect == @[0, 0, 0, 0, 0]
|
||||||
|
|
||||||
|
# Needed to get the problem. Could also use "var".
|
||||||
|
let vectCopy = vect
|
||||||
|
|
||||||
|
# Then some procedure definition is needed to get the problem.
|
||||||
|
proc p(): int = 3
|
||||||
|
|
||||||
|
doAssert vect == @[0, 0, 0, 0, 0]
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: '''nim c --styleCheck:hint $file'''
|
cmd: '''nim c --styleCheck:hint $file'''
|
||||||
nimout: '''
|
nimout: '''
|
||||||
|
tlinter.nim(25, 1) Hint: 'tyPE' should be: 'type' [Name]
|
||||||
tlinter.nim(21, 14) Hint: 'nosideeffect' should be: 'noSideEffect' [Name]
|
tlinter.nim(21, 14) Hint: 'nosideeffect' should be: 'noSideEffect' [Name]
|
||||||
tlinter.nim(21, 28) Hint: 'myown' should be: 'myOwn' [template declared in tlinter.nim(19, 9)] [Name]
|
tlinter.nim(21, 28) Hint: 'myown' should be: 'myOwn' [template declared in tlinter.nim(19, 9)] [Name]
|
||||||
tlinter.nim(21, 35) Hint: 'inLine' should be: 'inline' [Name]
|
tlinter.nim(21, 35) Hint: 'inLine' should be: 'inline' [Name]
|
||||||
tlinter.nim(25, 1) Hint: 'tyPE' should be: 'type' [Name]
|
|
||||||
tlinter.nim(23, 1) Hint: 'foO' should be: 'foo' [proc declared in tlinter.nim(21, 6)] [Name]
|
tlinter.nim(23, 1) Hint: 'foO' should be: 'foo' [proc declared in tlinter.nim(21, 6)] [Name]
|
||||||
tlinter.nim(27, 14) Hint: 'Foo_bar' should be: 'FooBar' [type declared in tlinter.nim(25, 6)] [Name]
|
tlinter.nim(27, 14) Hint: 'Foo_bar' should be: 'FooBar' [type declared in tlinter.nim(25, 6)] [Name]
|
||||||
tlinter.nim(29, 6) Hint: 'someVAR' should be: 'someVar' [var declared in tlinter.nim(27, 5)] [Name]
|
tlinter.nim(29, 6) Hint: 'someVAR' should be: 'someVar' [var declared in tlinter.nim(27, 5)] [Name]
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,19 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''0
|
output: '''
|
||||||
|
3
|
||||||
|
0
|
||||||
true
|
true
|
||||||
3'''
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
# bug #798
|
||||||
|
template t012{(0|1|2){x}}(x: untyped): untyped = x+1
|
||||||
|
let z = 1
|
||||||
|
# outputs 3 thanks to fixpoint iteration:
|
||||||
|
echo z
|
||||||
|
|
||||||
|
|
||||||
template arithOps: untyped = (`+` | `-` | `*`)
|
template arithOps: untyped = (`+` | `-` | `*`)
|
||||||
template testOr{ (arithOps{f})(a, b) }(a, b, f: untyped): untyped = f(a mod 10, b)
|
template testOr{ (arithOps{f})(a, b) }(a, b, f: untyped): untyped = f(a mod 10, b)
|
||||||
|
|
||||||
|
|
@ -20,9 +30,3 @@ var
|
||||||
c = false
|
c = false
|
||||||
a = b and a
|
a = b and a
|
||||||
echo a
|
echo a
|
||||||
|
|
||||||
# bug #798
|
|
||||||
template t012{(0|1|2){x}}(x: untyped): untyped = x+1
|
|
||||||
let z = 1
|
|
||||||
# outputs 3 thanks to fixpoint iteration:
|
|
||||||
echo z
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue