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

Partial fix for invalid syntax in emitted precompile statements #28808 #32610

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tehrengruber
Copy link

@tehrengruber tehrengruber commented Jul 17, 2019

This pull request fixes some of the issues encoutered in #28808, namely incorrect output from --trace-compile. Just run julia --trace-compile=stderr with the following example codes to see the altered behaviour.

Case 1:

foo(::T) where T = 1
struct A{B} end
foo(A{Symbol("a\\b")})

Previous output:

precompile(Tuple{typeof(Main.foo), Type{Main.A{Symbol("a\b")}}})

New output:

precompile(Tuple{typeof(Main.foo), Type{Main.A{Symbol("a\\b")}}})

Case 2:

foo(::T) where T = 1
struct A{B} end
foo(A{Char(0x56)})

Previous output:

precompile(Tuple{typeof(Main.foo), Type{Main.A{Char(0x56000000)}}})

New output:

precompile(Tuple{typeof(Main.foo), Type{Main.A{reinterpret(Char, 0x56000000)}}})

I used reinterpret for primitive types instead of directly calling the constructor here (which to my understanding is wrong since the constructor can do whatever it likes with the argument). This should work correctly even for user defined primitive types.

@KristofferC
Copy link
Sponsor Member

@JeffBezanson, could you look at this?

n += ninc;
jl_uv_puts(out, buf, ninc);
}
n += sz;
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Isn't the n += ninc inside the loop sufficient to count the amount of output?

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Also would be good to use this code for showing strings as well.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

seems like a good thing to put in a helper function

n += jl_static_show_x(out, (jl_value_t*)vt, depth);
n += jl_printf(out, ", 0x");
uint32_t a = 0x01020304;
uint8_t *endian_bom = (uint8_t*) &a;
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 undefined behavior (since it is observably different on different platforms). use the standard macro (BYTE_ORDER)

n += jl_printf(out, "%02" PRIx8, data[i]);
}
else {
n += jl_printf(out, "reinterpret(");
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Suggested change
n += jl_printf(out, "reinterpret(");
n += jl_printf(out, "bitcast(");

uint32_t a = 0x01020304;
uint8_t *endian_bom = (uint8_t*) &a;
if (*endian_bom == 0x01) { // big endian
for(int i = 0; i < nb; ++i)
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Suggested change
for(int i = 0; i < nb; ++i)
for (int i = 0; i < nb; ++i)

for(int i = nb - 1; i >= 0; --i)
n += jl_printf(out, "%02" PRIx8, data[i]);
} else {
assert(0); // unsupported endianness
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

use a compile-time error

n += ninc;
jl_uv_puts(out, buf, ninc);
}
n += sz;
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

seems like a good thing to put in a helper function

@quinnj
Copy link
Member

quinnj commented Sep 19, 2019

Bump; it'd be great to get this fixed

@tehrengruber
Copy link
Author

Sorry for not getting back to this yet. I'll adopt the requested changes as soon as I finished my thesis in 2 weeks.

@quinnj
Copy link
Member

quinnj commented Oct 9, 2019

Bump again :)

@brenhinkeller brenhinkeller added the bugfix This change fixes an existing bug label Jul 24, 2022
@KristofferC KristofferC changed the title Partial fix for #28808 Partial fix for invalid syntax in emitted precompile statements #28808 Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants