Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FfiConverter for metadata generation/storage #1469

Merged
merged 6 commits into from
Mar 31, 2023

Commits on Mar 31, 2023

  1. New system for interface metadata

    - Added the `uniffi_core::metadata` module, which provides a system for
      building metadata buffers using const code.
    - Added the `FfiConverter::TYPE_ID_META` const, which holds metadata
      to identify the type.
    - Made the proc-macros generate use the new system to generate metadata
      consts, then export them using static variables.
    - Removed the current code to generate/store metadata based on the syn
      parsing.
    - Removed the type assertions and the requirement for a `uniffi_types`
      module.  We don't need them now that we`re getting the type ids from
      the type itself.
    - Made the `FnMetadata.throws` field a Type rather than a String.
    - Calculate module paths with the `module_path!()` macro.  This means we
      get accurate module paths without nightly.  Changed mod_path to be a
      String, rather than a Vec since this is what `module_path!()` outputs.
    - Added code to strip the `r#` part out of raw idents before serializing
      it into the metadata.
    - Replaced the `collect_params()` function with the `ScaffoldingBits`
      struct.  There was too much complexity for a single function -- for
      example unzip() only works with pairs, not 3-tuples.
    
    In general, the new metadata system is more reliable doing everything in
    the proc-macros.  Proc-macros can only see the type identifiers, but
    they don't anything about the underlying type, since users can rename
    types with type aliases.  It's also simpler since you don't have to walk
    the AST so much.
    
    One TODO is getting checksum working again.  One limitation of the const
    code is that we can't use it to generate function identifiers.
    bendk committed Mar 31, 2023
    Configuration menu
    Copy the full SHA
    5367a3d View commit details
    Browse the repository at this point in the history
  2. Added return handling to FfiConverter

    Added the `FfiConverter::lower_return` method.  This is like `lower()`
    but specialized for scaffolding returns.  This allows us to always use a
    single function to handle scaffolding calls, rather than
    `call_with_output` or `call_with_result` depending on if the return type
    is a `Result<>` or not.
    
    Having a single code-path for return handling simplifies the code
    generation, especially the macros.  We no longer need to try to parse
    `Result<>` type names.  This is especially useful for crates that
    type-alias their `Result<>` types.
    
    Updated the async code to work with the new system.  Now `RustFuture`
    only needs 1 generic argument.
    
    Updated `object_references.md` and removed example code that's no longer
    valid.  Replaced it with higher-level descriptions of what's going on,
    hopefully this will stay not get out of date as quickly.
    bendk committed Mar 31, 2023
    Configuration menu
    Copy the full SHA
    8e10392 View commit details
    Browse the repository at this point in the history
  3. Fixes from review.

    bendk committed Mar 31, 2023
    Configuration menu
    Copy the full SHA
    e1fcb39 View commit details
    Browse the repository at this point in the history
  4. Refactoring the rustcall/rustfuture code

    Define a lower-level version of `rust_call()` that
    `uniffi_rustfuture_poll` can use without going through so many hoops.
    bendk committed Mar 31, 2023
    Configuration menu
    Copy the full SHA
    6bd31ad View commit details
    Browse the repository at this point in the history
  5. New checksum handling

    Updated the checksum handling to work with the new proc-macro metadata
    system.  Now that the metadata is calcualted using const functions
    rather than inside the macro code, we don't have a way to include the
    checksum in the exported symbol name.
    
    Instead, calculate the metadata and store it as its own symbol.  Then
    the bindings code checks the checksums on startup as well as the
    contract ABI version.  One nice aspect of this is that we can output a
    nicer error message than just "linker error".
    
    - Added scripts to test this.
    - Added flag to allow FFIFunctions to not always have the `&mut
      RustCallStatus` arg.
    - Changed the contract version to be a u32 rather than a &str.  This
      simplifies the bindings code.
    - Added the `uniffi_meta::ffi_names` module.  This contains the
      canonical code to generate ffi symbol names.
    - Use the module path that we calculate in the proc-macro when
      generating the metadata rather than calling `module_path!()`.
      `module_path!()` returns the full module path, but it's more important
      that our metadata agrees with the module path we used whene generating
      the scaffolding.
    - Reworked the `metadata::reader` code
    - Make `uniffi_meta` depend on `uniffi_core`.  I was trying to avoid
      this, but uniffi_core is where the metadata buffer code lives and I
      don't want to duplicate it.  Maybe we could make this a separate
      crate, but it doesn't seem worth it yet since `uniffi_core`
      is fairly small.
    bendk committed Mar 31, 2023
    Configuration menu
    Copy the full SHA
    b20b228 View commit details
    Browse the repository at this point in the history
  6. Fixes from review

    bendk committed Mar 31, 2023
    Configuration menu
    Copy the full SHA
    e8e5ff6 View commit details
    Browse the repository at this point in the history