Skip to content

Implement @impl directive#6031

Closed
samsondav wants to merge 3 commits intoelixir-lang:masterfrom
samsondav:implement_impl
Closed

Implement @impl directive#6031
samsondav wants to merge 3 commits intoelixir-lang:masterfrom
samsondav:implement_impl

Conversation

@samsondav
Copy link
Copy Markdown

@samsondav samsondav commented Apr 23, 2017

Implement @impl directive

- See: #5734

Comment thread lib/elixir/lib/kernel.ex Outdated
unquote(stack), unquote(line))

:lists.member(name, [:moduledoc, :typedoc, :doc]) ->
:lists.member(name, [:moduledoc, :typedoc, :doc, :impl]) ->
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to not rely on the line number. That's not a general feature of Elixir module attributes and as such it should be relied on very rarely.

@josevalim
Copy link
Copy Markdown
Member

According to the build it is working: https://travis-ci.org/elixir-lang/elixir/jobs/224857673#L237

It is just failing elsewhere inside the check_impl function.

@samsondav
Copy link
Copy Markdown
Author

@josevalim This is about as far as I can go on my own before getting feedback, would you mind taking a look?

Comment thread lib/elixir/lib/module.ex Outdated
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should actually raise instead of warn here?

Comment thread lib/elixir/lib/module.ex Outdated
Copy link
Copy Markdown
Author

@samsondav samsondav Apr 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josevalim The original proposal specified an @impl true variant but I actually prefer the explicitness of @impl Module and think we should enforce this form.

Perhaps we could ship the @impl Module specific case and see how people like it. If it seems obvious that @impl true would be nice to have in addition, we can easily add it later. Conversely, adding it now and removing it later would be much more difficult.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samphilipd I am already decided on making @impl true part of the implementation so we should go ahead with it.

Comment thread lib/elixir/lib/module.ex Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use pattern matching to extract line, file, module and others out.

%{module: module, line: line, file: file} = env

Comment thread lib/elixir/lib/module.ex Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we need to change store_typespec? :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. It's not necessary.

Comment thread lib/elixir/lib/module.ex Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For internal attributes, such as :impl_required, you can namespace it as{:elixir, :impl_required} to avoid conflicts with user attributes.

Comment thread lib/elixir/src/elixir_module.erl Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing. :) This is during bootstrap, so we don't care. If there are warnings, the modules will be recompiled after bootstrap, so we get them anyway.

Comment thread README.md Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please send those changes in another PR? :)

@samsondav
Copy link
Copy Markdown
Author

@josevalim I addressed your comments, this is ready for a second round of feedback.

Comment thread lib/elixir/lib/module.ex Outdated
Copy link
Copy Markdown
Author

@samsondav samsondav Apr 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's probably room for refactoring here and combining logic between msg_impl_true_but_function_is_not_callback and msg_impl_behaviour_but_function_is_not_callback

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't work. Is there another way to get the @doc of a module?

Comment thread lib/elixir/lib/module.ex Outdated
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should always be a warning rather than an outright ArgumentError?

Comment thread lib/elixir/lib/module.ex Outdated
Copy link
Copy Markdown
Author

@samsondav samsondav Apr 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to merge this somehow with the true case since they both duplicate this callbacks_with_behaviour logic.

Comment thread lib/elixir/lib/module.ex Outdated
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This to_sentence function seems a bit too much for Module, but I couldn't think of another way to nicely present the warnings.

@samsondav samsondav force-pushed the implement_impl branch 4 times, most recently from 0924fcf to db5186c Compare April 25, 2017 13:01
@samsondav
Copy link
Copy Markdown
Author

@josevalim OK I'm fairly happy with this, only two questions:

  1. Should we ever raise in any case? Or always warn?
  2. See the test at the bottom of warnings_test.exs, I can't see how to implement this case.

@samsondav samsondav changed the title Implement impl Implement @impl directive Apr 25, 2017
@samsondav samsondav force-pushed the implement_impl branch 2 times, most recently from 03fc3ce to 960d503 Compare April 28, 2017 09:24
@samsondav
Copy link
Copy Markdown
Author

@josevalim just a polite nudge for a review on this :)

Comment thread lib/elixir/lib/module.ex

You may pass either `false`, `true`, or a specific behaviour to `@impl`.

defmodule Foo do
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please indent with four spaces.

@josevalim
Copy link
Copy Markdown
Member

Thank you @samphilipd! I will merge it locally and tidy up what is left. :)

@josevalim
Copy link
Copy Markdown
Member

This has been merged and push to master. In order for the last test to pass, we had to change when the check happens, and this one done in a another commit: 92e5d04

Thank you so much! ❤️ 💚 💙 💛 💜

@josevalim josevalim closed this May 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants