Skip to content

Commit

Permalink
usingmodule()! Who would have guessed!
Browse files Browse the repository at this point in the history
  • Loading branch information
staticfloat committed Jul 17, 2013
1 parent e5101d2 commit 16f5086
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions test/perf/perfutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ const ntrials = 5
print_output = isempty(ARGS)
codespeed = length(ARGS) > 0 && ARGS[1] == "codespeed"

try
Pkg.init()
Pkg.add("JSON")
Pkg.add("Curl")
end

if( codespeed )
using JSON
using Curl
if codespeed
try
Pkg.init()
Pkg.add("JSON")
Pkg.add("Curl")
end
usingmodule("JSON")
usingmodule("Curl")

# Ensure that we've got the environment variables we want:
if !haskey(ENV, "JULIA_FLAVOR")
Expand Down

9 comments on commit 16f5086

@JeffBezanson
Copy link
Member

Choose a reason for hiding this comment

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

Oh dear. I wish usingmodule didn't have to exist.

@staticfloat
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this a syntax parsing issue? I must admit, I was a little surprised by this

@timholy
Copy link
Member

Choose a reason for hiding this comment

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

It was based on a PR that sat for many months, and only ever got upvotes. So eventually I decided to pull the trigger.

@staticfloat
Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, is this because using inside an if statement would be evaluated in the scope of the if block? I guess I'm still not sure why a using directive in nested scope would throw an error, though.....

@JeffBezanson
Copy link
Member

Choose a reason for hiding this comment

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

Originally I wanted using to be a more static thing, making it easier to deal with cases like #3648 . But since this workaround exists anyway, there's no point, and I might as well allow using inside an if. I guess it is ok as long as the using happens at load time, since we can't change global bindings arbitrarily after that point.

@staticfloat
Copy link
Member Author

Choose a reason for hiding this comment

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

So what happens if someone tries to do exactly that? e.g. uses the usingmodule() trick in the middle of running some huge piece of code?

@JeffBezanson
Copy link
Member

Choose a reason for hiding this comment

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

It's not a disaster, but (1) it affects the dynamically current module (likely Main) rather than the module the call appears in, which is probably not what you want, and (2) it's not clear which bindings will be affected, since most global variables you're using will probably be resolved already, but perhaps not all, and those remaining ones could resovle differently as a result of the usingmodule.

@staticfloat
Copy link
Member Author

Choose a reason for hiding this comment

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

I see. Is this roughly the same problem as #265, only generalized beyond functions to just generic symbols? (I suppose I'm assuming resolve(symbol) ~== compile(function))

@JeffBezanson
Copy link
Member

Choose a reason for hiding this comment

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

Yes, it is similar, but not as serious since we simply don't allow changing how global bindings resolve, while we do allow changing method tables.

Please sign in to comment.