summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorArne Döring <arne.doering@gmx.net>2019-05-29 22:21:51 +0200
committerAndreas Rumpf <rumpf_a@web.de>2019-05-29 22:21:51 +0200
commit5b27b263fd76484fa6251ccd29520c2764b55818 (patch)
tree0629164266d4183ace4503d77f0d2a999fc9693f /compiler
parenteb471acffb02ebb14ada8483f8c8043a1c8e8210 (diff)
downloadNim-5b27b263fd76484fa6251ccd29520c2764b55818.tar.gz
Remove immediate pragma (#11308)
* remove immediate from tests
* remove immediate from the compiler
Diffstat (limited to 'compiler')
-rw-r--r--compiler/ast.nim4
-rw-r--r--compiler/astalgo.nim33
-rw-r--r--compiler/condsyms.nim1
-rw-r--r--compiler/evaltempl.nim2
-rw-r--r--compiler/pragmas.nim10
-rw-r--r--compiler/sem.nim3
-rw-r--r--compiler/semexprs.nim12
-rw-r--r--compiler/vm.nim17
-rw-r--r--compiler/vmgen.nim4
9 files changed, 21 insertions, 65 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 56c7edb90..197b7f22d 100644
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -286,10 +286,6 @@ type
 const
   sfNoInit* = sfMainModule       # don't generate code to init the variable
 
-  sfImmediate* = sfDispatcher
-    # macro or template is immediately expanded
-    # without considering any possible overloads
-
   sfCursor* = sfDispatcher
     # local variable has been computed to be a "cursor".
     # see cursors.nim for details about what that means.
diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim
index c1df74a3f..4100c3629 100644
--- a/compiler/astalgo.nim
+++ b/compiler/astalgo.nim
@@ -667,31 +667,14 @@ proc strTableContains*(t: TStrTable, n: PSym): bool =
 
 proc strTableRawInsert(data: var seq[PSym], n: PSym) =
   var h: Hash = n.name.h and high(data)
-  if sfImmediate notin n.flags:
-    # fast path:
-    while data[h] != nil:
-      if data[h] == n:
-        # allowed for 'export' feature:
-        #InternalError(n.info, "StrTableRawInsert: " & n.name.s)
-        return
-      h = nextTry(h, high(data))
-    assert(data[h] == nil)
-    data[h] = n
-  else:
-    # slow path; we have to ensure immediate symbols are preferred for
-    # symbol lookups.
-    # consider the chain: foo (immediate), foo, bar, bar (immediate)
-    # then bar (immediate) gets replaced with foo (immediate) and the non
-    # immediate foo is picked! Thus we need to replace it with the first
-    # slot that has in fact the same identifier stored in it!
-    var favPos = -1
-    while data[h] != nil:
-      if data[h] == n: return
-      if favPos < 0 and data[h].name.id == n.name.id: favPos = h
-      h = nextTry(h, high(data))
-    assert(data[h] == nil)
-    data[h] = n
-    if favPos >= 0: swap data[h], data[favPos]
+  while data[h] != nil:
+    if data[h] == n:
+      # allowed for 'export' feature:
+      #InternalError(n.info, "StrTableRawInsert: " & n.name.s)
+      return
+    h = nextTry(h, high(data))
+  assert(data[h] == nil)
+  data[h] = n
 
 proc symTabReplaceRaw(data: var seq[PSym], prevSym: PSym, newSym: PSym) =
   assert prevSym.name.h == newSym.name.h
diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim
index 7ae5412f5..c8f3dede5 100644
--- a/compiler/condsyms.nim
+++ b/compiler/condsyms.nim
@@ -54,7 +54,6 @@ proc initDefines*(symbols: StringTableRef) =
   defineSymbol("nimKnowsNimvm")
   defineSymbol("nimArrIdx")
   defineSymbol("nimHasalignOf")
-  defineSymbol("nimImmediateDeprecated")
   defineSymbol("nimNewShiftOps")
   defineSymbol("nimDistros")
   defineSymbol("nimHasCppDefine")
diff --git a/compiler/evaltempl.nim b/compiler/evaltempl.nim
index a7d319360..8acb85907 100644
--- a/compiler/evaltempl.nim
+++ b/compiler/evaltempl.nim
@@ -104,7 +104,7 @@ proc evalTemplateArgs(n: PNode, s: PSym; conf: ConfigRef; fromHlo: bool): PNode
     # their bodies. We could try to fix this, but it may be
     # wiser to just deprecate immediate templates and macros
     # now that we have working untyped parameters.
-    genericParams = if sfImmediate in s.flags or fromHlo: 0
+    genericParams = if fromHlo: 0
                     else: s.ast[genericParamsPos].len
     expectedRegularParams = s.typ.len-1
     givenRegularParams = totalParams - genericParams
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim
index 77c037e51..2065f587d 100644
--- a/compiler/pragmas.nim
+++ b/compiler/pragmas.nim
@@ -28,9 +28,9 @@ const
     wConstructor, wExportNims, wUsed, wLiftLocals, wStacktrace, wLinetrace}
   converterPragmas* = procPragmas
   methodPragmas* = procPragmas+{wBase}-{wImportCpp}
