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

Rename begin_unwind lang item and core function #16114

Closed
brson opened this issue Jul 30, 2014 · 6 comments
Closed

Rename begin_unwind lang item and core function #16114

brson opened this issue Jul 30, 2014 · 6 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@brson
Copy link
Contributor

brson commented Jul 30, 2014

The unwind code has had a long and storied life. Currently there are two naming conventions in use: fail and begin_unwind, the code for which is divided between core::failure and rustrt::unwind.

In the rustrt case, the naming is accurate because the runtime provides unwinding, but core, which contains two functions named begin_unwind, one of which is a lang item, provides no particular failure semantics, and ultimately the language definition will allow for different implementations of failure.

The four 'core' failure functions are:

// Compiler-emitted failure
#[lang="fail_"]
fn fail_(expr_file_line: &(&'static str, &'static str, uint)) -> !;

// Compiler-emitted index oob failure
#[lang="fail_bounds_check"]
fn fail_bounds_check(file_line: &(&'static str, uint),
                     index: uint, len: uint) -> !;

// Library-emitted `fail!` calls inside the std facade
pub fn begin_unwind(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> !;

// The declaration of the lang item that actually implements failure.
// All failure goes through this method which must be provided downsteam,
// and is implemented in the 'std' crate.
extern {
    #[lang = "begin_unwind"]
    fn begin_unwind(fmt: &fmt::Arguments, file: &'static str, line: uint) -> !;
}

The begin_unwind lang item and the function core::failure::begin_unwind should be renamed to be implementation-agnostic. Perhaps fail_fmt and fail_impl.

@alexcrichton
Copy link
Member

While we're renaming, we could rename fail_ to fail as well now that it's not a keyword.

I'd also vote for fail_fmt

@brson brson added the E-mentor label Jul 30, 2014
@brson
Copy link
Contributor Author

brson commented Jul 30, 2014

I can mentor.

@brson
Copy link
Contributor Author

brson commented Jul 30, 2014

A patch implementing this will conflict with #16100 until it lands.

@metalogical
Copy link

I'm interested in taking a look at this (first time touching the codebase). I've spent a little time trying to understand how the begin_unwind lang item is used internally, but I'm a little confused by the difference between the begin_unwind and rust_begin_unwind identifiers in librustc/middle/lang_items.rs and weak_lang_items.rs, as well as the variants defined in librustrt/unwind.rs

@brson
Copy link
Contributor Author

brson commented Aug 14, 2014

@namanbharadwaj 'weak lang items' are lang items that the compiler may emit calls to, even if the required code has not yet been defined in any upstream crates. In the case of begin_unwind it also allows library code to call into a runtime function that doesn't yet exist. This is specifically to allow code in crate core to initiate stack unwinding (which is defined in rustrt).

The way it does this is by relying on the linker to make the lang item's symbol available during the final application link step. What this means in practice is that calls to the begin_unwind extern declared in core end up as calls to the begin_unwind definition in rustrt. Because these lang items have unmangled symbols, their definitions are prefixed rust_ so they don't clash with other symbols.

Hope that helps.

@metalogical
Copy link

That helps a lot, thanks! I've made a bunch of changes to rename the lang item, but I've just realized that I'm going to run into bootstrapping issues, as the snapshot will be looking for the begin_unwind lang item and does not know about any fail_fmt lang item.

Seems like we will need some intermediate versions that know about both begin_unwind and fail_fmt, but I'm not precisely sure how that will work.

fhahn added a commit to fhahn/rust that referenced this issue Sep 24, 2014
bors added a commit that referenced this issue Sep 25, 2014
…r=alexcrichton

This is a PR for #16114 and includes to following things:

* Rename `begin_unwind` lang item to `fail_fmt`
*  Rename `core::failure::begin_unwind` to `fail_impl`
* Rename `fail_` lang item to `fail`
@bors bors closed this as completed in 1c7d253 Sep 25, 2014
lnicola pushed a commit to lnicola/rust that referenced this issue Jan 3, 2024
…ykril

fix: self type replacement in inline-function

Fix rust-lang#16113, fix rust-lang#16091

The problem described in this issue actually involves three bugs.

Firstly, when using `ted` to modify the syntax tree, the offset of nodes on the tree changes, which causes the syntax range information from `hir` to become invalid. Therefore, we need to edit the AST after the last usage for `usages_for_locals`.

The second issue is that when inserting nodes, it's necessary to use `clone_subtree` for duplication because the `ted::replace` operation essentially moves a node.

The third issue is that we should use `ancestors_with_macros` instead of `ancestors` to handle impl definition in macros.

I have fixed the three bugs mentioned above and added unit tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

No branches or pull requests

3 participants