the compiler uses tyAlias internally; tester compiles again

This commit is contained in:
Araq
2016-11-16 00:13:45 +01:00
parent e6c5622aa7
commit 0e1304a3e2
6 changed files with 49 additions and 24 deletions

View File

@@ -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:

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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:

View File

@@ -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",