optimizations for system.compiles

This commit is contained in:
Araq 2012-07-20 16:23:07 +02:00
commit 8413772063
3 changed files with 25 additions and 16 deletions

View file

@ -69,15 +69,19 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
InternalError(n.info, "x.state is not csMatch") InternalError(n.info, "x.state is not csMatch")
#writeMatches(best) #writeMatches(best)
#writeMatches(alt) #writeMatches(alt)
var args = "(" if c.inCompilesContext > 0:
for i in countup(1, sonsLen(n) - 1): # quick error message for performance of 'compiles' built-in:
if i > 1: add(args, ", ") LocalError(n.Info, errAmbiguousCallXYZ, "")
add(args, typeToString(n.sons[i].typ)) else:
add(args, ")") 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) % [ LocalError(n.Info, errGenerated, msgKindToString(errAmbiguousCallXYZ) % [
getProcHeader(best.calleeSym), getProcHeader(alt.calleeSym), getProcHeader(best.calleeSym), getProcHeader(alt.calleeSym),
args]) args])
proc semResolvedCall(c: PContext, n: PNode, x: TCandidate): PNode = proc semResolvedCall(c: PContext, n: PNode, x: TCandidate): PNode =
assert x.state == csMatch assert x.state == csMatch

View file

@ -607,14 +607,18 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
var m: TCandidate var m: TCandidate
initCandidate(m, t) initCandidate(m, t)
matches(c, n, nOrig, m) matches(c, n, nOrig, m)
if m.state != csMatch: if m.state != csMatch:
var msg = msgKindToString(errTypeMismatch) if c.inCompilesContext > 0:
for i in countup(1, sonsLen(n) - 1): # speed up error generation:
if i > 1: add(msg, ", ") GlobalError(n.Info, errTypeMismatch, "")
add(msg, typeToString(n.sons[i].typ)) else:
add(msg, ")\n" & msgKindToString(errButExpected) & "\n" & var msg = msgKindToString(errTypeMismatch)
typeToString(n.sons[0].typ)) for i in countup(1, sonsLen(n) - 1):
GlobalError(n.Info, errGenerated, msg) 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 result = nil
else: else:
result = m.call result = m.call

View file

@ -118,6 +118,7 @@ proc getNotFoundError*(c: PContext, n: PNode): string =
# Gives a detailed error message; this is separated from semOverloadedCall, # Gives a detailed error message; this is separated from semOverloadedCall,
# as semOverlodedCall is already pretty slow (and we need this information # as semOverlodedCall is already pretty slow (and we need this information
# only in case of an error). # only in case of an error).
if c.InCompilesContext > 0: return ""
result = msgKindToString(errTypeMismatch) result = msgKindToString(errTypeMismatch)
for i in countup(1, sonsLen(n) - 1): for i in countup(1, sonsLen(n) - 1):
#debug(n.sons[i].typ) #debug(n.sons[i].typ)