language cleanup: the .unchecked pragma is dead

This commit is contained in:
Araq 2018-11-05 14:53:04 +01:00 • committed by Andreas Rumpf
commit e71410d74e
8 changed files with 20 additions and 26 deletions

View file

@ -565,7 +565,6 @@ const
routineKinds* = {skProc, skFunc, skMethod, skIterator, routineKinds* = {skProc, skFunc, skMethod, skIterator,
skConverter, skMacro, skTemplate} skConverter, skMacro, skTemplate}
tfIncompleteStruct* = tfVarargs tfIncompleteStruct* = tfVarargs
tfUncheckedArray* = tfVarargs
tfUnion* = tfNoSideEffect tfUnion* = tfNoSideEffect
tfGcSafe* = tfThread tfGcSafe* = tfThread
tfObjHasKids* = tfEnumHasHoles tfObjHasKids* = tfEnumHasHoles

View file

@ -872,7 +872,7 @@ proc genArrayElem(p: BProc, n, x, y: PNode, d: var TLoc) =
var ty = skipTypes(a.t, abstractVarRange + abstractPtrs + tyUserTypeClasses) var ty = skipTypes(a.t, abstractVarRange + abstractPtrs + tyUserTypeClasses)
var first = intLiteral(firstOrd(p.config, ty)) var first = intLiteral(firstOrd(p.config, ty))
# emit range check: # 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): if not isConstExpr(y):
# semantic pass has already checked for const index expressions # semantic pass has already checked for const index expressions
if firstOrd(p.config, ty) == 0: if firstOrd(p.config, ty) == 0:
@ -909,11 +909,10 @@ proc genBoundsCheck(p: BProc; arr, a, b: TLoc) =
rdLoc(a), rdLoc(b), rdLoc(arr)) rdLoc(a), rdLoc(b), rdLoc(arr))
of tyArray: of tyArray:
let first = intLiteral(firstOrd(p.config, ty)) let first = intLiteral(firstOrd(p.config, ty))
if tfUncheckedArray notin ty.flags: linefmt(p, cpsStmts,
linefmt(p, cpsStmts, "if ($2-$1 != -1 && " &
"if ($2-$1 != -1 && " & "($2-$1 < -1 || $1 < $3 || $1 > $4 || $2 < $3 || $2 > $4)) #raiseIndexError();$n",
"($2-$1 < -1 || $1 < $3 || $1 > $4 || $2 < $3 || $2 > $4)) #raiseIndexError();$n", rdCharLoc(a), rdCharLoc(b), first, intLiteral(lastOrd(p.config, ty)))
rdCharLoc(a), rdCharLoc(b), first, intLiteral(lastOrd(p.config, ty)))
of tySequence, tyString: of tySequence, tyString:
linefmt(p, cpsStmts, linefmt(p, cpsStmts,
"if ($2-$1 != -1 && " & "if ($2-$1 != -1 && " &

View file

@ -492,7 +492,7 @@ proc genRecordFieldsAux(m: BModule, n: PNode,
# with heavily templatized C++ code: # with heavily templatized C++ code:
if not isImportedCppType(rectype): if not isImportedCppType(rectype):
let fieldType = field.loc.lode.typ.skipTypes(abstractInst) 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", addf(result, "$1 $2[SEQ_DECL_SIZE];$n",
[getTypeDescAux(m, fieldType.elemType, check), sname]) [getTypeDescAux(m, fieldType.elemType, check), sname])
elif fieldType.kind == tySequence and m.config.selectedGC != gcDestructors: elif fieldType.kind == tySequence and m.config.selectedGC != gcDestructors:

View file

@ -1019,8 +1019,10 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
else: incl(sym.typ.flags, tfIncompleteStruct) else: incl(sym.typ.flags, tfIncompleteStruct)
of wUnchecked: of wUnchecked:
noVal(c, it) noVal(c, it)
if sym.typ == nil: invalidPragma(c, it) if sym.typ == nil or sym.typ.kind notin {tyArray, tyUncheckedArray}:
else: incl(sym.typ.flags, tfUncheckedArray) invalidPragma(c, it)
else:
sym.typ.kind = tyUncheckedArray
of wUnion: of wUnion:
noVal(c, it) noVal(c, it)
if sym.typ == nil: invalidPragma(c, it) if sym.typ == nil: invalidPragma(c, it)

View file

@ -200,7 +200,7 @@ proc liftBodyAux(c: var TLiftCtx; t: PType; body, x, y: PNode) =
tyPtr, tyRef, tyOpt, tyUncheckedArray: tyPtr, tyRef, tyOpt, tyUncheckedArray:
defaultOp(c, t, body, x, y) defaultOp(c, t, body, x, y)
of tyArray: of tyArray:
if {tfHasAsgn, tfUncheckedArray} * t.flags == {tfHasAsgn}: if tfHasAsgn in t.flags:
let i = declareCounter(c, body, firstOrd(c.c.config, t)) let i = declareCounter(c, body, firstOrd(c.c.config, t))
let whileLoop = genWhileLoop(c, i, x) let whileLoop = genWhileLoop(c, i, x)
let elemType = t.lastSon let elemType = t.lastSon

View file

@ -413,15 +413,14 @@ proc getAppType(n: PNode; g: ModuleGraph): PNode =
result = newStrNodeT("console", n, g) result = newStrNodeT("console", n, g)
proc rangeCheck(n: PNode, value: BiggestInt; g: ModuleGraph) = proc rangeCheck(n: PNode, value: BiggestInt; g: ModuleGraph) =
if tfUncheckedArray notin n.typ.flags: var err = false
var err = false if n.typ.skipTypes({tyRange}).kind in {tyUInt..tyUInt64}:
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)
err = value <% firstOrd(g.config, n.typ) or value >% lastOrd(g.config, n.typ, fixedUnsigned=true) else:
else: err = value < firstOrd(g.config, n.typ) or value > lastOrd(g.config, n.typ)
err = value < firstOrd(g.config, n.typ) or value > lastOrd(g.config, n.typ) if err:
if err: localError(g.config, n.info, "cannot convert " & $value &
localError(g.config, n.info, "cannot convert " & $value & " to " & typeToString(n.typ))
" to " & typeToString(n.typ))
proc foldConv(n, a: PNode; g: ModuleGraph; check = false): PNode = proc foldConv(n, a: PNode; g: ModuleGraph; check = false): PNode =
let dstTyp = skipTypes(n.typ, abstractRange) let dstTyp = skipTypes(n.typ, abstractRange)

View file

@ -30,11 +30,6 @@ proc checkConstructedType*(conf: ConfigRef; info: TLineInfo, typ: PType) =
localError(conf, info, "type 'var var' is not allowed") localError(conf, info, "type 'var var' is not allowed")
elif computeSize(conf, t) == szIllegalRecursion: elif computeSize(conf, t) == szIllegalRecursion:
localError(conf, info, "illegal recursion in type '" & typeToString(t) & "'") 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: when false:
if t.kind == tyObject and t.sons[0] != nil: if t.kind == tyObject and t.sons[0] != nil:
if t.sons[0].kind != tyObject or tfFinal in t.sons[0].flags: if t.sons[0].kind != tyObject or tfFinal in t.sons[0].flags:

View file

@ -400,7 +400,7 @@ block troofregression:
block tunchecked: block tunchecked:
{.boundchecks: on.} {.boundchecks: on.}
type Unchecked {.unchecked.} = array[0, char] type Unchecked = UncheckedArray[char]
var x = cast[ptr Unchecked](alloc(100)) var x = cast[ptr Unchecked](alloc(100))
x[5] = 'x' x[5] = 'x'