Skip to content

Add function versioning for better library management #349

@Sdoba16

Description

@Sdoba16

Project

compiler

Describe the feature

Motivation
Users will create libraries for SimplicityHL with specific functions. However, depending on the version of SimplicityHL, they would likely want to rewrite some functions with the additional functionality added in new releases. So we can create tooling for convenient usage of libraries to filter function versions in the same file.

Describe the feature
We suggest adding a #[cfg(simc "...")] attribute before a function definition to show the compiler when that specific function version should be used.

#[cfg(simc "<0.7.0")]
pub fn verify_sig(...) {
    // old logic of function
}

#[cfg(simc ">=0.7.0")]
pub fn verify_sig(...) {
    // new logic of function
}

Implementation Plan

  1. Parser Update: Add a chumsky combinator to parse the #[cfg(simc("..."))] attribute.
  2. Evaluation: Extract the SemVer string and evaluate it against the current compiler version using crate::version::VersionRequirement logic Versioning #263 .
  3. AST Pruning: If the version check fails, intercept the parser using .validate() and safely drop the item (e.g., mapping it to a dummy Item::Module).
  4. Safety: Because the unsupported function is pruned during parsing, the semantic analyzer never sees it. This guarantees that older compilers will not throw Type Error or Redefined Function errors when they encounter new code they don't understand, provided the attribute filters it out.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions