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

resolve: Refactor how the prelude is handled #32167

Merged
merged 5 commits into from
Mar 26, 2016

Conversation

jseyfried
Copy link
Contributor

This PR refactors how the prelude is handled in resolve.

Instead of importing names from the prelude into each module's resolutions, this PR adds a new field prelude: RefCell<Option<Module>> to ModuleS that is set during import resolution but used only when resolving in a lexical scope (i.e. the scope of an initial segment of a relative path).

r? @nikomatsakis

@jseyfried
Copy link
Contributor Author

cc @petrochenkov

@petrochenkov
Copy link
Contributor

Do you plan to change the prelude injection code in libsyntax? I'd suppose that with these changes prelude can be injected once into the crate root. (Is it ever useful to have different preludes used in different modules?)

@jseyfried
Copy link
Contributor Author

I wasn't planning on refactoring the prelude injection code in libsyntax in the near future (this PR is good enough groundwork for the new import semantics), but I think it would be an improvement.

If we decide to stabilize something allowing different preludes for different modules, we could always make the the field prelude per-module again pretty easily.

@bors
Copy link
Contributor

bors commented Mar 10, 2016

☔ The latest upstream changes (presumably #32097) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis
Copy link
Contributor

Can you elaborate a bit more on the larger picture you have in mind for this change? Sorry, there's been a lot in flight lately -- especially around resolve, huzzah! -- and I feel like I'm losing track.

@jseyfried
Copy link
Contributor Author

Can you elaborate a bit more on the larger picture you have in mind for this change?

Sure -- this is a pure refactoring. The primary motivation is to reflect the interpretation of the prelude we discussed in #31908 and to simplify the core import resolution algorithm by removing DefModifiers::PRELUDE bindings.

The last commit lays the groundwork for item-like private imports by making a distinction between resolving in a lexical scope (i.e. allowing private imports and the prelude) and allowing private imports but not the prelude. Right now, we never need to allow private imports and not the prelude, but eventually ...

struct Bar;
mod foo {
    use Bar;
    use foo::Bar as Baz; // ... we will want this to resolve (a private import),
    use foo::Ok; // but not this (a name from the prelude).
}

// Set the glob flag. This tells us that we don't know the
// module's exports ahead of time.
module_.inc_glob_count(is_public)
}
_ => {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest avoiding _ but rather keeping the match exhaustive, with a comment explaining why this case requires no action. This has two advantages:

  • Helps the reader know why the prelude case is different.
  • Gives you errors if you add new enum variants.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point

@nikomatsakis
Copy link
Contributor

Looks good, r=me modulo the match.

@jseyfried
Copy link
Contributor Author

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Mar 25, 2016

📌 Commit 54cd4d1 has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Mar 25, 2016

⌛ Testing commit 54cd4d1 with merge a1e29da...

bors added a commit that referenced this pull request Mar 25, 2016
resolve: Refactor how the prelude is handled

This PR refactors how the prelude is handled in `resolve`.

Instead of importing names from the prelude into each module's `resolutions`, this PR adds a new field `prelude: RefCell<Option<Module>>` to `ModuleS` that is set during import resolution but used only when resolving in a lexical scope (i.e. the scope of an initial segment of a relative path).

r? @nikomatsakis
@bors bors merged commit 54cd4d1 into rust-lang:master Mar 26, 2016
This was referenced Mar 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants