Skip to content

✨ Add basic library functionality#238

Draft
LesterEvSe wants to merge 5 commits intoBlockstreamResearch:masterfrom
LesterEvSe:feature/basic-library-functionality
Draft

✨ Add basic library functionality#238
LesterEvSe wants to merge 5 commits intoBlockstreamResearch:masterfrom
LesterEvSe:feature/basic-library-functionality

Conversation

@LesterEvSe
Copy link
Copy Markdown
Collaborator

@LesterEvSe LesterEvSe commented Mar 16, 2026

Added

  • Support for parsing use and pub keywords.
  • The --dep flag to load external libraries.
  • The driver directory to resolve external libraries.
  • The C3 Linearization algorithm to resolve the library order within the driver directory.
  • Test coverage for the new functionality.

Updated

Change the ast.rs file in accordance with the changes mention above.

Note: This PR contains a basic implementation of library support. Therefore, improved error display, loading multiple libraries, and handling reserved words will be addressed in future PR

@LesterEvSe LesterEvSe requested a review from KyrylR March 16, 2026 12:18
@LesterEvSe LesterEvSe requested a review from delta1 as a code owner March 16, 2026 12:18
@LesterEvSe LesterEvSe added the enhancement New feature or request label Mar 16, 2026
@LesterEvSe LesterEvSe marked this pull request as draft March 16, 2026 12:19
@LesterEvSe LesterEvSe force-pushed the feature/basic-library-functionality branch 8 times, most recently from 1939b43 to 640a195 Compare March 17, 2026 09:23
@LesterEvSe LesterEvSe marked this pull request as ready for review March 17, 2026 10:30
src/parse.rs Outdated
Comment on lines +118 to +123
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub enum Visibility {
Public,
Private,
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub enum Visibility {
Public,
Private,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, Default)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub enum Visibility {
Public,
#[default]
Private,
}

@LesterEvSe LesterEvSe force-pushed the feature/basic-library-functionality branch 14 times, most recently from 45456e9 to 71daba0 Compare March 19, 2026 09:50
@LesterEvSe LesterEvSe force-pushed the feature/basic-library-functionality branch from 71daba0 to 125177d Compare March 19, 2026 10:48
@LesterEvSe LesterEvSe requested a review from KyrylR March 19, 2026 11:26
@LesterEvSe LesterEvSe force-pushed the feature/basic-library-functionality branch 8 times, most recently from 2d983a2 to 99bff73 Compare March 23, 2026 10:13
@delta1
Copy link
Copy Markdown
Collaborator

delta1 commented Mar 24, 2026

@KyrylR please re-review

@apoelstra
Copy link
Copy Markdown
Contributor

99bff73 needs rebase

@LesterEvSe LesterEvSe force-pushed the feature/basic-library-functionality branch from 99bff73 to a69d210 Compare March 25, 2026 11:17
@LesterEvSe LesterEvSe force-pushed the feature/basic-library-functionality branch from a69d210 to 3dd5f03 Compare March 25, 2026 13:09
@KyrylR
Copy link
Copy Markdown
Collaborator

KyrylR commented Mar 25, 2026

@KyrylR please re-review

Sure, on it, though it will take time, as its quite a big feature

@LesterEvSe LesterEvSe marked this pull request as draft March 26, 2026 15:55
Copy link
Copy Markdown
Contributor

@stringhandler stringhandler left a comment

Choose a reason for hiding this comment

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

3dd5f03

I'm sorry I've taken so long to review this. I do like the concept and the driver.
I would like to suggest these changes:

  1. I suggest we distinguish between local modules and package manager includes. There is no package manager at the moment, but there may be one in future.
    For local files I suggest requiring the mod keyword in the entry point file for files that need to be included. Then I suggest we introduce a crate-like keyword for referencing items that are local to the project (in the same package).
// main.simf
mod math;

// reference the math mod inside this package
use crate::math::simple_op::hash;

// versus
// reference the math package from a package manager
use math::simple_op::hash;
  1. I suggest we pre-emptively choose a name for simplicityhl packages and create a Cargo.toml like package description now. Working with the symphony idea, perhaps I can suggest part, motif,movement for the crate replacement, and composer,orchestrate, arrange for the Cargo replacement.
    This is where we ask the question: Should this happen here or in simplex, which also has a simplex.toml? Rustc and Cargo have different roles, but I would argue that the case here is different. To my knowledge, rustc compiles individual files or mods and then they are linked. We are not linking after compile, but rather before analysis in the AST. So I would suggest that the package definition (cargo.toml) should be the responsibility of simc and not simplex.

That said, perhaps smplx can have the role of package manager in future and allow downloading packages (crates) from repositories.

//! 1. **Publishing:** Create a Rust library (`cargo new --lib`), and place
//! your `.simf` files inside it. Then publish the crate to `crates.io`.
//!
//! 2. **Downloading:** In the consuming Rust project, add the published crate to
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not a fan of this approach. The registry can be cleaned at any time.

Do we even need to suggest a way of doing this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if we are going to suggest, I would suggest using git clone or http download

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.

Okay, I can either add an additional approach using Git Clone and emphasise that it is basic, or I can simply replace it entirely. I prefer the first approach. What do you think?

This is a question for @KyrylR, too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would say, don't recommend any method for downloading, let the user decide.

//!
//! ## Distributing via npm
//!
//! NPM can also be used as a simple file delivery system for SimplicityHL,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This also seems more complicated than using git or http

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.

Same as above

@LesterEvSe
Copy link
Copy Markdown
Collaborator Author

2. I suggest we pre-emptively choose a name for `simplicityhl` packages and create a `Cargo.toml` like package description now. Working with the symphony idea, perhaps I can suggest `part`, `motif`,`movement` for the `crate` replacement, and `composer`,`orchestrate`, `arrange` for the `Cargo` replacement.
   This is where we ask the question: Should this happen here or in [simplex](https://github.com/BlockstreamResearch/smplx), which also has a `simplex.toml`? Rustc and Cargo have different roles, but I would argue that the case here is different. To my knowledge, `rustc` compiles individual files or mods and then they are linked. We are not linking after compile, but rather before analysis in the AST. So I would suggest that the package definition (cargo.toml) should be the responsibility of `simc` and not `simplex`.

That said, perhaps smplx can have the role of package manager in future and allow downloading packages (crates) from repositories.

I will answer the second question right away. Based on this Simplex issue #38, we assume that the load functionality will be in Simplex.

@LesterEvSe
Copy link
Copy Markdown
Collaborator Author

LesterEvSe commented Mar 27, 2026

1. I suggest we distinguish between local modules and package manager includes. There is no package manager at the moment, but there may be one in future.
   For local files I suggest requiring the `mod` keyword in the entry point file for files that need to be included. Then I suggest we introduce a `crate`-like keyword for referencing items that are local to the project (in the same package).
// main.simf
mod math;

// reference the math mod inside this package
use crate::math::simple_op::hash;

// versus
// reference the math package from a package manager
use math::simple_op::hash;

Thanks for your review! :)
Regarding this idea, I think it is good and could be implemented in a future PR. However, for this PR it would be excessive, because we are not implementing the mod keyword at all yet, and it would require additional changes to the resolve strategy. In my opinion, it would be better to finalize and merge the current functionality with imports, and then start thinking about mod, because it has a large scope.

Could you open an issue and detail your proposed approach for the mod keyword so we can track it?

@stringhandler
Copy link
Copy Markdown
Contributor

Thanks, I will open an issue. I would say that this should be resolved before we merge this though, because otherwise there will be conflicting meanings in future.

For example, if we merge this pr as is, then use std::hashing; could be valid in files, and later on will not be valid.

In order to not incur massive changes to this PR, maybe we can settle on always requiring crate in front of the use.

use crate::math::ops;

I personally don't like crate and would prefer one of the above names, but I prefer that over having the non-crate syntax being merged in main for a bit.

@LesterEvSe
Copy link
Copy Markdown
Collaborator Author

Thanks, I will open an issue. I would say that this should be resolved before we merge this though, because otherwise there will be conflicting meanings in future.

For example, if we merge this pr as is, then use std::hashing; could be valid in files, and later on will not be valid.

In order to not incur massive changes to this PR, maybe we can settle on always requiring crate in front of the use.

use crate::math::ops;

I personally don't like crate and would prefer one of the above names, but I prefer that over having the non-crate syntax being merged in main for a bit.

Hmm, okay, that makes sense. I will think about the best way to implement it

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.

6 participants