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

Change extern "ABI" to extern<ABI> or extern ABI or extern(ABI) #156

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions active/0000-extern-abi-new-syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
- Start Date: 2014-07-05
- RFC PR #: (leave this empty)
- Rust Issue #: (leave this empty)


# Summary

Change the current `extern "ABI"` syntax to either `extern<ABI>` or just `extern
ABI`.


# Motivation

The available ABIs are conceptually much more like members of an enumeration
than like arbitrary strings.

In the future, we may gain support for values (as opposed to types) as generic
parameters. When that happens, we could enumerate the available ABIs in an
`enum` for real:

enum ExternAbi {
Rust,
C,
StdCall,
...
}

In which case it becomes possible to write, for instance, a higher-order
function which is generic over a function pointer of any ABI:

fn calculate_something<static SOME_ABI: ExternAbi>(some_function: extern<SOME_ABI> fn(int, int) -> int) -> int {
/* ... use `some_function` ... */
}

Alternately, the same thing can be encoded today, only slightly less elegantly,
using plain types:

// wired into compiler, can't be implemented by user types
trait ExternAbi { };

enum Rust { };
impl ExternAbi for Rust { };

enum C { };
impl ExternAbi for C { };

enum StdCall { };
impl ExternAbi for StdCall { };

...

In which case the previous example is only slightly altered:

fn calculate_something<SomeAbi: ExternAbi>(some_function: extern<SomeAbi> fn(int, int) -> int) -> int {
/* ... use `some_function` ... */
}

# Detailed design

Everywhere an ABI for an `extern` thing is specified, change the syntax from

extern "ABI"

to either

extern<ABI>

or

extern ABI

.


# Drawbacks

Breaking change.

Not clear if it has benefits.


# Alternatives

Don't do it.


# Unresolved questions

Is the ability to abstract over ABIs *useful*?

Should it be `extern<ABI>` or `extern ABI`?

(The former is more suggestive, but there is precedent for omitting the `<>` for
built-in things, such as `&` references.)