Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove DrNim #130

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/modulegraphs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,15 @@ proc registerModule*(g: ModuleGraph; m: PSym) =

g.ifaces[m.position] = Iface(module: m, converters: @[], patterns: @[],
uniqueName: rope(uniqueModuleName(g.config, FileIndex(m.position))))

initStrTables(g, m)

proc registerModuleById*(g: ModuleGraph; m: FileIndex) =
registerModule(g, g.packed[int m].module)

proc initOperators*(g: ModuleGraph): Operators =
# These are safe for IC.
# Public because it's used by DrNim.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when DrNim is removed that means this can become private again?


result.opLe = createMagic(g, "<=", mLeI)
result.opLt = createMagic(g, "<", mLtI)
result.opAnd = createMagic(g, "and", mAnd)
Expand Down
78 changes: 17 additions & 61 deletions compiler/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const
wAsmNoStackFrame, wDiscardable, wNoInit, wCodegenDecl,
wGensym, wInject, wRaises, wEffectsOf, wTags, wLocks, wDelegator, wGcSafe,
wConstructor, wLiftLocals, wStackTrace, wLineTrace, wNoDestroy,
wRequires, wEnsures, wEnforceNoRaises}
wEnforceNoRaises}
converterPragmas* = procPragmas
methodPragmas* = procPragmas+{wBase}-{wImportCpp}
templatePragmas* = {wDeprecated, wError, wGensym, wInject, wDirty,
Expand All @@ -42,7 +42,7 @@ const
iteratorPragmas* = declPragmas + {FirstCallConv..LastCallConv, wNoSideEffect, wSideEffect,
wMagic, wBorrow,
wDiscardable, wGensym, wInject, wRaises, wEffectsOf,
wTags, wLocks, wGcSafe, wRequires, wEnsures}
wTags, wLocks, wGcSafe}
exprPragmas* = {wLine, wLocks, wNoRewrite, wGcSafe, wNoSideEffect}
stmtPragmas* = {wChecks, wObjChecks, wFieldChecks, wRangeChecks,
wBoundChecks, wOverflowChecks, wNilChecks, wStaticBoundchecks,
Expand All @@ -55,11 +55,11 @@ const
wDeprecated,
wFloatChecks, wInfChecks, wNanChecks, wPragma, wEmit, wUnroll,
wLinearScanEnd, wPatterns, wTrMacros, wEffects, wNoForward, wReorder, wComputedGoto,
wExperimental, wThis, wUsed, wInvariant, wAssume, wAssert}
wExperimental, wThis, wUsed}
lambdaPragmas* = {FirstCallConv..LastCallConv,
wNoSideEffect, wSideEffect, wNoreturn, wNosinks, wDynlib, wHeader,
wThread, wAsmNoStackFrame,
wRaises, wLocks, wTags, wRequires, wEnsures, wEffectsOf,
wRaises, wLocks, wTags, wEffectsOf,
wGcSafe, wCodegenDecl, wNoInit, wCompileTime}
typePragmas* = declPragmas + {wMagic, wAcyclic,
wPure, wHeader, wCompilerProc, wCore, wFinal, wSize, wShallow,
Expand All @@ -79,8 +79,7 @@ const
paramPragmas* = {wNoalias, wInject, wGensym}
letPragmas* = varPragmas
procTypePragmas* = {FirstCallConv..LastCallConv, wVarargs, wNoSideEffect,
wThread, wRaises, wEffectsOf, wLocks, wTags, wGcSafe,
wRequires, wEnsures}
wThread, wRaises, wEffectsOf, wLocks, wTags, wGcSafe}
forVarPragmas* = {wInject, wGensym}
allRoutinePragmas* = methodPragmas + iteratorPragmas + lambdaPragmas
enumFieldPragmas* = {wDeprecated}
Expand Down Expand Up @@ -118,45 +117,6 @@ proc newIllegalCustomPragmaNode*(c: PContext; n: PNode, s: PSym): PNode =
## create an error node (`nkError`) for an illegal custom pragma error
newError(n, IllegalCustomPragma, newSymNode(s))

