Merge branch 'devel' of github.com:nim-lang/Nim into devel

This commit is contained in:
Araq 2017-12-18 13:13:10 +01:00
commit ed616664f7
5 changed files with 48 additions and 43 deletions

View file

@ -1290,12 +1290,9 @@ proc takeImplicitAddr(c: PContext, n: PNode): PNode =
proc asgnToResultVar(c: PContext, n, le, ri: PNode) {.inline.} = proc asgnToResultVar(c: PContext, n, le, ri: PNode) {.inline.} =
if le.kind == nkHiddenDeref: if le.kind == nkHiddenDeref:
var x = le.sons[0] var x = le.sons[0]
if x.typ.kind == tyVar and x.kind == nkSym: if x.typ.kind == tyVar and x.kind == nkSym and x.sym.kind == skResult:
if x.sym.kind == skResult:
n.sons[0] = x # 'result[]' --> 'result' n.sons[0] = x # 'result[]' --> 'result'
n.sons[1] = takeImplicitAddr(c, ri) n.sons[1] = takeImplicitAddr(c, ri)
if x.sym.kind != skParam:
# XXX This is hacky. See bug #4910.
x.typ.flags.incl tfVarIsPtr x.typ.flags.incl tfVarIsPtr
#echo x.info, " setting it for this type ", typeToString(x.typ), " ", n.info #echo x.info, " setting it for this type ", typeToString(x.typ), " ", n.info
@ -1449,14 +1446,15 @@ proc semYieldVarResult(c: PContext, n: PNode, restype: PType) =
var t = skipTypes(restype, {tyGenericInst, tyAlias}) var t = skipTypes(restype, {tyGenericInst, tyAlias})
case t.kind case t.kind
of tyVar: of tyVar:
t.flags.incl tfVarIsPtr # bugfix for #4048, #4910, #6892
if n.sons[0].kind in {nkHiddenStdConv, nkHiddenSubConv}: if n.sons[0].kind in {nkHiddenStdConv, nkHiddenSubConv}:
n.sons[0] = n.sons[0].sons[1] n.sons[0] = n.sons[0].sons[1]
n.sons[0] = takeImplicitAddr(c, n.sons[0]) n.sons[0] = takeImplicitAddr(c, n.sons[0])
of tyTuple: of tyTuple:
for i in 0..<t.sonsLen: for i in 0..<t.sonsLen:
var e = skipTypes(t.sons[i], {tyGenericInst, tyAlias}) var e = skipTypes(t.sons[i], {tyGenericInst, tyAlias})
if e.kind == tyVar: if e.kind == tyVar:
e.flags.incl tfVarIsPtr # bugfix for #4048, #4910, #6892
if n.sons[0].kind == nkPar: if n.sons[0].kind == nkPar:
n.sons[0].sons[i] = takeImplicitAddr(c, n.sons[0].sons[i]) n.sons[0].sons[i] = takeImplicitAddr(c, n.sons[0].sons[i])
elif n.sons[0].kind in {nkHiddenStdConv, nkHiddenSubConv} and elif n.sons[0].kind in {nkHiddenStdConv, nkHiddenSubConv} and

View file

@ -441,7 +441,7 @@ template `|`(a, b): string = (if a.len > 0: a else: b)
proc tests(args: string) = proc tests(args: string) =
# we compile the tester with taintMode:on to have a basic # we compile the tester with taintMode:on to have a basic
# taint mode test :-) # taint mode test :-)
nimexec "cc --taintMode:on tests/testament/tester" nimexec "cc --taintMode:on --opt:speed tests/testament/tester"
# Since tests take a long time (on my machine), and we want to defy Murhpys # Since tests take a long time (on my machine), and we want to defy Murhpys
# law - lets make sure the compiler really is freshly compiled! # law - lets make sure the compiler really is freshly compiled!
nimexec "c --lib:lib -d:release --opt:speed compiler/nim.nim" nimexec "c --lib:lib -d:release --opt:speed compiler/nim.nim"

View file

