End INFERENCE.
(** * Type preservation during evaluation *)
(** The type system for RTL is not sound in that it does not guarantee progress: well-typed instructions such as [Icall] can fail because of run-time type tests (such as the equality between callee and caller's signatures).  However, the type system guarantees a type preservation property: if the execution does not fail because of a failed run-time test, the result values and register states match the static typing assumptions.  This preservation property will be useful later for the proof of semantic equivalence between [Linear] and [Mach]. Even though we do not need it for [RTL], we show preservation for [RTL] here, as a warm-up exercise and because some of the lemmas will be useful later. *)
Definition wt_regset (env: regenv) (rs: regset) : Prop :=
forall r, Val.has_type (rs#r) (env r).

Lemma wt_exec_Iop:
forall (ge: genv) env f sp op args res s rs m v,
wt_instr f env (Iop op args res s) ->
eval_operation ge sp op rs##args m = Some v ->
wt_regset env rs ->
wt_regset env (rs#res <- v).