proc pragmaProposition(c: PContext, n: PNode): PNode =
## drnim - `ensures` pragma, must be a callable with single arg predicate,
## producing either:
## 1. mutated `n` with the the proposition (2nd child) semantically checked
## analysed
## 2. nkError node over `n`, when a callable unary proposition isn't provided
if n.kind notin nkPragmaCallKinds or n.len != 2:
result = newError(n, "proposition expected")
else:
n[1] = c.semExpr(c, n[1])

proc pragmaEnsures(c: PContext, n: PNode): PNode =
## drnim - `ensures` pragma, must be a callable with single arg predicate,
## producing either:
## 1. mutated `n` with the the proposition (2nd child) semantically checked
## analysed, and if the current owner is a routineKind adds a `result`
## symbol.
## 2. nkError node over `n`, when a callable unary proposition isn't provided
##
## xxx: 1. the implementation is unclear, we create a `result` symbol for
## routines, adding it to the a sub-scope with the routine as owner, but
## won't that potentially create a duplicate `result` symbol? or does
## that get resolved later?
## 2. `routineKinds` includes template, so is that potentially an issue
## as well?
result = n
if n.kind notin nkPragmaCallKinds or n.len != 2:
result = newError(n, "proposition expected")
else:
openScope(c)
let o = getCurrOwner(c)
if o.kind in routineKinds and o.typ != nil and o.typ.sons[0] != nil:
var s = newSym(skResult, getIdent(c.cache, "result"), nextSymId(c.idgen), o, n.info)
s.typ = o.typ.sons[0]
incl(s.flags, sfUsed)
addDecl(c, s)
n[1] = c.semExpr(c, n[1])
closeScope(c)

proc pragmaAsm*(c: PContext, n: PNode): char =
result = '\0'
if n != nil:
Expand Down Expand Up @@ -277,7 +237,7 @@ proc getStrLitNode(c: PContext, n: PNode): PNode =
# for pragmas prior to changing, but we're meant to return n[1], yet
# on error we return a wrapped `n`, that's the wrong level of AST.
newError(n, StringLiteralExpected)


proc strLitToStrOrErr(c: PContext, n: PNode): (string, PNode) =
## extracts the string from an string literal, or errors if it's not a string
Expand All @@ -288,7 +248,7 @@ proc strLitToStrOrErr(c: PContext, n: PNode): (string, PNode) =
(r.strVal, nil)
of nkError:
("", r)
else:
else:
("", newError(n, errStringLiteralExpected))

proc intLitToIntOrErr(c: PContext, n: PNode): (int, PNode) =
Expand Down Expand Up @@ -355,7 +315,7 @@ proc isTurnedOn(c: PContext, n: PNode): (bool, PNode) =
(x.intVal != 0, nil)
else:
(false, newError(n, "'on' or 'off' expected"))
else:
else:
(false, newError(n, "'on' or 'off' expected"))

proc onOff(c: PContext, n: PNode, op: TOptions, resOptions: var TOptions): PNode =
Expand Down Expand Up @@ -474,7 +434,7 @@ proc processNote(c: PContext, n: PNode): PNode =
if x.kind == nkIntLit and x.intVal != 0: incl(notes, nk)
else: excl(notes, nk)
n

let
validPragma = n.kind in nkPragmaCallKinds and n.len == 2
exp =
Expand All @@ -485,7 +445,7 @@ proc processNote(c: PContext, n: PNode): PNode =
bracketExpr =
if useExp: exp
else: newInvalidPragmaNode(c, n)

