Binject/debug

Parse should take a func instead of a map to query object file paths

Closed this issue · 1 comments

mvdan commented

That is, instead of:

func Parse(objPath, pkgPath string, importCfg ImportCfg) (*Package, error)

just:

func Parse(objPath, pkgPath string, importMap func(importPath string) (objectPath string)) (*Package, error)

Reasons to do so:

  1. It can be implemented in more ways. For example, right now in garble we have a map[string]importedPkg which also contains the object path, but since it's not a map[string]ExportInfo, I can't reuse it. I'd need two maps with the same keys, which is not ideal.
  2. It doesn't require having all the paths in memory upfront in a map. For example, we could fill a map as we go, memoizing previous queries.
mvdan commented

If you want to keep the func signature short, it would always be possible to do type ImportMap = func(importPath string) (objectPath string) and then importMap ImportMap.