Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proofgen: generate new definitions needed for initialization support #65

Merged
merged 17 commits into from
Mar 7, 2025

Conversation

tchajed
Copy link
Collaborator

@tchajed tchajed commented Mar 5, 2025

This PR adds generation of PkgIsDefined instances and a new definition imported_pkgs, a list of packages whose initialization a package depends on. I also shifted all the WpFuncCall and related instances to be based on pkg_defined to be systematic.

Copy link
Collaborator

@upamanyus upamanyus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to you if you want to move the import list into the trusted Goose (and make relevant changes to the initialize' function) or merge this as is; in the latter case, I may make that change in the future.

return pkgPath[i+1:]
}

func (tr *importsTranslator) translateImportList(w io.Writer, pkg *packages.Package) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point, it might be better to emit a list of imported packages in the trusted Goose translation, which would eliminate the need for this. The Go code's translation currently inlines calls to importA.initialize', importB.initialize' and so forth into the current package's initialize function, which prevents any abstraction in Coq about the import phase of initializing a package.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list of imported packages is now in trusted code. Initialization uses globals.package_init which now takes most of its parameters through the PkgInfo class, but the translator still produces a function that calls all the dependencies - as with is_defined, abstracting this out is hard since we would need the PkgInfo of every dependent package and this isn't easy to abstract over.

@tchajed tchajed merged commit 702c1bf into new Mar 7, 2025
2 checks passed
tchajed added a commit to mit-pdos/perennial that referenced this pull request Mar 7, 2025
This PR adds new typeclasses `PkgIsInitialized pkg_name` and `PkgIsDefined pkg_nam` that associate a package with its "initialization" and "definenedness" predicate, respectively. The latter is already automatically generated, while the former is defined in manual proofs but in the absence of global variables or initialization functions consists of `is_defined` for that package and is_initialized for all imported packages. The instances of these typeclasses essentially register a predicate to a package name, accessed via `is_pkg_init` and `is_pkg_defined`.

This PR also adds a new `PkgInfo` typeclass, which is used to get the information that constructs `is_defined` and the list of imports.

This PR depends on goose-lang/goose#65 to create new instances and definitions.

These typeclasses permit some useful automation of initialization predicates, most of which is included here:

- The tactic `basic_pkg_init` defines an initialization predicate.
- `wp_apply` automatically proves any pkg_init preconditions it finds from any found in the persistent context.
- A new `wp_start` tactic automatically introduces the initialization predicate and names only the remaining hypotheses according to the user pattern.

---------

Co-authored-by: Upamanyu Sharma <[email protected]>
@tchajed tchajed deleted the tchajed/new-init branch March 7, 2025 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants