Skip to content

Commit

Permalink
Revert "Remove dead code from sem/procfind"
Browse files Browse the repository at this point in the history
This reverts commit fb45aec.
  • Loading branch information
Clyybber committed Mar 12, 2024
1 parent 0d1afe8 commit 23e869b
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions compiler/sem/procfind.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ import
from compiler/ast/reports_sem import reportSym
from compiler/ast/report_enums import ReportKind

proc equalGenericParams(procA, procB: PNode): bool {.used.} =
# currently unused, but might be used again
if procA.len != procB.len: return false
for i in 0..<procA.len:
if procA[i].kind != nkSym:
return false
if procB[i].kind != nkSym:
return false
let a = procA[i].sym
let b = procB[i].sym
if a.name.id != b.name.id or
not sameTypeOrNil(a.typ, b.typ, {ExactTypeDescValues}): return
if a.ast != nil and b.ast != nil:
if not exprStructuralEquivalent(a.ast, b.ast): return
result = true

proc searchForProcAux(c: PContext, scope: PScope, fn: PSym): PSym =
var it: TIdentIter
result = initIdentIter(it, scope.symbols, fn.name)
Expand Down Expand Up @@ -56,3 +72,29 @@ proc searchForProc*(c: PContext, scope: PScope, fn: PSym): tuple[proto: PSym, co
result.proto = searchForProcAux(c, scope, fn)
result.comesFromShadowScope = true

when false:
proc paramsFitBorrow(child, parent: PNode): bool =
result = false
if child.len == parent.len:
for i in 1..<child.len:
var m = child[i].sym
var n = parent[i].sym
assert((m.kind == skParam) and (n.kind == skParam))
if not compareTypes(m.typ, n.typ, dcEqOrDistinctOf): return
if not compareTypes(child[0].typ, parent[0].typ,
dcEqOrDistinctOf): return
result = true

proc searchForBorrowProc*(c: PContext, startScope: PScope, fn: PSym): PSym =
# Searches for the fn in the symbol table. If the parameter lists are suitable
# for borrowing the sym in the symbol table is returned, else nil.
var it: TIdentIter
for scope in walkScopes(startScope):
result = initIdentIter(it, scope.symbols, fn.Name)
while result != nil:
# watchout! result must not be the same as fn!
if (result.Kind == fn.kind) and (result.id != fn.id):
if equalGenericParams(result.ast[genericParamsPos],
fn.ast[genericParamsPos]):
if paramsFitBorrow(fn.typ.n, result.typ.n): return
result = NextIdentIter(it, scope.symbols)

0 comments on commit 23e869b

Please sign in to comment.