IC: next steps (#16729)

* IC: dead code elimination pass
* preparations for a different codegen strategy
* added documentation to the newly written code
* IC: backend code
* IC: backend adjustments
* optimized the compiler a bit
* IC: yet another massive refactoring
* fixes regressions
* cleanups
This commit is contained in:
Andreas Rumpf 2021-01-23 08:06:15 +01:00 • committed by GitHub
commit 8241e55023
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 729 additions and 323 deletions

View file

@ -11,7 +11,7 @@
import
intsets, ast, astalgo, trees, msgs, strutils, platform, renderer, options,
lineinfos, int128
lineinfos, int128, modulegraphs
type
TPreferedDesc* = enum
@ -1307,11 +1307,12 @@ proc containsGenericTypeIter(t: PType, closure: RootRef): bool =
proc containsGenericType*(t: PType): bool =
result = iterOverType(t, containsGenericTypeIter, nil)
proc baseOfDistinct*(t: PType; idgen: IdGenerator): PType =
proc baseOfDistinct*(t: PType; g: ModuleGraph; idgen: IdGenerator): PType =
if t.kind == tyDistinct:
result = t[0]
else:
result = copyType(t, nextTypeId idgen, t.owner)
copyTypeProps(g, idgen.module, result, t)
var parent: PType = nil
var it = result
while it.kind in {tyPtr, tyRef, tyOwned}:
@ -1449,7 +1450,7 @@ proc isEmptyContainer*(t: PType): bool =
of tyGenericInst, tyAlias, tySink: result = isEmptyContainer(t.lastSon)
else: result = false
proc takeType*(formal, arg: PType; idgen: IdGenerator): PType =
proc takeType*(formal, arg: PType; g: ModuleGraph; idgen: IdGenerator): PType =
# param: openArray[string] = []
# [] is an array constructor of length 0 of type string!
if arg.kind == tyNil:
@ -1458,6 +1459,7 @@ proc takeType*(formal, arg: PType; idgen: IdGenerator): PType =
elif formal.kind in {tyOpenArray, tyVarargs, tySequence} and
arg.isEmptyContainer:
let a = copyType(arg.skipTypes({tyGenericInst, tyAlias}), nextTypeId(idgen), arg.owner)
copyTypeProps(g, idgen.module, a, arg)
a[ord(arg.kind == tyArray)] = formal[0]
result = a
elif formal.kind in {tyTuple, tySet} and arg.kind == formal.kind:
@ -1465,14 +1467,14 @@ proc takeType*(formal, arg: PType; idgen: IdGenerator): PType =
else:
result = arg
proc skipHiddenSubConv*(n: PNode; idgen: IdGenerator): PNode =
proc skipHiddenSubConv*(n: PNode; g: ModuleGraph; idgen: IdGenerator): PNode =
if n.kind == nkHiddenSubConv:
# param: openArray[string] = []
# [] is an array constructor of length 0 of type string!
let formal = n.typ
result = n[1]
let arg = result.typ
let dest = takeType(formal, arg, idgen)
let dest = takeType(formal, arg, g, idgen)
if dest == arg and formal.kind != tyUntyped:
#echo n.info, " came here for ", formal.typeToString
result = n