Skip to content

Commit

Permalink
fix all I can, maybe not permanent
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Sep 29, 2024
1 parent 7679d4a commit 3e4b4ad
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
64 changes: 33 additions & 31 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2197,7 +2197,7 @@ proc isLValue(c: PContext; n: PNode, isOutParam = false): bool {.inline.} =
result = false

proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType,
arg: PNode): PNode =
arg: PNode, doInc = true): PNode =
result = nil
for i in 0..<c.converters.len:
var src = c.converters[i].typ.firstParamType
Expand Down Expand Up @@ -2244,13 +2244,13 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType,
dest.flags.incl tfVarIsPtr
result = newDeref(result)

inc(m.convMatches)
if doInc: inc(m.convMatches)
if not m.genericConverter:
m.genericConverter = srca == isGeneric or destIsGeneric
return result

proc localConvMatch(c: PContext, m: var TCandidate, f, a: PType,
arg: PNode): PNode =
arg: PNode, doInc = true): PNode =
# arg.typ can be nil in 'suggest':
if isNil(arg.typ): return nil

Expand All @@ -2273,7 +2273,7 @@ proc localConvMatch(c: PContext, m: var TCandidate, f, a: PType,
var r = typeRel(m, f[0], result.typ)
if r < isGeneric: return nil
if result.kind == nkCall: result.transitionSonsKind(nkHiddenCallConv)
inc(m.convMatches)
if doInc: inc(m.convMatches)
if r == isGeneric:
result.typ = getInstantiatedType(c, arg, m, base(f))
m.baseTypeMatch = true
Expand All @@ -2294,10 +2294,10 @@ template matchesVoidProc(t: PType): bool =
(t.kind == tyBuiltInTypeClass and t.elementType.kind == tyProc)

proc paramTypesMatch*(m: var TCandidate, f, a: PType,
arg, argOrig: PNode): PNode
arg, argOrig: PNode, doInc = true): PNode

proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
argSemantized, argOrig: PNode): PNode =
argSemantized, argOrig: PNode, doInc = true): PNode =
result = nil
var
fMaybeStatic = f.skipTypes({tyDistinct})
Expand Down Expand Up @@ -2329,8 +2329,8 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
elif arg.kind != nkEmpty:
var evaluated = c.semTryConstExpr(c, arg)
if evaluated != nil:
if f.kind == tyStatic:
let converted = paramTypesMatch(m, f.base, evaluated.typ, evaluated, argOrig)
if f.kind == tyStatic and f.base.kind != tyNone:
let converted = paramTypesMatch(m, f.base, evaluated.typ, evaluated, argOrig, doInc = false)
# if for some reason `evaluated` doesn't match `f.base`:
if converted == nil: return nil
evaluated = converted
Expand Down Expand Up @@ -2403,40 +2403,42 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,

