Emit a benign dummy value for MLdummy (#14) - #18
Merged
Conversation
An MLdummy is the residue of erased logical (Prop) content. Unlike MLexn/MLaxiom it is a normal value that extracted code passes around and may even apply at runtime, so it must not become a throwing expression (Haskell gets away with a lazy error; strict Java cannot). - MLdummy now prints as [__()], a generic method call target-typed by its context (assignment, argument, ternary branch, ...). - [class Main] gains an unconditional [__dummy] value, self-applicable like the OCaml backend's [let rec f _ = Obj.repr f], and the [static <A> A __()] accessor. - Tdummy/Tunknown type positions now print as [Object] (previously the invalid [__]); a finer type strategy (generics) is future work. New scripted test case [mldummy] extracts Prop constants directly and checks the resulting values are benign and self-applicable. Existing goldens change only by the new helper block. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
cedretaber
commented
Jul 22, 2026
| fnl() ++ fnl() ++ | ||
| str "@SuppressWarnings(\"unchecked\")" ++ | ||
| fnl() ++ | ||
| str "static <A> A __() { return (A) __dummy; }" ++ |
Author
There was a problem hiding this comment.
使う場合だけ出すようにするのが良さそうだけど、とりあえずは全部出しても良いか。
Author
|
📝 私の理解
例: Definition twice (A : Type) (f : A -> A) (x : A) : A := f (f x).
Definition weird : True := twice True (fun p => p) I.というコードがあるとき、 let weird = __この |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#14 の一部。#17 の完了分です(MLexn/MLaxiom は #13 で対応済み、本 PR が残りの MLdummy)。
MLdummy が MLexn/MLaxiom と異なる理由
MLdummyは論理的内容(Prop)の消去跡に残る値です。MLexn/MLaxiomと違って「実行が到達してはいけない場所」ではなく、抽出後のコードが保持し、引き回し、場合によっては適用すらする正常な実行時値です。したがって throw する式にしてはいけません — さもないと Prop 由来の値に触れるプログラムがクラスロード時に死にます。let __ = let rec f _ = Obj.repr f in Obj.repr f__ = Prelude.error "..."は遅延評価だから成立している実装
MLdummyは__()として出力 — generic メソッド呼び出しは poly expression なので、各出現箇所が文脈(代入・引数・三項演算子の枝など)からターゲット型付けされます。適用引数は OCaml バックエンド同様に破棄します: 抽出コードは純粋で、dummy の自己適用は dummy 自身を返すだけなので、結果に影響しません。class Mainにヘルパーを2つ追加(既存のerror/letと同じく無条件出力。pp_structはunsafe_needsを受け取れないため):__と同じトリックです。Tdummy/TunknownはObjectとして出力(従来は不正な Java となる__を出力していた)。generics によるより精密な型付けは No.5 のスコープで、本 PR では扱いません。let/error/__/__dummyを追加 — 同名の Coq 識別子が生成ヘルパーと衝突しないよう rename させます(ocaml.mlが__を予約しているのと同じ流儀。let/errorについては既存の穴も同時に修正)。テスト
新規ケース
mldummyを追加: Prop 定数(tt_prop : True、both : True /\ True)を直接抽出するとstatic Object tt_prop = __();が生成されます。driver では「値が non-null であること(axiomケースと違いクラスロードで throw しない)」と「dummy が自己適用可能であること」を検証します。既存の golden はヘルパーブロック追加分のみの変更です。全7ケース PASS。テストがトップレベル定数に限定される理由
「実行時に引数として渡される dummy」(OCaml 出力での
konst __ xの形)は、多相関数を Prop で実体化した場合にしか発生しません。その場合は出力される型にTvarが現れ、generics 未対応(No.5)の現状では Java がコンパイルできないため、テスト不能です。OCaml バックエンドをオラクルとして実験的に確認済み:Extraction Implicit+ 部分適用も eta 簡約されて単なる参照になる(dummy は出ない)したがって「適用される dummy」のシナリオは generics 対応後に初めてテスト可能になります。ヘルパー側はその時に備えて既に良性・自己適用可能に作ってあります。
🤖 Generated with Claude Code