]> git.lizzy.rs Git - rust.git/blob - src/librustc/metadata/creader.rs
rollup merge of #24711: alexcrichton/fs2.1
[rust.git] / src / librustc / metadata / creader.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(non_camel_case_types)]
12
13 //! Validates all used crates and extern libraries and loads their metadata
14
15 use back::svh::Svh;
16 use session::{config, Session};
17 use session::search_paths::PathKind;
18 use metadata::cstore;
19 use metadata::cstore::{CStore, CrateSource, MetadataBlob};
20 use metadata::decoder;
21 use metadata::loader;
22 use metadata::loader::CratePaths;
23
24 use std::path::PathBuf;
25 use std::rc::Rc;
26 use std::fs;
27
28 use syntax::ast;
29 use syntax::abi;
30 use syntax::attr;
31 use syntax::attr::AttrMetaMethods;
32 use syntax::codemap::{self, Span, mk_sp, Pos};
33 use syntax::parse;
34 use syntax::parse::token::InternedString;
35 use syntax::parse::token;
36 use syntax::visit;
37 use log;
38
39 pub struct CrateReader<'a> {
40     sess: &'a Session,
41     next_crate_num: ast::CrateNum,
42 }
43
44 impl<'a, 'v> visit::Visitor<'v> for CrateReader<'a> {
45     fn visit_item(&mut self, a: &ast::Item) {
46         self.process_item(a);
47         visit::walk_item(self, a);
48     }
49 }
50
51 fn dump_crates(cstore: &CStore) {
52     debug!("resolved crates:");
53     cstore.iter_crate_data_origins(|_, data, opt_source| {
54         debug!("  name: {}", data.name());
55         debug!("  cnum: {}", data.cnum);
56         debug!("  hash: {}", data.hash());
57         opt_source.map(|cs| {
58             let CrateSource { dylib, rlib, cnum: _ } = cs;
59             dylib.map(|dl| debug!("  dylib: {}", dl.0.display()));
60             rlib.map(|rl|  debug!("   rlib: {}", rl.0.display()));
61         });
62     })
63 }
64
65 fn should_link(i: &ast::Item) -> bool {
66     !attr::contains_name(&i.attrs, "no_link")
67 }
68
69 struct CrateInfo {
70     ident: String,
71     name: String,
72     id: ast::NodeId,
73     should_link: bool,
74 }
75
76 pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
77     let say = |s: &str| {
78         match (sp, sess) {
79             (_, None) => panic!("{}", s),
80             (Some(sp), Some(sess)) => sess.span_err(sp, s),
81             (None, Some(sess)) => sess.err(s),
82         }
83     };
84     if s.is_empty() {
85         say("crate name must not be empty");
86     }
87     for c in s.chars() {
88         if c.is_alphanumeric() { continue }
89         if c == '_'  { continue }
90         say(&format!("invalid character `{}` in crate name: `{}`", c, s));
91     }
92     match sess {
93         Some(sess) => sess.abort_if_errors(),
94         None => {}
95     }
96 }
97
98
99 fn register_native_lib(sess: &Session,
100                        span: Option<Span>,
101                        name: String,
102                        kind: cstore::NativeLibraryKind) {
103     if name.is_empty() {
104         match span {
105             Some(span) => {
106                 sess.span_err(span, "#[link(name = \"\")] given with \
107                                      empty name");
108             }
109             None => {
110                 sess.err("empty library name given via `-l`");
111             }
112         }
113         return
114     }
115     let is_osx = sess.target.target.options.is_like_osx;
116     if kind == cstore::NativeFramework && !is_osx {
117         let msg = "native frameworks are only available on OSX targets";
118         match span {
119             Some(span) => sess.span_err(span, msg),
120             None => sess.err(msg),
121         }
122     }
123     sess.cstore.add_used_library(name, kind);
124 }
125
126 // Extra info about a crate loaded for plugins or exported macros.
127 struct ExtensionCrate {
128     metadata: PMDSource,
129     dylib: Option<PathBuf>,
130     target_only: bool,
131 }
132
133 enum PMDSource {
134     Registered(Rc<cstore::crate_metadata>),
135     Owned(MetadataBlob),
136 }
137
138 impl PMDSource {
139     pub fn as_slice<'a>(&'a self) -> &'a [u8] {
140         match *self {
141             PMDSource::Registered(ref cmd) => cmd.data(),
142             PMDSource::Owned(ref mdb) => mdb.as_slice(),
143         }
144     }
145 }
146
147 impl<'a> CrateReader<'a> {
148     pub fn new(sess: &'a Session) -> CrateReader<'a> {
149         CrateReader {
150             sess: sess,
151             next_crate_num: sess.cstore.next_crate_num(),
152         }
153     }
154
155     // Traverses an AST, reading all the information about use'd crates and
156     // extern libraries necessary for later resolving, typechecking, linking,
157     // etc.
158     pub fn read_crates(&mut self, krate: &ast::Crate) {
159         self.process_crate(krate);
160         visit::walk_crate(self, krate);
161
162         if log_enabled!(log::DEBUG) {
163             dump_crates(&self.sess.cstore);
164         }
165
166         for &(ref name, kind) in &self.sess.opts.libs {
167             register_native_lib(self.sess, None, name.clone(), kind);
168         }
169     }
170
171     fn process_crate(&self, c: &ast::Crate) {
172         for a in c.attrs.iter().filter(|m| m.name() == "link_args") {
173             match a.value_str() {
174                 Some(ref linkarg) => self.sess.cstore.add_used_link_args(&linkarg),
175                 None => { /* fallthrough */ }
176             }
177         }
178     }
179
180     fn extract_crate_info(&self, i: &ast::Item) -> Option<CrateInfo> {
181         match i.node {
182             ast::ItemExternCrate(ref path_opt) => {
183                 let ident = token::get_ident(i.ident);
184                 debug!("resolving extern crate stmt. ident: {} path_opt: {:?}",
185                        ident, path_opt);
186                 let name = match *path_opt {
187                     Some(name) => {
188                         validate_crate_name(Some(self.sess), name.as_str(),
189                                             Some(i.span));
190                         name.as_str().to_string()
191                     }
192                     None => ident.to_string(),
193                 };
194                 Some(CrateInfo {
195                     ident: ident.to_string(),
196                     name: name,
197                     id: i.id,
198                     should_link: should_link(i),
199                 })
200             }
201             _ => None
202         }
203     }
204
205     fn process_item(&mut self, i: &ast::Item) {
206         match i.node {
207             ast::ItemExternCrate(_) => {
208                 if !should_link(i) {
209                     return;
210                 }
211
212                 match self.extract_crate_info(i) {
213                     Some(info) => {
214                         let (cnum, _, _) = self.resolve_crate(&None,
215                                                               &info.ident,
216                                                               &info.name,
217                                                               None,
218                                                               i.span,
219                                                               PathKind::Crate);
220                         self.sess.cstore.add_extern_mod_stmt_cnum(info.id, cnum);
221                     }
222                     None => ()
223                 }
224             }
225             ast::ItemForeignMod(ref fm) => {
226                 if fm.abi == abi::Rust || fm.abi == abi::RustIntrinsic {
227                     return;
228                 }
229
230                 // First, add all of the custom link_args attributes
231                 let link_args = i.attrs.iter()
232                     .filter_map(|at| if at.name() == "link_args" {
233                         Some(at)
234                     } else {
235                         None
236                     })
237                     .collect::<Vec<&ast::Attribute>>();
238                 for m in &link_args {
239                     match m.value_str() {
240                         Some(linkarg) => self.sess.cstore.add_used_link_args(&linkarg),
241                         None => { /* fallthrough */ }
242                     }
243                 }
244
245                 // Next, process all of the #[link(..)]-style arguments
246                 let link_args = i.attrs.iter()
247                     .filter_map(|at| if at.name() == "link" {
248                         Some(at)
249                     } else {
250                         None
251                     })
252                     .collect::<Vec<&ast::Attribute>>();
253                 for m in &link_args {
254                     match m.meta_item_list() {
255                         Some(items) => {
256                             let kind = items.iter().find(|k| {
257                                 k.name() == "kind"
258                             }).and_then(|a| a.value_str());
259                             let kind = match kind {
260                                 Some(k) => {
261                                     if k == "static" {
262                                         cstore::NativeStatic
263                                     } else if self.sess.target.target.options.is_like_osx
264                                               && k == "framework" {
265                                         cstore::NativeFramework
266                                     } else if k == "framework" {
267                                         cstore::NativeFramework
268                                     } else if k == "dylib" {
269                                         cstore::NativeUnknown
270                                     } else {
271                                         self.sess.span_err(m.span,
272                                             &format!("unknown kind: `{}`",
273                                                     k));
274                                         cstore::NativeUnknown
275                                     }
276                                 }
277                                 None => cstore::NativeUnknown
278                             };
279                             let n = items.iter().find(|n| {
280                                 n.name() == "name"
281                             }).and_then(|a| a.value_str());
282                             let n = match n {
283                                 Some(n) => n,
284                                 None => {
285                                     self.sess.span_err(m.span,
286                                         "#[link(...)] specified without \
287                                          `name = \"foo\"`");
288                                     InternedString::new("foo")
289                                 }
290                             };
291                             register_native_lib(self.sess, Some(m.span),
292                                                 n.to_string(), kind);
293                         }
294                         None => {}
295                     }
296                 }
297             }
298             _ => { }
299         }
300     }
301
302     fn existing_match(&self, name: &str, hash: Option<&Svh>, kind: PathKind)
303                       -> Option<ast::CrateNum> {
304         let mut ret = None;
305         self.sess.cstore.iter_crate_data(|cnum, data| {
306             if data.name != name { return }
307
308             match hash {
309                 Some(hash) if *hash == data.hash() => { ret = Some(cnum); return }
310                 Some(..) => return,
311                 None => {}
312             }
313
314             // When the hash is None we're dealing with a top-level dependency
315             // in which case we may have a specification on the command line for
316             // this library. Even though an upstream library may have loaded
317             // something of the same name, we have to make sure it was loaded
318             // from the exact same location as well.
319             //
320             // We're also sure to compare *paths*, not actual byte slices. The
321             // `source` stores paths which are normalized which may be different
322             // from the strings on the command line.
323             let source = self.sess.cstore.get_used_crate_source(cnum).unwrap();
324             if let Some(locs) = self.sess.opts.externs.get(name) {
325                 let found = locs.iter().any(|l| {
326                     let l = fs::canonicalize(l).ok();
327                     source.dylib.as_ref().map(|p| &p.0) == l.as_ref() ||
328                     source.rlib.as_ref().map(|p| &p.0) == l.as_ref()
329                 });
330                 if found {
331                     ret = Some(cnum);
332                 }
333                 return
334             }
335
336             // Alright, so we've gotten this far which means that `data` has the
337             // right name, we don't have a hash, and we don't have a --extern
338             // pointing for ourselves. We're still not quite yet done because we
339             // have to make sure that this crate was found in the crate lookup
340             // path (this is a top-level dependency) as we don't want to
341             // implicitly load anything inside the dependency lookup path.
342             let prev_kind = source.dylib.as_ref().or(source.rlib.as_ref())
343                                   .unwrap().1;
344             if ret.is_none() && (prev_kind == kind || prev_kind == PathKind::All) {
345                 ret = Some(cnum);
346             }
347         });
348         return ret;
349     }
350
351     fn register_crate(&mut self,
352                       root: &Option<CratePaths>,
353                       ident: &str,
354                       name: &str,
355                       span: Span,
356                       lib: loader::Library)
357                       -> (ast::CrateNum, Rc<cstore::crate_metadata>,
358                           cstore::CrateSource) {
359         // Claim this crate number and cache it
360         let cnum = self.next_crate_num;
361         self.next_crate_num += 1;
362
363         // Stash paths for top-most crate locally if necessary.
364         let crate_paths = if root.is_none() {
365             Some(CratePaths {
366                 ident: ident.to_string(),
367                 dylib: lib.dylib.clone().map(|p| p.0),
368                 rlib:  lib.rlib.clone().map(|p| p.0),
369             })
370         } else {
371             None
372         };
373         // Maintain a reference to the top most crate.
374         let root = if root.is_some() { root } else { &crate_paths };
375
376         let loader::Library { dylib, rlib, metadata } = lib;
377
378         let cnum_map = self.resolve_crate_deps(root, metadata.as_slice(), span);
379         let codemap_import_info = import_codemap(self.sess.codemap(), &metadata);
380
381         let cmeta = Rc::new( cstore::crate_metadata {
382             name: name.to_string(),
383             data: metadata,
384             cnum_map: cnum_map,
385             cnum: cnum,
386             codemap_import_info: codemap_import_info,
387             span: span,
388         });
389
390         let source = cstore::CrateSource {
391             dylib: dylib,
392             rlib: rlib,
393             cnum: cnum,
394         };
395
396         self.sess.cstore.set_crate_data(cnum, cmeta.clone());
397         self.sess.cstore.add_used_crate_source(source.clone());
398         (cnum, cmeta, source)
399     }
400
401     fn resolve_crate(&mut self,
402                      root: &Option<CratePaths>,
403                      ident: &str,
404                      name: &str,
405                      hash: Option<&Svh>,
406                      span: Span,
407                      kind: PathKind)
408                          -> (ast::CrateNum, Rc<cstore::crate_metadata>,
409                              cstore::CrateSource) {
410         match self.existing_match(name, hash, kind) {
411             None => {
412                 let mut load_ctxt = loader::Context {
413                     sess: self.sess,
414                     span: span,
415                     ident: ident,
416                     crate_name: name,
417                     hash: hash.map(|a| &*a),
418                     filesearch: self.sess.target_filesearch(kind),
419                     target: &self.sess.target.target,
420                     triple: &self.sess.opts.target_triple,
421                     root: root,
422                     rejected_via_hash: vec!(),
423                     rejected_via_triple: vec!(),
424                     rejected_via_kind: vec!(),
425                     should_match_name: true,
426                 };
427                 let library = load_ctxt.load_library_crate();
428                 self.register_crate(root, ident, name, span, library)
429             }
430             Some(cnum) => (cnum,
431                            self.sess.cstore.get_crate_data(cnum),
432                            self.sess.cstore.get_used_crate_source(cnum).unwrap())
433         }
434     }
435
436     // Go through the crate metadata and load any crates that it references
437     fn resolve_crate_deps(&mut self,
438                           root: &Option<CratePaths>,
439                           cdata: &[u8], span : Span)
440                        -> cstore::cnum_map {
441         debug!("resolving deps of external crate");
442         // The map from crate numbers in the crate we're resolving to local crate
443         // numbers
444         decoder::get_crate_deps(cdata).iter().map(|dep| {
445             debug!("resolving dep crate {} hash: `{}`", dep.name, dep.hash);
446             let (local_cnum, _, _) = self.resolve_crate(root,
447                                                    &dep.name,
448                                                    &dep.name,
449                                                    Some(&dep.hash),
450                                                    span,
451                                                    PathKind::Dependency);
452             (dep.cnum, local_cnum)
453         }).collect()
454     }
455
456     fn read_extension_crate(&mut self, span: Span, info: &CrateInfo) -> ExtensionCrate {
457         let target_triple = &self.sess.opts.target_triple[..];
458         let is_cross = target_triple != config::host_triple();
459         let mut should_link = info.should_link && !is_cross;
460         let mut target_only = false;
461         let ident = info.ident.clone();
462         let name = info.name.clone();
463         let mut load_ctxt = loader::Context {
464             sess: self.sess,
465             span: span,
466             ident: &ident[..],
467             crate_name: &name[..],
468             hash: None,
469             filesearch: self.sess.host_filesearch(PathKind::Crate),
470             target: &self.sess.host,
471             triple: config::host_triple(),
472             root: &None,
473             rejected_via_hash: vec!(),
474             rejected_via_triple: vec!(),
475             rejected_via_kind: vec!(),
476             should_match_name: true,
477         };
478         let library = match load_ctxt.maybe_load_library_crate() {
479             Some(l) => l,
480             None if is_cross => {
481                 // Try loading from target crates. This will abort later if we
482                 // try to load a plugin registrar function,
483                 target_only = true;
484                 should_link = info.should_link;
485
486                 load_ctxt.target = &self.sess.target.target;
487                 load_ctxt.triple = target_triple;
488                 load_ctxt.filesearch = self.sess.target_filesearch(PathKind::Crate);
489                 load_ctxt.load_library_crate()
490             }
491             None => { load_ctxt.report_load_errs(); unreachable!() },
492         };
493
494         let dylib = library.dylib.clone();
495         let register = should_link && self.existing_match(&info.name,
496                                                           None,
497                                                           PathKind::Crate).is_none();
498         let metadata = if register {
499             // Register crate now to avoid double-reading metadata
500             let (_, cmd, _) = self.register_crate(&None, &info.ident,
501                                 &info.name, span, library);
502             PMDSource::Registered(cmd)
503         } else {
504             // Not registering the crate; just hold on to the metadata
505             PMDSource::Owned(library.metadata)
506         };
507
508         ExtensionCrate {
509             metadata: metadata,
510             dylib: dylib.map(|p| p.0),
511             target_only: target_only,
512         }
513     }
514
515     /// Read exported macros.
516     pub fn read_exported_macros(&mut self, krate: &ast::Item) -> Vec<ast::MacroDef> {
517         let ci = self.extract_crate_info(krate).unwrap();
518         let ekrate = self.read_extension_crate(krate.span, &ci);
519
520         let source_name = format!("<{} macros>", krate.ident);
521         let mut macros = vec![];
522         decoder::each_exported_macro(ekrate.metadata.as_slice(),
523                                      &*self.sess.cstore.intr,
524             |name, attrs, body| {
525                 // NB: Don't use parse::parse_tts_from_source_str because it parses with
526                 // quote_depth > 0.
527                 let mut p = parse::new_parser_from_source_str(&self.sess.parse_sess,
528                                                               self.sess.opts.cfg.clone(),
529                                                               source_name.clone(),
530                                                               body);
531                 let lo = p.span.lo;
532                 let body = match p.parse_all_token_trees() {
533                     Ok(body) => body,
534                     Err(err) => panic!(err),
535                 };
536                 let span = mk_sp(lo, p.last_span.hi);
537                 p.abort_if_errors();
538                 macros.push(ast::MacroDef {
539                     ident: name.ident(),
540                     attrs: attrs,
541                     id: ast::DUMMY_NODE_ID,
542                     span: span,
543                     imported_from: Some(krate.ident),
544                     // overridden in plugin/load.rs
545                     export: false,
546                     use_locally: false,
547                     allow_internal_unstable: false,
548
549                     body: body,
550                 });
551                 true
552             }
553         );
554         macros
555     }
556
557     /// Look for a plugin registrar. Returns library path and symbol name.
558     pub fn find_plugin_registrar(&mut self, span: Span, name: &str)
559                                  -> Option<(PathBuf, String)> {
560         let ekrate = self.read_extension_crate(span, &CrateInfo {
561              name: name.to_string(),
562              ident: name.to_string(),
563              id: ast::DUMMY_NODE_ID,
564              should_link: false,
565         });
566
567         if ekrate.target_only {
568             // Need to abort before syntax expansion.
569             let message = format!("plugin `{}` is not available for triple `{}` \
570                                    (only found {})",
571                                   name,
572                                   config::host_triple(),
573                                   self.sess.opts.target_triple);
574             self.sess.span_err(span, &message[..]);
575             self.sess.abort_if_errors();
576         }
577
578         let registrar = decoder::get_plugin_registrar_fn(ekrate.metadata.as_slice())
579             .map(|id| decoder::get_symbol(ekrate.metadata.as_slice(), id));
580
581         match (ekrate.dylib.as_ref(), registrar) {
582             (Some(dylib), Some(reg)) => Some((dylib.to_path_buf(), reg)),
583             (None, Some(_)) => {
584                 let message = format!("plugin `{}` only found in rlib format, \
585                                        but must be available in dylib format",
586                                        name);
587                 self.sess.span_err(span, &message[..]);
588                 // No need to abort because the loading code will just ignore this
589                 // empty dylib.
590                 None
591             }
592             _ => None,
593         }
594     }
595 }
596
597 /// Imports the codemap from an external crate into the codemap of the crate
598 /// currently being compiled (the "local crate").
599 ///
600 /// The import algorithm works analogous to how AST items are inlined from an
601 /// external crate's metadata:
602 /// For every FileMap in the external codemap an 'inline' copy is created in the
603 /// local codemap. The correspondence relation between external and local
604 /// FileMaps is recorded in the `ImportedFileMap` objects returned from this
605 /// function. When an item from an external crate is later inlined into this
606 /// crate, this correspondence information is used to translate the span
607 /// information of the inlined item so that it refers the correct positions in
608 /// the local codemap (see `astencode::DecodeContext::tr_span()`).
609 ///
610 /// The import algorithm in the function below will reuse FileMaps already
611 /// existing in the local codemap. For example, even if the FileMap of some
612 /// source file of libstd gets imported many times, there will only ever be
613 /// one FileMap object for the corresponding file in the local codemap.
614 ///
615 /// Note that imported FileMaps do not actually contain the source code of the
616 /// file they represent, just information about length, line breaks, and
617 /// multibyte characters. This information is enough to generate valid debuginfo
618 /// for items inlined from other crates.
619 fn import_codemap(local_codemap: &codemap::CodeMap,
620                   metadata: &MetadataBlob)
621                   -> Vec<cstore::ImportedFileMap> {
622     let external_codemap = decoder::get_imported_filemaps(metadata.as_slice());
623
624     let imported_filemaps = external_codemap.into_iter().map(|filemap_to_import| {
625         // Try to find an existing FileMap that can be reused for the filemap to
626         // be imported. A FileMap is reusable if it is exactly the same, just
627         // positioned at a different offset within the codemap.
628         let reusable_filemap = {
629             local_codemap.files
630                          .borrow()
631                          .iter()
632                          .find(|fm| are_equal_modulo_startpos(&fm, &filemap_to_import))
633                          .map(|rc| rc.clone())
634         };
635
636         match reusable_filemap {
637             Some(fm) => {
638                 cstore::ImportedFileMap {
639                     original_start_pos: filemap_to_import.start_pos,
640                     original_end_pos: filemap_to_import.end_pos,
641                     translated_filemap: fm
642                 }
643             }
644             None => {
645                 // We can't reuse an existing FileMap, so allocate a new one
646                 // containing the information we need.
647                 let codemap::FileMap {
648                     name,
649                     start_pos,
650                     end_pos,
651                     lines,
652                     multibyte_chars,
653                     ..
654                 } = filemap_to_import;
655
656                 let source_length = (end_pos - start_pos).to_usize();
657
658                 // Translate line-start positions and multibyte character
659                 // position into frame of reference local to file.
660                 // `CodeMap::new_imported_filemap()` will then translate those
661                 // coordinates to their new global frame of reference when the
662                 // offset of the FileMap is known.
663                 let lines = lines.into_inner().map_in_place(|pos| pos - start_pos);
664                 let multibyte_chars = multibyte_chars
665                     .into_inner()
666                     .map_in_place(|mbc|
667                         codemap::MultiByteChar {
668                             pos: mbc.pos - start_pos,
669                             bytes: mbc.bytes
670                         });
671
672                 let local_version = local_codemap.new_imported_filemap(name,
673                                                                        source_length,
674                                                                        lines,
675                                                                        multibyte_chars);
676                 cstore::ImportedFileMap {
677                     original_start_pos: start_pos,
678                     original_end_pos: end_pos,
679                     translated_filemap: local_version
680                 }
681             }
682         }
683     }).collect();
684
685     return imported_filemaps;
686
687     fn are_equal_modulo_startpos(fm1: &codemap::FileMap,
688                                  fm2: &codemap::FileMap)
689                                  -> bool {
690         if fm1.name != fm2.name {
691             return false;
692         }
693
694         let lines1 = fm1.lines.borrow();
695         let lines2 = fm2.lines.borrow();
696
697         if lines1.len() != lines2.len() {
698             return false;
699         }
700
701         for (&line1, &line2) in lines1.iter().zip(lines2.iter()) {
702             if (line1 - fm1.start_pos) != (line2 - fm2.start_pos) {
703                 return false;
704             }
705         }
706
707         let multibytes1 = fm1.multibyte_chars.borrow();
708         let multibytes2 = fm2.multibyte_chars.borrow();
709
710         if multibytes1.len() != multibytes2.len() {
711             return false;
712         }
713
714         for (mb1, mb2) in multibytes1.iter().zip(multibytes2.iter()) {
715             if (mb1.bytes != mb2.bytes) ||
716                ((mb1.pos - fm1.start_pos) != (mb2.pos - fm2.start_pos)) {
717                 return false;
718             }
719         }
720
721         true
722     }
723 }