summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2018-04-28 18:37:45 +0200
committerAndreas Rumpf <rumpf_a@web.de>2018-04-28 18:37:45 +0200
commit6408646b02a8a7bc7a7182277499978cd16fcd70 (patch)
tree97c6f1ce6f78e3b7e3afe1262462b33a1eb1dd78
parent4adc31ee3d5d56e1566da746b464ec11a6865863 (diff)
downloadNim-6408646b02a8a7bc7a7182277499978cd16fcd70.tar.gz
minor speedup: concept tests still green
-rw-r--r--compiler/semcall.nim7
-rw-r--r--compiler/semexprs.nim3
-rw-r--r--compiler/sigmatch.nim19
3 files changed, 15 insertions, 14 deletions
diff --git a/compiler/semcall.nim b/compiler/semcall.nim
index 0df943531..3a12ca980 100644
--- a/compiler/semcall.nim
+++ b/compiler/semcall.nim
@@ -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:
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 66fe81ed3..feca087fc 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -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))
 
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 0426a22f3..2b105f48a 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -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