tree: e42efc026cbdd25f58d063ef0a0599f53a06dbc0 [path history] [tgz]
  1. dart/
  2. fidl/
  3. go/
  4. hlcpp/
  5. llcpp/
  6. rust/
  7. BUILD.gn
  8. README.md
  9. test.json
  10. test_gn_sidecar.json
src/tests/fidl/source_compatibility/protocol-method-remove/README.md

Remove a protocol method

Overview

-initstep 1step 2step 3step 4
fidllinklinklink
dartlinklink
golinklinklink
hlcpplinklink
llcpplinklink
rustlinklinklink

Initial State

FIDL

protocol Example {
    ExistingMethod();
    OldMethod();
};

Dart

class Server extends fidllib.Example {
  @override
  Future<void> existingMethod() async {}

  @override
  Future<void> oldMethod() async {}
}

void client(fidllib.ExampleProxy client) async {
  await client.existingMethod();
  await client.oldMethod();
}

Go

type client struct {
	removeMethod *lib.ExampleWithCtxInterface
}

func (c client) test() {
	c.removeMethod.ExistingMethod(context.Background())
	c.removeMethod.OldMethod(context.Background())
}

type server struct{}

// Assert that server implements the Example interface
var _ lib.ExampleWithCtx = &server{}

func (*server) ExistingMethod(fidl.Context) error {
	return nil
}

func (*server) OldMethod(fidl.Context) error {
	return nil
}

HLCPP

class Server : public fidl_test::Example {
  void ExistingMethod() final {}
  void OldMethod() final {}
};

void client(fidl_test::ExamplePtr client) {
  client->ExistingMethod();
  client->OldMethod();
}

LLCPP

class Server final : public fidl_test::Example::Interface {
 public:
  void ExistingMethod(ExistingMethodCompleter::Sync& completer) final {}
  void OldMethod(OldMethodCompleter::Sync& completer) final {}
};

void client(fidl::Client<fidl_test::Example> client) {
  client->ExistingMethod();
  client->OldMethod();
}

Rust

struct ExampleFakeProxy;

impl fidl_lib::ExampleProxyInterface for ExampleFakeProxy {
    fn existing_method(&self) -> Result<(), fidl::Error> {
        Ok(())
    }
    fn old_method(&self) -> Result<(), fidl::Error> {
        Ok(())
    }
}

async fn example_service(chan: fasync::Channel) -> Result<(), fidl::Error> {
    let mut stream = fidl_lib::ExampleRequestStream::from_channel(chan);
    while let Some(req) = stream.try_next().await? {
        match req {
            fidl_lib::ExampleRequest::ExistingMethod { .. } => {}
            fidl_lib::ExampleRequest::OldMethod { .. } => {}
        }
    }
    Ok(())
}

Update FIDL Library

  • Mark the method that is being removed with the [Transitional] attribute.
  protocol Example {
      ExistingMethod();
+     [Transitional]
      OldMethod();
  };

Update Source Code

Dart

  • Remove references to the method in client code and server code.
  class Server extends fidllib.Example {
    @override
    Future<void> existingMethod() async {}
- 
-   @override
-   Future<void> oldMethod() async {}
  }
  
  void client(fidllib.ExampleProxy client) async {
    await client.existingMethod();
-   await client.oldMethod();
  }

Go

  • Embed the protocol's WithCtxTransitionBase struct into the server type.
  • Remove the implementation for the method being removed from the server.
  • Remove any references to the method in client code (e.g. request calls being made)
  type client struct {
  	removeMethod *lib.ExampleWithCtxInterface
  }
  
  func (c client) test() {
  	c.removeMethod.ExistingMethod(context.Background())
- 	c.removeMethod.OldMethod(context.Background())
  }
  
- type server struct{}
+ type server struct {
+ 	lib.ExampleWithCtxInterface
+ }
  
  // Assert that server implements the Example interface
  var _ lib.ExampleWithCtx = &server{}
  
  func (*server) ExistingMethod(fidl.Context) error {
  	return nil
  }
  
- func (*server) OldMethod(fidl.Context) error {
- 	return nil
- }
- 

HLCPP

  • Remove references to the method in client code and server code.
  class Server : public fidl_test::Example {
    void ExistingMethod() final {}
-   void OldMethod() final {}
  };
  
- void client(fidl_test::ExamplePtr client) {
-   client->ExistingMethod();
-   client->OldMethod();
- }
+ void client(fidl_test::ExamplePtr client) { client->ExistingMethod(); }

LLCPP

  • Remove references to the method in client code and server code.
  class Server final : public fidl_test::Example::Interface {
   public:
    void ExistingMethod(ExistingMethodCompleter::Sync& completer) final {}
-   void OldMethod(OldMethodCompleter::Sync& completer) final {}
  };
  
- void client(fidl::Client<fidl_test::Example> client) {
-   client->ExistingMethod();
-   client->OldMethod();
- }
+ void client(fidl::Client<fidl_test::Example> client) { client->ExistingMethod(); }

Rust

  • Add #[allow(unreachable_patterns)] to the server's request stream match.
  • Replace the match arm for the method that is being removed with a catchall (_) arm.
  • Remove any references to the method in client code (e.g. as part of implementations of the ProxyInterface).
  struct ExampleFakeProxy;
  
  impl fidl_lib::ExampleProxyInterface for ExampleFakeProxy {
      fn existing_method(&self) -> Result<(), fidl::Error> {
-         Ok(())
-     }
-     fn old_method(&self) -> Result<(), fidl::Error> {
          Ok(())
      }
  }
  
  async fn example_service(chan: fasync::Channel) -> Result<(), fidl::Error> {
      let mut stream = fidl_lib::ExampleRequestStream::from_channel(chan);
      while let Some(req) = stream.try_next().await? {
+         #[allow(unreachable_patterns)]
          match req {
              fidl_lib::ExampleRequest::ExistingMethod { .. } => {}
-             fidl_lib::ExampleRequest::OldMethod { .. } => {}
+             _ => {}
          }
      }
      Ok(())
  }

Update FIDL Library

  • Remove the method.
  protocol Example {
      ExistingMethod();
-     [Transitional]
-     OldMethod();
  };

Update Source Code

Go

  • Remove the embedded WithCtxInterface struct.
  type client struct {
  	removeMethod *lib.ExampleWithCtxInterface
  }
  
  func (c client) test() {
  	c.removeMethod.ExistingMethod(context.Background())
  }
  
- type server struct {
- 	lib.ExampleWithCtxInterface
- }
+ type server struct{}
  
  // Assert that server implements the Example interface
  var _ lib.ExampleWithCtx = &server{}
  
  func (*server) ExistingMethod(fidl.Context) error {
  	return nil
  }
  

Rust

  • Remove the #[allow(unreachable_patterns)] attribute and the catch-all match arm.
  struct ExampleFakeProxy;
  
  impl fidl_lib::ExampleProxyInterface for ExampleFakeProxy {
      fn existing_method(&self) -> Result<(), fidl::Error> {
          Ok(())
      }
  }
  
  async fn example_service(chan: fasync::Channel) -> Result<(), fidl::Error> {
      let mut stream = fidl_lib::ExampleRequestStream::from_channel(chan);
      while let Some(req) = stream.try_next().await? {
-         #[allow(unreachable_patterns)]
          match req {
              fidl_lib::ExampleRequest::ExistingMethod { .. } => {}
-             _ => {}
          }
      }
      Ok(())
  }