result =
if isBracketExpr:
var nk: TNoteKind
Expand Down Expand Up @@ -694,7 +654,7 @@ proc relativeFile(c: PContext; name: string, info: TLineInfo;
proc processCompile(c: PContext, n: PNode): PNode =
## compile pragma
## produces (mutates) `n`, which must be a callable, analysing its arg, or returning
## `n` wrapped in an error.
## `n` wrapped in an error.
result = n
proc docompile(c: PContext; it: PNode; src, dest: AbsoluteFile; customArgs: string) =
var cf = Cfile(nimname: splitFile(src).name,
Expand Down Expand Up @@ -1109,7 +1069,7 @@ proc prepareSinglePragma(
): PNode =
## given a `sym`bol with pragmas `n`, check and prepare `i`'th pragma, if
## it's a single valid pragma, where valid is a kind within `validPragmas`.
##
##
## With special handling for:
## * comes from a push
## * whether it's `isStatement`
Expand Down Expand Up @@ -1185,7 +1145,7 @@ proc prepareSinglePragma(
if extLit.kind == nkError:
result = it
else:
let ext = extLit.strVal
let ext = extLit.strVal
case makeExternExport(c, sym, ext)
of ExternNameSet:
if k == wExportCpp:
Expand Down Expand Up @@ -1410,7 +1370,7 @@ proc prepareSinglePragma(
incl(sym.flags, sfGeneratedOp)
of wNosinks:
result = noVal(c, it)
incl(sym.flags, sfWasForwarded)
incl(sym.flags, sfWasForwarded)
of wDynlib:
result = processDynLib(c, it, sym)
of wCompilerProc, wCore:
Expand Down Expand Up @@ -1497,7 +1457,7 @@ proc prepareSinglePragma(
if sym.kind != skType: incl(sym.flags, sfThread)
if sym.typ != nil:
incl(sym.typ.flags, tfGcSafe)
else:
else:
result = newInvalidPragmaNode(c, it)
else:
discard "no checking if used as a code block"
Expand Down Expand Up @@ -1562,7 +1522,7 @@ proc prepareSinglePragma(
result =
if err.isNil:
extccomp.addLinkOption(c.config, s)
recordPragma(c, it, "passl", s)
recordPragma(c, it, "passl", s)
it
else:
err
Expand Down Expand Up @@ -1777,13 +1737,9 @@ proc prepareSinglePragma(
sym.flags.incl sfUsed
of wLiftLocals:
result = it
of wRequires, wInvariant, wAssume, wAssert:
result = pragmaProposition(c, it)
of wEnsures:
result = pragmaEnsures(c, it)
of wEnforceNoRaises:
sym.flags.incl sfNeverRaises
else:
else:
result = newInvalidPragmaNode(c, it)
elif comesFromPush and whichKeyword(ident) != wInvalid:
discard "ignore the .push pragma; it doesn't apply"
Expand Down
4 changes: 1 addition & 3 deletions compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ proc effectProblem(f, a: PType; result: var string; c: PContext) =
"proc with {.locks: 0.} to get extended error information."
of efEffectsDelayed:
result.add "\n The `.effectsOf` annotations differ."
when defined(drnim):
if not c.graph.compatibleProps(c.graph, f, a):
result.add "\n The `.requires` or `.ensures` properties are incompatible."


proc renderNotLValue(n: PNode): string =
result = $n
Expand Down
31 changes: 2 additions & 29 deletions compiler/sempass2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -756,8 +756,6 @@ proc patchResult(c: PEffects; n: PNode) =
let fn = c.owner
if fn != nil and fn.kind in routineKinds and fn.ast != nil and resultPos < fn.ast.len:
n.sym = fn.ast[resultPos].sym
else:
localError(c.config, n.info, "routine has no return type, but .requires contains 'result'")
else:
for i in 0..<safeLen(n):
patchResult(c, n[i])
Expand Down Expand Up @@ -1310,10 +1308,6 @@ proc checkMethodEffects*(g: ModuleGraph; disp, branch: PSym) =
if sfThread in disp.flags and notGcSafe(branch.typ):
localError(g.config, branch.info, "base method is GC-safe, but '$1' is not" %
branch.name.s)
when defined(drnim):
if not g.compatibleProps(g, disp.typ, branch.typ):
localError(g.config, branch.info, "for method '" & branch.name.s &
"' the `.requires` or `.ensures` properties are incompatible.")

if branch.typ.lockLevel > disp.typ.lockLevel:
when true:
Expand Down Expand Up @@ -1344,13 +1338,6 @@ proc setEffectsForProcType*(g: ModuleGraph; t: PType, n: PNode; s: PSym = nil) =
elif s != nil and (s.magic != mNone or {sfImportc, sfExportc} * s.flags == {sfImportc}):
effects[tagEffects] = newNodeI(nkArgList, effects.info)

let requiresSpec = propSpec(n, wRequires)
if not isNil(requiresSpec):
effects[requiresEffects] = requiresSpec
let ensuresSpec = propSpec(n, wEnsures)
if not isNil(ensuresSpec):
effects[ensuresEffects] = ensuresSpec

effects[pragmasEffects] = n
if s != nil and s.magic != mNone:
if s.magic != mEcho:
Expand All @@ -1374,10 +1361,7 @@ proc initEffects(g: ModuleGraph; effects: PNode; s: PSym; t: var TEffects; c: PC
t.init = @[]
t.guards.s = @[]
t.guards.g = g
when defined(drnim):
t.currOptions = g.config.options + s.options - {optStaticBoundsCheck}
else:
t.currOptions = g.config.options + s.options
t.currOptions = g.config.options + s.options
t.guards.beSmart = optStaticBoundsCheck in t.currOptions
t.locked = @[]
t.graph = g
Expand Down Expand Up @@ -1443,14 +1427,6 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
else:
effects[tagEffects] = t.tags

let requiresSpec = propSpec(p, wRequires)
if not isNil(requiresSpec):
effects[requiresEffects] = requiresSpec
let ensuresSpec = propSpec(p, wEnsures)
if not isNil(ensuresSpec):
patchResult(t, ensuresSpec)
effects[ensuresEffects] = ensuresSpec

var mutationInfo = MutationInfo()
var hasMutationSideEffect = false
if {strictFuncs, views} * c.features != {}:
Expand Down Expand Up @@ -1494,8 +1470,7 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) =
message(g.config, s.info, warnLockLevel,
"declared lock level is $1, but real lock level is $2" %
[$s.typ.lockLevel, $t.maxLockLevel])
when defined(drnim):
if c.graph.strongSemCheck != nil: c.graph.strongSemCheck(c.graph, s, body)

when defined(useDfa):
if s.name.s == "testp":
dataflowAnalysis(s, body)
Expand All @@ -1514,5 +1489,3 @@ proc trackStmt*(c: PContext; module: PSym; n: PNode, isTopLevel: bool) =
initEffects(g, effects, module, t, c)
t.isTopLevel = isTopLevel
track(t, n)
when defined(drnim):
if c.graph.strongSemCheck != nil: c.graph.strongSemCheck(c.graph, module, n)
4 changes: 1 addition & 3 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type

TCandidateState* = enum
csEmpty, csMatch, csNoMatch

CandidateDiagnostic* = PNode
## PNode is only ever an `nkError` kind, often converted to a string for
## display purpopses
Expand Down Expand Up @@ -638,8 +638,6 @@ proc procTypeRel(c: var TCandidate, f, a: PType): TTypeRelation =

when useEffectSystem:
if compatibleEffects(f, a) != efCompat: return isNone
when defined(drnim):
if not c.c.graph.compatibleProps(c.c.graph, f, a): return isNone

of tyNil:
result = f.allowsNil
Expand Down
2 changes: 0 additions & 2 deletions compiler/wordrecg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ type
wSinkInference = "sinkInference", wWarnings = "warnings",
wHints = "hints", wOptimization = "optimization", wRaises = "raises",
wWrites = "writes", wReads = "reads", wSize = "size", wEffects = "effects", wTags = "tags",
wRequires = "requires", wEnsures = "ensures", wInvariant = "invariant",
wAssume = "assume", wAssert = "assert",
wDeadCodeElimUnused = "deadCodeElim", # deprecated, dead code elim always happens
wSafecode = "safecode", wPackage = "package", wNoForward = "noforward", wReorder = "reorder",
wNoRewrite = "norewrite", wNoDestroy = "nodestroy", wPragma = "pragma",
Expand Down
Loading