llvm icon indicating copy to clipboard operation
llvm copied to clipboard

Generic and New API

Open dannypsnl opened this issue 4 years ago • 2 comments

Generic(a.k.a. parametric polymorphism) added into Go, let's explore how would it change our codebase, this issue is created to track related discussion.

  • Go 1.18 Beta 1 or later
  • https://go.dev/doc/tutorial/generics

dannypsnl avatar Aug 28 '21 21:08 dannypsnl

Great that you started to track the discussion @dannypsnl!

Just to clarify, we will evaluate how using generics would change the llir/llvm API, and based on this evaluation of benefits and drawbacks, we would then decide whether to actually update the API to use generics or not. It is also a possibility that generics brings with it more cons than pros in our specific case. Experimentation and evaluation will tell! :)

Cheers, Robin

mewmew avatar Aug 29 '21 10:08 mewmew

Just thinking, maybe https://github.com/llir/llvm/issues/59#issuecomment-993037757 is not hopeless now with Generic concept in Go(actually union part).

Previously, we must write

type Function interface {
    // ...
}
var _ Function = &function{}
type function struct {
    // ...
}

To let users have their own Function, now we can have

type Function struct {
    // ...
}

type Func interface {
    LLString() string
    // anything we need internally
}

// use point of Function
func foo[F *Function | Func](f F) {
    // ...
}

dannypsnl avatar Jan 25 '22 04:01 dannypsnl