Skip to content

Made type checking fully polymorphic - #134

Open
mlaveaux wants to merge 19 commits into
MERCorg:mainfrom
mlaveaux:feature/polymorphic_typechecking
Open

Made type checking fully polymorphic#134
mlaveaux wants to merge 19 commits into
MERCorg:mainfrom
mlaveaux:feature/polymorphic_typechecking

Conversation

@mlaveaux

@mlaveaux mlaveaux commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Previously there were all kinds of special cases for polymorphic containers. This branch focusses on introducing proper syntax (now called type_var) for the type variables.

Also added source_map and import statements, these are also used to include the system defined and generated sorts, such that errors can be reported on them.

The next step is to clean up all special cases in type inference.

@mlaveaux mlaveaux self-assigned this Sep 8, 2026
@mlaveaux mlaveaux added the enhancement New feature or request label Sep 8, 2026
//! Rewrites every sort-position [`SortExpressionKind::Reference`] naming one of a
//! specification's own `type_var` declarations into a [`SortExpressionKind::TypeVar`].
//!
//! This runs as part of parsing (see the `type_var`-handling call sites in `consume.rs`), before

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Clean up these comments

/// aliases, constructor, map and equation-variable sorts, and binder sorts inside equation bodies
/// (a quantifier, lambda, or set/bag comprehension). A no-op when the spec declares no type
/// variables.
pub(crate) fn bind_type_vars(spec: &mut UntypedDataSpecification) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This might be called resolve in other places, make it consistent

fn with_binder_scope<T>(
&mut self,
variables: &'a [IdDecl],
f: impl FnOnce(&mut Self, &[ResolvedSortId]) -> Result<T, GenFailure>,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Remove this inline impl

/// the shadowing done inline for a comprehension's single bound variable.
/// Used by `lambda` and `forall`/`exists`, which declare their variables'
/// sorts, unlike a `whr` binding whose sort follows from its right-hand side.
/// binder sort, see [Self::binder_sort]) and registers it in `self.declared_sorts`, by each

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This comment seems weird, what scope, we just have resolved all

// variables per occurrence, mirroring mCRL2's polymorphic symbol
// table; Phase-4 lowering recovers the concrete operation from the
// name and the inferred sort.
for scheme in self.builtin_schemes.clone().get(name).into_iter().flatten() {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Avoid this clone

/// Instantiates the leaves of a `Product` domain spine in declaration
/// order, the template counterpart of `resolve_function_domain`.
fn template_domain(
/// A fresh instance of a scheme's already-*interned* sort: every bound

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Clean up comment

/// comment), parenthesized when it is itself an arrow (matching how a `map`/`cons` declaration's
/// own function sort is parenthesized in this same file's header).
///
/// `cursor` walks `typing.sorts`/`typing.spans` (both `ExprId`-indexed) one entry per recursive

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This seems to be some weird dependency

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant