Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Src/PeasyAI/src/core/services/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
This service is UI-agnostic.
"""

import os
import subprocess
import logging
import traceback
Expand Down Expand Up @@ -85,13 +86,20 @@ def compile(self, project_path: str) -> CompilationResult:
return_code=-1,
)

# Run P compiler
# Run P compiler. Default to collecting-mode (`P_COMPILER_COLLECT_ERRORS=1`)
# so a project with N independent type errors produces all N diagnostics
# in one compile, letting PeasyAI's fix loop converge in N/k iterations
# instead of N. setdefault preserves an explicit user override (set the
# env var to "0" or "false" in the parent shell to keep strict mode).
env = os.environ.copy()
env.setdefault("P_COMPILER_COLLECT_ERRORS", "1")
result = subprocess.run(
['p', 'compile'],
capture_output=True,
cwd=project_path,
text=True,
timeout=300, # 5 minute timeout
env=env,
)

# Check for success
Expand Down
5 changes: 5 additions & 0 deletions Src/PeasyAI/src/core/services/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1442,12 +1442,17 @@ def _compile_check_candidates(
env = ensure_environment()
if env.is_valid and env.p_compiler_path:
import subprocess
# Default to collecting-mode compilation (see
# core/services/compilation.py for full rationale).
subprocess_env = os.environ.copy()
subprocess_env.setdefault("P_COMPILER_COLLECT_ERRORS", "1")
result = subprocess.run(
[env.p_compiler_path, "compile"],
cwd=project_path,
capture_output=True,
text=True,
timeout=30,
env=subprocess_env,
)
if result.returncode == 0:
logger.info(f" Candidate compiles successfully (+{COMPILE_BONUS} bonus)")
Expand Down
11 changes: 10 additions & 1 deletion Src/PeasyAI/src/utils/compile_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ def try_compile(ppath, captured_streams_output_dir):
flags = ['-pf', ppath, "-o", str(p.parent)] if p.is_file() else []

final_cmd_arr = ['p', 'compile', *flags]
result = subprocess.run(final_cmd_arr, capture_output=True, cwd=ppath if not p.is_file() else None)
# Default to collecting-mode compilation (see compilation.py for full rationale).
# setdefault preserves an explicit user override.
env = os.environ.copy()
env.setdefault("P_COMPILER_COLLECT_ERRORS", "1")
result = subprocess.run(
final_cmd_arr,
capture_output=True,
cwd=ppath if not p.is_file() else None,
env=env,
)

out_dir = f"{captured_streams_output_dir}/compile"
os.makedirs(out_dir, exist_ok=True)
Expand Down
Loading