Skip to content

Commit

Permalink
Add Gallina bindings for type parameters
Browse files Browse the repository at this point in the history
This only adds the bindings to function definitions. The parameters
aren't yet passed in function calls, so uses of generic functions won't
work.
  • Loading branch information
tchajed committed Jul 12, 2024
1 parent d7b31db commit cfe58ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion glang/coq.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ func (e FuncLit) Coq(needs_paren bool) string {
// FuncDecl declares a function, including its parameters and body.
type FuncDecl struct {
Name string
TypeParams []TypeIdent
RecvArg *FieldDecl
Args []FieldDecl
ReturnType Type
Expand Down Expand Up @@ -810,7 +811,12 @@ func (d FuncDecl) CoqDecl() string {
var pp buffer
pp.AddComment(d.Comment)

pp.Add("Definition %s : val :=", d.Name)
typeParams := ""
for _, t := range d.TypeParams {
typeParams += fmt.Sprintf("(%s: go_type) ", t.Coq(false))
}

pp.Add("Definition %s %s: val :=", d.Name, typeParams)
func() {
pp.Indent(2)
defer pp.Indent(-2)
Expand Down
1 change: 1 addition & 0 deletions goose.go
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,7 @@ func (ctx Ctx) funcDecl(d *ast.FuncDecl) glang.FuncDecl {
fd := glang.FuncDecl{Name: d.Name.Name, AddTypes: ctx.Config.TypeCheck}
addSourceDoc(d.Doc, &fd.Comment)
ctx.addSourceFile(d, &fd.Comment)
fd.TypeParams = ctx.typeParamList(d.Type.TypeParams)
if d.Recv != nil {
if len(d.Recv.List) != 1 {
ctx.nope(d, "function with multiple receivers")
Expand Down

0 comments on commit cfe58ea

Please sign in to comment.