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

Reimplement public interface for stability #71

Merged
merged 1 commit into from
Mar 31, 2018
Merged

Reimplement public interface for stability #71

merged 1 commit into from
Mar 31, 2018

Conversation

alexcrichton
Copy link
Contributor

More information to come later about this, but this is a result of the
work week discussions we've had about stabilizing procedural macros

src/lib.rs Outdated
pub fn def_site() -> Span {
Span(imp::Span::def_site())
Span::_new(imp::Span::def_site())
}

/// Creates a new span with the same line/column information as `self` but
/// that resolves symbols as though it were at `other`.
pub fn resolved_at(&self, other: Span) -> Span {
Copy link
Owner

Choose a reason for hiding this comment

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

Should this and located_at be procmacro2_semver_exempt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I initially had that yeah but this was used by serde_derive, but I can remove the usage from serde_derive

@@ -1,3 +1,5 @@
#![allow(dead_code)]
Copy link
Owner

Choose a reason for hiding this comment

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

Will need to clean this up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps yeah, I personally find the soup of #[cfg] on imports somewhat unappealing and am generally ok with dead code otherwise, so I might personally lean towards leaving this

src/stable.rs Outdated
TokenNode::Group(delim, ref stream) => {
let (start, end) = match delim {
match *tt {
TokenTree::Group(ref g) => {
Copy link
Owner

Choose a reason for hiding this comment

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

I would prefer to use the Syn match naming convention here, https://docs.rs/syn/0.12.15/syn/enum.Expr.html#syntax-tree-enums. For example TokenTree::Op(ref tt) => ... tt.op() ... to avoid op.op().

@@ -158,11 +162,9 @@ impl fmt::Debug for TokenTreeIter {
}
}

#[cfg(procmacro2_semver_exempt)]
Copy link
Owner

Choose a reason for hiding this comment

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

Why is this being changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah this is the same as the #[cfg] soup above

src/lib.rs Outdated
}
}

pub struct TokenTreeIter(imp::TokenTreeIter);
pub struct TokenTreeIter {
Copy link
Owner

Choose a reason for hiding this comment

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

We may want a different name here because if we ever implement IntoIterator for &TokenStream then we will want this name.

src/lib.rs Outdated
}

pub fn as_str(&self) -> &str {
self.0.as_str()
pub fn stream(&self) -> &TokenStream {
Copy link
Owner

Choose a reason for hiding this comment

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

This is sort of an unfortunate signature because you can't do anything with &TokenStream except clone or check if empty. Would it work to implement IntoIterator for &TokenStream? Or is there a cheap way to return TokenStream here?

}
}

pub fn set_span(&mut self, span: Span) {
Copy link
Owner

Choose a reason for hiding this comment

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

We may need to clarify that this is a shallow set_span. Same for Group::set_span. Is that going to be confusing?

.travis.yml Outdated
@@ -3,7 +3,7 @@ sudo: false

matrix:
include:
- rust: 1.15.0
- rust: 1.23.0
Copy link
Owner

Choose a reason for hiding this comment

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

Please restore support for 1.15.0.

@alexcrichton alexcrichton force-pushed the v3 branch 6 times, most recently from 5993cd2 to 1f0e797 Compare March 29, 2018 18:59
More information to come later about this, but this is a result of the
work week discussions we've had about stabilizing procedural macros
Literal(f.into())
pub fn f32_unsuffixed(f: f32) -> Literal {
assert!(f.is_finite());
Literal::_new(imp::Literal::float(f as f64))
Copy link

Choose a reason for hiding this comment

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

This is a bit scary, don't we want to stringify the exact f32 value? Not sure if this specific case is a problem but the compiler tried really hard (before APFloat, mostly) to avoid casting between f32 and f64.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this'll get fixed one we update upstream to match this api

@eddyb
Copy link

eddyb commented Mar 30, 2018

Aside from #71 (comment) (and a broader question of "what do we even want literals to be?"), I'm curious what the plans for bringing the built-in proc_macro in line with this (or a similar) API are.

Specifically, this design is much nicer for the decoupling being done in rust-lang/rust#49219, so I would prefer if we could first land this new API on rust-lang/rust master, simplifying my PR.

Should it be done in lockstep, just to avoid friction for people who are using proc-macro2 on nightly?

@alexcrichton
Copy link
Contributor Author

@eddyb I plan to land this here and then land referenced prs shortly after. Once that's done I'll send a PR to Rust nightly and we can update proc-macro2 once that lands

That's the current plan at least!

@alexcrichton
Copy link
Contributor Author

Ok! After lots of discussion at the work week I think we've settled on this API as the best way forward for stabilizing the proc_macro crate itself. I'm going to merge this, wait for CI to pass and docs get published, make sure it all looks ok, and then publish a new version on crates.io. This new version I'll then plumb through to quote/syn/etc

@alexcrichton alexcrichton merged commit b2b4df1 into master Mar 31, 2018
@alexcrichton alexcrichton deleted the v3 branch March 31, 2018 09:36
Repository owner locked and limited conversation to collaborators Dec 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants