Write trait IDs instead of indices in typickle
Write trait IDs instead of indices in typickle

If trait prototypes are used and merged with the actual trait, there may
be entries in the trait table which have an ID corresponding to some
other entry.

When pickling types, write the trait ID instead of the index since the
trait definitions are written with their IDs. Otherwise, we may end up
reading types referring to non-existent traits, resulting in an error
like

	Unable to find trait for id 7

Also, only pickle traits whose index matches its ID to avoid duplicates.

oridb/mc,oridb/mc,oridb/mc,oridb/mc