diff options
author | Araq <rumpf_a@web.de> | 2016-11-16 00:13:45 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2016-11-16 00:13:45 +0100 |
commit | 0e1304a3e2e221cc5d380bea9158da5943b00cae (patch) | |
tree | 49754b159ae082f5ccf24a861cab7511260192e7 | |
parent | e6c5622aa74c1014b022071d9d525a0e13805246 (diff) | |
download | Nim-0e1304a3e2e221cc5d380bea9158da5943b00cae.tar.gz |
the compiler uses tyAlias internally; tester compiles again
-rw-r--r-- | compiler/ccgtypes.nim | 1 | ||||
-rw-r--r-- | compiler/cgen.nim | 19 | ||||
-rw-r--r-- | compiler/semstmts.nim | 7 | ||||
-rw-r--r-- | compiler/semtypes.nim | 35 | ||||
-rw-r--r-- | compiler/sighashes.nim | 9 | ||||
-rw-r--r-- | compiler/types.nim | 2 |
6 files changed, 49 insertions, 24 deletions
diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 9a7f9e037..82d655eac 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -106,6 +106,7 @@ proc typeName(typ: PType): Rope = else: ~"TY" proc getTypeName(m: BModule; typ: PType; sig: SigHash): Rope = + let typ = if typ.kind == tyAlias: typ.lastSon else: typ if typ.sym != nil and {sfImportc, sfExportc} * typ.sym.flags != {}: result = typ.sym.loc.r else: diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 89658279d..526a7b590 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -190,21 +190,24 @@ proc freshLineInfo(p: BProc; info: TLineInfo): bool = result = true proc genLineDir(p: BProc, t: PNode) = - var line = t.info.safeLineNm + let info = t.info + #if t.kind in nkCallKinds+{nkStmtListExpr} and t.len > 1: t[1].info + #else: t.info + var line = info.safeLineNm if optEmbedOrigSrc in gGlobalOptions: - add(p.s(cpsStmts), ~"//" & t.info.sourceLine & rnl) - genCLineDir(p.s(cpsStmts), t.info.toFullPath, line) + add(p.s(cpsStmts), ~"//" & info.sourceLine & rnl) + genCLineDir(p.s(cpsStmts), info.toFullPath, line) if ({optStackTrace, optEndb} * p.options == {optStackTrace, optEndb}) and (p.prc == nil or sfPure notin p.prc.flags): - if freshLineInfo(p, t.info): + if freshLineInfo(p, info): linefmt(p, cpsStmts, "#endb($1, $2);$n", - line.rope, makeCString(toFilename(t.info))) + line.rope, makeCString(toFilename(info))) elif ({optLineTrace, optStackTrace} * p.options == {optLineTrace, optStackTrace}) and - (p.prc == nil or sfPure notin p.prc.flags) and t.info.fileIndex >= 0: - if freshLineInfo(p, t.info): + (p.prc == nil or sfPure notin p.prc.flags) and info.fileIndex >= 0: + if freshLineInfo(p, info): linefmt(p, cpsStmts, "nimln($1, $2);$n", - line.rope, t.info.quotedFilename) + line.rope, info.quotedFilename) proc postStmtActions(p: BProc) {.inline.} = add(p.s(cpsStmts), p.module.injectStmt) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 5f74e484a..b59036ea5 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -745,7 +745,7 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) = var t = semTypeNode(c, a.sons[2], s.typ) if s.typ == nil: s.typ = t - elif t != s.typ: + elif t != s.typ and (s.typ == nil or s.typ.kind != tyAlias): # this can happen for e.g. tcan_alias_specialised_generic: assignType(s.typ, t) #debug s.typ @@ -804,8 +804,9 @@ proc typeSectionFinalPass(c: PContext, n: PNode) = assert t != nil if t.kind in {tyObject, tyEnum, tyDistinct}: assert s.typ != nil - assignType(s.typ, t) - s.typ.id = t.id # same id + if s.typ.kind != tyAlias: + assignType(s.typ, t) + s.typ.id = t.id # same id checkConstructedType(s.info, s.typ) if s.typ.kind in {tyObject, tyTuple} and not s.typ.n.isNil: checkForMetaFields(s.typ.n) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 9c84996eb..028baa555 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1152,6 +1152,13 @@ proc semProcTypeWithScope(c: PContext, n: PNode, when useEffectSystem: setEffectsForProcType(result, n.sons[1]) closeScope(c) +proc maybeAliasType(c: PContext; typeExpr, prev: PType): PType = + if typeExpr.kind in {tyObject, tyEnum, tyDistinct} and prev != nil: + result = newTypeS(tyAlias, c) + result.rawAddSon typeExpr + result.sym = prev.sym + assignType(prev, result) + proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = result = nil if gCmd == cmdIdeTools: suggestExpr(c, n) @@ -1267,15 +1274,18 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = of mTuple: result = semTuple(c, n, prev) else: result = semGeneric(c, n, s, prev) of nkDotExpr: - var typeExpr = semExpr(c, n) + let typeExpr = semExpr(c, n) if typeExpr.typ.kind != tyTypeDesc: localError(n.info, errTypeExpected) result = errorType(c) else: result = typeExpr.typ.base if result.isMetaType: - var preprocessed = semGenericStmt(c, n) + let preprocessed = semGenericStmt(c, n) result = makeTypeFromExpr(c, preprocessed.copyTree) + else: + let alias = maybeAliasType(c, result, prev) + if alias != nil: result = alias of nkIdent, nkAccQuoted: var s = semTypeIdent(c, n) if s.typ == nil: @@ -1287,16 +1297,23 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = elif prev == nil: result = s.typ else: - assignType(prev, s.typ) - # bugfix: keep the fresh id for aliases to integral types: - if s.typ.kind notin {tyBool, tyChar, tyInt..tyInt64, tyFloat..tyFloat128, - tyUInt..tyUInt64}: - prev.id = s.typ.id - result = prev + let alias = maybeAliasType(c, s.typ, prev) + if alias != nil: + result = alias + else: + assignType(prev, s.typ) + # bugfix: keep the fresh id for aliases to integral types: + if s.typ.kind notin {tyBool, tyChar, tyInt..tyInt64, tyFloat..tyFloat128, + tyUInt..tyUInt64}: + prev.id = s.typ.id + result = prev of nkSym: if n.sym.kind == skType and n.sym.typ != nil: var t = n.sym.typ - if prev == nil: + let alias = maybeAliasType(c, t, prev) + if alias != nil: + result = alias + elif prev == nil: result = t else: assignType(prev, t) diff --git a/compiler/sighashes.nim b/compiler/sighashes.nim index 7b76fe010..178023fcb 100644 --- a/compiler/sighashes.nim +++ b/compiler/sighashes.nim @@ -126,8 +126,6 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) = c &= "\254" return - c &= char(t.kind) - case t.kind of tyGenericInst: var x = t.lastSon @@ -148,9 +146,14 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) = else: c.hashSym(t.sym) return + of tyAlias: + c.hashType t.lastSon, flags + return else: discard + c &= char(t.kind) + case t.kind of tyObject, tyEnum: # Every cyclic type in Nim need to be constructed via some 't.sym', so this @@ -159,7 +162,7 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) = c.hashSym(t.sym) else: lowlevel(t.id) - of tyRef, tyPtr, tyGenericBody, tyAlias: + of tyRef, tyPtr, tyGenericBody: c.hashType t.lastSon, flags of tyUserTypeClass: if t.sym != nil and t.sym.owner != nil: diff --git a/compiler/types.nim b/compiler/types.nim index 7fc0af43e..d5ec2972a 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -398,7 +398,7 @@ proc rangeToStr(n: PNode): string = const typeToStr: array[TTypeKind, string] = ["None", "bool", "Char", "empty", - "Array Constructor [$1]", "nil", "untyped", "typed", "typeDesc", + "Alias", "nil", "untyped", "typed", "typeDesc", "GenericInvocation", "GenericBody", "GenericInst", "GenericParam", "distinct $1", "enum", "ordinal[$1]", "array[$1, $2]", "object", "tuple", "set[$1]", "range[$1]", "ptr ", "ref ", "var ", "seq[$1]", "proc", |