code: func findModuleRoot(dir, limit string, legacyConfigOK bool) (root, file string) {
  	dir = filepath.Clean(dir)
  	dir1 := dir
  	limit = filepath.Clean(limit)
  
  	// Look for enclosing go.mod.
  	for {
  		if fi, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil && !fi.IsDir() {
  			return dir, "go.mod"
  		}
  		if dir == limit {
  			break
  		}
  		d := filepath.Dir(dir)
  		if d == dir {
  			break
  		}
  		dir = d
  	}
  
  	// Failing that, look for enclosing alternate version config.
  	if legacyConfigOK {
  		dir = dir1
  		for {
  			for _, name := range altConfigs {
  				if fi, err := os.Stat(filepath.Join(dir, name)); err == nil && !fi.IsDir() {
  					return dir, name
  				}
  			}
  			if dir == limit {
  				break
  			}
  			d := filepath.Dir(dir)
  			if d == dir {
  				break
  			}
  			dir = d
  		}
  	}
  
  	return "", ""
  }
docs: // Copied from cmd/go/internal/modload/init.go.