# Michelson elaborator cleanups
## Revive onchain contracts collection
Prerequisite to next point
- https://gitlab.com/nomadic-labs/tezos/-/commits/vbot@get_contracts/
- https://gitlab.com/nomadic-labs/smart-contracts/-/merge_requests/3
### State of stored lambdas
Stored lambdas: https://gitlab.com/metastatedev/tezos/-/issues/153#note_455995114
Lambdas in big maps: none
`UNPACK`ed lambdas:
- [`exprtanLAEXhEwgMWYT3pp1C94f1izZQiZwWd8JERNr6EtMFD2hxne.tz`](https://gitlab.com/nomadic-labs/smart-contracts/-/blob/master/onchain/mainnet/scripts/exprtanLAEXhEwgMWYT3pp1C94f1izZQiZwWd8JERNr6EtMFD2hxne.tz)
- in stored lambdas
Packed lambdas in big maps: see below.
### How to get all the code?
- Code is:
- smart contracts' `code`
- lambdas
- Lambdas are:
- clear lambdas in contracts' storage or bigmaps
- bytes unpacked as a type containing lambdas
- Bytes are:
- constants in code
- clear bytes in contracts' storage or bigmaps
- bytes unpacked as a type containing bytes
So:
- collect all bytes:
1. start with contracts' constants, storages, and bigmaps
2. try to unpack them
- on success, collect bytes in them
- and do 2 recursively (it finishes as nested bytes are smaller than their container)
- collect all UNPACK types containing lambdas (can be done in Micheline)
- from contracts' code
- from all stored values, and unpacked values from 2 above
- collect lambdas trying to parse unpacked values with types collected above
- keep only the lambda part of the unpacked value
Done: https://gitlab.com/nomadic-labs/smart-contracts/-/merge_requests/4
## Remove legacy feature
```
For each `if/when legacy`:
if was introduced after the protocol currently running
add a comment to specify when it was introduced
else
if no existing contract uses it
remove it
else
add a rewriting to the stitching
```
See https://gitlab.com/nomadic-labs/tezos/-/issues/93
1. Packable contracts
- In `check_packable`
- Used in `PACK` only
2. `FAILWITH` on non-packable (added in Edo)
3. check for `well_formed_entrypoints`
- In `CREATE_CONTRACT`
- In `parse_code`
- In `typecheck_code`
4. `parse_toplevel` ignores spurious annotations
5. Will go away with annotations:
- In `merge_type_annot/merge_field_annot`
- In `parse_ty` for `T_option`
- In `parse_storage_ty`
- In `parse_(data)`
## Remove annotations
https://gitlab.com/metastatedev/tezos/-/issues/113
## Fix injectivity of types in the ty GADT
To remove `assert false` branches and help next point.
https://gitlab.com/metastatedev/tezos/-/issues/112
Ask Benjamin, he may have a patch for that already.
## Encode type properties in GADT
Typechecking has become too complex to rely only on humain brain.
Start with `comparable`.
Make sure it doesn't make everything bigger/slower (sync with Yann, hash-consing will help here).
Also consider local witnesses, like `has_big_map`.
## Random
Cons_none: type not needed in interpreter