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
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) let n = lowerings.wrapProcForSpawn(p.module.g.graph, p.module.module, e, e.typ, nil, nil)
expr(p, n, d) expr(p, n, d)
of mParallel: of mParallel:
let n = semparallel.liftParallel(p.module.g.graph, p.module.module, e) when defined(leanCompiler):
expr(p, n, d) 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: of mDeepCopy:
var a, b: TLoc var a, b: TLoc
let x = if e[1].kind in {nkAddr, nkHiddenAddr}: e[1][0] else: e[1] 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, nversion, nimsets, msgs, std / sha1, bitsets, idents, types,
ccgutils, os, ropes, math, passes, wordrecg, treetab, cgmeth, ccgutils, os, ropes, math, passes, wordrecg, treetab, cgmeth,
condsyms, rodutils, renderer, idgen, cgendata, ccgmerge, semfold, aliases, 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.`%` import strutils except `%` # collides with ropes.`%`

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -51,6 +51,9 @@ Boot options:
-d:release produce a release version of the compiler -d:release produce a release version of the compiler
-d:useLinenoise use the linenoise library for interactive mode -d:useLinenoise use the linenoise library for interactive mode
(not needed on Windows) (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: Commands for core developers:
docs [options] generates the full documentation docs [options] generates the full documentation