Skip to content
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

PRTEMP addrFrom #337

Draft
wants to merge 27 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,21 @@ type
PScope* = ref TScope

PLib* = ref TLib

ViewDep* = object
## for escape analysis, we model symbol dependency using a list of `ViewDep`
sym*: PSym ## lhs = foo.addr => ViewDep(sym: foo, addrLevel: 1)
## lhs = foo => ViewDep(sym: foo, addrLevel: 0)
## lhs = foo[] => ViewDep(sym: foo, addrLevel: -1)
## lhs = foo[][] => ViewDep(sym: foo, addrLevel: -2) etc
addrLevel*: int ## addressing level, <= 1, can be < 0

ViewConstraint* = object
# we could model other constraints, eg whether a parameter is being written to
lhs*: PSym
rhs*: PSym
addrLevel*: int # see also `ViewDep`

TSym* {.acyclic.} = object of TIdObj
# proc and type instantiations are cached in the generic symbol
case kind*: TSymKind
Expand All @@ -830,6 +845,7 @@ type
procInstCache*: seq[PInstantiation]
gcUnsafetyReason*: PSym # for better error messages wrt gcsafe
transformedBody*: PNode # cached body after transf pass
viewConstraints*: seq[ViewConstraint]
of skModule, skPackage:
# modules keep track of the generic symbols they use from other modules.
# this is because in incremental compilation, when a module is about to
Expand All @@ -847,6 +863,12 @@ type
bitsize*: int
alignment*: int # for alignment
else: nil

viewSyms*: seq[ViewDep] ## models dependency graph between symbols, see `ViewDep`
# only needed for `skLet, skVar, skField, skForVar` + `skParam`, `skResult`
# see https://github.com/nim-lang/RFCs/issues/19 which would allow that,
# else we could use different names + 1 common accessor.

magic*: TMagic
typ*: PType
name*: PIdent
Expand Down Expand Up @@ -1937,5 +1959,8 @@ proc toHumanStr*(kind: TTypeKind): string =
## strips leading `tk`
result = toHumanStrImpl(kind, 2)

import ./debugutils
export debugutils

proc skipAddr*(n: PNode): PNode {.inline.} =
(if n.kind == nkHiddenAddr: n[0] else: n)
1 change: 1 addition & 0 deletions compiler/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,4 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimHasStacktraceMsgs")
defineSymbol("nimDoesntTrackDefects")
defineSymbol("nimHasLentIterators")
defineSymbol("nimHasCapturedMsgs")
20 changes: 20 additions & 0 deletions compiler/debugutils.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#[
see also ./debugutils_basic
]#

import ./debugutils_basic
export debugutils_basic

when withDebugutils:
defineNoop:
dbg
dbg2

elif withDebugutilsTimn:
import timn/compilerutils/nimc_interface2 # D20200619T192931
export nimc_interface2

else:
defineNoop:
dbg
dbg2
62 changes: 62 additions & 0 deletions compiler/debugutils_basic.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#[
edit this as needed for debugging

]#
import std/macros

const withDebugutils* = defined(nimWithDebugUtils)
const withDebugutilsTimn* = defined(timn_with_compilerutils)

macro defineNoop*(body): untyped =
result = newStmtList()
for ai in body:
var name: NimNode
var body2: NimNode
case ai.kind
of nnkIdent:
name = ai
body2 = quote do: discard
else:
echo ai.repr
echo ai.treeRepr
doAssert ai.len == 2
name = ai[0]
body2 = ai[1]
doAssert name.kind == nnkIdent
result.add quote do:
template `name`*(args: varargs[untyped]): `untyped` = `body2`

when withDebugutilsTimn:
import timn/compilerutils/nimc_interface
export nimc_interface

from ./options import ConfigRef

type DebugCfg = ref object
nimWithDebugUtilsRT: bool
config: ConfigRef

let debugCfg = DebugCfg()

proc ndebugSetConfigExt*(conf: ConfigRef) =
#[
nimWithDebugUtilsRT: settable at nim RT (ie, no need to recompile nim for that)
nimWithDebugUtils: settable at nim CT
]#
debugCfg.config = conf

# debugCfg.nimWithDebugUtilsRT = conf.isDefined("nimWithDebugUtilsRT")
# if debugCfg.nimWithDebugUtilsRT:
# debugCfg.config = conf

when withDebugutilsTimn:
timn_setConfigExt(conf)

template debugGetConfig*(): untyped =
debugCfg.config

# timnEchoEnabled
template ndebugEchoEnabled*(): bool =
debugCfg.nimWithDebugUtilsRT = debugGetConfig.isDefined("nimWithDebugUtilsRT") # IMPROVE; compute once
var ret = debugCfg.nimWithDebugUtilsRT and debugGetConfig.isDefined("timn_enable_echo0b")
ret
9 changes: 9 additions & 0 deletions compiler/interfaces.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ast, options
import semdata # PContext

# lifetime
# {.pragma: mylib, importc, dynlib: "/tmp/libz11.dylib".} # PRTEMP PATH
{.pragma: mylib, importc.} # PRTEMP PATH
proc nimCheckViewFromCompat*(c: PContext, n, le, ri: PNode) {.mylib.}
proc nimSimulateCall*(c: PContext, fun: PSym, nCall: PNode) {.mylib.}
proc nimToHumanViewConstraint*(a: seq[ViewConstraint]): string {.importc.}
Loading