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_Iload:
forall env f chunk addr args dst s m a v rs,
wt_instr f env (Iload chunk addr args dst s) ->
Mem.loadv chunk m a = Some v ->
wt_regset env rs ->
wt_regset env (rs#dst <- v).