1 //! Defines `Module` and related types.
2 
3 // TODO: Should `ir::Function` really have a `name`?
4 
5 // TODO: Factor out `ir::Function`'s `ext_funcs` and `global_values` into a struct
6 // shared with `DataContext`?
7 
8 use super::HashMap;
9 use crate::data_context::DataContext;
10 use core::fmt::Display;
11 use cranelift_codegen::binemit::{CodeOffset, Reloc};
12 use cranelift_codegen::entity::{entity_impl, PrimaryMap};
13 use cranelift_codegen::ir::Function;
14 use cranelift_codegen::settings::SetError;
15 use cranelift_codegen::{binemit, MachReloc};
16 use cranelift_codegen::{ir, isa, CodegenError, CompileError, Context};
17 use cranelift_control::ControlPlane;
18 use std::borrow::ToOwned;
19 use std::string::String;
20 
21 /// A module relocation.
22 #[derive(Clone)]
23 pub struct ModuleReloc {
24     /// The offset at which the relocation applies, *relative to the
25     /// containing section*.
26     pub offset: CodeOffset,
27     /// The kind of relocation.
28     pub kind: Reloc,
29     /// The external symbol / name to which this relocation refers.
30     pub name: ModuleExtName,
31     /// The addend to add to the symbol value.
32     pub addend: i64,
33 }
34 
35 impl ModuleReloc {
36     /// Converts a `MachReloc` produced from a `Function` into a `ModuleReloc`.
37     pub fn from_mach_reloc(mach_reloc: &MachReloc, func: &Function) -> Self {
38         let name = match mach_reloc.name {
39             ir::ExternalName::User(reff) => {
40                 let name = &func.params.user_named_funcs()[reff];
41                 ModuleExtName::user(name.namespace, name.index)
42             }
43             ir::ExternalName::TestCase(_) => unimplemented!(),
44             ir::ExternalName::LibCall(libcall) => ModuleExtName::LibCall(libcall),
45             ir::ExternalName::KnownSymbol(ks) => ModuleExtName::KnownSymbol(ks),
46         };
47         Self {
48             offset: mach_reloc.offset,
49             kind: mach_reloc.kind,
50             name,
51             addend: mach_reloc.addend,
52         }
53     }
54 }
55 
56 /// A function identifier for use in the `Module` interface.
57 #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
58 pub struct FuncId(u32);
59 entity_impl!(FuncId, "funcid");
60 
61 /// Function identifiers are namespace 0 in `ir::ExternalName`
62 impl From<FuncId> for ModuleExtName {
63     fn from(id: FuncId) -> Self {
64         Self::User {
65             namespace: 0,
66             index: id.0,
67         }
68     }
69 }
70 
71 impl FuncId {
72     /// Get the `FuncId` for the function named by `name`.
73     pub fn from_name(name: &ModuleExtName) -> FuncId {
74         if let ModuleExtName::User { namespace, index } = name {
75             debug_assert_eq!(*namespace, 0);
76             FuncId::from_u32(*index)
77         } else {
78             panic!("unexpected name in DataId::from_name")
79         }
80     }
81 }
82 
83 /// A data object identifier for use in the `Module` interface.
84 #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
85 pub struct DataId(u32);
86 entity_impl!(DataId, "dataid");
87 
88 /// Data identifiers are namespace 1 in `ir::ExternalName`
89 impl From<DataId> for ModuleExtName {
90     fn from(id: DataId) -> Self {
91         Self::User {
92             namespace: 1,
93             index: id.0,
94         }
95     }
96 }
97 
98 impl DataId {
99     /// Get the `DataId` for the data object named by `name`.
100     pub fn from_name(name: &ModuleExtName) -> DataId {
101         if let ModuleExtName::User { namespace, index } = name {
102             debug_assert_eq!(*namespace, 1);
103             DataId::from_u32(*index)
104         } else {
105             panic!("unexpected name in DataId::from_name")
106         }
107     }
108 }
109 
110 /// Linkage refers to where an entity is defined and who can see it.
111 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
112 pub enum Linkage {
113     /// Defined outside of a module.
114     Import,
115     /// Defined inside the module, but not visible outside it.
116     Local,
117     /// Defined inside the module, visible outside it, and may be preempted.
118     Preemptible,
119     /// Defined inside the module, visible inside the current static linkage unit, but not outside.
120     ///
121     /// A static linkage unit is the combination of all object files passed to a linker to create
122     /// an executable or dynamic library.
123     Hidden,
124     /// Defined inside the module, and visible outside it.
125     Export,
126 }
127 
128 impl Linkage {
129     fn merge(a: Self, b: Self) -> Self {
130         match a {
131             Self::Export => Self::Export,
132             Self::Hidden => match b {
133                 Self::Export => Self::Export,
134                 Self::Preemptible => Self::Preemptible,
135                 _ => Self::Hidden,
136             },
137             Self::Preemptible => match b {
138                 Self::Export => Self::Export,
139                 _ => Self::Preemptible,
140             },
141             Self::Local => match b {
142                 Self::Export => Self::Export,
143                 Self::Hidden => Self::Hidden,
144                 Self::Preemptible => Self::Preemptible,
145                 Self::Local | Self::Import => Self::Local,
146             },
147             Self::Import => b,
148         }
149     }
150 
151     /// Test whether this linkage can have a definition.
152     pub fn is_definable(self) -> bool {
153         match self {
154             Self::Import => false,
155             Self::Local | Self::Preemptible | Self::Hidden | Self::Export => true,
156         }
157     }
158 
159     /// Test whether this linkage will have a definition that cannot be preempted.
160     pub fn is_final(self) -> bool {
161         match self {
162             Self::Import | Self::Preemptible => false,
163             Self::Local | Self::Hidden | Self::Export => true,
164         }
165     }
166 }
167 
168 /// A declared name may refer to either a function or data declaration
169 #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Debug)]
170 pub enum FuncOrDataId {
171     /// When it's a FuncId
172     Func(FuncId),
173     /// When it's a DataId
174     Data(DataId),
175 }
176 
177 /// Mapping to `ModuleExtName` is trivial based on the `FuncId` and `DataId` mapping.
178 impl From<FuncOrDataId> for ModuleExtName {
179     fn from(id: FuncOrDataId) -> Self {
180         match id {
181             FuncOrDataId::Func(funcid) => Self::from(funcid),
182             FuncOrDataId::Data(dataid) => Self::from(dataid),
183         }
184     }
185 }
186 
187 /// Information about a function which can be called.
188 #[derive(Debug)]
189 pub struct FunctionDeclaration {
190     #[allow(missing_docs)]
191     pub name: String,
192     #[allow(missing_docs)]
193     pub linkage: Linkage,
194     #[allow(missing_docs)]
195     pub signature: ir::Signature,
196 }
197 
198 impl FunctionDeclaration {
199     fn merge(&mut self, linkage: Linkage, sig: &ir::Signature) -> Result<(), ModuleError> {
200         self.linkage = Linkage::merge(self.linkage, linkage);
201         if &self.signature != sig {
202             return Err(ModuleError::IncompatibleSignature(
203                 self.name.clone(),
204                 self.signature.clone(),
205                 sig.clone(),
206             ));
207         }
208         Ok(())
209     }
210 }
211 
212 /// Error messages for all `Module` methods
213 #[derive(Debug)]
214 pub enum ModuleError {
215     /// Indicates an identifier was used before it was declared
216     Undeclared(String),
217 
218     /// Indicates an identifier was used as data/function first, but then used as the other
219     IncompatibleDeclaration(String),
220 
221     /// Indicates a function identifier was declared with a
222     /// different signature than declared previously
223     IncompatibleSignature(String, ir::Signature, ir::Signature),
224 
225     /// Indicates an identifier was defined more than once
226     DuplicateDefinition(String),
227 
228     /// Indicates an identifier was defined, but was declared as an import
229     InvalidImportDefinition(String),
230 
231     /// Wraps a `cranelift-codegen` error
232     Compilation(CodegenError),
233 
234     /// Memory allocation failure from a backend
235     Allocation {
236         /// Tell where the allocation came from
237         message: &'static str,
238         /// Io error the allocation failed with
239         err: std::io::Error,
240     },
241 
242     /// Wraps a generic error from a backend
243     Backend(anyhow::Error),
244 
245     /// Wraps an error from a flag definition.
246     Flag(SetError),
247 }
248 
249 impl<'a> From<CompileError<'a>> for ModuleError {
250     fn from(err: CompileError<'a>) -> Self {
251         Self::Compilation(err.inner)
252     }
253 }
254 
255 // This is manually implementing Error and Display instead of using thiserror to reduce the amount
256 // of dependencies used by Cranelift.
257 impl std::error::Error for ModuleError {
258     fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
259         match self {
260             Self::Undeclared { .. }
261             | Self::IncompatibleDeclaration { .. }
262             | Self::IncompatibleSignature { .. }
263             | Self::DuplicateDefinition { .. }
264             | Self::InvalidImportDefinition { .. } => None,
265             Self::Compilation(source) => Some(source),
266             Self::Allocation { err: source, .. } => Some(source),
267             Self::Backend(source) => Some(&**source),
268             Self::Flag(source) => Some(source),
269         }
270     }
271 }
272 
273 impl std::fmt::Display for ModuleError {
274     fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
275         match self {
276             Self::Undeclared(name) => {
277                 write!(f, "Undeclared identifier: {}", name)
278             }
279             Self::IncompatibleDeclaration(name) => {
280                 write!(f, "Incompatible declaration of identifier: {}", name,)
281             }
282             Self::IncompatibleSignature(name, prev_sig, new_sig) => {
283                 write!(
284                     f,
285                     "Function {} signature {:?} is incompatible with previous declaration {:?}",
286                     name, new_sig, prev_sig,
287                 )
288             }
289             Self::DuplicateDefinition(name) => {
290                 write!(f, "Duplicate definition of identifier: {}", name)
291             }
292             Self::InvalidImportDefinition(name) => {
293                 write!(
294                     f,
295                     "Invalid to define identifier declared as an import: {}",
296                     name,
297                 )
298             }
299             Self::Compilation(err) => {
300                 write!(f, "Compilation error: {}", err)
301             }
302             Self::Allocation { message, err } => {
303                 write!(f, "Allocation error: {}: {}", message, err)
304             }
305             Self::Backend(err) => write!(f, "Backend error: {}", err),
306             Self::Flag(err) => write!(f, "Flag error: {}", err),
307         }
308     }
309 }
310 
311 impl std::convert::From<CodegenError> for ModuleError {
312     fn from(source: CodegenError) -> Self {
313         Self::Compilation { 0: source }
314     }
315 }
316 
317 impl std::convert::From<SetError> for ModuleError {
318     fn from(source: SetError) -> Self {
319         Self::Flag { 0: source }
320     }
321 }
322 
323 /// A convenient alias for a `Result` that uses `ModuleError` as the error type.
324 pub type ModuleResult<T> = Result<T, ModuleError>;
325 
326 /// Information about a data object which can be accessed.
327 #[derive(Debug)]
328 pub struct DataDeclaration {
329     #[allow(missing_docs)]
330     pub name: String,
331     #[allow(missing_docs)]
332     pub linkage: Linkage,
333     #[allow(missing_docs)]
334     pub writable: bool,
335     #[allow(missing_docs)]
336     pub tls: bool,
337 }
338 
339 impl DataDeclaration {
340     fn merge(&mut self, linkage: Linkage, writable: bool, tls: bool) {
341         self.linkage = Linkage::merge(self.linkage, linkage);
342         self.writable = self.writable || writable;
343         assert_eq!(
344             self.tls, tls,
345             "Can't change TLS data object to normal or in the opposite way",
346         );
347     }
348 }
349 
350 /// A translated `ExternalName` into something global we can handle.
351 #[derive(Clone)]
352 pub enum ModuleExtName {
353     /// User defined function, converted from `ExternalName::User`.
354     User {
355         /// Arbitrary.
356         namespace: u32,
357         /// Arbitrary.
358         index: u32,
359     },
360     /// Call into a library function.
361     LibCall(ir::LibCall),
362     /// Symbols known to the linker.
363     KnownSymbol(ir::KnownSymbol),
364 }
365 
366 impl ModuleExtName {
367     /// Creates a user-defined external name.
368     pub fn user(namespace: u32, index: u32) -> Self {
369         Self::User { namespace, index }
370     }
371 }
372 
373 impl Display for ModuleExtName {
374     fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
375         match self {
376             Self::User { namespace, index } => write!(f, "u{}:{}", namespace, index),
377             Self::LibCall(lc) => write!(f, "%{}", lc),
378             Self::KnownSymbol(ks) => write!(f, "{}", ks),
379         }
380     }
381 }
382 
383 /// This provides a view to the state of a module which allows `ir::ExternalName`s to be translated
384 /// into `FunctionDeclaration`s and `DataDeclaration`s.
385 #[derive(Debug, Default)]
386 pub struct ModuleDeclarations {
387     names: HashMap<String, FuncOrDataId>,
388     functions: PrimaryMap<FuncId, FunctionDeclaration>,
389     data_objects: PrimaryMap<DataId, DataDeclaration>,
390 }
391 
392 impl ModuleDeclarations {
393     /// Get the module identifier for a given name, if that name
394     /// has been declared.
395     pub fn get_name(&self, name: &str) -> Option<FuncOrDataId> {
396         self.names.get(name).copied()
397     }
398 
399     /// Get an iterator of all function declarations
400     pub fn get_functions(&self) -> impl Iterator<Item = (FuncId, &FunctionDeclaration)> {
401         self.functions.iter()
402     }
403 
404     /// Return whether `name` names a function, rather than a data object.
405     pub fn is_function(name: &ModuleExtName) -> bool {
406         match name {
407             ModuleExtName::User { namespace, .. } => *namespace == 0,
408             ModuleExtName::LibCall(_) | ModuleExtName::KnownSymbol(_) => {
409                 panic!("unexpected module ext name")
410             }
411         }
412     }
413 
414     /// Get the `FunctionDeclaration` for the function named by `name`.
415     pub fn get_function_decl(&self, func_id: FuncId) -> &FunctionDeclaration {
416         &self.functions[func_id]
417     }
418 
419     /// Get an iterator of all data declarations
420     pub fn get_data_objects(&self) -> impl Iterator<Item = (DataId, &DataDeclaration)> {
421         self.data_objects.iter()
422     }
423 
424     /// Get the `DataDeclaration` for the data object named by `name`.
425     pub fn get_data_decl(&self, data_id: DataId) -> &DataDeclaration {
426         &self.data_objects[data_id]
427     }
428 
429     /// Declare a function in this module.
430     pub fn declare_function(
431         &mut self,
432         name: &str,
433         linkage: Linkage,
434         signature: &ir::Signature,
435     ) -> ModuleResult<(FuncId, Linkage)> {
436         // TODO: Can we avoid allocating names so often?
437         use super::hash_map::Entry::*;
438         match self.names.entry(name.to_owned()) {
439             Occupied(entry) => match *entry.get() {
440                 FuncOrDataId::Func(id) => {
441                     let existing = &mut self.functions[id];
442                     existing.merge(linkage, signature)?;
443                     Ok((id, existing.linkage))
444                 }
445                 FuncOrDataId::Data(..) => {
446                     Err(ModuleError::IncompatibleDeclaration(name.to_owned()))
447                 }
448             },
449             Vacant(entry) => {
450                 let id = self.functions.push(FunctionDeclaration {
451                     name: name.to_owned(),
452                     linkage,
453                     signature: signature.clone(),
454                 });
455                 entry.insert(FuncOrDataId::Func(id));
456                 Ok((id, self.functions[id].linkage))
457             }
458         }
459     }
460 
461     /// Declare an anonymous function in this module.
462     pub fn declare_anonymous_function(
463         &mut self,
464         signature: &ir::Signature,
465     ) -> ModuleResult<FuncId> {
466         let id = self.functions.push(FunctionDeclaration {
467             name: String::new(),
468             linkage: Linkage::Local,
469             signature: signature.clone(),
470         });
471         self.functions[id].name = format!(".L{:?}", id);
472         Ok(id)
473     }
474 
475     /// Declare a data object in this module.
476     pub fn declare_data(
477         &mut self,
478         name: &str,
479         linkage: Linkage,
480         writable: bool,
481         tls: bool,
482     ) -> ModuleResult<(DataId, Linkage)> {
483         // TODO: Can we avoid allocating names so often?
484         use super::hash_map::Entry::*;
485         match self.names.entry(name.to_owned()) {
486             Occupied(entry) => match *entry.get() {
487                 FuncOrDataId::Data(id) => {
488                     let existing = &mut self.data_objects[id];
489                     existing.merge(linkage, writable, tls);
490                     Ok((id, existing.linkage))
491                 }
492 
493                 FuncOrDataId::Func(..) => {
494                     Err(ModuleError::IncompatibleDeclaration(name.to_owned()))
495                 }
496             },
497             Vacant(entry) => {
498                 let id = self.data_objects.push(DataDeclaration {
499                     name: name.to_owned(),
500                     linkage,
501                     writable,
502                     tls,
503                 });
504                 entry.insert(FuncOrDataId::Data(id));
505                 Ok((id, self.data_objects[id].linkage))
506             }
507         }
508     }
509 
510     /// Declare an anonymous data object in this module.
511     pub fn declare_anonymous_data(&mut self, writable: bool, tls: bool) -> ModuleResult<DataId> {
512         let id = self.data_objects.push(DataDeclaration {
513             name: String::new(),
514             linkage: Linkage::Local,
515             writable,
516             tls,
517         });
518         self.data_objects[id].name = format!(".L{:?}", id);
519         Ok(id)
520     }
521 }
522 
523 /// Information about the compiled function.
524 pub struct ModuleCompiledFunction {
525     /// The size of the compiled function.
526     pub size: binemit::CodeOffset,
527 }
528 
529 /// A `Module` is a utility for collecting functions and data objects, and linking them together.
530 pub trait Module {
531     /// Return the `TargetIsa` to compile for.
532     fn isa(&self) -> &dyn isa::TargetIsa;
533 
534     /// Get all declarations in this module.
535     fn declarations(&self) -> &ModuleDeclarations;
536 
537     /// Get the module identifier for a given name, if that name
538     /// has been declared.
539     fn get_name(&self, name: &str) -> Option<FuncOrDataId> {
540         self.declarations().get_name(name)
541     }
542 
543     /// Return the target information needed by frontends to produce Cranelift IR
544     /// for the current target.
545     fn target_config(&self) -> isa::TargetFrontendConfig {
546         self.isa().frontend_config()
547     }
548 
549     /// Create a new `Context` initialized for use with this `Module`.
550     ///
551     /// This ensures that the `Context` is initialized with the default calling
552     /// convention for the `TargetIsa`.
553     fn make_context(&self) -> Context {
554         let mut ctx = Context::new();
555         ctx.func.signature.call_conv = self.isa().default_call_conv();
556         ctx
557     }
558 
559     /// Clear the given `Context` and reset it for use with a new function.
560     ///
561     /// This ensures that the `Context` is initialized with the default calling
562     /// convention for the `TargetIsa`.
563     fn clear_context(&self, ctx: &mut Context) {
564         ctx.clear();
565         ctx.func.signature.call_conv = self.isa().default_call_conv();
566     }
567 
568     /// Create a new empty `Signature` with the default calling convention for
569     /// the `TargetIsa`, to which parameter and return types can be added for
570     /// declaring a function to be called by this `Module`.
571     fn make_signature(&self) -> ir::Signature {
572         ir::Signature::new(self.isa().default_call_conv())
573     }
574 
575     /// Clear the given `Signature` and reset for use with a new function.
576     ///
577     /// This ensures that the `Signature` is initialized with the default
578     /// calling convention for the `TargetIsa`.
579     fn clear_signature(&self, sig: &mut ir::Signature) {
580         sig.clear(self.isa().default_call_conv());
581     }
582 
583     /// Declare a function in this module.
584     fn declare_function(
585         &mut self,
586         name: &str,
587         linkage: Linkage,
588         signature: &ir::Signature,
589     ) -> ModuleResult<FuncId>;
590 
591     /// Declare an anonymous function in this module.
592     fn declare_anonymous_function(&mut self, signature: &ir::Signature) -> ModuleResult<FuncId>;
593 
594     /// Declare a data object in this module.
595     fn declare_data(
596         &mut self,
597         name: &str,
598         linkage: Linkage,
599         writable: bool,
600         tls: bool,
601     ) -> ModuleResult<DataId>;
602 
603     /// Declare an anonymous data object in this module.
604     fn declare_anonymous_data(&mut self, writable: bool, tls: bool) -> ModuleResult<DataId>;
605 
606     /// Use this when you're building the IR of a function to reference a function.
607     ///
608     /// TODO: Coalesce redundant decls and signatures.
609     /// TODO: Look into ways to reduce the risk of using a FuncRef in the wrong function.
610     fn declare_func_in_func(&mut self, func_id: FuncId, func: &mut ir::Function) -> ir::FuncRef {
611         let decl = &self.declarations().functions[func_id];
612         let signature = func.import_signature(decl.signature.clone());
613         let user_name_ref = func.declare_imported_user_function(ir::UserExternalName {
614             namespace: 0,
615             index: func_id.as_u32(),
616         });
617         let colocated = decl.linkage.is_final();
618         func.import_function(ir::ExtFuncData {
619             name: ir::ExternalName::user(user_name_ref),
620             signature,
621             colocated,
622         })
623     }
624 
625     /// Use this when you're building the IR of a function to reference a data object.
626     ///
627     /// TODO: Same as above.
628     fn declare_data_in_func(&self, data: DataId, func: &mut ir::Function) -> ir::GlobalValue {
629         let decl = &self.declarations().data_objects[data];
630         let colocated = decl.linkage.is_final();
631         let user_name_ref = func.declare_imported_user_function(ir::UserExternalName {
632             namespace: 1,
633             index: data.as_u32(),
634         });
635         func.create_global_value(ir::GlobalValueData::Symbol {
636             name: ir::ExternalName::user(user_name_ref),
637             offset: ir::immediates::Imm64::new(0),
638             colocated,
639             tls: decl.tls,
640         })
641     }
642 
643     /// TODO: Same as above.
644     fn declare_func_in_data(&self, func: FuncId, ctx: &mut DataContext) -> ir::FuncRef {
645         ctx.import_function(ModuleExtName::user(0, func.as_u32()))
646     }
647 
648     /// TODO: Same as above.
649     fn declare_data_in_data(&self, data: DataId, ctx: &mut DataContext) -> ir::GlobalValue {
650         ctx.import_global_value(ModuleExtName::user(1, data.as_u32()))
651     }
652 
653     /// Define a function, producing the function body from the given `Context`.
654     ///
655     /// Returns the size of the function's code and constant data.
656     ///
657     /// Note: After calling this function the given `Context` will contain the compiled function.
658     fn define_function(
659         &mut self,
660         func: FuncId,
661         ctx: &mut Context,
662         ctrl_plane: &mut ControlPlane,
663     ) -> ModuleResult<ModuleCompiledFunction>;
664 
665     /// Define a function, taking the function body from the given `bytes`.
666     ///
667     /// This function is generally only useful if you need to precisely specify
668     /// the emitted instructions for some reason; otherwise, you should use
669     /// `define_function`.
670     ///
671     /// Returns the size of the function's code.
672     fn define_function_bytes(
673         &mut self,
674         func_id: FuncId,
675         func: &ir::Function,
676         alignment: u64,
677         bytes: &[u8],
678         relocs: &[MachReloc],
679     ) -> ModuleResult<ModuleCompiledFunction>;
680 
681     /// Define a data object, producing the data contents from the given `DataContext`.
682     fn define_data(&mut self, data: DataId, data_ctx: &DataContext) -> ModuleResult<()>;
683 }
684 
685 impl<M: Module> Module for &mut M {
686     fn isa(&self) -> &dyn isa::TargetIsa {
687         (**self).isa()
688     }
689 
690     fn declarations(&self) -> &ModuleDeclarations {
691         (**self).declarations()
692     }
693 
694     fn get_name(&self, name: &str) -> Option<FuncOrDataId> {
695         (**self).get_name(name)
696     }
697 
698     fn target_config(&self) -> isa::TargetFrontendConfig {
699         (**self).target_config()
700     }
701 
702     fn make_context(&self) -> Context {
703         (**self).make_context()
704     }
705 
706     fn clear_context(&self, ctx: &mut Context) {
707         (**self).clear_context(ctx)
708     }
709 
710     fn make_signature(&self) -> ir::Signature {
711         (**self).make_signature()
712     }
713 
714     fn clear_signature(&self, sig: &mut ir::Signature) {
715         (**self).clear_signature(sig)
716     }
717 
718     fn declare_function(
719         &mut self,
720         name: &str,
721         linkage: Linkage,
722         signature: &ir::Signature,
723     ) -> ModuleResult<FuncId> {
724         (**self).declare_function(name, linkage, signature)
725     }
726 
727     fn declare_anonymous_function(&mut self, signature: &ir::Signature) -> ModuleResult<FuncId> {
728         (**self).declare_anonymous_function(signature)
729     }
730 
731     fn declare_data(
732         &mut self,
733         name: &str,
734         linkage: Linkage,
735         writable: bool,
736         tls: bool,
737     ) -> ModuleResult<DataId> {
738         (**self).declare_data(name, linkage, writable, tls)
739     }
740 
741     fn declare_anonymous_data(&mut self, writable: bool, tls: bool) -> ModuleResult<DataId> {
742         (**self).declare_anonymous_data(writable, tls)
743     }
744 
745     fn declare_func_in_func(&mut self, func: FuncId, in_func: &mut ir::Function) -> ir::FuncRef {
746         (**self).declare_func_in_func(func, in_func)
747     }
748 
749     fn declare_data_in_func(&self, data: DataId, func: &mut ir::Function) -> ir::GlobalValue {
750         (**self).declare_data_in_func(data, func)
751     }
752 
753     fn declare_func_in_data(&self, func: FuncId, ctx: &mut DataContext) -> ir::FuncRef {
754         (**self).declare_func_in_data(func, ctx)
755     }
756 
757     fn declare_data_in_data(&self, data: DataId, ctx: &mut DataContext) -> ir::GlobalValue {
758         (**self).declare_data_in_data(data, ctx)
759     }
760 
761     fn define_function(
762         &mut self,
763         func: FuncId,
764         ctx: &mut Context,
765         ctrl_plane: &mut ControlPlane,
766     ) -> ModuleResult<ModuleCompiledFunction> {
767         (**self).define_function(func, ctx, ctrl_plane)
768     }
769 
770     fn define_function_bytes(
771         &mut self,
772         func_id: FuncId,
773         func: &ir::Function,
774         alignment: u64,
775         bytes: &[u8],
776         relocs: &[MachReloc],
777     ) -> ModuleResult<ModuleCompiledFunction> {
778         (**self).define_function_bytes(func_id, func, alignment, bytes, relocs)
779     }
780 
781     fn define_data(&mut self, data: DataId, data_ctx: &DataContext) -> ModuleResult<()> {
782         (**self).define_data(data, data_ctx)
783     }
784 }
785