Skip to content

Reintegrate package library entry points into main - #15

Merged
programmersd21 merged 4 commits into
mainfrom
feat/package-lib-manifest
Oct 10, 2026
Merged

programmersd21 merged 4 commits into
mainfrom
feat/package-lib-manifest

Conversation

@programmersd21

@programmersd21 programmersd21 commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Recovery PR: the original #14 is marked merged, but a fresh comparison against the current main ref still shows the four package-lib commits absent. Reapply the already-green change against main and require current CI before merging.

Summary by Sourcery

Reintegrate manifest-defined package library entry points into package installation and module resolution.

New Features:

  • Allow packages to declare an explicit .fl public entry point through the manifest's [package] lib field.
  • Resolve imports using the declared entry point while preserving legacy package layouts when no entry point is configured.

Bug Fixes:

  • Reject missing or invalid declared entry points instead of silently falling back to another module.

Documentation:

  • Document the package library entry point configuration, validation rules, and import resolution behavior.

Tests:

  • Add coverage verifying declared entry points override legacy layouts and are included in installed packages.

@sourcery-ai

sourcery-ai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Reintegrates explicit package library entry points across both runtime source copies, with manifest/path validation, strict resolution semantics, backward-compatible fallbacks, documentation, and an end-to-end package test.

Sequence diagram for package entry point resolution

sequenceDiagram
    participant Importer
    participant Runtime
    participant Package
    participant Filesystem
    Importer->>Runtime: sys_resolve_module(path)
    Runtime->>Package: pkg_declared_lib(package_dir, declared)
    Package->>Filesystem: Read flint.toml
    Filesystem-->>Package: [package] lib value
    alt lib declared
        Package->>Filesystem: Validate and locate declared .fl file
        Filesystem-->>Runtime: Entry point or missing result
        Runtime-->>Importer: Module or import error
    else lib not declared
        Runtime->>Filesystem: Check main.fl, same-named .fl, flat .fl
        Filesystem-->>Runtime: First matching legacy module
        Runtime-->>Importer: Resolved module
    end
Loading

Flow diagram for explicit package library resolution

flowchart TD
    Import["Bare package import"] --> PackageDir["Locate installed package directory"]
    PackageDir --> Manifest["Read flint.toml [package] lib"]
    Manifest --> Declared{Declared lib?}
    Declared -->|Yes| Validate["Validate relative .fl path"]
    Validate --> Entry["Resolve declared entry point"]
    Declared -->|No| Legacy["Try main.fl, same-named .fl, then flat .fl"]
    Entry --> Result["Return module or import error"]
    Legacy --> Result
Loading

File-Level Changes

Change Details Files
Add manifest-selected public library entry points while preserving legacy package layouts.
  • Document optional [package] lib semantics, validation, and fallback behavior.
  • Parse and validate the declared relative .fl path in installed package manifests.
  • Resolve declared entry points exclusively; retain main, same-named, and flat-file probing when lib is absent.
rust/flintlang/c-src/src/runtime/sys.c
src/runtime/sys.c
docs/packages.md
Cover explicit library entry-point installation and import resolution in package tests.
  • Create a package whose manifest points to a nested API module and verify it overrides main.fl.
  • Verify package installation copies the declared module.
