Skip to content

Commit

Permalink
adapt to nim-lang#15559
Browse files Browse the repository at this point in the history
(cherry picked from commit 1996614dc58c5dd9943986329c3edc1900fd7167)
  • Loading branch information
disruptek committed Oct 25, 2020
1 parent b756500 commit 5c15f74
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
6 changes: 6 additions & 0 deletions compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1971,3 +1971,9 @@ proc toHumanStr*(kind: TTypeKind): string =

proc skipAddr*(n: PNode): PNode {.inline.} =
(if n.kind == nkHiddenAddr: n[0] else: n)

proc hash*(n: ItemId): Hash =
var h: Hash = 0
h = h !& n.module
h = h !& n.item
result = !$h
8 changes: 4 additions & 4 deletions compiler/cgendata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ type

ConflictsTable* = object
names: Table[string, int]
identities: Table[int, int]
identities: Table[ConflictKey, int]

ConflictKey* = int
ConflictKey* = ItemId

# this mangling stuff is intentionally verbose; err on side of caution!
#
Expand Down Expand Up @@ -255,8 +255,8 @@ proc findPendingModule*(m: BModule; t: PType): BModule =
result = findPendingModule(m.g, t.owner)

# get a ConflictKey from a PSym or PType
template conflictKey*(s: PSym): ConflictKey = ConflictKey s.id
template conflictKey*(s: PType): ConflictKey = ConflictKey s.uniqueId
template conflictKey*(s: PSym): ConflictKey = s.itemId
template conflictKey*(s: PType): ConflictKey = s.uniqueId

# same idea, but for signatures
template conflictSig*(s: PType): SigHash = hashTypeDef(s)
Expand Down
16 changes: 9 additions & 7 deletions compiler/mangler.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,22 @@ const
# these types get unwrapped and discarded from mangling
unwrapTypeArg = irrelevantForNaming - {tyRange} + {tyRef, tyPtr,
tyUserTypeClass, tyUserTypeClassInst}
unIdentity = ItemId(module: -1, item: -1)

type
ModuleOrProc* = BProc or BModule

template config(): ConfigRef = cache.modules.config
template add_and(s: typed; chs: string) = s.add "_"; s.add chs
template add_and(s: typed; key: ConflictKey) = s.add_and $key.item

using
g: ModuleGraph

# useful for debugging
template conflictKey(s: BModule): int = conflictKey(s.module)
template conflictKey(s: BProc): int =
if s.prc == nil: 0 else: conflictKey(s.prc)
template conflictKey(s: BModule): ConflictKey = conflictKey(s.module)
template conflictKey(s: BProc): ConflictKey =
if s.prc == nil: unIdentity else: conflictKey(s.prc)

template mangle*(p: ModuleOrProc; t: PType): string = $getTypeName(p, t)
proc mangle*(p: ModuleOrProc; s: PSym): string
Expand Down Expand Up @@ -352,7 +354,7 @@ proc mayCollide(p: ModuleOrProc; s: PSym; name: var string): bool =
if result:
if name.len == 0:
name = mangle(s.name.s)
name.add_and $conflictKey(s)
name.add_and conflictKey(s)
assert not s.hasImmutableName

proc mangle*(p: ModuleOrProc; s: PSym): string =
Expand Down Expand Up @@ -387,7 +389,7 @@ proc mangle*(p: ModuleOrProc; s: PSym): string =

# something like `default` might need this check
if (unlikely) result in m.config.cppDefines:
result.add_and $conflictKey(s)
result.add_and conflictKey(s)

#if getModule(s).id.abs != m.module.id.abs: ...creepy for IC...
# XXX: we don't do anything special with regard to m.hcrOn
Expand Down Expand Up @@ -463,7 +465,7 @@ proc idOrSig*(p: ModuleOrProc; s: PSym): Rope =
when debugMangle:
if s.name.s == inspect:
echo "p is module ", p is BModule
echo "p key ", $conflictKey(p)
echo "p key ", conflictKey(p)

result = Rope getSetConflict(p, s)
when debugMangle:
Expand Down Expand Up @@ -671,7 +673,7 @@ proc mangleParamName*(p: BProc; s: PSym): Rope =
## make new local identifiers of the same name without colliding with it.

# It's likely that the symbol is already in the module scope!
if s.loc.r == nil or $conflictKey(s) notin p.sigConflicts:
if s.loc.r == nil or conflictKey(s) notin p.sigConflicts:
# discard any existing counter for this sym from the module scope
purgeConflict(p.module, s)
s.loc.r = nil # critically, destroy the location
Expand Down

0 comments on commit 5c15f74

Please sign in to comment.