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

Compiler: move checking function-scope-only builtins to AstGen #18096

Merged
merged 11 commits into from
Nov 25, 2023

Conversation

wrongnull
Copy link
Contributor

@wrongnull wrongnull commented Nov 23, 2023

No description provided.

Copy link
Member

@Vexu Vexu left a comment

Choose a reason for hiding this comment

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

This check should be in AstGen.

@wrongnull
Copy link
Contributor Author

This check should be in AstGen.

should I move check of all the functions such as @src or @setAlignStack to AstGen? If so, should I change the wording of the error message? Most of other builtins there use {builtinName} outside function scope meanwile @src for instance uses "@src outside function"

@Vexu
Copy link
Member

Vexu commented Nov 24, 2023

should I move check of all the functions such as @src or @setAlignStack to AstGen?

Yes please.

If so, should I change the wording of the error message?

That would be nice; and easier to implement since you can just switch on the builtin kind at the top of builtinCall.

@wrongnull
Copy link
Contributor Author

should I move check of all the functions such as @src or @setAlignStack to AstGen?

Yes please.

If so, should I change the wording of the error message?

That would be nice; and easier to implement since you can just switch on the builtin kind at the top of builtinCall.

It looks like astgen.fn_block is not null at least for comptime and test blocks. It's not yet clear for me, how to detect being exactly in function scope.

@nektro
Copy link
Contributor

nektro commented Nov 24, 2023

test blocks are indeed functions and should allow the builtins. it being non-null in comptime blocks seems sus though

@Vexu
Copy link
Member

Vexu commented Nov 24, 2023

It looks like astgen.fn_block is not null at least for comptime and test blocks. It's not yet clear for me, how to detect being exactly in function scope.

It is null for comptime blocks and correctly not null for tests:

comptime {
    try 1; //error: 'try' outside function scope
}

@wrongnull wrongnull changed the title Sema: make calling @setCold and @returnAddress outside the function body a compilation error Compiler: move checking function-scope-only builtins to AstGen Nov 25, 2023
@wrongnull
Copy link
Contributor Author

It looks like astgen.fn_block is not null at least for comptime and test blocks. It's not yet clear for me, how to detect being exactly in function scope.

It is null for comptime blocks and correctly not null for tests:

comptime {
    try 1; //error: 'try' outside function scope
}

not sure if latest commit contains complete list of such functions but I'm think it is

@Vexu Vexu enabled auto-merge (squash) November 25, 2023 09:43
auto-merge was automatically disabled November 25, 2023 11:36

Head branch was pushed to by a user without write access

@wrongnull
Copy link
Contributor Author

@Vexu forgot about @src sorry

@Vexu Vexu enabled auto-merge (squash) November 25, 2023 11:46
auto-merge was automatically disabled November 25, 2023 12:04

Head branch was pushed to by a user without write access

@Vexu Vexu enabled auto-merge (squash) November 25, 2023 12:19
@Vexu Vexu merged commit 2252dcc into ziglang:master Nov 25, 2023
10 checks passed
@wrongnull wrongnull deleted the add-errors-for-function-only-builtins branch November 25, 2023 17:29
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

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

Before, there was only one branch on the builtin tag. Now it does it twice. The way it was before was better, where it had if statements inside each of the branches of the switch.

If you wish to consolidate this information and make it declarative, then add a field to src/BuiltinFn.zig, don't add another switch like this.

@Vexu

@wrongnull
Copy link
Contributor Author

Before, there was only one branch on the builtin tag. Now it does it twice. The way it was before was better, where it had if statements inside each of the branches of the switch.

If you wish to consolidate this information and make it declarative, then add a field to src/BuiltinFn.zig, don't add another switch like this.

@Vexu

I can rewrite it in next pr

@andrewrk
Copy link
Member

Thanks

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.

4 participants