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

Zig 0.14-master update fixes #27

Merged
merged 2 commits into from
Oct 5, 2024
Merged

Conversation

sk3p7ic
Copy link
Contributor

@sk3p7ic sk3p7ic commented Oct 5, 2024

I've applied the fixes that I currently could toward allowing the majority of the tests to run once more (see #26). Namely,

  • Update the use of the @setCold(true) builtin to @branchHint(.cold)
  • Update Type fields to use the new naming:
    • .Pointer $\rightarrow$ .pointer
    • .Null $\rightarrow$ .null
    • .Enum $\rightarrow$ .@"enum"
    • and more

I was unable to get some of the comptime tests to continue to work and have disabled comptime tests in the meantime. If you have any ideas of why the expectComptimeRender and expectComptimeRenderPartials from src/rendering/rendering.zig functions would throw error: runtime value contains reference to comptime var when using zig build test, please let me know.

I also had to edit src/rendering/contexts/native/lambda.zig such that isValidLambdaFunction would no longer use the std.builtin.Type.@"fn".Param type due to receiving a error about there being invalid field access on a @"union". Each of these areas which I had issues with should be marked with "TODO" comments.

Lastly, I understand that this is a large change and apologize for that in advance. If these changes are not something that you wish to do at this time that is fine with me and this PR can be closed. That being said, if there is anything else you need please let me know.

Update `@setCold(true)` to `@branchHint(.cold)` builtin function as per
the migration made in ziglang/zig@6808ce27.
Commit
ziglang/zig@0fe3fd0
from the Zig repository introduced breaking changes in their migration
of the `Type` fields to follow naming conventions. Some blocks could not
be successfully migrated and have been marked with 'TODO' comments.
Comment on lines +84 to +85
// TODO: Re-enable comptime tests
const comptime_tests_enabled = b.option(bool, "comptime-tests", "Run comptime tests") orelse false;
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for the TODO!

I fear most of the comptime capabilities in mustache-zig are compromised due to recent changes in how Zig treats comptime memory (only const pointers are allowed to "leak" into runtime code). But let the language stabilize a bit more before trying to make this work again.

Comment on lines +266 to +268
// TODO: Determine why Zig states this line is "access of inactive union field"
//self.state = .{ .produce_close = close_state.part_type };
self.state = .{ .produce_close = close_state_copy.part_type };
Copy link
Owner

Choose a reason for hiding this comment

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

I faced this same issue ... I guess it's a miscompilation. Nice workaround!

Comment on lines +141 to +143
// TODO: Update types to oncemore be strict on the input type
//const Type = std.builtin.Type;
//const FnParam = Type.@"fn".Param;
Copy link
Owner

Choose a reason for hiding this comment

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

Can you motivate why this TODO?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies, I should've explained that better. If I change the lines such that lines 141-146 read

    // TODO: Update types to oncemore be strict on the input type
    const Type = std.builtin.Type;
    const FnParam = Type.@"fn".Param;
    
    const paramIs = struct {
        fn action(comptime param: FnParam, comptime types: []const type) bool {

Then upon running zig build test I am met with a plethora of errors all stating

src/rendering/contexts/native/lambda.zig:143:31: error: type '@typeInfo(builtin.Type).@"union".tag_type.?' does not support field access
    const FnParam = Type.@"fn".Param;
                    ~~~~~~~~~~^~~~~~
zig/lib/std/builtin.zig:257:18: note: enum declared here
pub const Type = union(enum) {
                 ^~~~~
src/rendering/contexts/native/invoker.zig:199:90: note: called from here
                            const is_valid_lambda = comptime lambda.isValidLambdaFunction(TValue, @TypeOf(bound_fn));
                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~

I was not sure how exactly to handle this and thus marked it as something to work on in the future. I'll be sure to be more clear about that next time and apologize for any confusion I may have caused.

Copy link
Owner

@batiati batiati Oct 6, 2024

Choose a reason for hiding this comment

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

Ah, in this case we don't need to change Fn to @"fn", as we do need to access the type, not the union field.
See https://ziglang.org/documentation/master/std/#std.builtin.Type.Fn.Param

Can you send another PR fixing it?

@batiati batiati merged commit 6756f0c into batiati:master Oct 5, 2024
3 checks passed
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.

2 participants