Support hint function declaration to bind with builtin function#199
Merged
Conversation
87ad74a to
5353d42
Compare
mimoo
approved these changes
Oct 23, 2024
Contributor
mimoo
left a comment
There was a problem hiding this comment.
LGTM, I'll have another pass but let's not wait to merge it!
| // unsafe attribute should only be used on hints | ||
| if !fn_info.is_hint && *unsafe_attr { | ||
| return Err(self.error(ErrorKind::UnexpectedUnsafeAttribute, expr.span)); | ||
| } |
Contributor
There was a problem hiding this comment.
maybe more concise:
match (fn_info.is_hint, unsafe_attr) {
(true, true) | (false, false) => (),
_ => return Err(self.error(ErrorKind::ExpectedUnsafeAttribute, expr.span));
}
Contributor
Author
There was a problem hiding this comment.
Actually there are two error types to handle:
Lines 476 to 500 in 18825a3
| } | ||
|
|
||
| /// Parse a hint function signature | ||
| pub fn parse_hint(ctx: &mut ParserCtx, tokens: &mut Tokens) -> Result<Self> { |
Contributor
There was a problem hiding this comment.
do you think it'd make sense to merge this with the parse function above?
Contributor
Author
There was a problem hiding this comment.
This new parser function is for hint function without a body.
So I think once we support the native hints, we can just remove this function, while the native hint function can get parsed using parser function above without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is the first step to support hint function, by making use the builtin functions as hint functions.
Although it is not yet fully supporting the native hint function, this PR makes it able to type check the
unsafe/hintattribute.Usage:
Declares a hint function in a
.nofile to wire up with a builtin function under the same full qualified name.It requires
unsafeattribute when calling a hint function, otherwise the type checker will throw error. So the hint function caller has to useunsafeto acknowledge they are calling a hint function.This can make the type checking ready for hint calculations before the native hint function support.
Once the hint function support is ready, we can just fill the hint function body in the native code and deprecate the hint builtin functions, while keeping existing hint function callers intact.