Skip to content

Commit 1684a2b

Browse files
authored
Simplify infc interface (#139)
1 parent 230381a commit 1684a2b

File tree

16 files changed

+311
-339
lines changed

16 files changed

+311
-339
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3939

4040
### CLI
4141

42+
- Simplify `infc` and `infs build` default behavior: running without phase flags now performs full compilation and writes `out/<name>.wasm` ([#138])
43+
- `infc example.inf` equivalent to `infc example.inf --codegen -o`
44+
- `infc example.inf -v` produces both `out/example.wasm` and `out/example.v`
45+
- Supplying `--parse`, `--analyze`, or `--codegen` still overrides the default
46+
- Matches conventional compiler UX (e.g. `gcc foo.c`)
4247
- Add `BuildProfile` (Debug/Release) with `resolve_opt_level()` for target-aware optimization ([#97])
4348
- Remove external toolchain dependencies: no `inf-llc`, `rust-lld`, or platform-specific library paths required ([#125])
4449
- Defer WASM compilation until output files are actually needed (`-o` or `-v` flags) ([#97])
@@ -311,3 +316,4 @@ Initial tagged release.
311316
[#127]: https://github.com/Inferara/inference/pull/127
312317
[#134]: https://github.com/Inferara/inference/pull/135
313318
[#136]: https://github.com/Inferara/inference/pull/136
319+
[#138]: https://github.com/Inferara/inference/pull/138

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ The `infs build` command compiles a single `.inf` source file through three phas
4141
2. **Analyze** (`--analyze`) – Perform type checking and semantic validation (WIP)
4242
3. **Codegen** (`--codegen`) – Emit WebAssembly binary with optional Rocq translation
4343

44-
You must specify at least one phase flag; phases run in canonical order (parse → analyze → codegen).
44+
Phases run in canonical order (parse → analyze → codegen). When no phase flag is given, `infs build` defaults to full compilation and writes the WASM binary to disk.
4545

4646
### Basic Usage
4747

4848
```bash
49-
# Via cargo
50-
cargo run -p infs -- build path/to/file.inf --parse
49+
# Full compilation (default — no flags needed)
50+
./target/debug/infs build path/to/file.inf
5151

52-
# After building, call the binary directly
53-
./target/debug/infs build path/to/file.inf --codegen -o
52+
# Parse only (syntax check)
53+
cargo run -p infs -- build path/to/file.inf --parse
5454
```
5555

5656
### Compilation Modes

apps/infs/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,30 @@ cargo build -p infs --release
6262
### Build Command
6363

6464
```bash
65+
# Full compilation with WASM output (default — no flags needed)
66+
infs build example.inf
67+
68+
# Full compilation with Rocq translation
69+
infs build example.inf -v
70+
6571
# Parse only (syntax check)
6672
infs build example.inf --parse
6773

6874
# Type checking
6975
infs build example.inf --analyze
70-
71-
# Full compilation with WASM output
72-
infs build example.inf --codegen -o
73-
74-
# Full compilation with Rocq translation
75-
infs build example.inf --codegen -o -v
7676
```
7777

7878
### Build Flags
7979

8080
| Flag | Description |
8181
|------|-------------|
82-
| `--parse` | Run the parse phase to build the typed AST |
83-
| `--analyze` | Run the analyze phase for type checking |
82+
| `--parse` | Run the parse phase to build the typed AST (overrides default) |
83+
| `--analyze` | Run the analyze phase for type checking (overrides default) |
8484
| `--codegen` | Run the codegen phase to emit WebAssembly |
8585
| `-o` | Generate WASM binary file in `out/` directory |
8686
| `-v` | Generate Rocq (.v) translation file |
8787

88-
At least one of `--parse`, `--analyze`, or `--codegen` must be specified.
88+
When no phase flag is given, `infs build` defaults to full compilation and writes the WASM binary to disk — equivalent to `--codegen -o`.
8989

9090
### Run Command
9191

@@ -245,7 +245,7 @@ When running `build`, `run` commands, `infs` locates the `infc` compiler using t
245245
**Priority 1 - INFC_PATH**: Use for development, testing, or CI/CD with a pre-built binary:
246246
```bash
247247
export INFC_PATH=/path/to/custom/infc
248-
infs build example.inf --codegen -o
248+
infs build example.inf
249249
```
250250

251251
**Priority 2 - System PATH**: Automatic if `infc` is installed system-wide (e.g., via package manager).

apps/infs/docs/qa-test-suite.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ This document contains tests that require manual verification or are not yet aut
121121
These should be verified via CI on each platform.
122122

123123
**Steps:**
124-
1. Run `infs build trivial.inf --parse --codegen -o`
124+
1. Run `infs build trivial.inf`
125125
2. Verify WASM output exists
126126
3. Run `infs run trivial.inf --entry-point hello_world`
127127

apps/infs/src/commands/build.rs

Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
//! via subprocess. This module acts as a lightweight bootstrapper, validating
55
//! arguments and forwarding them to infc.
66
//!
7-
//! ## Compilation Phases
7+
//! ## Behavior
88
//!
9-
//! 1. **Parse** (`--parse`) - Builds the typed AST using tree-sitter
10-
//! 2. **Analyze** (`--analyze`) - Performs type checking and semantic validation
11-
//! 3. **Codegen** (`--codegen`) - Emits WebAssembly binary
9+
//! `infs build` always performs full compilation (parse, analyze, codegen)
10+
//! and writes the WASM binary to disk. The `-v` flag additionally generates
11+
//! a Rocq (.v) translation file.
1212
//!
13-
//! Phases execute in canonical order (parse -> analyze -> codegen) regardless
14-
//! of the order flags appear on the command line. Each phase depends on the previous.
13+
//! ```bash
14+
//! infs build example.inf # parse -> codegen -> write out/example.wasm
15+
//! infs build example.inf -v # parse -> codegen -> write out/example.wasm + out/example.v
16+
//! ```
1517
1618
use anyhow::{Context, Result, bail};
1719
use clap::Args;
@@ -23,42 +25,14 @@ use crate::toolchain::find_infc;
2325

2426
/// Arguments for the build command.
2527
///
26-
/// The build command operates in phases, and users must explicitly request
27-
/// which phases to run via command line flags.
28-
///
29-
/// ## Phase Dependencies
30-
///
31-
/// - `--parse`: Standalone, builds the typed AST
32-
/// - `--analyze`: Requires parsing (automatically runs parse phase)
33-
/// - `--codegen`: Requires analysis (automatically runs parse and analyze phases)
34-
///
35-
/// ## Output Flags
36-
///
37-
/// - `-o`: Generate WASM binary file in `out/` directory
38-
/// - `-v`: Generate Rocq (.v) translation in `out/` directory
39-
#[derive(Args)]
40-
#[allow(clippy::struct_excessive_bools)]
28+
/// Always performs full compilation (parse, analyze, codegen) and writes
29+
/// the WASM binary to disk. Use `-v` to also generate a Rocq (.v) file.
30+
#[derive(Args, Clone)]
4131
pub struct BuildArgs {
4232
/// Path to the source file to compile.
4333
pub path: PathBuf,
4434

45-
/// Run the parse phase to build the typed AST.
46-
#[clap(long = "parse", action = clap::ArgAction::SetTrue)]
47-
pub parse: bool,
48-
49-
/// Run the analyze phase for semantic and type inference.
50-
#[clap(long = "analyze", action = clap::ArgAction::SetTrue)]
51-
pub analyze: bool,
52-
53-
/// Run the codegen phase to emit WebAssembly binary.
54-
#[clap(long = "codegen", action = clap::ArgAction::SetTrue)]
55-
pub codegen: bool,
56-
57-
/// Generate output WASM binary file.
58-
#[clap(short = 'o', action = clap::ArgAction::SetTrue)]
59-
pub generate_wasm_output: bool,
60-
61-
/// Generate Rocq (.v) translation file.
35+
/// Generate Rocq (.v) translation file in addition to the WASM binary.
6236
#[clap(short = 'v', action = clap::ArgAction::SetTrue)]
6337
pub generate_v_output: bool,
6438
}
@@ -68,48 +42,25 @@ pub struct BuildArgs {
6842
/// ## Execution Flow
6943
///
7044
/// 1. Validates that the source file exists
71-
/// 2. Ensures at least one phase flag is specified
72-
/// 3. Locates the infc compiler binary
73-
/// 4. Builds and executes the infc command with appropriate flags
74-
/// 5. Propagates exit code from infc
45+
/// 2. Locates the infc compiler binary
46+
/// 3. Builds and executes the infc command, forwarding `-v` if requested
47+
/// 4. Propagates exit code from infc
7548
///
7649
/// ## Errors
7750
///
7851
/// Returns an error if:
7952
/// - The source file does not exist
80-
/// - No phase flags are specified
8153
/// - infc compiler cannot be found
8254
/// - infc exits with non-zero code (as `InfsError::ProcessExitCode`)
8355
pub fn execute(args: &BuildArgs) -> Result<()> {
8456
if !args.path.exists() {
8557
bail!("Path not found: {}", args.path.display());
8658
}
8759

88-
let need_parse = args.parse;
89-
let need_analyze = args.analyze;
90-
let need_codegen = args.codegen;
91-
92-
if !(need_parse || need_analyze || need_codegen) {
93-
bail!("At least one of --parse, --analyze, or --codegen must be specified");
94-
}
95-
9660
let infc_path = find_infc()?;
97-
9861
let mut cmd = Command::new(&infc_path);
9962
cmd.arg(&args.path);
10063

101-
if need_parse {
102-
cmd.arg("--parse");
103-
}
104-
if need_analyze {
105-
cmd.arg("--analyze");
106-
}
107-
if need_codegen {
108-
cmd.arg("--codegen");
109-
}
110-
if args.generate_wasm_output {
111-
cmd.arg("-o");
112-
}
11364
if args.generate_v_output {
11465
cmd.arg("-v");
11566
}

apps/infs/src/commands/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub fn execute(args: &InitArgs) -> Result<()> {
5353
println!("Initialized Inference project in {display_name}");
5454
println!();
5555
println!("Next steps:");
56-
println!(" infs build src/main.inf --codegen -o");
56+
println!(" infs build src/main.inf");
5757
println!();
5858
println!("To learn more about Inference, visit:");
5959
println!(" https://inference-lang.org");

apps/infs/src/commands/new.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn execute(args: &NewArgs) -> Result<()> {
7979
println!();
8080
println!("Next steps:");
8181
println!(" cd {}", project_path.display());
82-
println!(" infs build src/main.inf --codegen -o");
82+
println!(" infs build src/main.inf");
8383
println!();
8484
println!("To learn more about Inference, visit:");
8585
println!(" https://inference-lang.org");

0 commit comments

Comments
 (0)