-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Bring emit-h back to life! #20353
Bring emit-h back to life! #20353
Conversation
If you're referring to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several TODOs you've noted, and a few more potential issues I've flagged up. However, this change overall seems pretty good. Since emit-h
is completely broken today, I think this PR is reasonable to merge as-is to unblock at least some use cases (such as your own!).
Upon merge, I will open a follow-up issue detailing the remaining issues with emit-h
. I will likely end up solving some of them in my upcoming Decl
refactor, which is another reason I think this should be merged as-is.
|
||
std.debug.assert(emit_h.allocated_emit_h.len == emit_h.decl_table.count()); | ||
|
||
var emitter = EmitH{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var emitter = EmitH{ | |
var emitter: EmitH = .{ |
src/Sema.zig
Outdated
@@ -6572,6 +6572,7 @@ fn addExport(mod: *Module, export_init: Module.Export) error{OutOfMemory}!void { | |||
const de_gop = mod.decl_exports.getOrPutAssumeCapacity(decl_index); | |||
if (!de_gop.found_existing) de_gop.value_ptr.* = .{}; | |||
try de_gop.value_ptr.append(gpa, new_export); | |||
try mod.emitHDecl(decl_index); | |||
}, | |||
.value => |value| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to handle this value
case -- this corresponds to an @export
of a comptime-known value. That doesn't need to block this merge.
@@ -0,0 +1,731 @@ | |||
const std = @import("std"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file's naming is a little confusing due to the existence of Zcu.EmitH
, but that need not block merge. Zcu.EmitH
will need to be restructured soon anyway to deal with serialization.
} | ||
} | ||
|
||
if (zcu.decl_exports.get(emitter.decl_index)) |exports| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a subtly weird case here: if a decl foo
is @export
ed by two different decls bar
and qux
, and bar
's emit_h_decl
job is run before qux
is analyzed, then we'll miss the export from qux
.
Now that I see this issue, I think I understand why the old implementation queued this work in Zcu.semaDecl
: presumably, it was (at least trying to) use export_owners
to deal with the exports created by the just-analyzed Decl
. However, I don't think that ought to block this PR, because using Decl
in this way is currently a little borked anyway (something my upcoming refactors will improve).
.Struct => { | ||
const should_make_opaque = switch (value_as_type.containerLayout(zcu)) { | ||
.@"extern" => false, | ||
.@"packed" => switch (value_as_type.bitSizeAdvanced(zcu, null) catch unreachable) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.@"packed" => switch (value_as_type.bitSizeAdvanced(zcu, null) catch unreachable) { | |
.@"packed" => switch (value_as_type.bitSize(zcu)) { |
Suggested future work:
|
Thanks for the feedback folks. I will try to address everything today. |
draft status, no updates in 30+ days |
@andrewrk can you provide some explanation on the issue closing and the plans on supporting "draft status, no updated in 30+ days" seems a bit too open and no solution is provided. Does it have to wait to something? Is there need to create a group of discussion? Why is it a draft not a "proper" solution? Is this because of who created it? If you could make these decisions more clear, it would be very nice. |
See the current results here: https://zigbin.io/a90812
Some things I still need to do:
@export
for example)Give structs better generated names(?)Decided to keep simple, not fully-qualified names for now. Can definitely cause issues, but this requires a larger rethinking potentially that should be in a proposal issue.Probably add a couple testsNot blocking for merge, can be added later.But it does work 100% better than the current emit-h! :P