diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 3b6f82c40d..9b3c66104c 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -719,26 +719,34 @@ proc pragmaGuard(c: PContext; it: PNode; kind: TSymKind): PSym = result = qualifiedLookUp(c, n, {checkUndeclared}) proc semCustomPragma(c: PContext, n: PNode): PNode = + var callNode: PNode + if n.kind == nkIdent: - result = newTree(nkCall, n) + # pragma -> pragma() + callNode = newTree(nkCall, n) elif n.kind == nkExprColonExpr: # pragma: arg -> pragma(arg) - result = newTree(nkCall, n[0], n[1]) + callNode = newTree(nkCall, n[0], n[1]) elif n.kind in nkPragmaCallKinds: - result = n + callNode = n else: invalidPragma(c, n) return n - let r = c.semOverloadedCall(c, result, n, {skTemplate}, {efNoUndeclared}) + let r = c.semOverloadedCall(c, callNode, n, {skTemplate}, {efNoUndeclared}) + if r.isNil or sfCustomPragma notin r[0].sym.flags: invalidPragma(c, n) - else: - result = r - if n.kind == nkIdent: - result = result[0] - elif n.kind == nkExprColonExpr: - result.kind = n.kind # pragma(arg) -> pragma: arg + return n + + result = r + # Transform the nkCall node back to its original form if possible + if n.kind == nkIdent and r.len == 1: + # pragma() -> pragma + result = result[0] + elif n.kind == nkExprColonExpr and r.len == 2: + # pragma(arg) -> pragma: arg + result.kind = n.kind proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, validPragmas: TSpecialWords, comesFromPush: bool) : bool = diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 5b7556b2e9..cd570caad9 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1136,7 +1136,7 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) = # its evaluated result here so that we don't execute it once again in the # final pass if a[2].kind in nkCallKinds: - a[2] = newNodeIT(nkType, a[2].info, t) + incl a[2].flags, nfSem # bug #10548 if sfExportc in s.flags and s.typ.kind == tyAlias: localError(c.config, name.info, "{.exportc.} not allowed for type aliases") let aa = a.sons[2] @@ -1191,24 +1191,27 @@ proc typeSectionFinalPass(c: PContext, n: PNode) = # compute the type's size and check for illegal recursions: if a.sons[1].kind == nkEmpty: var x = a[2] - while x.kind in {nkStmtList, nkStmtListExpr} and x.len > 0: - x = x.lastSon - if x.kind notin {nkObjectTy, nkDistinctTy, nkEnumTy, nkEmpty} and - s.typ.kind notin {tyObject, tyEnum}: - # type aliases are hard: - var t = semTypeNode(c, x, nil) - assert t != nil - if s.typ != nil and s.typ.kind notin {tyAlias, tySink}: - if t.kind in {tyProc, tyGenericInst} and not t.isMetaType: - assignType(s.typ, t) - s.typ.id = t.id - elif t.kind in {tyObject, tyEnum, tyDistinct}: - assert s.typ != nil - assignType(s.typ, t) - s.typ.id = t.id # same id - checkConstructedType(c.config, s.info, s.typ) - if s.typ.kind in {tyObject, tyTuple} and not s.typ.n.isNil: - checkForMetaFields(c, s.typ.n) + if x.kind in nkCallKinds and nfSem in x.flags: + discard "already semchecked, see line marked with bug #10548" + else: + while x.kind in {nkStmtList, nkStmtListExpr} and x.len > 0: + x = x.lastSon + if x.kind notin {nkObjectTy, nkDistinctTy, nkEnumTy, nkEmpty} and + s.typ.kind notin {tyObject, tyEnum}: + # type aliases are hard: + var t = semTypeNode(c, x, nil) + assert t != nil + if s.typ != nil and s.typ.kind notin {tyAlias, tySink}: + if t.kind in {tyProc, tyGenericInst} and not t.isMetaType: + assignType(s.typ, t) + s.typ.id = t.id + elif t.kind in {tyObject, tyEnum, tyDistinct}: + assert s.typ != nil + assignType(s.typ, t) + s.typ.id = t.id # same id + checkConstructedType(c.config, s.info, s.typ) + if s.typ.kind in {tyObject, tyTuple} and not s.typ.n.isNil: + checkForMetaFields(c, s.typ.n) instAllTypeBoundOp(c, n.info) diff --git a/koch.nim b/koch.nim index 5deda5ecd4..ac95c15663 100644 --- a/koch.nim +++ b/koch.nim @@ -291,13 +291,14 @@ proc boot(args: string) = hostOs & "_" & hostCpu let nimStart = findStartNim() - copyExe(nimStart, 0.thVersion) for i in 0..2: let defaultCommand = if useCpp: "cpp" else: "c" let bootOptions = if args.len == 0 or args.startsWith("-"): defaultCommand else: "" echo "iteration: ", i+1 var extraOption = "" + var nimi = i.thVersion if i == 0: + nimi = nimStart extraOption.add " --skipUserCfg --skipParentCfg" # The configs are skipped for bootstrap # (1st iteration) to prevent newer flags from breaking bootstrap phase. @@ -307,8 +308,9 @@ proc boot(args: string) = if version.startsWith "Nim Compiler Version 0.19.0": extraOption.add " -d:nimBoostrapCsources0_19_0" # remove this when csources get updated - exec i.thVersion & " $# $# $# --nimcache:$# compiler" / "nim.nim" % - [bootOptions, extraOption, args, smartNimcache] + + exec "$# $# $# $# --nimcache:$# compiler" / "nim.nim" % + [nimi, bootOptions, extraOption, args, smartNimcache] if sameFileContent(output, i.thVersion): copyExe(output, finalDest) echo "executables are equal: SUCCESS!" diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 43e61d660a..7ec1eefc63 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -1515,7 +1515,7 @@ macro getCustomPragmaVal*(n: typed, cp: typed{nkSym}): untyped = else: let def = p[0].getImpl[3] result = newTree(nnkPar) - for i in 1..