Skip to content

parser,checker: add top level comptime match support#25222

Merged
spytheman merged 1 commit into
vlang:masterfrom
kbkpbot:allow-top-level-comptime-match
Sep 2, 2025
Merged

parser,checker: add top level comptime match support#25222
spytheman merged 1 commit into
vlang:masterfrom
kbkpbot:allow-top-level-comptime-match

Conversation

@kbkpbot

@kbkpbot kbkpbot commented Sep 2, 2025

Copy link
Copy Markdown
Contributor

This PR enable top level $match.

Add @token support in $if and $match.
So we can write code such as :

$match $OS {
    'linux' {
        import mymodule_linux
    }
    'windows' {
        import mymodule_windows
    }
    'macos' {
        import mymodule_macos
    }
    $else {
        import mymodule_default
    }
}

Top level comptime $if or $match only support @token @MOD @OS @CCOMPILER @BACKEND or @PLATFORM right now.

I am not sure other @token is useful or not at top level: @VROOT, @VMODROOT, @VEXEROOT, @FN, @METHOD, @STRUCT,
@VEXE, @FILE, @DIR, @LINE, @COLUMN, @VHASH, @VCURRENTHASH, @VMOD_FILE,
@VMODHASH, @FILE_LINE, @LOCATION, @BUILD_DATE, @BUILD_TIME, @BUILD_TIMESTAMP

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-24612

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Excellent work.

@spytheman

Copy link
Copy Markdown
Contributor

Top level comptime $if or $match only support @MOD, @OS, @CCOMPILER, @BACKEND or @PLATFORM right now.

I think that is fine. The rest have values, that can not be compared easily against known ones (except perhaps the build ones, but I am not sure, if it is a good idea to do compile time logic based on them anyway), without also making builds a lot more brittle.

@spytheman spytheman merged commit f6b60e4 into vlang:master Sep 2, 2025
83 checks passed
@kbkpbot kbkpbot deleted the allow-top-level-comptime-match branch September 2, 2025 23:37
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