Skip to content

Added various parts of the well typedness checks#82

Open
mlaveaux wants to merge 18 commits intoMERCorg:mainfrom
mlaveaux:feature/typecheck
Open

Added various parts of the well typedness checks#82
mlaveaux wants to merge 18 commits intoMERCorg:mainfrom
mlaveaux:feature/typecheck

Conversation

@mlaveaux
Copy link
Copy Markdown
Collaborator

Implemented so far:

  • Check for syntactic empty sorts
  • Perform initial name resolution on the sorts.
  • Parse and add the rules for all the standard and basic sorts.
  • Check for alias cycles.

@mlaveaux mlaveaux self-assigned this Mar 28, 2026
@mlaveaux mlaveaux added the enhancement New feature or request label Mar 28, 2026
Copilot AI review requested due to automatic review settings March 28, 2026 16:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces an initial merc_typecheck crate that starts implementing well-typedness checks for data specifications (non-emptiness, name resolution, standard/basic sort rules, and alias-cycle detection), and extends the syntax AST/visitors to support resolved sort references and flattened function sorts.

Changes:

  • Add merc_typecheck crate with name resolution, alias-cycle detection, non-emptiness checking, and standard/basic sort specification helpers.
  • Extend merc_syntax sort AST with DefId, Resolved sort references, and FlattenedFunction, updating visitors/builders/display accordingly.
  • Wire the new crate into the workspace and dependents; add small utilities/tests in merc_collections.

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
crates/typecheck/src/standard_sorts.rs Generates/instantiates standard/basic sort data specs and helper replacements.
crates/typecheck/src/non_empty.rs Adds syntactic non-emptiness checking and a regression test.
crates/typecheck/src/name_resolution.rs Implements initial sort name resolution to DefIds.
crates/typecheck/src/lib.rs Exposes the new typecheck modules.
crates/typecheck/src/is_well_typed.rs Adds well-typedness checks and defines WellTypedError plus tests.
crates/typecheck/src/is_finite.rs Adds a finiteness predicate for sorts.
crates/typecheck/src/data_specification.rs Adds a DataSpecification::from_untyped pipeline (flatten, resolve, cycle-check, well-typed checks).
crates/typecheck/src/alias.rs Adds alias-cycle detection via SCC decomposition plus tests.
crates/typecheck/Cargo.toml Declares the new merc_typecheck crate.
crates/syntax/src/visitor.rs Updates sort-expression visiting APIs and adds traversal support for new sort variants.
crates/syntax/src/syntax_tree_display.rs Adds display for Resolved and FlattenedFunction.
crates/syntax/src/syntax_tree.rs Renames DeclIdDefId and adds Resolved/FlattenedFunction to SortExpression.
crates/syntax/src/consume.rs Minor parsing code style adjustment.
crates/syntax/src/builder.rs Generalizes apply_sort_expression error type and supports new sort variants.
crates/sabre/Cargo.toml Adds dependency on merc_typecheck.
crates/collections/src/indexed_set.rs Adds IndexedSet::get_unchecked.
crates/collections/src/block_partition.rs Updates docs, removes a debug assert in is_empty, and adjusts tests.
Cargo.toml Adds crates/typecheck to workspace members and workspace dependencies.
Cargo.lock Adds the new merc_typecheck package entry and dependency edges.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +133 to +142
let name = format!("Struct{}", name);

let spec = formatdoc!(
"sort {name}

"
);

UntypedDataSpecification::parse(&spec)
} else {
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

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

structured_sort_spec generates a sort declaration string without a terminating semicolon (e.g., sort StructX), which is unlikely to be accepted by the mCRL2 parser (other sort decls use sort D;). This will make UntypedDataSpecification::parse(&spec) fail at runtime for structured sorts; include the semicolon and any required body per the expected grammar.

Copilot uses AI. Check for mistakes.
@mlaveaux mlaveaux force-pushed the feature/typecheck branch from 75fc011 to 419b5f9 Compare April 1, 2026 16:44
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.

2 participants