diff options
author | Ayke van Laethem <[email protected]> | 2022-06-11 16:25:34 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2022-06-11 20:41:16 +0200 |
commit | bb65c5ce2b92e89940678117900c3e0d8427d371 (patch) | |
tree | 8fe1b9a919c2ad4fce56ed16ec3f4f0d639412a8 /loader | |
parent | 283fed16a5c112b1e6682b08ed61552059c90ccc (diff) | |
download | tinygo-bb65c5ce2b92e89940678117900c3e0d8427d371.tar.gz tinygo-bb65c5ce2b92e89940678117900c3e0d8427d371.zip |
compiler: add support for type parameters (aka generics)
...that was surprisingly easy.
Diffstat (limited to 'loader')
-rw-r--r-- | loader/loader.go | 5 | ||||
-rw-r--r-- | loader/loader_go118.go | 18 | ||||
-rw-r--r-- | loader/ssa.go | 2 |
3 files changed, 24 insertions, 1 deletions
diff --git a/loader/loader.go b/loader/loader.go index 88eb15dac..730eb7017 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -28,6 +28,8 @@ import ( "github.com/tinygo-org/tinygo/goenv" ) +var addInstances func(*types.Info) + // Program holds all packages and some metadata about the program as a whole. type Program struct { config *compileopts.Config @@ -164,6 +166,9 @@ func Load(config *compileopts.Config, inputPkg string, clangHeaders string, type Selections: make(map[*ast.SelectorExpr]*types.Selection), }, } + if addInstances != nil { + addInstances(&pkg.info) + } err := decoder.Decode(&pkg.PackageJSON) if err != nil { if err == io.EOF { diff --git a/loader/loader_go118.go b/loader/loader_go118.go new file mode 100644 index 000000000..d545160e7 --- /dev/null +++ b/loader/loader_go118.go @@ -0,0 +1,18 @@ +//go:build go1.18 +// +build go1.18 + +package loader + +// Workaround for Go 1.17 support. Should be removed once we drop Go 1.17 +// support. + +import ( + "go/ast" + "go/types" +) + +func init() { + addInstances = func(info *types.Info) { + info.Instances = make(map[*ast.Ident]types.Instance) + } +} diff --git a/loader/ssa.go b/loader/ssa.go index f97511ee3..a514d71d7 100644 --- a/loader/ssa.go +++ b/loader/ssa.go @@ -8,7 +8,7 @@ import ( // // The program must already be parsed and type-checked with the .Parse() method. func (p *Program) LoadSSA() *ssa.Program { - prog := ssa.NewProgram(p.fset, ssa.SanityCheckFunctions|ssa.BareInits|ssa.GlobalDebug) + prog := ssa.NewProgram(p.fset, ssa.SanityCheckFunctions|ssa.BareInits|ssa.GlobalDebug|ssa.InstantiateGenerics) for _, pkg := range p.sorted { prog.CreatePackage(pkg.Pkg, pkg.Files, &pkg.info, true) |