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
+11 -9
View File
@@ -55,7 +55,8 @@ let builtin_containers = [ "List"; "Option"; "Result" ]
let rec ty_affine st (t : Ast.ty) =
match t with
| T_fn { affine; _ } -> affine
| T_named { name; args; _ } ->
| T_named { modl; name; args; _ } ->
let name = match modl with Some a -> a ^ "." ^ name | None -> name in
let self =
match Hashtbl.find_opt st.aff name with Some b -> b | None -> false
in
@@ -68,7 +69,7 @@ let rec ty_affine st (t : Ast.ty) =
(* capability가 뿌리다. struct/enum은 필드에서 전이된다. 상호 재귀 타입을 위해
변화가 없을 때까지 돈다. *)
let derive_affinity st (m : modul) =
let derive_affinity st (items : item list) =
List.iter
(fun it ->
match it with
@@ -76,7 +77,7 @@ let derive_affinity st (m : modul) =
| I_struct { name; _ } -> Hashtbl.replace st.aff name false
| I_enum { name; _ } -> Hashtbl.replace st.aff name false
| _ -> ())
m.items;
items;
let changed = ref true in
while !changed do
changed := false;
@@ -96,7 +97,7 @@ let derive_affinity st (m : modul) =
(fun v -> List.exists (ty_affine st) v.v_args)
variants)
| _ -> ())
m.items
items
done;
(* copyable 선언과 affine 필드는 공존할 수 없다 *)
List.iter
@@ -112,7 +113,7 @@ let derive_affinity st (m : modul) =
fields;
ignore pos
| _ -> ())
m.items
items
(* ------------------------------------------------------------------ *)
(* 스코프 *)
@@ -398,7 +399,8 @@ and callee_info st callee =
with
| Some f -> Some f
| None -> None)
| None -> None)
(* 모듈 별칭을 통한 호출: 가져온 함수는 "Alias.f" 키로 들어와 있다 *)
| None -> Hashtbl.find_opt st.fns (o ^ "." ^ name))
| _ -> None
(* ------------------------------------------------------------------ *)
@@ -431,7 +433,7 @@ let check_fn st (d : fn_decl) =
| _ -> ());
pop st
let check (m : modul) : error list =
let check ?(imports : item list = []) (m : modul) : error list =
let st =
{
aff = Hashtbl.create 16;
@@ -445,7 +447,7 @@ let check (m : modul) : error list =
errors = [];
}
in
derive_affinity st m;
derive_affinity st (imports @ m.items);
List.iter
(fun it ->
match it with
@@ -459,7 +461,7 @@ let check (m : modul) : error list =
(d.fn_name, { f_params = d.fn_params; f_ret = d.fn_ret }))
methods)
| _ -> ())
m.items;
(imports @ m.items);
List.iter
(fun it -> match it with I_fn { decl; _ } -> check_fn st decl | _ -> ())
m.items;