mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-25 08:01:41 +00:00
make explicit
This commit is contained in:
@@ -268,7 +268,6 @@ type
|
||||
tyVoid
|
||||
# now different from tyEmpty, hurray!
|
||||
tyIterable
|
||||
tyStub
|
||||
|
||||
static:
|
||||
# remind us when TTypeKind stops to fit in a single 64-bit word
|
||||
@@ -693,10 +692,15 @@ type
|
||||
|
||||
PScope* = ref TScope
|
||||
|
||||
ItemState* = enum
|
||||
Complete # completely in memory
|
||||
Partial # partially in memory
|
||||
|
||||
PLib* = ref TLib
|
||||
TSym* {.acyclic.} = object # Keep in sync with PackedSym
|
||||
itemId*: ItemId
|
||||
# proc and type instantiations are cached in the generic symbol
|
||||
state*: ItemState
|
||||
case kind*: TSymKind
|
||||
of routineKinds:
|
||||
#procInstCache*: seq[PInstantiation]
|
||||
@@ -771,6 +775,7 @@ type
|
||||
# Keep in sync with PackedType
|
||||
itemId*: ItemId
|
||||
kind*: TTypeKind # kind of type
|
||||
state*: ItemState
|
||||
callConv*: TCallingConvention # for procs
|
||||
flags*: TTypeFlags # flags of the type
|
||||
sons: TTypeSeq # base types, etc.
|
||||
|
||||
@@ -192,7 +192,9 @@ proc writeType(w: var Writer; dest: var TokenBuf; typ: PType)
|
||||
proc writeSym(w: var Writer; dest: var TokenBuf; sym: PSym)
|
||||
|
||||
proc typeToNifSym(w: var Writer; typ: PType): string =
|
||||
result = "`t."
|
||||
result = "`t"
|
||||
result.addInt ord(typ.kind)
|
||||
result.add '.'
|
||||
result.addInt typ.uniqueId.item
|
||||
result.add '.'
|
||||
result.add modname(w.moduleToNifSuffix, typ.uniqueId.module, w.infos.config)
|
||||
@@ -207,7 +209,7 @@ proc writeTypeDef(w: var Writer; dest: var TokenBuf; typ: PType) =
|
||||
dest.buildTree tdefTag:
|
||||
dest.addSymDef pool.syms.getOrIncl(w.typeToNifSym(typ)), NoLineInfo
|
||||
|
||||
dest.addIdent toNifTag(typ.kind)
|
||||
#dest.addIdent toNifTag(typ.kind)
|
||||
writeFlags(dest, typ.flags)
|
||||
dest.addIdent toNifTag(typ.callConv)
|
||||
dest.addIntLit typ.size
|
||||
@@ -581,8 +583,13 @@ proc loadNode(c: var DecodeContext; n: var Cursor): PNode
|
||||
|
||||
proc loadTypeStub(c: var DecodeContext; t: SymId): PType =
|
||||
let name = pool.syms[t]
|
||||
assert name.startsWith("`t.")
|
||||
var i = len("`t.")
|
||||
assert name.startsWith("`t")
|
||||
var i = len("`t")
|
||||
var k = 0
|
||||
while i < name.len and name[i] in {'0'..'9'}:
|
||||
k = k * 10 + name[i].ord - ord('0')
|
||||
inc i
|
||||
if i < name.len and name[i] == '.': inc i
|
||||
var itemId = 0'i32
|
||||
while i < name.len and name[i] in {'0'..'9'}:
|
||||
itemId = itemId * 10'i32 + int32(name[i].ord - ord('0'))
|
||||
@@ -593,7 +600,7 @@ proc loadTypeStub(c: var DecodeContext; t: SymId): PType =
|
||||
result = c.types.getOrDefault(id)[0]
|
||||
if result == nil:
|
||||
let offs = c.getOffset(id.module, name)
|
||||
result = PType(itemId: id, uniqueId: id, kind: tyStub)
|
||||
result = PType(itemId: id, uniqueId: id, kind: TTypeKind(k), state: Partial)
|
||||
c.types[id] = (result, offs)
|
||||
|
||||
proc loadTypeStub(c: var DecodeContext; n: var Cursor): PType =
|
||||
@@ -622,7 +629,7 @@ proc loadSymStub(c: var DecodeContext; t: SymId): PSym =
|
||||
result = c.syms.getOrDefault(id)[0]
|
||||
if result == nil:
|
||||
let offs = c.getOffset(module, symAsStr)
|
||||
result = PSym(itemId: id, kind: skStub, name: c.cache.getIdent(sn.name), disamb: sn.count.int32)
|
||||
result = PSym(itemId: id, kind: skStub, name: c.cache.getIdent(sn.name), disamb: sn.count.int32, state: Partial)
|
||||
c.syms[id] = (result, offs)
|
||||
|
||||
proc loadSymStub(c: var DecodeContext; n: var Cursor): PSym =
|
||||
@@ -640,8 +647,8 @@ proc loadSymStub(c: var DecodeContext; n: var Cursor): PSym =
|
||||
else:
|
||||
raiseAssert "sym expected but got " & $n.kind
|
||||
|
||||
proc isStub*(t: PType): bool {.inline.} = t.kind == tyStub
|
||||
proc isStub*(s: PSym): bool {.inline.} = s.kind == skStub
|
||||
proc isStub*(t: PType): bool {.inline.} = t.state == Partial
|
||||
proc isStub*(s: PSym): bool {.inline.} = s.state == Partial
|
||||
|
||||
proc loadAtom[T](t: typedesc[set[T]]; n: var Cursor): set[T] =
|
||||
if n.kind == DotToken:
|
||||
@@ -681,7 +688,7 @@ proc loadLoc(c: var DecodeContext; n: var Cursor; loc: var TLoc) =
|
||||
loadField loc.snippet
|
||||
|
||||
proc loadType*(c: var DecodeContext; t: PType) =
|
||||
if t.kind != tyStub: return
|
||||
if t.state != Partial: return
|
||||
var buf = createTokenBuf(30)
|
||||
var n = cursorFromIndexEntry(c, t.itemId.module, c.types[t.itemId][1], buf)
|
||||
|
||||
@@ -692,7 +699,7 @@ proc loadType*(c: var DecodeContext; t: PType) =
|
||||
expect n, SymbolDef
|
||||
# ignore the type's name, we have already used it to create this PType's itemId!
|
||||
inc n
|
||||
loadField t.kind
|
||||
#loadField t.kind
|
||||
loadField t.flags
|
||||
loadField t.callConv
|
||||
loadField t.size
|
||||
|
||||
@@ -112,7 +112,7 @@ proc specializeResetT(p: BProc, accessor: Rope, typ: PType) =
|
||||
tyGenericParam, tyOrdinal, tyOpenArray, tyForward, tyVarargs,
|
||||
tyUncheckedArray, tyError, tyBuiltInTypeClass, tyUserTypeClass,
|
||||
tyUserTypeClassInst, tyCompositeTypeClass, tyAnd, tyOr, tyNot,
|
||||
tyAnything, tyStatic, tyFromExpr, tyConcept, tyVoid, tyIterable, tyStub:
|
||||
tyAnything, tyStatic, tyFromExpr, tyConcept, tyVoid, tyIterable:
|
||||
discard
|
||||
|
||||
proc specializeReset(p: BProc, a: TLoc) =
|
||||
|
||||
@@ -124,7 +124,7 @@ proc expandDefault(t: PType; info: TLineInfo): PNode =
|
||||
result = newZero(t, info, nkBracket)
|
||||
of tyString:
|
||||
result = newZero(t, info, nkStrLit)
|
||||
of tyNone, tyEmpty, tyUntyped, tyTyped, tyTypeDesc, tyStub,
|
||||
of tyNone, tyEmpty, tyUntyped, tyTyped, tyTypeDesc,
|
||||
tyNil, tyGenericInvocation, tyError, tyBuiltInTypeClass,
|
||||
tyUserTypeClass, tyUserTypeClassInst, tyCompositeTypeClass,
|
||||
tyAnd, tyOr, tyNot, tyAnything, tyConcept, tyIterable, tyForward:
|
||||
|
||||
@@ -469,7 +469,6 @@ proc toNifTag*(s: TTypeKind): string =
|
||||
of tyConcept: "concept"
|
||||
of tyVoid: "void"
|
||||
of tyIterable: "iterable"
|
||||
of tyStub: "stub"
|
||||
|
||||
|
||||
proc parse*(t: typedesc[TTypeKind]; s: string): TTypeKind =
|
||||
@@ -539,7 +538,6 @@ proc parse*(t: typedesc[TTypeKind]; s: string): TTypeKind =
|
||||
of "concept": tyConcept
|
||||
of "void": tyVoid
|
||||
of "iterable": tyIterable
|
||||
of "stub": tyStub
|
||||
else: tyNone
|
||||
|
||||
|
||||
|
||||
@@ -219,7 +219,7 @@ proc mapType(typ: PType): TJSTypeKind =
|
||||
else: result = etyNone
|
||||
of tyProc: result = etyProc
|
||||
of tyCstring: result = etyString
|
||||
of tyConcept, tyIterable, tyStub:
|
||||
of tyConcept, tyIterable:
|
||||
raiseAssert "unreachable"
|
||||
|
||||
proc mapType(p: PProc; typ: PType): TJSTypeKind =
|
||||
|
||||
@@ -972,7 +972,7 @@ proc ownedClosureOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||
|
||||
proc fillBody(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||
case t.kind
|
||||
of tyNone, tyEmpty, tyVoid, tyStub: discard
|
||||
of tyNone, tyEmpty, tyVoid: discard
|
||||
of tyPointer, tySet, tyBool, tyChar, tyEnum, tyInt..tyUInt64, tyCstring,
|
||||
tyPtr, tyUncheckedArray, tyVar, tyLent:
|
||||
defaultOp(c, t, body, x, y)
|
||||
|
||||
@@ -666,7 +666,6 @@ proc toNifTag(s: TTypeKind): string =
|
||||
of tyConcept: "concept"
|
||||
of tyVoid: "void"
|
||||
of tyIterable: "iterable"
|
||||
of tyStub: "stub"
|
||||
|
||||
proc atom(t: PType; c: var TranslationContext) =
|
||||
c.b.withTree toNifTag(t.kind):
|
||||
@@ -925,7 +924,7 @@ proc toNifType(t: PType; parent: PNode; c: var TranslationContext) =
|
||||
atom t, c, "err"
|
||||
of tyCompositeTypeClass: toNifType t.last, parent, c
|
||||
of tyInferred: toNifType t.skipModifier, parent, c
|
||||
of tyAnything, tyStub: atom t, c
|
||||
of tyAnything: atom t, c
|
||||
of tyStatic:
|
||||
c.typeHead t:
|
||||
if t.hasElementType:
|
||||
|
||||
@@ -201,7 +201,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
|
||||
result = typeAllowedNode(marker, t.n, kind, c, flags)
|
||||
of tyEmpty:
|
||||
if kind in {skVar, skLet}: result = t
|
||||
of tyError, tyStub:
|
||||
of tyError:
|
||||
# for now same as error node; we say it's a valid type as it should
|
||||
# prevent cascading errors:
|
||||
result = nil
|
||||
|
||||
@@ -491,7 +491,7 @@ const
|
||||
"BuiltInTypeClass", "UserTypeClass",
|
||||
"UserTypeClassInst", "CompositeTypeClass", "inferred",
|
||||
"and", "or", "not", "any", "static", "TypeFromExpr", "concept", # xxx bugfix
|
||||
"void", "iterable", "stub"]
|
||||
"void", "iterable"]
|
||||
|
||||
const preferToResolveSymbols = {preferName, preferTypeName, preferModuleInfo,
|
||||
preferGenericArg, preferResolved, preferMixed, preferInlayHint, preferInferredEffects}
|
||||
@@ -1344,8 +1344,6 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
|
||||
result = a.id == b.id and sameFlags(a, b)
|
||||
of tyError:
|
||||
result = b.kind == tyError
|
||||
of tyStub:
|
||||
result = false
|
||||
of tyTuple:
|
||||
withoutShallowFlags:
|
||||
cycleCheck()
|
||||
|
||||
@@ -97,7 +97,7 @@ proc mapTypeToAstX(cache: IdentCache; t: PType; info: TLineInfo;
|
||||
return atomicType(t.sym)
|
||||
|
||||
case t.kind
|
||||
of tyNone, tyStub: result = atomicType("none", mNone)
|
||||
of tyNone: result = atomicType("none", mNone)
|
||||
of tyBool: result = atomicType("bool", mBool)
|
||||
of tyChar: result = atomicType("char", mChar)
|
||||
of tyNil: result = atomicType("nil", mNil)
|
||||
|
||||
Reference in New Issue
Block a user