grammar: v0 EBNF 확정과 열린 문법 결정 8건

열려 있던 문법 항목을 언어 철학에 따라 전부 닫고 EBNF로 고정한다.

- 제네릭 인자를 대괄호로 통일(List[a], map[Int, String](...)). <>는 식
  위치에서 비교 연산자와 갈리지 않아 turbofish라는 제2 표기를 부르는데,
  effect 규칙이 명시적 인스턴스화 문법을 요구하므로 회피할 수 없다.
  대괄호는 전위=리터럴 / 후위=인스턴스화로 위치가 결정해 LL(1)이고 표기가
  하나다. 대가로 인덱싱 연산자를 두지 않는다.
- 파라미터 규칙을 callable 한정에서 전 파라미터로 일반화. 기본은 빌림,
  own만 소유 이전. capability를 예외로 두지 않는 이유는 capability의 존재가
  이미 타입과 effects 절에 드러나기 때문이다 — 표기가 실을 정보는 소유 이동뿐.
- 문 구분은 줄바꿈(Go식 자동 삽입), 블록은 식, return은 조기 탈출 전용.
  if/match를 식으로 두면 재대입이 줄어 move 검사가 단순해진다.
- match 가드 없음. 가드는 exhaustiveness를 흐리고 SMT 없이는 _ 분기를
  강요한다. 철학 1의 대표 항목을 문법 편의와 바꾸지 않는다.
- ?는 Result 전용 하드코딩. 조기 탈출도 블록 종료이므로 scope의 join/cancel이
  ? 경로에서도 실행된다. v1 linear 도입 시 이 경로가 암묵 drop 문제와 만난다.
- 수식어 순서는 바인딩(own, mut) 먼저, 타입(affine) 나중.

docs/grammar.ebnf는 LL(1)을 설계 제약으로 명시하고, effect 합집합을
결과 위치 전용 프로덕션으로 새겨 파라미터 위치의 역산을 파서가 거부하게 한다.
samples/는 확정 표기로 전면 갱신.

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 02:09:58 +09:00
co-authored by Claude Opus 5
parent e3b19b1300
commit 630d12104a
9 changed files with 329 additions and 108 deletions
+37 -26
View File
@@ -1,51 +1,54 @@
// 05. 컴파일 에러가 나야 하는 코드
//
// 각 함수는 주석에 적힌 진단 하나를 정확히 내야 한다.
// 파서·체커가 생기면 그대로 테스트 케이스가 된다.
// 체커가 생기면 그대로 테스트 케이스가 된다.
// close는 파일을 소비한다: own 유표기
pub fn close(own f: File) effects {File.close}
// [E-move-after-move] affine 값의 이중 소비
pub fn double_close(f: File) effects {File.close} {
File.close(f)
File.close(f) // ERROR: f는 이미 move됨 (앞줄에서 소비)
pub fn double_close(own f: File) effects {File.close} {
close(f)
close(f) // ERROR: f는 이미 move됨 (앞줄에서 소비)
}
// [E-move-join] 분기 병합은 보수적 합집합
pub fn conditional_close(f: File, c: Bool) effects {File.close} {
pub fn conditional_close(own f: File, c: Bool) effects {File.close} {
if c {
File.close(f)
close(f)
}
File.close(f) // ERROR: f는 이 분기에서 move됨 (조건부 소비)
close(f) // ERROR: f는 이 분기에서 move됨 (조건부 소비)
}
// 정당한 형태 — 양쪽 분기에서 소비하면 통과해야 한다.
pub fn both_branches_close(f: File, c: Bool) effects {File.close} {
pub fn both_branches_close(own f: File, c: Bool) effects {File.close} {
if c {
File.close(f)
close(f)
} else {
File.close(f)
close(f)
}
}
// [E-use-escape] use 값의 반환
pub fn leak_capability(use pay: PaymentGateway) -> PaymentGateway {
pay // ERROR: use 값은 반환할 수 없음
// [E-use-escape] 빌린 값의 반환
pub fn leak_capability(pay: PaymentGateway) -> PaymentGateway {
pay // ERROR: 빌린 값은 반환할 수 없음 (own이 아니다)
}
// [E-use-escape] use 값의 저장
// [E-use-escape] 빌린 값의 저장
pub struct Holder {
pay: PaymentGateway,
}
pub fn store_capability(use pay: PaymentGateway) -> Holder {
Holder { pay: pay } // ERROR: use 값은 struct에 저장할 수 없음
pub fn store_capability(pay: PaymentGateway) -> Holder {
Holder { pay: pay } // ERROR: 빌린 값은 struct에 저장할 수 없음
}
// [E-use-escape] use-closure를 own fn 위치에 전달
// [E-use-escape] 빌린 값을 capture한 클로저를 own 자리에 전달
pub fn register(handler: own fn()) effects {Registry.add}
pub fn escape_via_closure(use pay: PaymentGateway) effects {Registry.add} {
pub fn escape_via_closure(pay: PaymentGateway) effects {Registry.add} {
register(fn() { pay.refund(OrderId(1)) })
// ERROR: pay를 capture한 클로저는 use 값이며 own fn 위치에 전달할 수 없음
// ERROR: pay를 capture한 클로저는 빌린 값이며 own 자리에 전달할 수 없음
}
// [E-affinity-transitive] affine 필드를 가진 타입을 copyable로 선언
@@ -54,14 +57,13 @@ pub copyable struct Box {
}
// [E-callable-affinity] affine 값을 capture한 클로저를 fn 위치에 대입
// 반환 타입 위치의 callable은 무표기 owned이지만, affinity는 별개로 표기된다.
pub fn misuse_affine_closure(f: File) -> fn() effects {File.close} {
fn() { File.close(f) }
pub fn misuse_affine_closure(own f: File) -> fn() effects {File.close} {
fn() { close(f) }
// ERROR: f를 capture했으므로 타입은 affine fn()이며 fn() 위치에 대입할 수 없음
}
// [E-spawn-capture] spawn 클로저의 mutable capture
pub fn spawn_mutable(use sc: TaskScope, mut counter: Int) effects {TaskScope.spawn} {
pub fn spawn_mutable(sc: TaskScope, mut counter: Int) effects {TaskScope.spawn} {
scope sc {
sc.spawn(fn() { counter = counter + 1 })
// ERROR: spawn 클로저는 mutable 참조를 capture할 수 없음
@@ -69,13 +71,22 @@ pub fn spawn_mutable(use sc: TaskScope, mut counter: Int) effects {TaskScope.spa
}
// [E-effect-undeclared] 선언되지 않은 effect
pub fn silent_write(use log: Logger) {
pub fn silent_write(log: Logger) {
log.write("hi") // ERROR: effect Logger.write가 시그니처에 선언되지 않음
}
// [E-syntax-effect-union] 파라미터 위치의 합집합은 문법에 존재하지 않는다.
// 검사기가 거부하는 것이 아니라 파서가 거부한다.
pub fn peel<a, e: effects>(
// 검사기가 아니라 파서가 거부한다 (eff_param 프로덕션에 "|"가 없다).
pub fn peel[a, e: effects](
f: fn(a) effects e | {Logger.write},
) effects e -> fn(a)
// ERROR (parse): 파라미터 위치의 effects 절은 변수 단독 또는 리터럴 집합만 허용
// [E-syntax-match-guard] match 가드는 v0 문법에 없다
pub fn classify(e: PayError) -> String {
match e {
Network(r) if r.retryable => "retry",
// ERROR (parse): match 가드는 지원되지 않음. 분기 본문에서 if를 쓸 것
_ => "other",
}
}