llir / llvm

Library for interacting with LLVM IR in pure Go.
https://llir.github.io/document/
BSD Zero Clause License
1.19k stars 78 forks source link

Generic and New API #203

Closed dannypsnl closed 1 year ago

dannypsnl commented 3 years ago

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.

mewmew commented 3 years ago

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

dannypsnl commented 2 years ago

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) {
    // ...
}