From 830e0c0009d25d84a26fc997722eee4ecd015fd9 Mon Sep 17 00:00:00 2001 From: Araq Date: Sat, 8 Nov 2014 15:47:00 +0100 Subject: [PATCH] the codegen doesn't emit deepCopy for parallel statements --- compiler/lowerings.nim | 27 ++++++++++------- compiler/nimconf.nim | 8 +++-- readme.md | 6 ++-- tests/parallel/tconvexhull.nim | 2 ++ tests/parallel/tdeepcopy2.nim | 8 ++--- todo.txt | 5 ++-- web/community.txt | 54 +++++++++++++++++----------------- web/index.txt | 4 +-- web/news.txt | 2 ++ 9 files changed, 64 insertions(+), 52 deletions(-) diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim index ae19f53669..661472a052 100644 --- a/compiler/lowerings.nim +++ b/compiler/lowerings.nim @@ -204,7 +204,7 @@ proc flowVarKind(t: PType): TFlowVarKind = else: fvBlob proc addLocalVar(varSection, varInit: PNode; owner: PSym; typ: PType; - v: PNode): PSym = + v: PNode; useShallowCopy=false): PSym = result = newSym(skTemp, getIdent(genPrefix), owner, varSection.info) result.typ = typ incl(result.flags, sfFromGeneric) @@ -215,11 +215,14 @@ proc addLocalVar(varSection, varInit: PNode; owner: PSym; typ: PType; vpart.sons[2] = if varInit.isNil: v else: ast.emptyNode varSection.add vpart if varInit != nil: - let deepCopyCall = newNodeI(nkCall, varInit.info, 3) - deepCopyCall.sons[0] = newSymNode(createMagic("deepCopy", mDeepCopy)) - deepCopyCall.sons[1] = newSymNode(result) - deepCopyCall.sons[2] = v - varInit.add deepCopyCall + if useShallowCopy: + varInit.add newFastAsgnStmt(newSymNode(result), v) + else: + let deepCopyCall = newNodeI(nkCall, varInit.info, 3) + deepCopyCall.sons[0] = newSymNode(createMagic("deepCopy", mDeepCopy)) + deepCopyCall.sons[1] = newSymNode(result) + deepCopyCall.sons[2] = v + varInit.add deepCopyCall discard """ We generate roughly this: @@ -420,7 +423,8 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym; result.add newFastAsgnStmt(newDotExpr(scratchObj, fieldB), n[3]) let threadLocal = addLocalVar(varSection,nil, objType.owner, fieldA.typ, - indirectAccess(castExpr, fieldA, n.info)) + indirectAccess(castExpr, fieldA, n.info), + useShallowCopy=true) slice.sons[2] = threadLocal.newSymNode else: let a = genAddrOf(n) @@ -434,7 +438,8 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym; slice.sons[1] = genDeref(indirectAccess(castExpr, field, n.info)) let threadLocal = addLocalVar(varSection,nil, objType.owner, fieldB.typ, - indirectAccess(castExpr, fieldB, n.info)) + indirectAccess(castExpr, fieldB, n.info), + useShallowCopy=true) slice.sons[3] = threadLocal.newSymNode call.add slice elif (let size = computeSize(argType); size < 0 or size > 16) and @@ -445,7 +450,8 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym; objType.addField(field) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), a) let threadLocal = addLocalVar(varSection,nil, objType.owner, field.typ, - indirectAccess(castExpr, field, n.info)) + indirectAccess(castExpr, field, n.info), + useShallowCopy=true) call.add(genDeref(threadLocal.newSymNode)) else: # boring case @@ -454,7 +460,8 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym; result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n) let threadLocal = addLocalVar(varSection, varInit, objType.owner, field.typ, - indirectAccess(castExpr, field, n.info)) + indirectAccess(castExpr, field, n.info), + useShallowCopy=true) call.add(threadLocal.newSymNode) proc wrapProcForSpawn*(owner: PSym; spawnExpr: PNode; retType: PType; diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim index 98fe831d33..bcf9b53596 100644 --- a/compiler/nimconf.nim +++ b/compiler/nimconf.nim @@ -113,7 +113,7 @@ proc parseDirective(L: var TLexer, tok: var TToken) = case whichKeyword(tok.ident) of wIf: setLen(condStack, len(condStack) + 1) - var res = evalppIf(L, tok) + let res = evalppIf(L, tok) condStack[high(condStack)] = res if not res: jumpToDirective(L, tok, jdElseEndif) of wElif: doElif(L, tok) @@ -224,8 +224,10 @@ proc loadConfigs*(cfg: string) = if libpath == "": # choose default libpath: var prefix = getPrefixDir() - if prefix == "/usr": libpath = "/usr/lib/nim" - elif prefix == "/usr/local": libpath = "/usr/local/lib/nim" + when defined(posix): + if prefix == "/usr": libpath = "/usr/lib/nim" + elif prefix == "/usr/local": libpath = "/usr/local/lib/nim" + else: libpath = joinPath(prefix, "lib") else: libpath = joinPath(prefix, "lib") if optSkipConfigFile notin gGlobalOptions: diff --git a/readme.md b/readme.md index a2f83b4b03..3cc007e3b7 100644 --- a/readme.md +++ b/readme.md @@ -30,9 +30,9 @@ To build from source you will need: If you are on a fairly modern *nix system, the following steps should work: ``` -$ git clone git://github.com/Araq/Nimrod.git -$ cd Nimrod -$ git clone --depth 1 git://github.com/nimrod-code/csources +$ git clone git://github.com/Araq/Nim.git +$ cd Nim +$ git clone --depth 1 git://github.com/nim-code/csources $ cd csources && sh build.sh $ cd .. $ bin/nim c koch diff --git a/tests/parallel/tconvexhull.nim b/tests/parallel/tconvexhull.nim index c97fed39b3..d7e4f77168 100644 --- a/tests/parallel/tconvexhull.nim +++ b/tests/parallel/tconvexhull.nim @@ -5,6 +5,8 @@ true true true true''' + +ccodeCheck: "!'deepcopy('" """ # parallel convex hull for Nim bigbreak diff --git a/tests/parallel/tdeepcopy2.nim b/tests/parallel/tdeepcopy2.nim index eca19f6399..8ffdcc5f2b 100644 --- a/tests/parallel/tdeepcopy2.nim +++ b/tests/parallel/tdeepcopy2.nim @@ -27,9 +27,9 @@ proc main = var dummy: ref Bar[int] new(dummy) dummy.x = 44 - parallel: - let f = spawn foo(dummy) - let b = spawn foo(dummy) - echo "done", f, " ", b + #parallel: + let f = spawn foo(dummy) + let b = spawn foo(dummy) + echo "done", ^f, " ", ^b main() diff --git a/todo.txt b/todo.txt index a45a4f50a6..52b26f0060 100644 --- a/todo.txt +++ b/todo.txt @@ -1,9 +1,8 @@ version 0.10 ============ -- fix missing GC_ref bug for flow variables -- fix deepCopy bug in parallel section -- implement 'static_call' +- find out why global installations end up using the wrong stdlib +- implement 'procCall' - make nimble part of the distribution - split idetools into separate tool - split docgen into separate tool diff --git a/web/community.txt b/web/community.txt index d45e7df619..958f7aea1e 100644 --- a/web/community.txt +++ b/web/community.txt @@ -1,74 +1,74 @@ Forum ===== -The `Nimrod forum `_ is the place where most +The `Nim forum `_ is the place where most discussions related to the language happen. It not only includes discussions -relating to the design of Nimrod but also allows for beginners to ask questions -relating to Nimrod. +relating to the design of Nim but also allows for beginners to ask questions +relating to Nim. IRC ==== -Many Nimrod developers are a part of the -`#nimrod IRC channel `_ on -Freenode. That is the place where the rest of the discussion relating to Nimrod -occurs. Be sure to join us there if you wish to discuss Nimrod in real-time. -IRC is the perfect place for people just starting to learn Nimrod and we +Many Nim developers are a part of the +`#nim IRC channel `_ on +Freenode. That is the place where the rest of the discussion relating to Nim +occurs. Be sure to join us there if you wish to discuss Nim in real-time. +IRC is the perfect place for people just starting to learn Nim and we welcome any questions that you may have! You may also be interested in reading the -`IRC logs `_ which are an archive of all +`IRC logs `_ which are an archive of all of the previous discussions that took place in the IRC channel. Github ====== -Nimrod's `source code `_ is hosted on Github. -Together with the `wiki `_ and -`issue tracker `_. +Nim's `source code `_ is hosted on Github. +Together with the `wiki `_ and +`issue tracker `_. -Github also hosts other projects relating to Nimrod. These projects are a part -of the `nimrod-code organisation `_. -This includes the `Babel package manager `_ -and its `package repository `_. +Github also hosts other projects relating to Nim. These projects are a part +of the `nim-code organisation `_. +This includes the `Babel package manager `_ +and its `package repository `_. Twitter ======= -Follow us `@nimrodlang `_ for latest news about -Nimrod. +Follow us `@nimlang `_ for latest news about +Nim. Reddit ====== -Subscribe to `/r/nimrod `_ for latest news about -Nimrod. +Subscribe to `/r/nim `_ for latest news about +Nim. StackOverflow ============= -When asking a question relating to Nimrod, be sure to use the -`Nimrod `_ tag in your +When asking a question relating to Nim, be sure to use the +`Nim `_ tag in your question. How to help =========== There are always many things to be done in the main -`Nimrod repository `_, check out the -`issues `_ for +`Nim repository `_, check out the +`issues `_ for things to do; pull requests are always welcome. You can also contribute to the many other projects hosted by the -`nimrod-code `_ organisation on github. If you +`nim-code `_ organisation on github. If you can't find anything you fancy doing, you can always ask for inspiration on IRC -(irc.freenode.net #nimrod) or on the `Nimrod forums `_. +(irc.freenode.net #nim) or on the `Nim forums `_. Donations --------- If you love what we do and are feeling generous then you can always donate. Contributions of any quantity are greatly appreciated and will contribute to -making Nimrod even better! +making Nim even better! Gittip `````` diff --git a/web/index.txt b/web/index.txt index 04c9536282..e48c54f171 100644 --- a/web/index.txt +++ b/web/index.txt @@ -92,7 +92,7 @@ Nim plays nice with others the POSIX API, OpenGL, SDL, Cairo, Python, Lua, TCL, X11, libzip, PCRE, libcurl, mySQL and SQLite are included in the standard distribution or can easily be obtained via the - `Babel package manager `_. + `Nimble package manager `_. * A C to Nim conversion utility: New bindings to C libraries are easily generated by ``c2nim``. @@ -101,5 +101,5 @@ Roadmap to 1.0 ============== Please have a look at -this `wiki page `_ for +this `wiki page `_ for an up-to-date overview. diff --git a/web/news.txt b/web/news.txt index 2f2290b5b0..2a9c24231d 100644 --- a/web/news.txt +++ b/web/news.txt @@ -9,6 +9,8 @@ News Changes affecting backwards compatibility ----------------------------------------- + - **The language has been renamed from Nimrod to Nim.** The name of the + compiler changed from ``nimrod`` to ``nim`` too. - ``system.fileHandle`` has been renamed to ``system.getFileHandle`` to prevent name conflicts with the new type ``FileHandle``. - Comments are now not part of the AST, as such you cannot use them in place