From 841377206300aee0335cccfb3510766bb7c80e85 Mon Sep 17 00:00:00 2001 From: Araq Date: Fri, 20 Jul 2012 16:23:07 +0200 Subject: [PATCH] optimizations for system.compiles --- compiler/semcall.nim | 20 ++++++++++++-------- compiler/semexprs.nim | 20 ++++++++++++-------- compiler/sigmatch.nim | 1 + 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 8ba582a333..da96c77cd6 100755 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -69,15 +69,19 @@ proc resolveOverloads(c: PContext, n, orig: PNode, InternalError(n.info, "x.state is not csMatch") #writeMatches(best) #writeMatches(alt) - var args = "(" - for i in countup(1, sonsLen(n) - 1): - if i > 1: add(args, ", ") - add(args, typeToString(n.sons[i].typ)) - add(args, ")") + if c.inCompilesContext > 0: + # quick error message for performance of 'compiles' built-in: + LocalError(n.Info, errAmbiguousCallXYZ, "") + else: + var args = "(" + for i in countup(1, sonsLen(n) - 1): + if i > 1: add(args, ", ") + add(args, typeToString(n.sons[i].typ)) + add(args, ")") - LocalError(n.Info, errGenerated, msgKindToString(errAmbiguousCallXYZ) % [ - getProcHeader(best.calleeSym), getProcHeader(alt.calleeSym), - args]) + LocalError(n.Info, errGenerated, msgKindToString(errAmbiguousCallXYZ) % [ + getProcHeader(best.calleeSym), getProcHeader(alt.calleeSym), + args]) proc semResolvedCall(c: PContext, n: PNode, x: TCandidate): PNode = assert x.state == csMatch diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 63a19c8799..08dc4a8669 100755 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -607,14 +607,18 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode = var m: TCandidate initCandidate(m, t) matches(c, n, nOrig, m) - if m.state != csMatch: - var msg = msgKindToString(errTypeMismatch) - for i in countup(1, sonsLen(n) - 1): - if i > 1: add(msg, ", ") - add(msg, typeToString(n.sons[i].typ)) - add(msg, ")\n" & msgKindToString(errButExpected) & "\n" & - typeToString(n.sons[0].typ)) - GlobalError(n.Info, errGenerated, msg) + if m.state != csMatch: + if c.inCompilesContext > 0: + # speed up error generation: + GlobalError(n.Info, errTypeMismatch, "") + else: + var msg = msgKindToString(errTypeMismatch) + for i in countup(1, sonsLen(n) - 1): + if i > 1: add(msg, ", ") + add(msg, typeToString(n.sons[i].typ)) + add(msg, ")\n" & msgKindToString(errButExpected) & "\n" & + typeToString(n.sons[0].typ)) + GlobalError(n.Info, errGenerated, msg) result = nil else: result = m.call diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 6021d27ab7..8ae6250d5c 100755 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -118,6 +118,7 @@ proc getNotFoundError*(c: PContext, n: PNode): string = # Gives a detailed error message; this is separated from semOverloadedCall, # as semOverlodedCall is already pretty slow (and we need this information # only in case of an error). + if c.InCompilesContext > 0: return "" result = msgKindToString(errTypeMismatch) for i in countup(1, sonsLen(n) - 1): #debug(n.sons[i].typ)