A semantic foundation for sound gradual typing