Skip to content

Conversation

@lijunchen
Copy link
Owner

No description provided.

Copilot AI review requested due to automatic review settings January 15, 2026 15:35
Copy link

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 refactors package handling by consolidating package exports and FIR interface data into a single PackageInterface struct, simplifying the build pipeline and reducing redundant data structures.

Changes:

  • Introduced PackageInterface struct to encapsulate both exports and FIR interface
  • Added build_package and link_packages helper functions to modularize compilation
  • Simplified typecheck_package return type and streamlined package processing

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

Comment on lines +125 to +130
fn build_package<'a>(
gensym: &Gensym,
diagnostics: &mut Diagnostics,
package: &'a PackageArtifact,
deps: &[&PackageInterface],
) -> (&'a PackageInterface, crate::core::File) {
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The returned &'a PackageInterface reference is unused at the call site (line 367). The function should return only crate::core::File since the interface is already accessible through the package parameter.

Copilot uses AI. Check for mistakes.
Comment on lines +125 to +136
fn build_package<'a>(
gensym: &Gensym,
diagnostics: &mut Diagnostics,
package: &'a PackageArtifact,
deps: &[&PackageInterface],
) -> (&'a PackageInterface, crate::core::File) {
let mut env = GlobalTypeEnv::new();
for dep in deps {
dep.exports.apply_to(&mut env);
}
package.interface.exports.apply_to(&mut env);

Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The environment building logic here duplicates the pattern in typecheck_packages (lines 131-135 vs lines 273-289). Consider extracting this common pattern into a helper function to reduce code duplication.

Suggested change
fn build_package<'a>(
gensym: &Gensym,
diagnostics: &mut Diagnostics,
package: &'a PackageArtifact,
deps: &[&PackageInterface],
) -> (&'a PackageInterface, crate::core::File) {
let mut env = GlobalTypeEnv::new();
for dep in deps {
dep.exports.apply_to(&mut env);
}
package.interface.exports.apply_to(&mut env);
fn build_env_from_deps_and_package(
package: &PackageArtifact,
deps: &[&PackageInterface],
) -> GlobalTypeEnv {
let mut env = GlobalTypeEnv::new();
for dep in deps {
dep.exports.apply_to(&mut env);
}
package.interface.exports.apply_to(&mut env);
env
}
fn build_package<'a>(
gensym: &Gensym,
diagnostics: &mut Diagnostics,
package: &'a PackageArtifact,
deps: &[&PackageInterface],
) -> (&'a PackageInterface, crate::core::File) {
let env = build_env_from_deps_and_package(package, deps);

Copilot uses AI. Check for mistakes.
Comment on lines +349 to 370
let mut package_cores = Vec::new();
for name in graph.discovery_order.iter() {
let package = graph
.packages
.get(name)
.ok_or_else(|| compile_error(format!("package {} not found", name)))?;
let artifact = artifacts
.get(name)
.ok_or_else(|| compile_error(format!("missing package artifact for {}", name)))?;
let package_core =
compile_match::compile_file(&genv, &gensym, &mut diagnostics, &artifact.tast);
core_toplevels.extend(package_core.toplevels);
let mut deps: Vec<_> = package.imports.iter().cloned().collect();
deps.sort();
let mut dep_interfaces = Vec::new();
for dep in deps.iter() {
let dep_artifact = artifacts
.get(dep)
.ok_or_else(|| compile_error(format!("missing package artifact for {}", dep)))?;
dep_interfaces.push(&dep_artifact.interface);
}
let (_interface, core) =
build_package(&gensym, &mut diagnostics, artifact, &dep_interfaces);
package_cores.push(core);
}
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

This loop duplicates the dependency resolution logic from typecheck_packages (lines 274-283). Both locations fetch artifacts, collect dependencies, sort them, and build interface collections. Consider extracting this pattern into a shared helper function to improve maintainability.

Copilot uses AI. Check for mistakes.
@lijunchen lijunchen merged commit 9c4df11 into main Jan 15, 2026
7 checks passed
@lijunchen lijunchen deleted the refactor branch January 15, 2026 16:02
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.

2 participants