tests/pkg_test.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Oct 10, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6e8ee88e-3a7d-4ab8-a261-8a741672affd

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@programmersd21
programmersd21 merged commit 2539829 into main Oct 10, 2026
12 checks passed

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've found 4 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/runtime/sys.c" line_range="571-573" />
<code_context>
-							        need2,
-							        "%s.fl",
+					bool has_declared_lib = false;
+					found = pkg_declared_lib(
+					        dir_main, &has_declared_lib);
+					if (!has_declared_lib) {
+						size_t need = strlen(dir_main) + 9;
+						char *main_file = malloc(need);
</code_context>
<issue_to_address>
**Invalid package entry loads another module**

When a package declares a missing or invalid `lib` target and another module with the same name is reachable, `sys_resolve_module` continues to standard-library or relative resolution, and `import_file` can try an importer sibling, so the import loads a different module instead of reporting the invalid package entry point.

When a declared `lib` target cannot be resolved, stop module resolution and report that package entry point as invalid.

Also at `rust/flintlang/c-src/src/runtime/sys.c:571-573`.
</issue_to_address>

### Comment 2
<location path="src/runtime/sys.c" line_range="487-488" />
<code_context>
+		*declared = true;
+		if (*p++ != '"')
+			break;
+		char *end = strchr(p, '"');
+		if (end == NULL)
+			break;
+		char *tail = end + 1;
</code_context>
<issue_to_address>
**Escaped entry paths fail to resolve**

When a declared `lib` path contains a TOML escape, including an escaped quote or Unicode escape, `pkg_declared_lib` reads the raw TOML value, so it treats an escaped quote as the closing delimiter or rejects the backslash instead of resolving the decoded path. The package import fails even though the decoded target is present.

Parse and decode the TOML string value before validating and resolving the declared path.

Also at `rust/flintlang/c-src/src/runtime/sys.c:487-500`, `src/runtime/sys.c:498-500`.
</issue_to_address>

### Comment 3
<location path="src/runtime/sys.c" line_range="507-510" />
<code_context>
+			if (*q == '/' || *q == '\0') {
+				size_t part_len = (size_t)(q - part);
+				if (part_len == 0 ||
+				        (part_len == 1 && part[0] == '.') ||
+				        (part_len == 2 && part[0] == '.' &&
+				                part[1] == '.')) {
+					unsafe = true;
+					break;
+				}
</code_context>
<issue_to_address>
**Dot-prefixed paths fail to resolve**

When a package declares an existing `lib` target using a `.` path component, such as `./src/api.fl`, `pkg_declared_lib` marks the `.` component unsafe and returns no target, so `sys_resolve_module` skips legacy layouts and the import fails despite the target file existing.

Allow safe `.` path components when validating an in-package declared path.

Also at `rust/flintlang/c-src/src/runtime/sys.c:507-510`.
</issue_to_address>

### Comment 4
<location path="src/runtime/sys.c" line_range="571-572" />
<code_context>
-							        need2,
-							        "%s.fl",
+					bool has_declared_lib = false;
+					found = pkg_declared_lib(
+					        dir_main, &has_declared_lib);
+					if (!has_declared_lib) {
+						size_t need = strlen(dir_main) + 9;
</code_context>
<issue_to_address>
**Declared packages are missing import hints**

When a package is available through its declared `lib` path, has no `main.fl`, and code references its name without importing it, `sys_module_file_exists` checks only `<name>/main.fl`, so `unimported_module` omits the “forgot to import” hint for the declared package.

Have `sys_module_file_exists` recognize packages resolved through their declared `lib` path.

Also at `rust/flintlang/c-src/src/runtime/sys.c:571-572`.
</issue_to_address>

Sourcery assessment

Approval pending. 3 findings to address first.

Blocking findings: src/runtime/sys.c:573, src/runtime/sys.c:488, src/runtime/sys.c:510


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/runtime/sys.c
Comment on lines +571 to +573
found = pkg_declared_lib(
dir_main, &has_declared_lib);
if (!has_declared_lib) {

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.

🟡 Medium · Invalid package entry loads another module

When a package declares a missing or invalid lib target and another module with the same name is reachable, sys_resolve_module continues to standard-library or relative resolution, and import_file can try an importer sibling, so the import loads a different module instead of reporting the invalid package entry point.

When a declared lib target cannot be resolved, stop module resolution and report that package entry point as invalid.

Also at rust/flintlang/c-src/src/runtime/sys.c:571-573.

Prompt for AI agents
In `src/runtime/sys.c` at lines 571-573:

**Invalid package entry loads another module**

When a package declares a missing or invalid `lib` target and another module with the same name is reachable, `sys_resolve_module` continues to standard-library or relative resolution, and `import_file` can try an importer sibling, so the import loads a different module instead of reporting the invalid package entry point.

When a declared `lib` target cannot be resolved, stop module resolution and report that package entry point as invalid.

Also at `rust/flintlang/c-src/src/runtime/sys.c:571-573`.

Comment thread src/runtime/sys.c
Comment on lines +487 to +488
char *end = strchr(p, '"');
if (end == NULL)

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.

🟡 Medium · Escaped entry paths fail to resolve

When a declared lib path contains a TOML escape, including an escaped quote or Unicode escape, pkg_declared_lib reads the raw TOML value, so it treats an escaped quote as the closing delimiter or rejects the backslash instead of resolving the decoded path. The package import fails even though the decoded target is present.

Parse and decode the TOML string value before validating and resolving the declared path.

Also at rust/flintlang/c-src/src/runtime/sys.c:487-500, src/runtime/sys.c:498-500.

Prompt for AI agents
In `src/runtime/sys.c` at lines 487-488:

**Escaped entry paths fail to resolve**

When a declared `lib` path contains a TOML escape, including an escaped quote or Unicode escape, `pkg_declared_lib` reads the raw TOML value, so it treats an escaped quote as the closing delimiter or rejects the backslash instead of resolving the decoded path. The package import fails even though the decoded target is present.

Parse and decode the TOML string value before validating and resolving the declared path.

Also at `rust/flintlang/c-src/src/runtime/sys.c:487-500`, `src/runtime/sys.c:498-500`.

Comment thread src/runtime/sys.c
Comment on lines +507 to +510
(part_len == 1 && part[0] == '.') ||
(part_len == 2 && part[0] == '.' &&
part[1] == '.')) {
unsafe = true;

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.

🟡 Medium · Dot-prefixed paths fail to resolve

When a package declares an existing lib target using a . path component, such as ./src/api.fl, pkg_declared_lib marks the . component unsafe and returns no target, so sys_resolve_module skips legacy layouts and the import fails despite the target file existing.

Allow safe . path components when validating an in-package declared path.

Also at rust/flintlang/c-src/src/runtime/sys.c:507-510.

Prompt for AI agents
In `src/runtime/sys.c` at lines 507-510:

**Dot-prefixed paths fail to resolve**

When a package declares an existing `lib` target using a `.` path component, such as `./src/api.fl`, `pkg_declared_lib` marks the `.` component unsafe and returns no target, so `sys_resolve_module` skips legacy layouts and the import fails despite the target file existing.

Allow safe `.` path components when validating an in-package declared path.

Also at `rust/flintlang/c-src/src/runtime/sys.c:507-510`.

Comment thread src/runtime/sys.c
Comment on lines +571 to +572
found = pkg_declared_lib(
dir_main, &has_declared_lib);

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.

⚪ Low · Declared packages are missing import hints

When a package is available through its declared lib path, has no main.fl, and code references its name without importing it, sys_module_file_exists checks only <name>/main.fl, so unimported_module omits the “forgot to import” hint for the declared package.

Have sys_module_file_exists recognize packages resolved through their declared lib path.

Also at rust/flintlang/c-src/src/runtime/sys.c:571-572.

Prompt for AI agents
In `src/runtime/sys.c` at lines 571-572:

**Declared packages are missing import hints**

When a package is available through its declared `lib` path, has no `main.fl`, and code references its name without importing it, `sys_module_file_exists` checks only `<name>/main.fl`, so `unimported_module` omits the “forgot to import” hint for the declared package.

Have `sys_module_file_exists` recognize packages resolved through their declared `lib` path.

Also at `rust/flintlang/c-src/src/runtime/sys.c:571-572`.

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