mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-08 14:03:23 +00:00
minor speedup: concept tests still green
This commit is contained in:
@@ -103,7 +103,7 @@ proc pickBestCandidate(c: PContext, headSymbol: PNode,
|
||||
var cmp = cmpCandidates(best, z)
|
||||
if cmp < 0: best = z # x is better than the best so far
|
||||
elif cmp == 0: alt = z # x is as good as the best so far
|
||||
elif errors.enabled or z.diagnostics.enabled:
|
||||
elif errors.enabled or z.diagnosticsEnabled:
|
||||
errors.s.safeAdd(CandidateError(
|
||||
sym: sym,
|
||||
unmatchedVarParam: int z.mutabilityProblem,
|
||||
@@ -197,7 +197,7 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
|
||||
candidates.add(" for a 'var' type a variable needs to be passed, but '" &
|
||||
renderNotLValue(n[err.unmatchedVarParam]) &
|
||||
"' is immutable\n")
|
||||
for diag in err.diagnostics.s:
|
||||
for diag in err.diagnostics:
|
||||
candidates.add(diag & "\n")
|
||||
|
||||
result = (prefer, candidates)
|
||||
@@ -230,7 +230,8 @@ proc bracketNotFoundError(c: PContext; n: PNode) =
|
||||
if symx.kind in routineKinds:
|
||||
errors.s.add(CandidateError(sym: symx,
|
||||
unmatchedVarParam: 0, firstMismatch: 0,
|
||||
diagnostics: OptionalStringSeq(enabled: false, s: @[])))
|
||||
diagnostics: nil,
|
||||
enabled: false))
|
||||
errors.enabled = true
|
||||
symx = nextOverloadIter(o, c, headSymbol)
|
||||
if errors.s.len == 0:
|
||||
|
||||
@@ -306,7 +306,8 @@ proc isOpImpl(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||
var m: TCandidate
|
||||
initCandidate(c, m, t2)
|
||||
if efExplain in flags:
|
||||
m.diagnostics = OptionalStringSeq(enabled: true, s: @[])
|
||||
m.diagnostics = @[]
|
||||
m.diagnosticsEnabled = true
|
||||
let match = typeRel(m, t2, t1) >= isSubtype # isNone
|
||||
result = newIntNode(nkIntLit, ord(match))
|
||||
|
||||
|
||||
@@ -22,14 +22,11 @@ type
|
||||
TCandidateState* = enum
|
||||
csEmpty, csMatch, csNoMatch
|
||||
|
||||
OptionalStringSeq* = object
|
||||
enabled*: bool
|
||||
s*: seq[string]
|
||||
|
||||
CandidateError* = object
|
||||
sym*: PSym
|
||||
unmatchedVarParam*, firstMismatch*: int
|
||||
diagnostics*: OptionalStringSeq # seq[string]
|
||||
diagnostics*: seq[string]
|
||||
enabled*: bool
|
||||
|
||||
CandidateErrors* = object
|
||||
enabled*: bool
|
||||
@@ -66,7 +63,7 @@ type
|
||||
# matching. they will be reset if the matching
|
||||
# is not successful. may replace the bindings
|
||||
# table in the future.
|
||||
diagnostics*: OptionalStringSeq # \
|
||||
diagnostics*: seq[string] # \
|
||||
# when diagnosticsEnabled, the matching process
|
||||
# will collect extra diagnostics that will be
|
||||
# displayed to the user.
|
||||
@@ -77,6 +74,7 @@ type
|
||||
inheritancePenalty: int # to prefer closest father object type
|
||||
firstMismatch*: int # position of the first type mismatch for
|
||||
# better error messages
|
||||
diagnosticsEnabled*: bool
|
||||
|
||||
TTypeRelFlag* = enum
|
||||
trDontBind
|
||||
@@ -147,7 +145,8 @@ proc initCandidate*(ctx: PContext, c: var TCandidate, callee: PSym,
|
||||
c.calleeScope = 1
|
||||
else:
|
||||
c.calleeScope = calleeScope
|
||||
c.diagnostics = OptionalStringSeq(enabled: diagnosticsEnabled, s: @[])
|
||||
c.diagnostics = if diagnosticsEnabled: @[] else: nil
|
||||
c.diagnosticsEnabled = diagnosticsEnabled
|
||||
c.magic = c.calleeSym.magic
|
||||
initIdTable(c.bindings)
|
||||
if binding != nil and callee.kind in routineKinds:
|
||||
@@ -725,7 +724,7 @@ proc matchUserTypeClass*(m: var TCandidate; ff, a: PType): PType =
|
||||
diagnostics: seq[string]
|
||||
errorPrefix: string
|
||||
flags: TExprFlags = {}
|
||||
collectDiagnostics = m.diagnostics.enabled or
|
||||
collectDiagnostics = m.diagnosticsEnabled or
|
||||
sfExplain in typeClass.sym.flags
|
||||
|
||||
if collectDiagnostics:
|
||||
@@ -745,8 +744,8 @@ proc matchUserTypeClass*(m: var TCandidate; ff, a: PType): PType =
|
||||
if collectDiagnostics:
|
||||
writelnHook = oldWriteHook
|
||||
for msg in diagnostics:
|
||||
m.diagnostics.s.safeAdd msg
|
||||
m.diagnostics.enabled = true
|
||||
m.diagnostics.safeAdd msg
|
||||
m.diagnosticsEnabled = true
|
||||
|
||||
if checkedBody == nil: return nil
|
||||
|
||||
|
||||
Reference in New Issue
Block a user