fix: Add comptime
to trait impls and structs
#5511
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Problem*
Resolves
Summary*
This is somewhat of a quick fix to the issue in the trait constraint PR and in @asterite's comptime prefix operator PR.
The issue was that the comptime functions/blocks were using other functions which weren't elaborated yet. So they saw an empty function body. Just adding
comptime
to a function in an impl wasn't sufficient since the compiler didn't look in every function within an impl to know whether to add the impl to the list of comptime items. Moreover, it wouldn't be possible to only add thiscomptime
to a subset of functions within an impl so I decided to allowcomptime
as a keyword on an entire impl as well - and this is what decides whether or not to add it to the comptime items.I'm not really satisfied with this solution since it overloads
comptime
to mean both "run this at compile-time (always)" and "able to be run at compile-time" but I don't have a better solution right now. To some degree the separation is necessary since we need to separate runtime functions that can be modified by comptime functions from comptime functions that cannot be modified (because we've already run them).Additional Context
Requires #5517 to work
Documentation*
Check one:
PR Checklist*
cargo fmt
on default settings.