8000 internal: validate virtual pkg usage by Young-Flash · Pull Request #785 · moonbitlang/moon · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

internal: validate virtual pkg usage #785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2025
Merged

Conversation

Young-Flash
Copy link
Collaborator

No description provided.

Copy link
peter-jerry-ye-code-review bot commented Apr 30, 2025
Potential memory issue in core dependency replacement

Category
Correctness
Code Snippet
crates/moonbuild/src/gen/gen_build.rs:248-252
fn replace_virtual_pkg_core_with_impl_pkg_core(
m: &ModuleDB,
pkg: &Package,
core_deps: &mut [String],
)
Recommendation
Consider keeping the function signature with Vec for more flexibility:

fn replace_virtual_pkg_core_with_impl_pkg_core(
    m: &ModuleDB,
    pkg: &Package,
    core_deps: &mut Vec<String>,
)```
**Reasoning**
Changing from &mut Vec<String> to &mut [String] prevents the function from resizing the array if needed. While the current implementation works, it's more restrictive and could cause issues if future modifications require adding or removing elements.

</details>
<details>

<summary> Validation logic could be better organized </summary>

**Category**
Maintainability
**Code Snippet**
crates/moonutil/src/module.rs:524-622
pub fn validate_virtual_pkg(&self)
**Recommendation**
Split validation into smaller, focused functions:
```rust
impl ModuleDB {
    fn validate_virtual_pkg(&self) -> anyhow::Result<()> {
        self.validate_virtual_pkg_impl_constraints()?;
        self.validate_virtual_pkg_overrides()?;
        Ok(())
    }
    
    fn validate_virtual_pkg_impl_constraints(&self) -> anyhow::Result<()> {...}
    fn validate_virtual_pkg_overrides(&self) -> anyhow::Result<()> {...}
}```
**Reasoning**
The current validate_virtual_pkg function is quite long and handles multiple concerns. Breaking it into smaller, focused functions would improve readability and maintainability while making the code easier to test.

</details>
<details>

<summary> Missing validation for circular implementation dependencies </summary>

**Category**
Correctness
**Code Snippet**
crates/moonutil/src/module.rs:524
pub fn validate_virtual_pkg(&self)
**Recommendation**
Add validation to detect circular dependencies:
```rust
fn check_circular_impl(&self, pkg: &Package, seen: &mut HashSet<String>) -> anyhow::Result<()> {
    if let Some(impl_pkg) = &pkg.implement {
        if !seen.insert(impl_pkg.clone()) {
            bail!("Circular implementation dependency detected");
        }
        self.check_circular_impl(&self.get_package_by_name(impl_pkg), seen)?;
    }
    Ok(())
}```
**Reasoning**
The current validation doesn't prevent circular dependencies where package A implements B which implements C which implements A. This could lead to build issues or infinite recursion.

</details>

@Young-Flash Young-Flash force-pushed the validate_virtual_pkg branch from bb4c758 to ee4e4c0 Compare April 30, 2025 05:52
@Young-Flash Young-Flash force-pushed the validate_virtual_pkg branch from ee4e4c0 to 9398a6d Compare April 30, 2025 06:07
@Young-Flash Young-Flash merged commit c7bd59b into main Apr 30, 2025
9 of 13 checks passed
@Young-Flash Young-Flash deleted the validate_virtual_pkg branch April 30, 2025 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0