-  templatePragmas* = {wImmediate, wDeprecated, wError, wGensym, wInject, wDirty,
+  templatePragmas* = {wDeprecated, wError, wGensym, wInject, wDirty,
     wDelegator, wExportNims, wUsed, wPragma}
-  macroPragmas* = {FirstCallConv..LastCallConv, wImmediate, wImportc, wExportc,
+  macroPragmas* = {FirstCallConv..LastCallConv, wImportc, wExportc,
     wNodecl, wMagic, wNosideeffect, wCompilerProc, wNonReloadable, wCore, wDeprecated, wExtern,
     wImportCpp, wImportObjC, wError, wDiscardable, wGensym, wInject, wDelegator,
     wExportNims, wUsed}
@@ -789,12 +789,6 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
         recordPragma(c, it, "cppdefine", name)
         processImportCompilerProc(c, sym, name, it.info)
       of wExtern: setExternName(c, sym, expectStrLit(c, it), it.info)
-      of wImmediate:
-        if sym.kind in {skTemplate, skMacro}:
-          incl(sym.flags, sfImmediate)
-          incl(sym.flags, sfAllUntyped)
-          message(c.config, n.info, warnDeprecated, "use 'untyped' parameters instead; immediate is deprecated")
-        else: invalidPragma(c, it)
       of wDirty:
         if sym.kind == skTemplate: incl(sym.flags, sfDirty)
         else: invalidPragma(c, it)
diff --git a/compiler/sem.nim b/compiler/sem.nim
index 3c5d036dc..918c4eeff 100644
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -455,8 +455,7 @@ proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
   if sym == c.p.owner:
     globalError(c.config, info, "recursive dependency: '$1'" % sym.name.s)
 
-  let genericParams = if sfImmediate in sym.flags: 0
-                      else: sym.ast[genericParamsPos].len
+  let genericParams = sym.ast[genericParamsPos].len
   let suppliedParams = max(n.safeLen - 1, 0)
 
   if suppliedParams < genericParams:
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 118ebbcc1..52c6815b2 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -2586,16 +2586,8 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
       #if c.config.cmd == cmdPretty and n.sons[0].kind == nkDotExpr:
       #  pretty.checkUse(n.sons[0].sons[1].info, s)
       case s.kind
-      of skMacro:
-        if sfImmediate notin s.flags:
-          result = semDirectOp(c, n, flags)
-        else:
-          result = semMacroExpr(c, n, n, s, flags)
-      of skTemplate:
-        if sfImmediate notin s.flags:
-          result = semDirectOp(c, n, flags)
-        else:
-          result = semTemplateExpr(c, n, s, flags)
+      of skMacro, skTemplate:
+        result = semDirectOp(c, n, flags)
       of skType:
         # XXX think about this more (``set`` procs)
         let ambig = contains(c.ambiguousSymbols, s.id)
diff --git a/compiler/vm.nim b/compiler/vm.nim
index 4f6208c59..884500be8 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -2089,19 +2089,14 @@ proc evalMacroCall*(module: PSym; g: ModuleGraph;
 
   let gp = sym.ast[genericParamsPos]
   for i in 0 ..< gp.len:
-    if sfImmediate notin sym.flags:
-      let idx = sym.typ.len + i
-      if idx < n.len:
-        tos.slots[idx] = setupMacroParam(n.sons[idx], gp[i].sym.typ)
-      else:
-        dec(g.config.evalMacroCounter)
-        c.callsite = nil
-        localError(c.config, n.info, "expected " & $gp.len &
-                   " generic parameter(s)")
-    elif gp[i].sym.typ.kind in {tyStatic, tyTypeDesc}:
+    let idx = sym.typ.len + i
+    if idx < n.len:
+      tos.slots[idx] = setupMacroParam(n.sons[idx], gp[i].sym.typ)
+    else:
       dec(g.config.evalMacroCounter)
       c.callsite = nil
-      globalError(c.config, n.info, "static[T] or typedesc nor supported for .immediate macros")
+      localError(c.config, n.info, "expected " & $gp.len &
+                 " generic parameter(s)")
   # temporary storage:
   #for i in L ..< maxSlots: tos.slots[i] = newNode(nkEmpty)
   result = rawExecute(c, start, tos).regToNode
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim
index 6fe51dba6..035ab25cd 100644
--- a/compiler/vmgen.nim
+++ b/compiler/vmgen.nim
@@ -2242,9 +2242,7 @@ proc genProc(c: PCtx; s: PSym): int =
     genParams(c, s.typ.n)
 
     # allocate additional space for any generically bound parameters
-    if s.kind == skMacro and
-       sfImmediate notin s.flags and
-       s.ast[genericParamsPos].kind != nkEmpty:
+    if s.kind == skMacro and s.ast[genericParamsPos].kind != nkEmpty:
       genGenericParams(c, s.ast[genericParamsPos])
 
     if tfCapturesEnv in s.typ.flags: