make Nim take roughly 100MB less RAM for bootstrapping via a new compiler switch -d:leanCompiler; useful for the Raberry PI

This commit is contained in:
Andreas Rumpf
2018-11-07 18:36:45 +01:00
parent d5e113c3a6
commit cb4d810659
8 changed files with 110 additions and 63 deletions

View File

@@ -2030,8 +2030,11 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
let n = lowerings.wrapProcForSpawn(p.module.g.graph, p.module.module, e, e.typ, nil, nil)
expr(p, n, d)
of mParallel:
let n = semparallel.liftParallel(p.module.g.graph, p.module.module, e)
expr(p, n, d)
when defined(leanCompiler):
quit "compiler built without support for the 'parallel' statement"
else:
let n = semparallel.liftParallel(p.module.g.graph, p.module.module, e)
expr(p, n, d)
of mDeepCopy:
var a, b: TLoc
let x = if e[1].kind in {nkAddr, nkHiddenAddr}: e[1][0] else: e[1]

View File

@@ -14,7 +14,10 @@ import
nversion, nimsets, msgs, std / sha1, bitsets, idents, types,
ccgutils, os, ropes, math, passes, wordrecg, treetab, cgmeth,
condsyms, rodutils, renderer, idgen, cgendata, ccgmerge, semfold, aliases,
lowerings, semparallel, tables, sets, ndi, lineinfos, pathutils, transf
lowerings, tables, sets, ndi, lineinfos, pathutils, transf
when not defined(leanCompiler):
import semparallel
import strutils except `%` # collides with ropes.`%`

View File

@@ -15,12 +15,15 @@ when not defined(nimcore):
import
llstream, strutils, ast, astalgo, lexer, syntaxes, renderer, options, msgs,
os, condsyms, times,
wordrecg, sem, semdata, idents, passes, docgen, extccomp,
cgen, jsgen, json, nversion,
wordrecg, sem, semdata, idents, passes, extccomp,
cgen, json, nversion,
platform, nimconf, importer, passaux, depends, vm, vmdef, types, idgen,
docgen2, parser, modules, ccgutils, sigmatch, ropes,
parser, modules, ccgutils, sigmatch, ropes,
modulegraphs, tables, rod, lineinfos, pathutils
when not defined(leanCompiler):
import jsgen, docgen, docgen2
from magicsys import resetSysTypes
proc codegenPass(g: ModuleGraph) =
@@ -57,13 +60,14 @@ proc commandCheck(graph: ModuleGraph) =
semanticPasses(graph) # use an empty backend for semantic checking only
compileProject(graph)
proc commandDoc2(graph: ModuleGraph; json: bool) =
graph.config.errorMax = high(int) # do not stop after first error
semanticPasses(graph)
if json: registerPass(graph, docgen2JsonPass)
else: registerPass(graph, docgen2Pass)
compileProject(graph)
finishDoc2Pass(graph.config.projectName)
when not defined(leanCompiler):
proc commandDoc2(graph: ModuleGraph; json: bool) =
graph.config.errorMax = high(int) # do not stop after first error
semanticPasses(graph)
if json: registerPass(graph, docgen2JsonPass)
else: registerPass(graph, docgen2Pass)
compileProject(graph)
finishDoc2Pass(graph.config.projectName)
proc commandCompileToC(graph: ModuleGraph) =
let conf = graph.config
@@ -84,15 +88,16 @@ proc commandJsonScript(graph: ModuleGraph) =
let proj = changeFileExt(graph.config.projectFull, "")
extccomp.runJsonBuildInstructions(graph.config, proj)
proc commandCompileToJS(graph: ModuleGraph) =
#incl(gGlobalOptions, optSafeCode)
setTarget(graph.config.target, osJS, cpuJS)
#initDefines()
defineSymbol(graph.config.symbols, "ecmascript") # For backward compatibility
defineSymbol(graph.config.symbols, "js")
semanticPasses(graph)
registerPass(graph, JSgenPass)
compileProject(graph)
when not defined(leanCompiler):
proc commandCompileToJS(graph: ModuleGraph) =
#incl(gGlobalOptions, optSafeCode)
setTarget(graph.config.target, osJS, cpuJS)
#initDefines()
defineSymbol(graph.config.symbols, "ecmascript") # For backward compatibility
defineSymbol(graph.config.symbols, "js")
semanticPasses(graph)
registerPass(graph, JSgenPass)
compileProject(graph)
proc interactivePasses(graph: ModuleGraph) =
initDefines(graph.config.symbols)
@@ -177,49 +182,76 @@ proc mainCommand*(graph: ModuleGraph) =
else:
rawMessage(conf, errGenerated, "'run' command not available; rebuild with -d:tinyc")
of "js", "compiletojs":
conf.cmd = cmdCompileToJS
commandCompileToJS(graph)
when defined(leanCompiler):
quit "compiler wasn't built with JS code generator"
else:
conf.cmd = cmdCompileToJS
commandCompileToJS(graph)
of "doc0":
wantMainModule(conf)
conf.cmd = cmdDoc
loadConfigs(DocConfig, cache, conf)
commandDoc(cache, conf)
when defined(leanCompiler):
quit "compiler wasn't built with documentation generator"
else:
wantMainModule(conf)
conf.cmd = cmdDoc
loadConfigs(DocConfig, cache, conf)
commandDoc(cache, conf)
of "doc2", "doc":
conf.cmd = cmdDoc
loadConfigs(DocConfig, cache, conf)
defineSymbol(conf.symbols, "nimdoc")
commandDoc2(graph, false)
when defined(leanCompiler):
quit "compiler wasn't built with documentation generator"
else:
conf.cmd = cmdDoc
loadConfigs(DocConfig, cache, conf)
defineSymbol(conf.symbols, "nimdoc")
commandDoc2(graph, false)
of "rst2html":
conf.cmd = cmdRst2html
loadConfigs(DocConfig, cache, conf)
commandRst2Html(cache, conf)
when defined(leanCompiler):
quit "compiler wasn't built with documentation generator"
else:
conf.cmd = cmdRst2html
loadConfigs(DocConfig, cache, conf)
commandRst2Html(cache, conf)
of "rst2tex":
conf.cmd = cmdRst2tex
loadConfigs(DocTexConfig, cache, conf)
commandRst2TeX(cache, conf)
when defined(leanCompiler):
quit "compiler wasn't built with documentation generator"
else:
conf.cmd = cmdRst2tex
loadConfigs(DocTexConfig, cache, conf)
commandRst2TeX(cache, conf)
of "jsondoc0":
wantMainModule(conf)
conf.cmd = cmdDoc
loadConfigs(DocConfig, cache, conf)
wantMainModule(conf)
defineSymbol(conf.symbols, "nimdoc")
commandJson(cache, conf)
when defined(leanCompiler):
quit "compiler wasn't built with documentation generator"
else:
wantMainModule(conf)
conf.cmd = cmdDoc
loadConfigs(DocConfig, cache, conf)
wantMainModule(conf)
defineSymbol(conf.symbols, "nimdoc")
commandJson(cache, conf)
of "jsondoc2", "jsondoc":
conf.cmd = cmdDoc
loadConfigs(DocConfig, cache, conf)
wantMainModule(conf)
defineSymbol(conf.symbols, "nimdoc")
commandDoc2(graph, true)
when defined(leanCompiler):
quit "compiler wasn't built with documentation generator"
else:
conf.cmd = cmdDoc
loadConfigs(DocConfig, cache, conf)
wantMainModule(conf)
defineSymbol(conf.symbols, "nimdoc")
commandDoc2(graph, true)
of "ctags":
wantMainModule(conf)
conf.cmd = cmdDoc
loadConfigs(DocConfig, cache, conf)
defineSymbol(conf.symbols, "nimdoc")
commandTags(cache, conf)
when defined(leanCompiler):
quit "compiler wasn't built with documentation generator"
else:
wantMainModule(conf)
conf.cmd = cmdDoc
loadConfigs(DocConfig, cache, conf)
defineSymbol(conf.symbols, "nimdoc")
commandTags(cache, conf)
of "buildindex":
conf.cmd = cmdDoc
loadConfigs(DocConfig, cache, conf)
commandBuildIndex(cache, conf)
when defined(leanCompiler):
quit "compiler wasn't built with documentation generator"
else:
conf.cmd = cmdDoc
loadConfigs(DocConfig, cache, conf)
commandBuildIndex(cache, conf)
of "gendepend":
conf.cmd = cmdGenDepend
commandGenDepend(graph)

