Skip to content

Conversation

@stevengj
Copy link
Member

@stevengj stevengj commented Jan 30, 2020

This PR adds an optional mapexpr keyword first argument to include and include_string, allowing you to specify a function that rewrites each expression after it is parsed. I've needed this functionality several times, e.g. in SoftScope.jl and ChangePrecision.jl, and it is tricky implement manually in a way that preserves line-number information and other semantics of include.

Moreover, now that #33864 has merged, I would like to use the "official" REPL.softscope! function in IJulia instead of SoftScope.jl, or equivalently change SoftScope.jl to use this function on newer Julia releases. With this PR, one can just pass REPL.softscope! to include_string.

To do:

  • Tests
  • Documentation
  • Benchmarking. Invoking the identity transformation x->x adds a 2–3% overhead to include_string measured for "nothing\n"^10000, but I eliminated this by optimizing the default case of mapexpr === identity.

@stevengj stevengj changed the title mapexpr argument to include to transform each parsed expression mapexpr argument to include: transform each parsed expression Jan 30, 2020
@stevengj stevengj changed the title mapexpr argument to include: transform each parsed expression mapexpr argument for include: transform each parsed expression Jan 30, 2020
@stevengj
Copy link
Member Author

stevengj commented Jan 31, 2020

@JeffBezanson, where is a module's include(x) function defined? I need to add an include(mapexpr, ex) method there… Update: found it in jlfrontend.scm, see below.

@StefanKarpinski
Copy link
Member

I like the mapping function as the first argument. What else would one pass there, after all?

@stevengj
Copy link
Member Author

stevengj commented Feb 1, 2020

If I do

julia> module Foo; end; methods(Foo.include)
# 1 method for generic function "include":
[1] include(x) in Main.Foo at REPL[1]:1

where is Foo.include(x) defined? I'm having trouble tracking it down.

Update: I found it — it's in module-default-defs in jlfrontend.scm.

@StefanKarpinski StefanKarpinski added parser Language parsing and surface syntax compiler:lowering Syntax lowering (compiler front end, 2nd stage) labels Feb 1, 2020
@StefanKarpinski StefanKarpinski added this to the 1.5 milestone Feb 1, 2020
@stevengj stevengj force-pushed the sgj/include_mapexpr branch from 97fe1e7 to 3a0f5ff Compare February 10, 2020 13:39
@stevengj
Copy link
Member Author

Rebased. Is there anything else that is needed here?

@StefanKarpinski
Copy link
Member

I think only for @JeffBezanson to have a look. He was traveling last week so a bit occupied. He'll probably be able to take a look and merge if he approves this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:lowering Syntax lowering (compiler front end, 2nd stage) parser Language parsing and surface syntax

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants