Add specTypeToLaurelActual for unified PySpec type mapping#665
Draft
joehendrix wants to merge 2 commits intomainfrom
Draft
Add specTypeToLaurelActual for unified PySpec type mapping#665joehendrix wants to merge 2 commits intomainfrom
joehendrix wants to merge 2 commits intomainfrom
Conversation
Replace the two-step specTypeToLaurelType/preconditionForType pattern with specTypeToLaurelActual that directly maps PySpec types to their Laurel representation: - Value types (primitives, lists, dicts) → Core(Any) with isfrom_X preconditions - Heap types (user-defined classes) → UserDefined(Composite) - Optional/union patterns → Or(isfrom_none, isfrom_X) preconditions funcDeclToLaurel now uses specTypeToLaurelActual for parameters and return types, generating typed preconditions and postconditions. Opaque procedures without preconditions use postconditions in Body.Opaque. Also adds anyConstructorForType/anyDestructorForType helpers for Any↔typed wrapping/unwrapping, and validates List element types to reject composites incompatible with Any. Co-Authored-By: Claude Opus 4.6 <[email protected]>
PySpec instance methods now include a `self: Composite` first parameter. translateCall in PythonToLaurel prepends the target object as self when calling resolved instance methods, fixing arity mismatches. Also removes the transparent-only guard on Attribute calls — all resolved procedures (not just those with preconditions) now emit StaticCall. Co-Authored-By: Claude Opus 4.6 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
specTypeToLaurelActual: Unified function that maps PySpec types directly to Laurel types with preconditions. Value types (int, str, bool, float, list, dict) becomeCore(Any)withisfrom_Xpreconditions. Heap types (user-defined classes) becomeUserDefined(Composite).funcDeclToLaurel: Now usesspecTypeToLaurelActualfor all parameter and return types, generating typed preconditions. Opaque procedures store postconditions inBody.Opaque.Optional[T]patterns generateOr(isfrom_none, isfrom_T)preconditions. Homogeneous literal unions (all strings, all ints) get single-type constraints.anyConstructorForTypeandanyDestructorForTypefor Any↔typed wrapping/unwrapping.List[CompositeType]since composites live on the heap and can't be embedded in Any.Known limitation
The
selfparameter for instance methods is not added in this PR. Adding it here would cause arity mismatches since PythonToLaurel callers don't yet prependself. This is tracked for a follow-up PR.Test plan
lake buildpasses cleanly (no warnings)By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
🤖 Generated with Claude Code