View File

@@ -16,13 +16,16 @@ import
procfind, lookups, pragmas, passes, semdata, semtypinst, sigmatch,
intsets, transf, vmdef, vm, idgen, aliases, cgmeth, lambdalifting,
evaltempl, patterns, parampatterns, sempass2, linter, semmacrosanity,
semparallel, lowerings, pluginsupport, plugins/active, rod, lineinfos
lowerings, pluginsupport, plugins/active, rod, lineinfos
from modulegraphs import ModuleGraph, PPassContext
when defined(nimfix):
import nimfix/prettybase
when not defined(leanCompiler):
import semparallel
# implementation
proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.procvar.}

View File

@@ -9,9 +9,12 @@
import
intsets, ast, astalgo, msgs, renderer, magicsys, types, idents, trees,
wordrecg, strutils, options, guards, writetracking, lineinfos, semfold,
wordrecg, strutils, options, guards, lineinfos, semfold,
modulegraphs
when not defined(leanCompiler):
import writetracking
when defined(useDfa):
import dfa
@@ -713,7 +716,7 @@ proc track(tracked: PEffects, n: PNode) =
track(tracked, n.sons[i])
of nkCallKinds:
if getConstExpr(tracked.owner_module, n, tracked.graph) != nil:
return
return
# p's effects are ours too:
var a = n.sons[0]
let op = a.typ

View File

@@ -15,7 +15,7 @@ import
magicsys, condsyms, idents, lexer, options, parampatterns, strutils, trees,
linter, lineinfos
when defined(booting) or defined(nimsuggest):
when (defined(booting) or defined(nimsuggest)) and not defined(leanCompiler):
import docgen
type

View File

@@ -115,7 +115,7 @@ proc symToSuggest(conf: ConfigRef; s: PSym, isLocal: bool, section: IdeCmd, info
result.forth = typeToString(s.typ)
else:
result.forth = ""
when defined(nimsuggest) and not defined(noDocgen):
when defined(nimsuggest) and not defined(noDocgen) and not defined(leanCompiler):
result.doc = s.extractDocComment
let infox = if section in {ideUse, ideHighlight, ideOutline}: info else: s.info
result.filePath = toFullPath(conf, infox)
@@ -153,7 +153,7 @@ proc `$`*(suggest: Suggest): string =
result.add(sep)
result.add($suggest.column)
result.add(sep)
when defined(nimsuggest) and not defined(noDocgen):
when defined(nimsuggest) and not defined(noDocgen) and not defined(leanCompiler):
result.add(suggest.doc.escape)
if suggest.version == 0:
result.add(sep)

View File

@@ -51,6 +51,9 @@ Boot options:
-d:release produce a release version of the compiler
-d:useLinenoise use the linenoise library for interactive mode
(not needed on Windows)
-d:leanCompiler produce a compiler without JS codegen or
documentation generator in order to use less RAM
for bootstrapping
Commands for core developers:
docs [options] generates the full documentation