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

Improve proc-macro def ids #38278

Merged
merged 1 commit into from
Dec 14, 2016
Merged

Conversation

jseyfried
Copy link
Contributor

Support cstore.relative_def_path(id) and cstore.def_key(id) with proc-macro def ids.
Fixes #38207.
r? @nikomatsakis

@jseyfried
Copy link
Contributor Author

I manually verified via logs that cstore.relative_def_path(id) and cstore.def_key(id) work correctly with proc-macro def ids, but I'm not sure how best to add a regression test -- having trouble reproducing the underlying bug.

@jseyfried
Copy link
Contributor Author

cc @nrc

@nikomatsakis
Copy link
Contributor

@jseyfried I can take a stab at making a regr test involving incremental compilation

@nikomatsakis
Copy link
Contributor

@jseyfried This seems pretty clean though -- confined to metadata, as you promised. :)

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Dec 12, 2016

Well, I failed to produce a regr test and am now on vacation for a week. =) I'm inclined to r+ -- though I suspect that creating an incremental test that uses a proc macro would suffice.

@nikomatsakis
Copy link
Contributor

r? @michaelwoerister

@michaelwoerister
Copy link
Member

Unfortunately I also failed in producing a small test case.

Why is it that these DefIds need special handling?

@nikomatsakis
Copy link
Contributor

@michaelwoerister normally we create an Entry structure for each element of the module tree, and then we reconstruct a DefId by retracing the DefPath through these entries. However, for procedural macros, we are not creating the same structure in the metadata -- we're making a synthetic one. At least this is what I understand, @jseyfried can confirm.

That said, I find this mildly confusing too. That is, in my mind's eye, we could still encode the procedural macro crate's items, since the path to the procedural macro that the user should be using is basically the path to the item that is annotated with #[proc_macro].

That is, the way I think of it, the procedural macro is conceptually executed by interpreting the MIR attached to the procedural macro crate -- or, put another way, we attach some executable data to the #[proc_macro] fn.

I guess this view is inaccurate?

@michaelwoerister
Copy link
Member

Sounds about right to me. I don't think that there can be dynamically created procedural macros (although the macro/plugin registrar function infrastructure would probably allow that).

@michaelwoerister
Copy link
Member

@bors r+

I think we should refactor how DefPaths are handled in metadata but I don't want to block this PR on that.

@bors
Copy link
Contributor

bors commented Dec 13, 2016

📌 Commit 5200a11 has been approved by michaelwoerister

@bors
Copy link
Contributor

bors commented Dec 13, 2016

⌛ Testing commit 5200a11 with merge a274617...

bors added a commit that referenced this pull request Dec 13, 2016
…lwoerister

Improve proc-macro def ids

Support `cstore.relative_def_path(id)` and `cstore.def_key(id)` with proc-macro def ids.
Fixes #38207.
r? @nikomatsakis
@bors bors merged commit 5200a11 into rust-lang:master Dec 14, 2016
@bors bors mentioned this pull request Dec 14, 2016
2 tasks
@jseyfried jseyfried deleted the improve_proc_macro_def_ids branch December 14, 2016 00:26
@jseyfried
Copy link
Contributor Author

@nikomatsakis
Yeah, I think that view is conceptually accurate. Ideally, I think a proc macro def id should be either the def id of the underlying #[proc_macro] function or should correspond to a specially encoded Entry with with a new kind EntryKind::ProcMacro.

However, refactoring the current registrar-based system implemented in #35957 to either of these options will probably be quite a bit of work (it might be a good idea to combine this with a transition from dynamic linking to IPC -- cc @eddyb).

@Arnavion
Copy link

@jseyfried The repro in #38237 hits the assert you added to maybe_entry. Can you take a look?

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.

5 participants