diff --git a/compiler/cgmeth.nim b/compiler/cgmeth.nim index 76f5414eca..687653aaf4 100755 --- a/compiler/cgmeth.nim +++ b/compiler/cgmeth.nim @@ -10,7 +10,8 @@ ## This module implements code generation for multi methods. import - intsets, options, ast, astalgo, msgs, idents, renderer, types, magicsys + intsets, options, ast, astalgo, msgs, idents, renderer, types, magicsys, + sempass2 proc genConv(n: PNode, d: PType, downcast: bool): PNode = var dest = skipTypes(d, abstractPtrs) @@ -81,10 +82,12 @@ proc attachDispatcher(s: PSym, dispatcher: PNode) = proc methodDef*(s: PSym, fromCache: bool) = var L = len(gMethods) - for i in countup(0, L - 1): - if sameMethodBucket(gMethods[i][0], s): + for i in countup(0, L - 1): + let disp = gMethods[i][0] + if sameMethodBucket(disp, s): add(gMethods[i], s) - attachDispatcher(s, lastSon(gMethods[i][0].ast)) + attachDispatcher(s, lastSon(disp.ast)) + when useEffectSystem: checkMethodEffects(disp, s) return add(gMethods, @[s]) # create a new dispatcher: diff --git a/compiler/options.nim b/compiler/options.nim index f5e54a6131..2051953ced 100755 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -12,7 +12,7 @@ import const hasTinyCBackend* = defined(tinyc) - useEffectSystem* = false + useEffectSystem* = true type # please make sure we have under 32 options # (improves code efficiency a lot!) diff --git a/compiler/sem.nim b/compiler/sem.nim index 93d0238065..bd1ad14686 100755 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -15,7 +15,7 @@ import magicsys, parser, nversion, nimsets, semfold, importer, procfind, lookups, rodread, pragmas, passes, semdata, semtypinst, sigmatch, semthreads, intsets, transf, evals, idgen, aliases, cgmeth, lambdalifting, - evaltempl, patterns, parampatterns + evaltempl, patterns, parampatterns, sempass2 proc semPass*(): TPass # implementation diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 936fe18229..4199aa5f7f 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -25,7 +25,7 @@ import # io, time (time dependent), gc (performs GC'ed allocation), exceptions, # side effect (accesses global), store (stores into *type*), # store_unkown (performs some store) --> store(any)|store(x) -# load (loads from *type*), recursive (recursive call), +# load (loads from *type*), recursive (recursive call), unsafe, # endless (has endless loops), --> user effects are defined over *patterns* # --> a TR macro can annotate the proc with user defined annotations # --> the effect system can access these @@ -84,20 +84,16 @@ type PEffects = var TEffects proc throws(tracked: PEffects, n: PNode) = - # since a 'raise' statement occurs rarely and we need distinct reasons; - # we simply do not merge anything here, this would be problematic for the - # stack of exceptions anyway: tracked.exc.add n proc excType(n: PNode): PType = - assert n.kind == nkRaiseStmt + assert n.kind != nkRaiseStmt # reraise is like raising E_Base: - let t = if n.sons[0].kind == nkEmpty: sysTypeFromName"E_Base" - else: n.sons[0].typ + let t = if n.kind == nkEmpty: sysTypeFromName"E_Base" else: n.typ result = skipTypes(t, skipPtrs) proc addEffect(a: PEffects, e: PNode, useLineInfo=true) = - assert e.kind == nkRaiseStmt + assert e.kind != nkRaiseStmt var aa = a.exc for i in a.bottom ..