DEV Community

ringabout
ringabout

Posted on

My Nim Development Weekly Report (3/5)

Progress

chores

remove nosinks hacks from compiler.

test DLL generation with ORC.

fixes sinkinference documentation, which has been disabled.

implements wasMoved hook

fixes #19291; implements wasMoved hook.

You can now register a wasMoved hook.

type
  Game = object

proc `=wasMoved`(x: var Game) {.error.}
Enter fullscreen mode Exit fullscreen mode

hash types based on custom paths

fixes #20139; hash types based on custom paths.

Now the object type with the same name in the same file name but resides in different directories won't conflict with each other anymore. The PR takes the path of the type into consideration, which prevents conflicts.

fixes top level variables inside loops are not reset in VM

fixes #10938; fixes #13312; fixes #13918; fixes #20985; always initializes global variables with null values in VM.

static:
  for i in '1' .. '2':
    var s: set[char]
    doAssert s == {}
    incl(s, i)
Enter fullscreen mode Exit fullscreen mode

The variable s wasn't initialized properly in the loop. It caused s to keep the old value after the first iteration. My solution is to initialize s each time the var section is executed, which is reset for every iteration.

fixes type erasures for quoted variables

fixes #21326; fixes #7375; fixes #11986; fixes #9607; rework quote do; getAst uses type info to annotate the type of quoted variables; no more type erasures for quoted variables.

import macros

macro foo(body: untyped): untyped =
  let a = body.lineInfoObj()
  result = quote do:
    echo `a`

foo:
  let c = 1
Enter fullscreen mode Exit fullscreen mode

The VM is an untyped executor, which erases types of expressions after execution. In this case, a is evaluated in the VM, which loses its type, namely LineInfo after evaluation. So we should collect the type information and annotate the type of a when expanding quote do. I store the type information in the parameters of the dummy templates used by quote do, which is used to restore the type of quoted variables.

replaces implicit passes array registered at runtime with explicit function calls; simplify compilation pipeline

replaces implicit passes array registered at runtime with explicit function calls; simplify compilation pipeline.

proc processPipeline(graph: ModuleGraph; semNode: PNode; bModule: PPassContext): PNode =
  case graph.pipelinePass
  of CgenPass:
    result = semNode
    if bModule != nil:
      genTopLevelStmt(BModule(bModule), result)
  of JSgenPass:
    when not defined(leanCompiler):
      result = processJSCodeGen(bModule, semNode)
  of GenDependPass:
    result = addDotDependency(bModule, semNode)
  of SemPass:
    result = graph.emptyNode
  of Docgen2Pass, Docgen2TexPass:
    when not defined(leanCompiler):
      result = processNode(bModule, semNode)
  of Docgen2JsonPass:
    when not defined(leanCompiler):
      result = processNodeJson(bModule, semNode)
  of EvalPass, InterpreterPass:
    result = interpreterCode(bModule, semNode)
  of NonePass:
    doAssert false, "use setPipeLinePass to set a proper PipelinePass"
Enter fullscreen mode Exit fullscreen mode

The processPipeline explicitly calls the code generator, which makes the code more clear. It is the second step towards to remove forward declaration.

Weekly collection

https://forum.nim-lang.org/t/9908 (2/19)

https://forum.nim-lang.org/t/9940 (2/26)

Participating in contributions

I have created a matrix space for contributions to the official Nim projects. If you are already a contributor of the official Nim projects, welcome to this space to discuss contributions. If you are willing to take up some quests for fun, I have prepared a list for you, which contains a few contribution-friendly issues.

Sponsorship

Many thanks to @Yepoleb, @lenis0012, @pietroppeter, @Clonkk, @mode80, @phil, @CxPlanner, @shirleyquirk, @elcritch, @geotre, @thinkwelltwd, @xrfez, @enthus1ast for sponsoring me on GitHub.

Top comments (0)