lang: ast: ExprBind is now monomorphic

This adds ExprTopLevel and ExprSingleton and ensures that ExprBind is
now monomorphic.

This corrects a previous design bug where it was not monomorphic and
would thus cause spawning of many more copies than necessary. In most
cases this was only harmful to memory and performance, and not
behaviour, since these functions were pure, and we didn't have a test
for this.

This also adds a bunch more tests. Most notably, the graph shape tests
generally produce smaller graphs now.

Lastly, a lambda cannot have two different types when used at two
different call sites. It is rare that this would be used, and when it
would make sense, there are easy workarounds to accomplish equivalent
goals.

This was mostly authored by Sam, James helped with some cleanup and
debugging.

Co-authored-by: James Shubin <james@shubin.ca>
This commit is contained in:
Samuel Gélineau
2023-12-04 21:56:42 -05:00
committed by James Shubin
parent 9d208e8795
commit 1c0a98a0cc
28 changed files with 677 additions and 140 deletions

View File

@@ -195,6 +195,28 @@ func (obj *ExprPoly) ScopeGraph(g *pgraph.Graph) {
g.AddEdge(obj, obj.Definition, &pgraph.SimpleEdge{Name: "def"})
}
// ScopeGraph adds nodes and vertices to the supplied graph.
func (obj *ExprTopLevel) ScopeGraph(g *pgraph.Graph) {
g.AddVertex(obj)
definition, ok := obj.Definition.(interfaces.ScopeGrapher)
if !ok {
panic("can't graph scope") // programming error
}
definition.ScopeGraph(g)
g.AddEdge(obj, obj.Definition, &pgraph.SimpleEdge{Name: "def"})
}
// ScopeGraph adds nodes and vertices to the supplied graph.
func (obj *ExprSingleton) ScopeGraph(g *pgraph.Graph) {
g.AddVertex(obj)
definition, ok := obj.Definition.(interfaces.ScopeGrapher)
if !ok {
panic("can't graph scope") // programming error
}
definition.ScopeGraph(g)
g.AddEdge(obj, obj.Definition, &pgraph.SimpleEdge{Name: "def"})
}
// ScopeGraph adds nodes and vertices to the supplied graph.
func (obj *ExprIf) ScopeGraph(g *pgraph.Graph) {
g.AddVertex(obj)