the compiler uses tyAlias internally; tester compiles again
This commit is contained in:
parent
e6c5622aa7
commit
0e1304a3e2
6 changed files with 49 additions and 24 deletions
|
|
@ -106,6 +106,7 @@ proc typeName(typ: PType): Rope =
|
||||||
else: ~"TY"
|
else: ~"TY"
|
||||||
|
|
||||||
proc getTypeName(m: BModule; typ: PType; sig: SigHash): Rope =
|
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 != {}:
|
if typ.sym != nil and {sfImportc, sfExportc} * typ.sym.flags != {}:
|
||||||
result = typ.sym.loc.r
|
result = typ.sym.loc.r
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -190,21 +190,24 @@ proc freshLineInfo(p: BProc; info: TLineInfo): bool =
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
proc genLineDir(p: BProc, t: PNode) =
|
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:
|
if optEmbedOrigSrc in gGlobalOptions:
|
||||||
add(p.s(cpsStmts), ~"//" & t.info.sourceLine & rnl)
|
add(p.s(cpsStmts), ~"//" & info.sourceLine & rnl)
|
||||||
genCLineDir(p.s(cpsStmts), t.info.toFullPath, line)
|
genCLineDir(p.s(cpsStmts), info.toFullPath, line)
|
||||||
if ({optStackTrace, optEndb} * p.options == {optStackTrace, optEndb}) and
|
if ({optStackTrace, optEndb} * p.options == {optStackTrace, optEndb}) and
|
||||||
(p.prc == nil or sfPure notin p.prc.flags):
|
(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",
|
linefmt(p, cpsStmts, "#endb($1, $2);$n",
|
||||||
line.rope, makeCString(toFilename(t.info)))
|
line.rope, makeCString(toFilename(info)))
|
||||||
elif ({optLineTrace, optStackTrace} * p.options ==
|
elif ({optLineTrace, optStackTrace} * p.options ==
|
||||||
{optLineTrace, optStackTrace}) and
|
{optLineTrace, optStackTrace}) and
|
||||||
(p.prc == nil or sfPure notin p.prc.flags) and t.info.fileIndex >= 0:
|
(p.prc == nil or sfPure notin p.prc.flags) and info.fileIndex >= 0:
|
||||||
if freshLineInfo(p, t.info):
|
if freshLineInfo(p, info):
|
||||||
linefmt(p, cpsStmts, "nimln($1, $2);$n",
|
linefmt(p, cpsStmts, "nimln($1, $2);$n",
|
||||||
line.rope, t.info.quotedFilename)
|
line.rope, info.quotedFilename)
|
||||||
|
|
||||||
proc postStmtActions(p: BProc) {.inline.} =
|
proc postStmtActions(p: BProc) {.inline.} =
|
||||||
add(p.s(cpsStmts), p.module.injectStmt)
|
add(p.s(cpsStmts), p.module.injectStmt)
|
||||||
|
|
|
||||||
|
|
@ -745,7 +745,7 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||||
var t = semTypeNode(c, a.sons[2], s.typ)
|
var t = semTypeNode(c, a.sons[2], s.typ)
|
||||||
if s.typ == nil:
|
if s.typ == nil:
|
||||||
s.typ = t
|
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:
|
# this can happen for e.g. tcan_alias_specialised_generic:
|
||||||
assignType(s.typ, t)
|
assignType(s.typ, t)
|
||||||
#debug s.typ
|
#debug s.typ
|
||||||
|
|
@ -804,8 +804,9 @@ proc typeSectionFinalPass(c: PContext, n: PNode) =
|
||||||
assert t != nil
|
assert t != nil
|
||||||
if t.kind in {tyObject, tyEnum, tyDistinct}:
|
if t.kind in {tyObject, tyEnum, tyDistinct}:
|
||||||
assert s.typ != nil
|
assert s.typ != nil
|
||||||
assignType(s.typ, t)
|
if s.typ.kind != tyAlias:
|
||||||
s.typ.id = t.id # same id
|
assignType(s.typ, t)
|
||||||
|
s.typ.id = t.id # same id
|
||||||
checkConstructedType(s.info, s.typ)
|
checkConstructedType(s.info, s.typ)
|
||||||
if s.typ.kind in {tyObject, tyTuple} and not s.typ.n.isNil:
|
if s.typ.kind in {tyObject, tyTuple} and not s.typ.n.isNil:
|
||||||
checkForMetaFields(s.typ.n)
|
checkForMetaFields(s.typ.n)
|
||||||
|
|
|
||||||
|
|
@ -1152,6 +1152,13 @@ proc semProcTypeWithScope(c: PContext, n: PNode,
|
||||||
when useEffectSystem: setEffectsForProcType(result, n.sons[1])
|
when useEffectSystem: setEffectsForProcType(result, n.sons[1])
|
||||||
closeScope(c)
|
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 =
|
proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
result = nil
|
result = nil
|
||||||
if gCmd == cmdIdeTools: suggestExpr(c, n)
|
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)
|
of mTuple: result = semTuple(c, n, prev)
|
||||||
else: result = semGeneric(c, n, s, prev)
|
else: result = semGeneric(c, n, s, prev)
|
||||||
of nkDotExpr:
|
of nkDotExpr:
|
||||||
var typeExpr = semExpr(c, n)
|
let typeExpr = semExpr(c, n)
|
||||||
if typeExpr.typ.kind != tyTypeDesc:
|
if typeExpr.typ.kind != tyTypeDesc:
|
||||||
localError(n.info, errTypeExpected)
|
localError(n.info, errTypeExpected)
|
||||||
result = errorType(c)
|
result = errorType(c)
|
||||||
else:
|
else:
|
||||||
result = typeExpr.typ.base
|
result = typeExpr.typ.base
|
||||||
if result.isMetaType:
|
if result.isMetaType:
|
||||||
var preprocessed = semGenericStmt(c, n)
|
let preprocessed = semGenericStmt(c, n)
|
||||||
result = makeTypeFromExpr(c, preprocessed.copyTree)
|
result = makeTypeFromExpr(c, preprocessed.copyTree)
|
||||||
|
else:
|
||||||
|
let alias = maybeAliasType(c, result, prev)
|
||||||
|
if alias != nil: result = alias
|
||||||
of nkIdent, nkAccQuoted:
|
of nkIdent, nkAccQuoted:
|
||||||
var s = semTypeIdent(c, n)
|
var s = semTypeIdent(c, n)
|
||||||
if s.typ == nil:
|
if s.typ == nil:
|
||||||
|
|
@ -1287,16 +1297,23 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
elif prev == nil:
|
elif prev == nil:
|
||||||
result = s.typ
|
result = s.typ
|
||||||
else:
|
else:
|
||||||
assignType(prev, s.typ)
|
let alias = maybeAliasType(c, s.typ, prev)
|
||||||
# bugfix: keep the fresh id for aliases to integral types:
|
if alias != nil:
|
||||||
if s.typ.kind notin {tyBool, tyChar, tyInt..tyInt64, tyFloat..tyFloat128,
|
result = alias
|
||||||
tyUInt..tyUInt64}:
|
else:
|
||||||
prev.id = s.typ.id
|
assignType(prev, s.typ)
|
||||||
result = prev
|
# 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:
|
of nkSym:
|
||||||
if n.sym.kind == skType and n.sym.typ != nil:
|
if n.sym.kind == skType and n.sym.typ != nil:
|
||||||
var t = n.sym.typ
|
var t = n.sym.typ
|
||||||
if prev == nil:
|
let alias = maybeAliasType(c, t, prev)
|
||||||
|
if alias != nil:
|
||||||
|
result = alias
|
||||||
|
elif prev == nil:
|
||||||
result = t
|
result = t
|
||||||
else:
|
else:
|
||||||
assignType(prev, t)
|
assignType(prev, t)
|
||||||
|
|
|
||||||
|
|
@ -126,8 +126,6 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
|
||||||
c &= "\254"
|
c &= "\254"
|
||||||
return
|
return
|
||||||
|
|
||||||
c &= char(t.kind)
|
|
||||||
|
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyGenericInst:
|
of tyGenericInst:
|
||||||
var x = t.lastSon
|
var x = t.lastSon
|
||||||
|
|
@ -148,9 +146,14 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
|
||||||
else:
|
else:
|
||||||
c.hashSym(t.sym)
|
c.hashSym(t.sym)
|
||||||
return
|
return
|
||||||
|
of tyAlias:
|
||||||
|
c.hashType t.lastSon, flags
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
c &= char(t.kind)
|
||||||
|
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyObject, tyEnum:
|
of tyObject, tyEnum:
|
||||||
# Every cyclic type in Nim need to be constructed via some 't.sym', so this
|
# 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)
|
c.hashSym(t.sym)
|
||||||
else:
|
else:
|
||||||
lowlevel(t.id)
|
lowlevel(t.id)
|
||||||
of tyRef, tyPtr, tyGenericBody, tyAlias:
|
of tyRef, tyPtr, tyGenericBody:
|
||||||
c.hashType t.lastSon, flags
|
c.hashType t.lastSon, flags
|
||||||
of tyUserTypeClass:
|
of tyUserTypeClass:
|
||||||
if t.sym != nil and t.sym.owner != nil:
|
if t.sym != nil and t.sym.owner != nil:
|
||||||
|
|
|
||||||
|
|
@ -398,7 +398,7 @@ proc rangeToStr(n: PNode): string =
|
||||||
|
|
||||||
const
|
const
|
||||||
typeToStr: array[TTypeKind, string] = ["None", "bool", "Char", "empty",
|
typeToStr: array[TTypeKind, string] = ["None", "bool", "Char", "empty",
|
||||||
"Array Constructor [$1]", "nil", "untyped", "typed", "typeDesc",
|
"Alias", "nil", "untyped", "typed", "typeDesc",
|
||||||
"GenericInvocation", "GenericBody", "GenericInst", "GenericParam",
|
"GenericInvocation", "GenericBody", "GenericInst", "GenericParam",
|
||||||
"distinct $1", "enum", "ordinal[$1]", "array[$1, $2]", "object", "tuple",
|
"distinct $1", "enum", "ordinal[$1]", "array[$1, $2]", "object", "tuple",
|
||||||
"set[$1]", "range[$1]", "ptr ", "ref ", "var ", "seq[$1]", "proc",
|
"set[$1]", "range[$1]", "ptr ", "ref ", "var ", "seq[$1]", "proc",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue