Skip to content

assertion failures in quasi-quoting #1926

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

Closed
nikomatsakis opened this issue Mar 5, 2012 · 7 comments
Closed

assertion failures in quasi-quoting #1926

nikomatsakis opened this issue Mar 5, 2012 · 7 comments
Assignees
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@nikomatsakis
Copy link
Contributor

The following test fails with assertion failures about the "gather" ordering not being properly setup:

use rustc;
import rustc::driver::diagnostic;
import rustc::syntax::ast;
import rustc::syntax::codemap;
import rustc::syntax::print::pprust;

fn new_parse_sess() -> parser::parse_sess {
    let cm = codemap::new_codemap();
    let handler = diagnostic::mk_handler(option::none);
    let sess = @{
        cm: cm,
        mutable next_id: 1,
        span_diagnostic: diagnostic::mk_span_handler(handler, cm),
        mutable chpos: 0u,
        mutable byte_pos: 0u
    };
    ret sess;
}

iface fake_ext_ctxt {
    fn session() -> fake_session;
}

type fake_options = {cfg: ast::crate_cfg};

type fake_session = {opts: @fake_options,
                     parse_sess: parser::parse_sess};

impl of fake_ext_ctxt for fake_session {
    fn session() -> fake_session {self}
}

fn mk_ctxt() -> fake_ext_ctxt {
    let opts : fake_options = {cfg: []};
    {opts: @opts, parse_sess: new_parse_sess()} as fake_ext_ctxt
}


fn main() {
    let ext_cx = mk_ctxt();
    let s = #ast(expr){__s};
    let e = #ast(expr){__e};
    let f = #ast(expr){$(s).foo {|__e| $(e)}}; // THIS IS THE PROBLEM EXPR
    pprust::print_expr(f);
}
@nikomatsakis
Copy link
Contributor Author

@kevina for some reason I cannot assign you, but I think you'd be interested.

@kevina
Copy link
Contributor

kevina commented Mar 6, 2012

I try to look into this in the next few days. It might be as easy as reordering the gather list, but at this point I'm not sure.

The string slicing approach is inherently fragile, in the long term I think I want to switch a serialized AST in some fashion now that we has a working serializer.

@nikomatsakis
Copy link
Contributor Author

My workaround was to construct the expr call myself, so:

let f = #ast(expr){$(s).foo {|__e| $(e)}}; // THIS IS THE PROBLEM EXPR

becomes

            cx.expr(
                ty.span,
                ast::expr_call(
                    #ast(expr){$(s).emit_from_vec},
                    [#ast(expr){{|__e| $(ser_e)}}],
                    false)))]

where cx.expr is a helper method I wrote that generates an @ast::expr given a span and a expr_

kevina added a commit to kevina/rust that referenced this issue Mar 7, 2012
@kevina
Copy link
Contributor

kevina commented Mar 7, 2012

@nikomatsakis the above commit should fix it, please try it out and let me know if it causes you any problems, if it works for you fell free to use the commit.

@nikomatsakis
Copy link
Contributor Author

That seems to fix it. I've cherrypicked the commit into a branch and will push it hopefully soon.

@ghost ghost assigned nikomatsakis Mar 8, 2012
@kevina
Copy link
Contributor

kevina commented Mar 9, 2012

Thanks, fell free to close once pushed.

@catamorphism
Copy link
Contributor

I had to modify this code somewhat to get it to compile, but the mentioned assertion failure doesn't arise, so am closing this.

Kobzol pushed a commit to Kobzol/rust that referenced this issue Dec 30, 2024
Co-authored-by: SparrowLii <[email protected]>
Co-authored-by: Jieyou Xu <[email protected]>
bors pushed a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
Co-authored-by: SparrowLii <[email protected]>
Co-authored-by: Jieyou Xu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

3 participants