case r
of isConvertible:
if f.skipTypes({tyRange}).kind in {tyInt, tyUInt}:
if doInc:
if f.skipTypes({tyRange}).kind in {tyInt, tyUInt}:
inc(m.convMatches)
inc(m.convMatches)
inc(m.convMatches)
result = implicitConv(nkHiddenStdConv, f, arg, m, c)
of isIntConv:
# I'm too lazy to introduce another ``*matches`` field, so we conflate
# ``isIntConv`` and ``isIntLit`` here:
if f.skipTypes({tyRange}).kind notin {tyInt, tyUInt}:
if doInc:
if f.skipTypes({tyRange}).kind notin {tyInt, tyUInt}:
inc(m.intConvMatches)
inc(m.intConvMatches)
inc(m.intConvMatches)
result = implicitConv(nkHiddenStdConv, f, arg, m, c)
of isSubtype:
inc(m.subtypeMatches)
if doInc: inc(m.subtypeMatches)
if f.kind == tyTypeDesc:
result = arg
else:
result = implicitConv(nkHiddenSubConv, f, arg, m, c)
of isSubrange:
inc(m.subtypeMatches)
if doInc: inc(m.subtypeMatches)
if f.kind in {tyVar}:
result = arg
else:
result = implicitConv(nkHiddenStdConv, f, arg, m, c)
of isInferred:
# result should be set in above while loop:
assert result != nil
inc(m.genericMatches)
if doInc: inc(m.genericMatches)
of isInferredConvertible:
# result should be set in above while loop:
assert result != nil
inc(m.convMatches)
if doInc: inc(m.convMatches)
result = implicitConv(nkHiddenStdConv, f, result, m, c)
of isGeneric:
inc(m.genericMatches)
if doInc: inc(m.genericMatches)
if arg.typ == nil:
result = arg
elif skipTypes(arg.typ, abstractVar-{tyTypeDesc}).kind == tyTuple or cmpInheritancePenalty(oldInheritancePenalty, m.inheritancePenalty) > 0:
Expand All @@ -2449,15 +2451,15 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
of isBothMetaConvertible:
# result should be set in above while loop:
assert result != nil
inc(m.convMatches)
if doInc: inc(m.convMatches)
result = arg
of isFromIntLit:
# too lazy to introduce another ``*matches`` field, so we conflate
# ``isIntConv`` and ``isIntLit`` here:
inc(m.intConvMatches, 256)
if doInc: inc(m.intConvMatches, 256)
result = implicitConv(nkHiddenStdConv, f, arg, m, c)
of isEqual:
inc(m.exactMatches)
if doInc: inc(m.exactMatches)
result = arg
let ff = skipTypes(f, abstractVar-{tyTypeDesc})
if ff.kind == tyTuple or
Expand All @@ -2467,7 +2469,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
# do not do this in ``typeRel`` as it then can't infer T in ``ref T``:
if a.kind == tyFromExpr: return nil
elif a.kind == tyError:
inc(m.genericMatches)
if doInc: inc(m.genericMatches)
m.matchedErrorType = true
return arg
elif a.kind == tyVoid and f.matchesVoidProc and argOrig.kind == nkStmtList:
Expand All @@ -2481,43 +2483,43 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
if f.kind == tyBuiltInTypeClass:
inc m.genericMatches
put(m, f, lifted.typ)
inc m.convMatches
if doInc: inc m.convMatches
return implicitConv(nkHiddenStdConv, f, lifted, m, c)
result = userConvMatch(c, m, f, a, arg)
# check for a base type match, which supports varargs[T] without []
# constructor in a call:
if result == nil and f.kind == tyVarargs:
if f.n != nil:
# Forward to the varargs converter
result = localConvMatch(c, m, f, a, arg)
result = localConvMatch(c, m, f, a, arg, doInc)
elif f[0].kind == tyTyped:
inc m.genericMatches
if doInc: inc m.genericMatches
result = arg
else:
r = typeRel(m, base(f), a)
case r
of isGeneric:
inc(m.convMatches)
if doInc: inc(m.convMatches)
result = copyTree(arg)
result.typ = getInstantiatedType(c, arg, m, base(f))
m.baseTypeMatch = true
of isFromIntLit:
inc(m.intConvMatches, 256)
if doInc: inc(m.intConvMatches, 256)
result = implicitConv(nkHiddenStdConv, f[0], arg, m, c)
m.baseTypeMatch = true
of isEqual:
inc(m.convMatches)
if doInc: inc(m.convMatches)
result = copyTree(arg)
m.baseTypeMatch = true
of isSubtype: # bug #4799, varargs accepting subtype relation object
inc(m.subtypeMatches)
if doInc: inc(m.subtypeMatches)
if base(f).kind == tyTypeDesc:
result = arg
else:
result = implicitConv(nkHiddenSubConv, base(f), arg, m, c)
m.baseTypeMatch = true
else:
result = userConvMatch(c, m, base(f), a, arg)
result = userConvMatch(c, m, base(f), a, arg, doInc)
if result != nil: m.baseTypeMatch = true

proc staticAwareTypeRel(m: var TCandidate, f: PType, arg: var PNode): TTypeRelation =
Expand All @@ -2532,9 +2534,9 @@ proc staticAwareTypeRel(m: var TCandidate, f: PType, arg: var PNode): TTypeRelat


proc paramTypesMatch*(m: var TCandidate, f, a: PType,
arg, argOrig: PNode): PNode =
arg, argOrig: PNode, doInc = true): PNode =
if arg == nil or arg.kind notin nkSymChoices:
result = paramTypesMatchAux(m, f, a, arg, argOrig)
result = paramTypesMatchAux(m, f, a, arg, argOrig, doInc)
else:
# symbol kinds that don't participate in symchoice type disambiguation:
let matchSet = {low(TSymKind)..high(TSymKind)} - {skModule, skPackage}
Expand Down
4 changes: 2 additions & 2 deletions tests/stdlib/ttasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ block:
block:
var a1: seq[int]
var a2: int
proc hello(a: int, c: static varargs[int]) =
proc hello(a: int, c: static openArray[int]) =
a1 = @c
a2 = a

Expand All @@ -260,7 +260,7 @@ block:
block:
var a1: seq[int]
var a2: int
proc hello(a: int, c: static varargs[int]) =
proc hello(a: int, c: static openArray[int]) =
a1 = @c
a2 = a

Expand Down

0 comments on commit 3e4b4ad

Please sign in to comment.