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

WIP: change lowering of ccall cconvert arguments #9913

Closed
wants to merge 98 commits into from

Conversation

vtjnash
Copy link
Sponsor Member

@vtjnash vtjnash commented Jan 24, 2015

ccall(:a, B, (C,), d) is now lowered as:

  d#1 = cconvert(C, d)
  Expr(:call, :ccall, :a, B, (C,), convert(C, d#1), d#1)

This allows implementation of the special-case ccall lowering logic in Julia.
It also means that the fall-back cconvert method is now a no-op, with the main
work being done by convert. But it also means we get a GC root for both
the result of cconvert and convert (as needed).

ps: this was the motivation for #9729

@@ -100,6 +101,7 @@ end
function study(regex::Ptr{Void}, options::Integer)
# NOTE: options should always be zero in current PCRE
errstr = Array(Ptr{UInt8},1)
errstr[1] = C_NULL
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Looks like a bug fix? Could this go directly to master?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

mostly this was caused because I accidentally was passing a copy of the array in the pointer, rather than the array itself (during work on this PR). it shouldn't strictly be necessary on master (since pcre should set this variable)

@JeffBezanson
Copy link
Sponsor Member

Really nice change. The amount of code deletion speaks for itself :)

*needStackRestore = true;
Value *jvt = emit_typeof(jv);
Value *p;
BasicBlock *mutableBB = BasicBlock::Create(getGlobalContext(),"is-mutable",ctx->f);
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

This is a great hack. It looks correct to me; hope I'm right about that :)

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

(added WIP title)

yeah, i'll definately have to do more testing on this. i probably will hold off on merging until I get a few more of the ccall-related PR's ready. the runtime code branch is identical to the compile-time code branch directly above it, however.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

oops, it /was/ slightly broken.

@vtjnash vtjnash changed the title change lowering of ccall cconvert arguments WIP: change lowering of ccall cconvert arguments Jan 24, 2015
@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Jan 24, 2015

Really nice change. The amount of code deletion speaks for itself :)

indeed. i'm also working on deprecating & (#8134 and https://github.com/JuliaLang/julia/compare/jn/add_ref_type and https://gist.github.com/vtjnash/7296634) which should delete some more of this code.

@JeffBezanson
Copy link
Sponsor Member

Could we remove the extra d#1 argument from ccall? It looks like it will always be rooted anyway. In fact I'm having trouble remembering why it is there in the current system.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Jan 24, 2015

it's possibly there to help inference correctly count usages correctly? i'm not really sure

@JeffBezanson
Copy link
Sponsor Member

Does the travis failure make any sense to you?

If neither of us can figure out why the extra root is there we should try removing it.

@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Jan 24, 2015

yeah, that should be fixed in my followup fix (two bugs: i was looking for mutabl at the wrong offset in the type (rounded to the nearest i8* offset, and forgot to add the special case for Ptr{Void}&

amitmurthy and others added 27 commits January 29, 2015 15:20
fix bug in worker-to-worker connection setup. closes #9951
fix rational vs float comparisons (attempt 2)
remove unwarranted handling of SIGPIPE instead of ignoring it.
Conflicts:
	src/julia-syntax.scm
Fix `show_method_candidates` so it do not fail for methods with zero args.
Inbuilt managers throw on unused arguments. Closes #9958
Ref: f9da849

ReST tables must have not have text in between columns delimited by headers.
more fixes for worker-worker connection setups
Correct rounding mode after calling fma
ccall(:a, B, (C,), d) is now lowered as:
  d#1 = cconvert_gcroot(C, d)
  Expr(:call, :ccall, :a, B, (C,), cconvert(C, d#1), d#1)

This allows implementation of the special-case ccall lowering logic in Julia
and still create a gcroot for it as needed

the Ref{T} type is the new supertype of Ptr{T}. the ccall emission
turns a Ref{T} into a Ptr{T}, as if the &addressOf operator had been
applied. the specific rules for this will be moved from the current
gist to the documentation at a later point.
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.