Implement canon lower of a canon lift function in the same component (#4347)
* Implement `canon lower` of a `canon lift` function in the same component This commit implements the "degenerate" logic for implementing a function within a component that is lifted and then immediately lowered again. In this situation the lowered function will immediately generate a trap and doesn't need to implement anything else. The implementation in this commit is somewhat heavyweight but I think is probably justified moreso in future additions to the component model rather than what exactly is here right now. It's not expected that this "always trap" functionality will really be used all that often since it would generally mean a buggy component, but the functionality plumbed through here is hopefully going to be useful for implementing component-to-component adapter trampolines. Specifically this commit implements a strategy where the `canon.lower`'d function is generated by Cranelift and simply has a single trap instruction when called, doing nothing else. The main complexity comes from juggling around all the data associated with these functions, primarily plumbing through the traps into the `ModuleRegistry` to ensure that the global `is_wasm_trap_pc` function returns `true` and at runtime when we lookup information about the trap it's all readily available (e.g. translating the trapping pc to a `TrapCode`). * Fix non-component build * Fix some offset calculations * Only create one "always trap" per signature Use an internal map to deduplicate during compilation.
This commit is contained in:
@@ -98,6 +98,10 @@ pub enum TrapCode {
|
||||
/// Execution has potentially run too long and may be interrupted.
|
||||
/// This trap is resumable.
|
||||
Interrupt,
|
||||
|
||||
/// Used for the component model when functions are lifted/lowered in a way
|
||||
/// that generates a function that always traps.
|
||||
AlwaysTrapAdapter,
|
||||
// if adding a variant here be sure to update the `check!` macro below
|
||||
}
|
||||
|
||||
@@ -205,6 +209,7 @@ pub fn lookup_trap_code(section: &[u8], offset: usize) -> Option<TrapCode> {
|
||||
BadConversionToInteger
|
||||
UnreachableCodeReached
|
||||
Interrupt
|
||||
AlwaysTrapAdapter
|
||||
}
|
||||
|
||||
if cfg!(debug_assertions) {
|
||||
|
||||
Reference in New Issue
Block a user