@ -22,10 +22,18 @@ proc getSubsystem*[T](): ptr T {.
let input: ptr Input = getSubsystem[Input]() let input: ptr Input = getSubsystem[Input]()
# bug #4910 # bugs #4910, #6892
proc modify(x: var int) =
x = 123
proc foo() = proc foo() =
var ts: array[10, int] var ts: array[2, int]
for t in mitems(ts): for t in mitems(ts):
t = 123 discard
for t in mitems(ts):
modify(t)
for i, t in mpairs(ts):
modify(t)

View file

@ -15,58 +15,52 @@
const const
rodfilesDir = "tests/rodfiles" rodfilesDir = "tests/rodfiles"
nimcacheDir = rodfilesDir / "nimcache"
proc delNimCache() = proc delNimCache(filename, options: string) =
let dir = nimcacheDir(filename, options)
try: try:
removeDir(nimcacheDir) removeDir(dir)
except OSError: except OSError:
echo "[Warning] could not delete: ", nimcacheDir echo "[Warning] could not delete: ", dir
proc runRodFiles(r: var TResults, cat: Category, options: string) = proc runRodFiles(r: var TResults, cat: Category, options: string) =
template test(filename: untyped) = template test(filename: string, clearCacheFirst=false) =
if clearCacheFirst: delNimCache(filename, options)
testSpec r, makeTest(rodfilesDir / filename, options, cat, actionRun) testSpec r, makeTest(rodfilesDir / filename, options, cat, actionRun)
delNimCache()
# test basic recompilation scheme: # test basic recompilation scheme:
test "hallo" test "hallo", true
test "hallo" test "hallo"
when false: when false:
# test incremental type information: # test incremental type information:
test "hallo2" test "hallo2"
delNimCache()
# test type converters: # test type converters:
test "aconv" test "aconv", true
test "bconv" test "bconv"
delNimCache()
# test G, A, B example from the documentation; test init sections: # test G, A, B example from the documentation; test init sections:
test "deada" test "deada", true
test "deada2" test "deada2"
delNimCache()
when false: when false:
# test method generation: # test method generation:
test "bmethods" test "bmethods", true
test "bmethods2" test "bmethods2"
delNimCache()
# test generics: # test generics:
test "tgeneric1" test "tgeneric1", true
test "tgeneric2" test "tgeneric2"
delNimCache()
proc compileRodFiles(r: var TResults, cat: Category, options: string) = proc compileRodFiles(r: var TResults, cat: Category, options: string) =
template test(filename: untyped) = template test(filename: untyped, clearCacheFirst=true) =
if clearCacheFirst: delNimCache(filename, options)
testSpec r, makeTest(rodfilesDir / filename, options, cat) testSpec r, makeTest(rodfilesDir / filename, options, cat)
delNimCache()
# test DLL interfacing: # test DLL interfacing:
test "gtkex1" test "gtkex1", true
test "gtkex2" test "gtkex2"
delNimCache()
# --------------------- DLL generation tests ---------------------------------- # --------------------- DLL generation tests ----------------------------------

View file

@ -12,7 +12,7 @@
import import
parseutils, strutils, pegs, os, osproc, streams, parsecfg, json, parseutils, strutils, pegs, os, osproc, streams, parsecfg, json,
marshal, backend, parseopt, specs, htmlgen, browsers, terminal, marshal, backend, parseopt, specs, htmlgen, browsers, terminal,
algorithm, compiler/nodejs, times, sets algorithm, compiler/nodejs, times, sets, md5
const const
resultsFile = "testresults.html" resultsFile = "testresults.html"
@ -71,8 +71,14 @@ proc getFileDir(filename: string): string =
if not result.isAbsolute(): if not result.isAbsolute():
result = getCurrentDir() / result result = getCurrentDir() / result
proc nimcacheDir(filename, options: string): string =
## Give each test a private nimcache dir so they don't clobber each other's.
return "nimcache" / (filename & '_' & options.getMD5)
proc callCompiler(cmdTemplate, filename, options: string, proc callCompiler(cmdTemplate, filename, options: string,
target: TTarget): TSpec = target: TTarget, extraOptions=""): TSpec =
let nimcache = nimcacheDir(filename, options)
let options = options & " --nimCache:" & nimcache.quoteShell & extraOptions
let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target], let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
"options", options, "file", filename.quoteShell, "options", options, "file", filename.quoteShell,
"filedir", filename.getFileDir()]) "filedir", filename.getFileDir()])
@ -222,9 +228,10 @@ proc cmpMsgs(r: var TResults, expected, given: TSpec, test: TTest, target: TTarg
r.addResult(test, target, expected.msg, given.msg, reSuccess) r.addResult(test, target, expected.msg, given.msg, reSuccess)
inc(r.passed) inc(r.passed)
proc generatedFile(path, name: string, target: TTarget): string = proc generatedFile(test: TTest, target: TTarget): string =
let (_, name, _) = test.name.splitFile
let ext = targetToExt[target] let ext = targetToExt[target]
result = path / "nimcache" / result = nimcacheDir(test.name, test.options) /
(if target == targetJS: "" else: "compiler_") & (if target == targetJS: "" else: "compiler_") &
name.changeFileExt(ext) name.changeFileExt(ext)
@ -234,8 +241,7 @@ proc needsCodegenCheck(spec: TSpec): bool =
proc codegenCheck(test: TTest, target: TTarget, spec: TSpec, expectedMsg: var string, proc codegenCheck(test: TTest, target: TTarget, spec: TSpec, expectedMsg: var string,
given: var TSpec) = given: var TSpec) =
try: try:
let (path, name, _) = test.name.splitFile let genFile = generatedFile(test, target)
let genFile = generatedFile(path, name, target)
let contents = readFile(genFile).string let contents = readFile(genFile).string
let check = spec.ccodeCheck let check = spec.ccodeCheck
if check.len > 0: if check.len > 0:
@ -325,9 +331,8 @@ proc testSpec(r: var TResults, test: TTest, target = targetC) =
case expected.action case expected.action
of actionCompile: of actionCompile:
var given = callCompiler(expected.cmd, test.name, var given = callCompiler(expected.cmd, test.name, test.options, target,
test.options & " --stdout --hint[Path]:off --hint[Processing]:off", extraOptions=" --stdout --hint[Path]:off --hint[Processing]:off")
target)
compilerOutputTests(test, target, given, expected, r) compilerOutputTests(test, target, given, expected, r)
of actionRun, actionRunNoSpec: of actionRun, actionRunNoSpec:
# In this branch of code "early return" pattern is clearer than deep # In this branch of code "early return" pattern is clearer than deep
@ -342,8 +347,8 @@ proc testSpec(r: var TResults, test: TTest, target = targetC) =
let isJsTarget = target == targetJS let isJsTarget = target == targetJS
var exeFile: string var exeFile: string
if isJsTarget: if isJsTarget:
let (dir, file, _) = splitFile(tname) let (_, file, _) = splitFile(tname)
exeFile = dir / "nimcache" / file & ".js" # *TODO* hardcoded "nimcache" exeFile = nimcacheDir(test.name, test.options) / file & ".js"
else: else:
exeFile = changeFileExt(tname, ExeExt) exeFile = changeFileExt(tname, ExeExt)