Skip to content

Extract shared boundary_common utilities from duplicated frontend code#2

Merged
undivisible merged 3 commits into
masterfrom
devin/1782093030-refactor-boundary-common
Jun 22, 2026
Merged

Extract shared boundary_common utilities from duplicated frontend code#2
undivisible merged 3 commits into
masterfrom
devin/1782093030-refactor-boundary-common

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Seven boundary language frontends (Clojure, Crystal, D, Hare, Nim, Odin, VB) plus ECMAScript all duplicated identical scaffolding for file I/O, artifact assembly, boundary JSON extraction, and main-function injection. This PR factors that boilerplate into a new compiler::boundary_common module, eliminating ~250 lines of repetition across 8 files.

New shared helpers in boundary_common:

// Generic file-read → parse dispatch
pub fn parse_file_with<F>(path, parse_source: F) -> Result<UnifiedModule, String>

// File-read → parse + boundary → CompileArtifact
pub fn parse_artifact_with<P, B>(path, parse_source: P, extract_boundary: B) -> Result<CompileArtifact, String>

// Semantic + boundary assembly (no I/O)
pub fn artifact_from_source<P, B>(src, parse_source: P, extract_boundary: B) -> Result<CompileArtifact, String>

// First-line JSON extraction with configurable comment prefixes
pub fn extract_boundary_from_comment(src, prefixes: &[&str]) -> Option<BoundaryModule>

// Append default main() if absent
pub fn ensure_main(decls: &mut Vec<Decl>)

Each frontend now declares only a BOUNDARY_PREFIXES const and its language-specific parsing logic, delegating everything else to the shared module. Behavior is unchanged—all existing boundary tests pass.

Link to Devin session: https://app.devin.ai/sessions/044d1730fc5f41e2ae796230b73a3482
Requested by: @undivisible

Seven boundary language frontends (Clojure, Crystal, D, Hare, Nim, Odin, VB)
plus the ECMAScript boundary all duplicated the same scaffolding: read a file,
parse source, extract inline boundary JSON from the first-line comment, combine
semantic + boundary into a CompileArtifact, and inject a default main function.

New module compiler::boundary_common provides:
- parse_file_with: generic file-read + parse dispatch
- parse_artifact_with: file-read + parse + boundary extraction
- artifact_from_source: semantic + boundary -> CompileArtifact
- extract_boundary_from_comment: first-line JSON extraction with configurable
  comment prefixes
- ensure_main: append default main if none present

Each frontend now delegates to these helpers and only retains its language-
specific declaration parsing logic. Eliminates ~250 lines of duplicated code
across 8 files while preserving identical behavior (all existing tests pass).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@undivisible undivisible self-assigned this Jun 22, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

undivisible and others added 2 commits June 22, 2026 01:52
Latest stable rustfmt (1.96.0) reformats several long lines that were
previously accepted. This is a whole-crate format pass.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Replace or_else(|| match ...) with or(match ...) where the closure
captures no state (unnecessary_lazy_evaluations), and collapse nested
if into if-let chain (collapsible_if).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@undivisible undivisible merged commit 9c5ac19 into master Jun 22, 2026
10 of 12 checks passed
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