modules: 모듈 경계, interface hash, 그리고 고정점 invalidation

되돌리기 비싼 결정 중 마지막 하나 — incremental 아키텍처 — 를 코드와
테스트로 닫는다.

- iface.ml: exported surface 추출과 해시. 별칭 한정(qualify)은 소비 시점에만
  일어나므로 가져오는 쪽의 별칭이 정의 모듈의 hash에 새지 않는다.
- session.ml: 모듈 로딩과 고정점 전파. hash 비교가 dependents 재검사보다
  앞선다 — 이 순서가 "본문만 수정 시 downstream 0건"의 전부다.
- 한정 이름(Alias.Type, Alias.Ctor, Alias.fn)을 타입 검사, 패턴, 소진성,
  move 검사가 모두 하나의 키("Alias.name")로 본다.
- 패키지 경로(cool.dev/std/list)는 v0에서 해소하지 않고 불투명하게 둔다.
  없다고 말하지 않는다.
- 회귀 테스트: 본문만 고치면 자기 자신만 재검사(1건), variant를 추가하면
  downstream까지 전파되고 실제로 소진성이 깨진다(2건).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019ZVDeU6KLuUVL3gs18Hm3E
This commit is contained in:
2026-08-30 14:11:30 +09:00
co-authored by Claude Opus 5
parent 5218bc59a7
commit 801a7b330b
12 changed files with 646 additions and 54 deletions
+73
View File
@@ -913,3 +913,76 @@ let () =
in
check "variant 둘일 때는 통과" (type_ok (two ^ user));
check "variant가 늘면 같은 코드가 깨진다" (type_has (three ^ user) "빠진 경우: C")
(* ------------------------------------------------------------------ *)
(* 모듈 경계와 incremental 전파 *)
(* *)
(* 이 세 검사가 아키텍처 주장 전체다: *)
(* 1. 다른 모듈의 타입과 생성자가 별칭으로 보인다 *)
(* 2. 본문만 고치면 downstream은 재검사되지 않는다 *)
(* 3. 시그니처를 고치면 downstream까지 전파되고, 실제로 깨진다 *)
(* ------------------------------------------------------------------ *)
let has_sub hay needle =
let n = String.length needle and h = String.length hay in
let rec go i = i + n <= h && (String.sub hay i n = needle || go (i + 1)) in
n = 0 || go 0
let write file s =
let oc = open_out_bin file in
output_string oc s;
close_out oc
let () =
let dir = Filename.concat (Filename.get_temp_dir_name ()) "cool_modtest" in
ignore (Sys.command (Printf.sprintf "mkdir -p %s" (Filename.quote dir)));
let a = Filename.concat dir "shapes.cool" in
let b = Filename.concat dir "area.cool" in
let shapes_body body =
"pub enum Shape {\n\
\ Circle(Int),\n\
\ Square(Int),\n\
}\n\n\
pub fn double(n: Int) -> Int {\n\
\ " ^ body ^ "\n}\n"
in
let shapes_three =
"pub enum Shape {\n\
\ Circle(Int),\n\
\ Square(Int),\n\
\ Tri(Int),\n\
}\n\n\
pub fn double(n: Int) -> Int {\n\
\ n + n\n\
}\n"
in
let area =
"import \"shapes\" as Shapes\n\n\
pub fn area(s: Shapes.Shape) -> Int {\n\
\ match s {\n\
\ Shapes.Circle(r) => Shapes.double(r),\n\
\ Shapes.Square(w) => w * w,\n\
\ }\n\
}\n"
in
write a (shapes_body "n + n");
write b area;
let st = Session.create ~root:dir () in
Session.load st b;
check "모듈 경계를 넘는 타입과 생성자가 보인다" (Session.errors st = []);
(* 본문만 수정 — hash가 그대로이므로 downstream은 손대지 않는다 *)
write a (shapes_body "n * 2");
let touched = Session.recheck st [ a ] in
check "본문만 고치면 자기 자신만 재검사된다" (touched = [ a ]);
check "본문 수정 후에도 오류 없음" (Session.errors st = []);
(* 시그니처 수정 — hash가 변하므로 dependents까지 전파된다 *)
write a shapes_three;
let touched = Session.recheck st [ a ] in
check "variant를 추가하면 downstream까지 전파된다" (List.mem b touched);
check "전파된 downstream이 실제로 깨진다"
(List.exists
(fun (e : Session.error) ->
e.file = b && String.length e.message > 0 && has_sub e.message "빠진 경우")
(Session.errors st))