Skip to content

Add a resolution phase to Laurel#501

Open
keyboardDrummer wants to merge 97 commits intomainfrom
remy/LaurelResolution
Open

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

Conversation

@keyboardDrummer
Copy link
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
-- Collect ALL errors from both functions and procedures before deciding whether to fail
let allErrors := pureErrors ++ procDiags ++ constantsState.diagnostics
-- Collect ALL errors from both functions, procedures, and resolution before deciding whether to fail
let allErrors := -- resolutionDiags.toList ++
Copy link
Contributor

@joehendrix joehendrix Mar 4, 2026

Choose a reason for hiding this comment

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

_resolutionDiags is not included here — the addition is commented out. Is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a clarifying comment

Copy link
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)?

op composite (name: Ident, extending: Option OptionalExtends, fields: Seq Field): Composite => "composite " name extending "{" fields "}";

// Datatype definitions
category DatatypeConstructorArg;
Copy link
Contributor

Choose a reason for hiding this comment

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

This will not allow recursive type definitions, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Grammar wise I think it would be allowed, but it might fail later in the pipeline, depending on whether Core datatypes support this or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Core datatypes support this. The Laurel grammar does not right now I believe because the type definition is not in scope in the constructor types. We use the @[scopeDatatype] annotation for this in the Core grammar to handle this. I am not saying that Laurel should or not support this, just wanted to let you know that I do not believe this is supported right now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, thanks.

@keyboardDrummer keyboardDrummer requested a review from joscoh March 5, 2026 16:04



datatype Workaround {}
Copy link
Contributor

@joehendrix joehendrix Mar 5, 2026

Choose a reason for hiding this comment

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

The Workaround datatype can be deleted — I removed it locally and lake build strata:exe completed successfully (368/368 jobs, no errors).strata:exe` completed successfully (368/368 jobs, no errors).

Scratch that I see the test failure. I'll investigate further for a fix, but don't consider this blocking obviously.

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