diff options
-rw-r--r-- | compiler/ast.nim | 1 | ||||
-rw-r--r-- | compiler/ccgexprs.nim | 11 | ||||
-rw-r--r-- | compiler/ccgtypes.nim | 2 | ||||
-rw-r--r-- | compiler/pragmas.nim | 6 | ||||
-rw-r--r-- | compiler/semasgn.nim | 2 | ||||
-rw-r--r-- | compiler/semfold.nim | 17 | ||||
-rw-r--r-- | compiler/semtypinst.nim | 5 | ||||
-rw-r--r-- | tests/array/tarray.nim | 2 |
8 files changed, 20 insertions, 26 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 5fc8e5978..bc54367f6 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -565,7 +565,6 @@ const routineKinds* = {skProc, skFunc, skMethod, skIterator, skConverter, skMacro, skTemplate} tfIncompleteStruct* = tfVarargs - tfUncheckedArray* = tfVarargs tfUnion* = tfNoSideEffect tfGcSafe* = tfThread tfObjHasKids* = tfEnumHasHoles diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 6678a07ca..e13af14b0 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -872,7 +872,7 @@ proc genArrayElem(p: BProc, n, x, y: PNode, d: var TLoc) = var ty = skipTypes(a.t, abstractVarRange + abstractPtrs + tyUserTypeClasses) var first = intLiteral(firstOrd(p.config, ty)) # emit range check: - if optBoundsCheck in p.options and tfUncheckedArray notin ty.flags: + if optBoundsCheck in p.options and ty.kind != tyUncheckedArray: if not isConstExpr(y): # semantic pass has already checked for const index expressions if firstOrd(p.config, ty) == 0: @@ -909,11 +909,10 @@ proc genBoundsCheck(p: BProc; arr, a, b: TLoc) = rdLoc(a), rdLoc(b), rdLoc(arr)) of tyArray: let first = intLiteral(firstOrd(p.config, ty)) - if tfUncheckedArray notin ty.flags: - linefmt(p, cpsStmts, - "if ($2-$1 != -1 && " & - "($2-$1 < -1 || $1 < $3 || $1 > $4 || $2 < $3 || $2 > $4)) #raiseIndexError();$n", - rdCharLoc(a), rdCharLoc(b), first, intLiteral(lastOrd(p.config, ty))) + linefmt(p, cpsStmts, + "if ($2-$1 != -1 && " & + "($2-$1 < -1 || $1 < $3 || $1 > $4 || $2 < $3 || $2 > $4)) #raiseIndexError();$n", + rdCharLoc(a), rdCharLoc(b), first, intLiteral(lastOrd(p.config, ty))) of tySequence, tyString: linefmt(p, cpsStmts, "if ($2-$1 != -1 && " & diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 75566fb38..386d7f60c 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -492,7 +492,7 @@ proc genRecordFieldsAux(m: BModule, n: PNode, # with heavily templatized C++ code: if not isImportedCppType(rectype): let fieldType = field.loc.lode.typ.skipTypes(abstractInst) - if fieldType.kind == tyArray and tfUncheckedArray in fieldType.flags: + if fieldType.kind == tyUncheckedArray: addf(result, "$1 $2[SEQ_DECL_SIZE];$n", [getTypeDescAux(m, fieldType.elemType, check), sname]) elif fieldType.kind == tySequence and m.config.selectedGC != gcDestructors: diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 08e3c34d4..1c07a3309 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -1019,8 +1019,10 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, else: incl(sym.typ.flags, tfIncompleteStruct) of wUnchecked: noVal(c, it) - if sym.typ == nil: invalidPragma(c, it) - else: incl(sym.typ.flags, tfUncheckedArray) + if sym.typ == nil or sym.typ.kind notin {tyArray, tyUncheckedArray}: + invalidPragma(c, it) + else: + sym.typ.kind = tyUncheckedArray of wUnion: noVal(c, it) if sym.typ == nil: invalidPragma(c, it) diff --git a/compiler/semasgn.nim b/compiler/semasgn.nim index 7d6ae70de..272b2ec6c 100644 --- a/compiler/semasgn.nim +++ b/compiler/semasgn.nim @@ -200,7 +200,7 @@ proc liftBodyAux(c: var TLiftCtx; t: PType; body, x, y: PNode) = tyPtr, tyRef, tyOpt, tyUncheckedArray: defaultOp(c, t, body, x, y) of tyArray: - if {tfHasAsgn, tfUncheckedArray} * t.flags == {tfHasAsgn}: + if tfHasAsgn in t.flags: let i = declareCounter(c, body, firstOrd(c.c.config, t)) let whileLoop = genWhileLoop(c, i, x) let elemType = t.lastSon diff --git a/compiler/semfold.nim b/compiler/semfold.nim index 5565e8ed9..d9bec5e41 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -413,15 +413,14 @@ proc getAppType(n: PNode; g: ModuleGraph): PNode = result = newStrNodeT("console", n, g) proc rangeCheck(n: PNode, value: BiggestInt; g: ModuleGraph) = - if tfUncheckedArray notin n.typ.flags: - var err = false - if n.typ.skipTypes({tyRange}).kind in {tyUInt..tyUInt64}: - err = value <% firstOrd(g.config, n.typ) or value >% lastOrd(g.config, n.typ, fixedUnsigned=true) - else: - err = value < firstOrd(g.config, n.typ) or value > lastOrd(g.config, n.typ) - if err: - localError(g.config, n.info, "cannot convert " & $value & - " to " & typeToString(n.typ)) + var err = false + if n.typ.skipTypes({tyRange}).kind in {tyUInt..tyUInt64}: + err = value <% firstOrd(g.config, n.typ) or value >% lastOrd(g.config, n.typ, fixedUnsigned=true) + else: + err = value < firstOrd(g.config, n.typ) or value > lastOrd(g.config, n.typ) + if err: + localError(g.config, n.info, "cannot convert " & $value & + " to " & typeToString(n.typ)) proc foldConv(n, a: PNode; g: ModuleGraph; check = false): PNode = let dstTyp = skipTypes(n.typ, abstractRange) diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index be6ffc586..b05fb37ae 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -30,11 +30,6 @@ proc checkConstructedType*(conf: ConfigRef; info: TLineInfo, typ: PType) = localError(conf, info, "type 'var var' is not allowed") elif computeSize(conf, t) == szIllegalRecursion: localError(conf, info, "illegal recursion in type '" & typeToString(t) & "'") - - t = typ.skipTypes({tyGenericInst}) - if t.kind == tyArray and tfUncheckedArray in t.flags: - t[0].flags.incl tfUncheckedArray # mark range of unchecked array also unchecked - when false: if t.kind == tyObject and t.sons[0] != nil: if t.sons[0].kind != tyObject or tfFinal in t.sons[0].flags: diff --git a/tests/array/tarray.nim b/tests/array/tarray.nim index 4a31a4d6d..8551d324c 100644 --- a/tests/array/tarray.nim +++ b/tests/array/tarray.nim @@ -400,7 +400,7 @@ block troofregression: block tunchecked: {.boundchecks: on.} - type Unchecked {.unchecked.} = array[0, char] + type Unchecked = UncheckedArray[char] var x = cast[ptr Unchecked](alloc(100)) x[5] = 'x' |