move assertions out of system (#19599)

This commit is contained in:
flywind 2022-03-24 03:34:53 +08:00 • committed by GitHub
commit 7f6e800caf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
110 changed files with 361 additions and 10 deletions

View file

@ -12,6 +12,9 @@
import
ast, astalgo, types, trees, intsets
when defined(nimPreviewSlimSystem):
import std/assertions
type
TAnalysisResult* = enum
arNo, arMaybe, arYes

View file

@ -13,6 +13,9 @@ import
lineinfos, hashes, options, ropes, idents, int128, tables
from strutils import toLowerAscii
when defined(nimPreviewSlimSystem):
import std/assertions
export int128
type

View file

@ -15,6 +15,9 @@ import
ast, hashes, intsets, strutils, options, lineinfos, ropes, idents, rodutils,
msgs
when defined(nimPreviewSlimSystem):
import std/assertions
proc hashNode*(p: RootRef): Hash
proc treeToYaml*(conf: ConfigRef; n: PNode, indent: int = 0, maxRecDepth: int = - 1): Rope
# Convert a tree into its YAML representation; this is used by the

View file

@ -10,6 +10,9 @@
# this unit handles Nim sets; it implements bit sets
# the code here should be reused in the Nim standard library
when defined(nimPreviewSlimSystem):
import std/assertions
type
ElemType = byte
TBitSet* = seq[ElemType] # we use byte here to avoid issues with

View file

@ -10,6 +10,9 @@
## BTree implementation with few features, but good enough for the
## Nim compiler's needs.
when defined(nimPreviewSlimSystem):
import std/assertions
const
M = 512 # max children per B-tree node = M-1
# (must be even and greater than 2)

View file

@ -13,6 +13,9 @@ import
ast, types, hashes, strutils, msgs, wordrecg,
platform, trees, options, cgendata
when defined(nimPreviewSlimSystem):
import std/assertions
proc getPragmaStmt*(n: PNode, w: TSpecialWord): PNode =
case n.kind
of nkStmtList:

View file

@ -17,6 +17,10 @@ import
lowerings, tables, sets, ndi, lineinfos, pathutils, transf,
injectdestructors, astmsgs
when defined(nimPreviewSlimSystem):
import std/assertions
when not defined(leanCompiler):
import spawn, semparallel

View file

@ -13,6 +13,10 @@ import
intsets, options, ast, msgs, idents, renderer, types, magicsys,
sempass2, strutils, modulegraphs, lineinfos
when defined(nimPreviewSlimSystem):
import std/assertions
proc genConv(n: PNode, d: PType, downcast: bool; conf: ConfigRef): PNode =
var dest = skipTypes(d, abstractPtrs)
var source = skipTypes(n.typ, abstractPtrs)

View file

@ -133,6 +133,9 @@ import
renderer, magicsys, lowerings, lambdalifting, modulegraphs, lineinfos,
tables, options
when defined(nimPreviewSlimSystem):
import std/assertions
type
Ctx = object
g: ModuleGraph

View file

@ -31,6 +31,9 @@ import
from ast import setUseIc, eqTypeFlags, tfGcSafe, tfNoSideEffect
when defined(nimPreviewSlimSystem):
import std/assertions
# but some have deps to imported modules. Yay.
bootSwitch(usedTinyC, hasTinyCBackend, "-d:tinyc")
bootSwitch(usedFFI, hasFFI, "-d:nimHasLibFFI")

View file

@ -15,6 +15,9 @@ import ast, astalgo, semdata, lookups, lineinfos, idents, msgs, renderer, types,
from magicsys import addSonSkipIntLit
when defined(nimPreviewSlimSystem):
import std/assertions
const
logBindings = false

View file

@ -32,6 +32,9 @@
import ast, intsets, lineinfos, renderer
import std/private/asciitables
when defined(nimPreviewSlimSystem):
import std/assertions
type
InstrKind* = enum
goto, fork, def, use

View file

@ -1,6 +1,10 @@
import ast, idents, lineinfos, modulegraphs, magicsys
when defined(nimPreviewSlimSystem):
import std/assertions
proc genEnumToStrProc*(t: PType; info: TLineInfo; g: ModuleGraph; idgen: IdGenerator): PSym =
result = newSym(skProc, getIdent(g.cache, "$"), nextSymId idgen, t.owner, info)

View file

@ -12,6 +12,9 @@
import ast, renderer, options, strutils, types
when defined(nimPreviewSlimSystem):
import std/assertions
type
ErrorKind* = enum ## expand as you need.
RawTypeMismatchError

View file

@ -16,6 +16,9 @@ import ropes, platform, condsyms, options, msgs, lineinfos, pathutils
import std/[os, strutils, osproc, sha1, streams, sequtils, times, strtabs, json, jsonutils, sugar]
when defined(nimPreviewSlimSystem):
import std/syncio
type
TInfoCCProp* = enum # properties of the C compiler:
hasSwitchRange, # CC allows ranges in switch statements (GNU C)

View file

@ -12,6 +12,9 @@
import msgs, std / sha1, os, osproc, streams, options,
lineinfos, pathutils
when defined(nimPreviewSlimSystem):
import std/syncio
proc readOutput(p: Process): (string, int) =
result[0] = ""
var output = p.outputStream

View file

@ -12,6 +12,9 @@
import ast, astalgo, msgs, magicsys, nimsets, trees, types, renderer, idents,
saturate, modulegraphs, options, lineinfos, int128
when defined(nimPreviewSlimSystem):
import std/assertions
const
someEq = {mEqI, mEqF64, mEqEnum, mEqCh, mEqB, mEqRef, mEqProc,
mEqStr, mEqSet, mEqCString}

View file

@ -9,6 +9,9 @@
# This include implements the high level optimization pass.
when defined(nimPreviewSlimSystem):
import std/assertions
proc hlo(c: PContext, n: PNode): PNode
proc evalPattern(c: PContext, n, orig: PNode): PNode =

View file

@ -3,6 +3,9 @@
import hashes, rodfiles
when defined(nimPreviewSlimSystem):
import std/assertions
type
LitId* = distinct uint32

View file

@ -20,6 +20,9 @@
import std/packedsets, algorithm, tables
when defined(nimPreviewSlimSystem):
import std/assertions
import ".."/[ast, options, lineinfos, modulegraphs, cgendata, cgen,
pathutils, extccomp, msgs]

View file

@ -10,6 +10,10 @@
## Dead code elimination (=DCE) for IC.
import std/[intsets, tables]
when defined(nimPreviewSlimSystem):
import std/assertions
import ".." / [ast, options, lineinfos, types]
import packed_ast, ic, bitabs

View file

@ -14,6 +14,9 @@ import ".." / [ast, idents, lineinfos, msgs, ropes, options,
#import ".." / [renderer, astalgo]
from os import removeFile, isAbsolute
when defined(nimPreviewSlimSystem):
import std/[syncio, assertions]
type
PackedConfig* = object
backend: TBackend

View file

@ -11,6 +11,10 @@
## The set must cover a complete Nim project.
import sets
when defined(nimPreviewSlimSystem):
import std/assertions
import ".." / [ast, modulegraphs]
import packed_ast, bitabs, ic

View file

@ -16,6 +16,9 @@ import sets
from os import nil
from std/private/miscdollars import toLocation
when defined(nimPreviewSlimSystem):
import std/assertions
import ".." / [ast, modulegraphs, msgs, options]
import packed_ast, bitabs, ic

View file

@ -16,6 +16,9 @@ import hashes, tables, strtabs
import bitabs
import ".." / [ast, options]
when defined(nimPreviewSlimSystem):
import std/assertions
type
SymId* = distinct int32
ModuleId* = distinct int32

View file

@ -16,6 +16,9 @@ import ".." / [ast, modulegraphs, trees, extccomp, btrees,
import tables
when defined(nimPreviewSlimSystem):
import std/assertions
import packed_ast, ic, bitabs
proc replayStateChanges*(module: PSym; g: ModuleGraph) =

View file

@ -16,6 +16,9 @@
from typetraits import supportsCopyMem
when defined(nimPreviewSlimSystem):
import std/[syncio, assertions]
## Overview
## ========
## `RodFile` represents a Rod File (versioned binary format), and the

View file

@ -14,6 +14,9 @@
import
hashes, wordrecg
when defined(nimPreviewSlimSystem):
import std/assertions
type
PIdent* = ref TIdent
TIdent*{.acyclic.} = object

View file

@ -15,6 +15,9 @@ import
modulegraphs, wordrecg, tables
from strutils import `%`
when defined(nimPreviewSlimSystem):
import std/assertions
proc readExceptSet*(c: PContext, n: PNode): IntSet =
assert n.kind in {nkImportExceptStmt, nkExportExceptStmt}
result = initIntSet()

View file

@ -19,6 +19,9 @@ import
lineinfos, parampatterns, sighashes, liftdestructors, optimizer,
varpartitions
when defined(nimPreviewSlimSystem):
import std/assertions
from trees import exprStructuralEquivalent, getRoot
type

View file

@ -5,6 +5,9 @@
from math import trunc
when defined(nimPreviewSlimSystem):
import std/assertions
type
Int128* = object
udata: array[4, uint32]

View file

@ -13,6 +13,9 @@
import
ast, types, renderer, intsets
when defined(nimPreviewSlimSystem):
import std/assertions
proc canAlias(arg, ret: PType; marker: var IntSet): bool
proc canAliasN(arg: PType; n: PNode; marker: var IntSet): bool =

View file

@ -14,6 +14,9 @@ import
idents, renderer, types, magicsys, lowerings, tables, modulegraphs, lineinfos,
transf, liftdestructors, typeallowed
when defined(nimPreviewSlimSystem):
import std/assertions
discard """
The basic approach is that captured vars need to be put on the heap and
that the calling chain needs to be explicitly modelled. Things to consider:

View file

@ -19,6 +19,9 @@ import
hashes, options, msgs, strutils, platform, idents, nimlexbase, llstream,
wordrecg, lineinfos, pathutils, parseutils
when defined(nimPreviewSlimSystem):
import std/assertions
const
MaxLineLength* = 80 # lines longer than this lead to a warning
numChars*: set[char] = {'0'..'9', 'a'..'z', 'A'..'Z'}

View file

@ -15,6 +15,9 @@ import modulegraphs, lineinfos, idents, ast, renderer, semdata,
from trees import isCaseObj
when defined(nimPreviewSlimSystem):
import std/assertions
type
TLiftCtx = object
g: ModuleGraph

View file

@ -12,6 +12,9 @@
import
pathutils
when defined(nimPreviewSlimSystem):
import std/syncio
# support `useGnuReadline`, `useLinenoise` for backwards compatibility
const hasRstdin = (defined(nimUseLinenoise) or defined(useLinenoise) or defined(useGnuReadline)) and
not defined(windows)

View file

@ -9,6 +9,10 @@
# This module implements lookup helpers.
import std/[algorithm, strutils]
when defined(nimPreviewSlimSystem):
import std/assertions
import
intsets, ast, astalgo, idents, semdata, types, msgs, options,
renderer, nimfix/prettybase, lineinfos, modulegraphs, astmsgs

View file

@ -15,6 +15,9 @@ const
import ast, astalgo, types, idents, magicsys, msgs, options, modulegraphs,
lineinfos
when defined(nimPreviewSlimSystem):
import std/assertions
proc newDeref*(n: PNode): PNode {.inline.} =
result = newNodeIT(nkHiddenDeref, n.info, n.typ[0])
result.add n

View file

@ -22,6 +22,10 @@ import
modules,
modulegraphs, lineinfos, pathutils, vmprofiler
when defined(nimPreviewSlimSystem):
import std/[syncio, assertions]
import ic / [cbackend, integrity, navigator]
from ic / ic import rodViewer

View file

@ -15,6 +15,9 @@ import intsets, tables, hashes, md5_old
import ast, astalgo, options, lineinfos,idents, btrees, ropes, msgs, pathutils
import ic / [packed_ast, ic]
when defined(nimPreviewSlimSystem):
import std/assertions
type
SigHash* = distinct MD5Digest

View file

@ -14,6 +14,9 @@ import
idents, lexer, passes, syntaxes, llstream, modulegraphs,
lineinfos, pathutils, tables
when defined(nimPreviewSlimSystem):
import std/[syncio, assertions]
import ic / replayer
proc resetSystemArtifacts*(g: ModuleGraph) =

View file

@ -12,6 +12,10 @@ import
std/private/miscdollars,
options, ropes, lineinfos, pathutils, strutils2
when defined(nimPreviewSlimSystem):
import std/[syncio, assertions]
type InstantiationInfo* = typeof(instantiationInfo())
template instLoc*(): InstantiationInfo = instantiationInfo(-2, fullPaths = true)

View file

@ -12,6 +12,9 @@
import ast, msgs, ropes, options, pathutils
when defined(nimPreviewSlimSystem):
import std/[syncio, assertions]
type
NdiFile* = object
enabled: bool

View file

@ -10,6 +10,9 @@
import ast, renderer, intsets, tables, msgs, options, lineinfos, strformat, idents, treetab, hashes
import sequtils, strutils, sets
when defined(nimPreviewSlimSystem):
import std/assertions
# IMPORTANT: notes not up to date, i'll update this comment again
#
# notes:

View file

@ -8,6 +8,10 @@
#
import std/[os, strutils, parseopt]
when defined(nimPreviewSlimSystem):
import std/assertions
when defined(windows) and not defined(nimKochBootstrap):
# remove workaround pending bootstrap >= 1.5.1
# refs https://github.com/nim-lang/Nim/issues/18334#issuecomment-867114536

View file

@ -12,6 +12,9 @@
import parseutils, strutils, os, options, msgs, sequtils, lineinfos, pathutils,
std/sha1, tables
when defined(nimPreviewSlimSystem):
import std/[syncio, assertions]
proc addPath*(conf: ConfigRef; path: AbsoluteDir, info: TLineInfo) =
if not conf.searchPaths.contains(path):
conf.searchPaths.insert(path, 0)

View file

@ -13,6 +13,9 @@ import
llstream, commands, os, strutils, msgs, lexer, ast,
options, idents, wordrecg, strtabs, lineinfos, pathutils, scriptconfig
when defined(nimPreviewSlimSystem):
import std/syncio
# ---------------- configuration file parser -----------------------------
# we use Nim's lexer here to save space and work

View file

@ -15,6 +15,9 @@
import
llstream, strutils
when defined(nimPreviewSlimSystem):
import std/assertions
const
Lrz* = ' '
Apo* = '\''

View file

@ -19,6 +19,10 @@ Unstable API
import os, strutils
when defined(nimPreviewSlimSystem):
import std/assertions
const
docCss* = "$nimr/doc/nimdoc.css"
docHackNim* = "$nimr/tools/dochack/dochack.nim"

View file

@ -12,6 +12,9 @@
import
ast, astalgo, lineinfos, bitsets, types, options
when defined(nimPreviewSlimSystem):
import std/assertions
proc inSet*(s: PNode, elem: PNode): bool =
assert s.kind == nkCurly
if s.kind != nkCurly:

View file

@ -14,6 +14,11 @@ import
from terminal import isatty
from times import utc, fromUnix, local, getTime, format, DateTime
from std/private/globs import nativeToUnixPath
when defined(nimPreviewSlimSystem):
import std/[syncio, assertions]
const
hasTinyCBackend* = defined(tinyc)
useEffectSystem* = true

View file

@ -36,6 +36,9 @@ import
when defined(nimpretty):
import layouter
when defined(nimPreviewSlimSystem):
import std/assertions
type
Parser* = object # A Parser object represents a file that
# is being parsed

View file

@ -16,6 +16,9 @@ import
syntaxes, modulegraphs, reorder,
lineinfos, pathutils
when defined(nimPreviewSlimSystem):
import std/syncio
type
TPassData* = tuple[input: PNode, closeOutput: PNode]

View file

@ -13,7 +13,7 @@
import os, pathnorm
when defined(nimPreviewSlimSystem):
import std/syncio
import std/[syncio, assertions]
type
AbsoluteFile* = distinct string

View file

@ -13,6 +13,9 @@
import
ast, types, semdata, sigmatch, idents, aliases, parampatterns, trees
when defined(nimPreviewSlimSystem):
import std/assertions
type
TPatternContext = object
owner: PSym

View file

@ -16,6 +16,10 @@
import
strutils
when defined(nimPreviewSlimSystem):
import std/assertions
type
TSystemOS* = enum # Also add OS in initialization section and alias
# conditionals to condsyms (end of module).

View file

@ -14,6 +14,9 @@ import
wordrecg, ropes, options, strutils, extccomp, math, magicsys, trees,
types, lookups, lineinfos, pathutils, linter
when defined(nimPreviewSlimSystem):
import std/assertions
from ic / ic import addCompilerProc
const

View file

@ -17,6 +17,9 @@ when defined(nimHasUsed):
import
lexer, options, idents, strutils, ast, msgs, lineinfos
when defined(nimPreviewSlimSystem):
import std/[syncio, assertions]
type
TRenderFlag* = enum
renderNone, renderNoBody, renderNoComments, renderDocComments,

View file

@ -4,6 +4,9 @@ import
msgs, modulegraphs, syntaxes, options, modulepaths,
lineinfos
when defined(nimPreviewSlimSystem):
import std/assertions
type
DepN = ref object
pnode: PNode

View file

@ -10,6 +10,9 @@
## Serialization utilities for the compiler.
import strutils, math
when defined(nimPreviewSlimSystem):
import std/assertions
# bcc on windows doesn't have C99 functions
when defined(windows) and defined(bcc):
{.emit: """#if defined(_MSC_VER) && _MSC_VER < 1900

View file

@ -60,6 +60,10 @@ import
from pathutils import AbsoluteFile
when defined(nimPreviewSlimSystem):
import std/[assertions, syncio]
type
FormatStr* = string # later we may change it to CString for better
# performance of the code generator (assignments

View file

@ -16,6 +16,9 @@ import
os, times, osproc, wordrecg, strtabs, modulegraphs,
pathutils
when defined(nimPreviewSlimSystem):
import std/syncio
# we support 'cmpIgnoreStyle' natively for efficiency:
from strutils import cmpIgnoreStyle, contains

View file

@ -11,6 +11,9 @@
import tables
when defined(nimPreviewSlimSystem):
import std/assertions
import
intsets, options, ast, astalgo, msgs, idents, renderer,
magicsys, vmdef, modulegraphs, lineinfos, sets, pathutils

View file

@ -17,6 +17,9 @@ import
from system/memory import nimCStrLen
when defined(nimPreviewSlimSystem):
import std/assertions
proc errorType*(g: ModuleGraph): PType =
## creates a type representing an error state
result = newType(tyError, nextTypeId(g.idgen), g.owners[^1])

View file

@ -12,6 +12,9 @@ import
wordrecg, strutils, options, guards, lineinfos, semfold, semdata,
modulegraphs, varpartitions, typeallowed, nilcheck, errorhandling, tables
when defined(nimPreviewSlimSystem):
import std/assertions
when defined(useDfa):
import dfa

View file

@ -14,6 +14,9 @@ import ast, astalgo, msgs, types, magicsys, semdata, renderer, options,
from concepts import makeTypeDesc
when defined(nimPreviewSlimSystem):
import std/assertions
const tfInstClearedFlags = {tfHasMeta, tfUnresolved}
proc checkPartialConstructedType(conf: ConfigRef; info: TLineInfo, t: PType) =

View file

@ -13,6 +13,10 @@ import ast, tables, ropes, md5_old, modulegraphs
from hashes import Hash
import types
when defined(nimPreviewSlimSystem):
import std/assertions
proc `&=`(c: var MD5Context, s: string) = md5Update(c, s, s.len)
proc `&=`(c: var MD5Context, ch: char) =
# XXX suspicious code here; relies on ch being zero terminated?

View file

@ -15,6 +15,9 @@ import
magicsys, idents, lexer, options, parampatterns, strutils, trees,
linter, lineinfos, lowerings, modulegraphs, concepts
when defined(nimPreviewSlimSystem):
import std/assertions
type
MismatchKind* = enum
kUnknown, kAlreadyGiven, kUnknownNamedParam, kTypeMismatch, kVarNeeded,

View file

@ -13,6 +13,9 @@ import
strutils, llstream, ast, idents, lexer, options, msgs, parser,
filters, filter_tmpl, renderer, lineinfos, pathutils
when defined(nimPreviewSlimSystem):
import std/[syncio, assertions]
export Parser, parseAll, parseTopLevelStmt, closeParser
type

View file

@ -24,6 +24,9 @@ import
lowerings, liftlocals,
modulegraphs, lineinfos
when defined(nimPreviewSlimSystem):
import std/assertions
proc transformBody*(g: ModuleGraph; idgen: IdGenerator, prc: PSym, cache: bool): PNode
import closureiters, lambdalifting

View file

@ -12,6 +12,9 @@
import
hashes, ast, astalgo, types
when defined(nimPreviewSlimSystem):
import std/assertions
proc hashTree*(n: PNode): Hash =
if n.isNil:
return

View file

@ -13,6 +13,9 @@
import
intsets, ast, renderer, options, semdata, types
when defined(nimPreviewSlimSystem):
import std/assertions
type
TTypeAllowedFlag* = enum
taField,

View file

@ -13,6 +13,9 @@ import
intsets, ast, astalgo, trees, msgs, strutils, platform, renderer, options,
lineinfos, int128, modulegraphs, astmsgs
when defined(nimPreviewSlimSystem):
import std/assertions
type
TPreferedDesc* = enum
preferName, # default

View file

@ -32,6 +32,9 @@ import ast, types, lineinfos, options, msgs, renderer, typeallowed, modulegraphs
from trees import getMagic, isNoSideEffectPragma, stupidStmtListExpr
from isolation_check import canAlias
when defined(nimPreviewSlimSystem):
import std/assertions
type
AbstractTime = distinct int

View file

@ -10,6 +10,9 @@
import ast, types, msgs, os, options, idents, lineinfos
from pathutils import AbsoluteFile
when defined(nimPreviewSlimSystem):
import std/syncio
proc opSlurp*(file: string, info: TLineInfo, module: PSym; conf: ConfigRef): string =
try:
var filename = parentDir(toFullPath(conf, info)) / file

View file

@ -29,6 +29,9 @@
import tables
when defined(nimPreviewSlimSystem):
import std/assertions
import
strutils, ast, types, msgs, renderer, vmdef,
intsets, magicsys, options, lowerings, lineinfos, transf, astmsgs

View file

@ -9,6 +9,9 @@
import pathutils
when defined(nimPreviewSlimSystem):
import std/assertions
template setX(k, field) {.dirty.} =
a.slots[a.ra].ensureKind(k)
a.slots[a.ra].field = v

View file

@ -12,6 +12,9 @@
import streams, json, intsets, tables, ast, astalgo, idents, types, msgs,
options, lineinfos
when defined(nimPreviewSlimSystem):
import std/assertions
proc ptrToInt(x: PNode): int {.inline.} =
result = cast[int](x) # don't skip alignment

View file

@ -31,6 +31,10 @@ from std/osproc import nil
from system/formatfloat import addFloatRoundtrip, addFloatSprintf
when defined(nimPreviewSlimSystem):
import std/[syncio, assertions]
# There are some useful procs in vmconv.
import vmconv, vmmarshal