Skip to content

Add a resolution phase to Laurel#501

Merged
keyboardDrummer merged 97 commits intomainfrom
remy/LaurelResolution
Mar 6, 2026
Merged

Add a resolution phase to Laurel#501
keyboardDrummer merged 97 commits intomainfrom
remy/LaurelResolution

Conversation

@keyboardDrummer
Copy link
Copy Markdown
Contributor

@keyboardDrummer keyboardDrummer commented Mar 1, 2026

Changes

Instead of redefining how to do name resolution in each phase in the translation from Laurel to Core, define resolution once in a single phase. Currently resolution is done again after each phase. This introduces partially duplicated work but we expect to reduce that in the future using caching.

The Python through Laurel pipeline currently can not resolve each reference because it adds some prelude definitions, that are referenced by the generated code, only at the Core level instead of at the Laurel level. To still enable the Python through Laurel pipeline to work, I had to turn off reporting of resolution errors. I'll resolve that in a follow-up PR.

For Laurel tests, this PR includes changes to ensure that the program resolves without errors after each phase:

  • Fix issue in DDM parsing caused by Lean.Name.toString inserting guillemets "« »"
  • Datatype support has been improved. References to the type of a datatype now translate to Core correctly. There's now grammar support for datatypes
  • The prelude for Laurel is now added during HeapParameterization phase, since that's the phase that depends on these definitions, instead of after the translation to Core.
  • The typeTag: TypeTag field of the composite datatype is only added to that datatype during the typeHierarchy phase, since that's the phase where TypeTag is defined.
  • const,select and update are now added as part of CoreDefinitionsForLaurel.lean, as Laurel functions with an "External" body, meaning they're ignored during the translation to Core. This way, references to them can be resolved during resolution.
  • During HeapParameterization, fields for composite type definitions are deleted, so their names don't conflict with the constructors of the generated Field datatype
  • Small refactoring to simplify the definition of Forall and Exists, by reusing the Parameter type.

Testing

Refactoring. No changes to existing tests. I will follow-up with first removing the hacks, and then adding tests containing name conflicts that'll make use of this new resolution phase.

@keyboardDrummer keyboardDrummer requested a review from joscoh March 2, 2026 15:52
Comment thread Strata/Languages/Laurel/Laurel.lean
Comment thread Strata/Languages/Laurel/Laurel.lean
Comment thread Strata/Languages/Laurel/LaurelToCoreTranslator.lean Outdated
Copy link
Copy Markdown
Contributor

@joscoh joscoh left a comment

Choose a reason for hiding this comment

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

Do you have any tests for these changes (e.g. ensuring resolution works, Laurel programs with datatypes)?

Comment thread Strata/Languages/Laurel/Grammar/ConcreteToAbstractTreeTranslator.lean Outdated
Comment thread Strata/Languages/Laurel/Grammar/LaurelGrammar.st
Comment thread Strata/Languages/Laurel/CoreDefinitionsForLaurel.lean
Comment thread Strata/Languages/Laurel/Resolution.lean Outdated
Comment thread Strata/Languages/Laurel/HeapParameterization.lean Outdated
Comment thread Strata/Languages/Laurel/Laurel.lean
Comment thread Strata/Languages/Laurel/LaurelToCoreTranslator.lean Outdated
Comment thread Strata/Languages/Laurel/LaurelToCoreTranslator.lean Outdated
Comment thread Strata/Languages/Laurel/LaurelToCoreTranslator.lean
Comment thread Strata/Languages/Laurel/LaurelToCoreTranslator.lean Outdated
@keyboardDrummer keyboardDrummer requested a review from joscoh March 5, 2026 16:04
Comment thread Strata/Languages/Laurel/HeapParameterizationConstants.lean
@keyboardDrummer keyboardDrummer added this pull request to the merge queue Mar 6, 2026
Merged via the queue into main with commit ea7beb9 Mar 6, 2026
15 checks passed
@keyboardDrummer keyboardDrummer deleted the remy/LaurelResolution branch March 6, 2026 09:09
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.

4 participants