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

GDScript: Improve call analysis #75988

Merged
merged 1 commit into from
Sep 27, 2023

Conversation

dalexeev
Copy link
Member

@dalexeev dalexeev commented Apr 12, 2023

@dalexeev dalexeev requested a review from a team as a code owner April 12, 2023 14:43
@Calinou Calinou added this to the 4.1 milestone Apr 12, 2023
@adamscott
Copy link
Member

Notes from the GDScript meeting:

  • The missing warning is a problem;
  • The error message should be changed. Something like: "the function expects an int, but the value is only inferred" instead of "int (variant)";
  • The formatting of DataType to string should maybe not change, or at least, this should belong in another PR.

@dalexeev
Copy link
Member Author

I removed the DataType::to_string() changes from this PR. In the future, we may investigate this issue separately.

@dalexeev dalexeev force-pushed the gds-unsafe-call-argument branch 2 times, most recently from 06cfa39 to ce9c682 Compare April 27, 2023 06:54
Copy link
Contributor

@anvilfolk anvilfolk left a comment

Choose a reason for hiding this comment

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

A small typo noticed, and needs a rebase, but is there a reason this hasn't been merged? It feels like it's good to go otherwise :)

Copy link
Contributor

@anvilfolk anvilfolk left a comment

Choose a reason for hiding this comment

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

I just noticed some discrepancies in whether mark_node_unsafe should be protected by #ifdef DEBUG_ENABLED compared to existing code. I didn't do a thorough review of the analyzer, but I believe there's an existing pattern that isn't being followed here that could have unintended consequences?

@@ -4838,18 +4838,33 @@ void GDScriptAnalyzer::validate_call_arg(const List<GDScriptParser::DataType> &p

if ((arg_type.is_variant() || !arg_type.is_hard_type()) && !(par_type.is_hard_type() && par_type.is_variant())) {
// Argument can be anything, so this is unsafe.
#ifdef DEBUG_ENABLED
mark_node_unsafe(p_call->arguments[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

So all of the push_warning() that I saw in the analyzer were protected by DEBUG_ENABLED, but none of the mark_node_unsafe() calls were. I think it might make sense to pull this one outside the #ifdef block here?

Copy link
Member Author

Choose a reason for hiding this comment

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

void GDScriptAnalyzer::mark_node_unsafe(const GDScriptParser::Node *p_node) {
#ifdef DEBUG_ENABLED
if (p_node == nullptr) {
return;
}
for (int i = p_node->start_line; i <= p_node->end_line; i++) {
parser->unsafe_lines.insert(i);
}
#endif
}

Copy link
Contributor

Choose a reason for hiding this comment

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

hahahahah, well, that resolves it as not mattering for sure :)

modules/gdscript/gdscript_analyzer.cpp Show resolved Hide resolved
Copy link
Contributor

@anvilfolk anvilfolk left a comment

Choose a reason for hiding this comment

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

LGTM :)

@dalexeev dalexeev changed the title GDScript: Add missing UNSAFE_CALL_ARGUMENT warning GDScript: Improve call analysis (part 1) Jun 8, 2023
@dalexeev
Copy link
Member Author

dalexeev commented Jun 8, 2023

I extended this PR. Please remove the cherrypick:4.0 label.

@santouits
Copy link
Contributor

Should you remove this code too?

} else if (first == SNAME("Object")) {
// Object is treated like a native type, not a built-in.
result.kind = GDScriptParser::DataType::NATIVE;
result.builtin_type = Variant::OBJECT;
result.native_type = SNAME("Object");

@akien-mga akien-mga requested a review from a team June 19, 2023 21:05
@adamscott adamscott modified the milestones: 4.1, 4.2 Jun 22, 2023
@adamscott
Copy link
Member

Moved the milestone to 4.2, as we entered yesterday the release freeze for 4.1, where only urgent bugfixes are merged. Added the "cherrypick 4.1" tag as this would be interesting to patch 4.1.x with your PR.

@adamscott adamscott added the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Jun 22, 2023
@adamscott
Copy link
Member

The GDScript team thinks that this PR should be merged for 4.2. We should take a look again at this before the feature freeze.

@dalexeev dalexeev removed the cherrypick:4.1 Considered for cherry-picking into a future 4.1.x release label Sep 21, 2023
* Add missing `UNSAFE_CALL_ARGUMENT` warning.
* Fix `Object` constructor.
* Display an error for non-existent static methods.
@dalexeev dalexeev changed the title GDScript: Improve call analysis (part 1) GDScript: Improve call analysis Sep 21, 2023
Copy link
Member

@vnen vnen left a comment

Choose a reason for hiding this comment

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

Overall looks good to me.

@@ -24,7 +24,8 @@ func test():
print(StringName("hello"))
print(NodePath("hello/world"))
var node := Node.new()
print(RID(node))
@warning_ignore("unsafe_call_argument")
print(RID(node)) # TODO: Why is the constructor (or implicit cast) not documented?
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no RID(Object) constructor (or something like this).

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah right, we should document the explicit conversion.

@YuriSizov YuriSizov merged commit aa474c9 into godotengine:master Sep 27, 2023
15 checks passed
@YuriSizov
Copy link
Contributor

Thanks!

@dalexeev dalexeev deleted the gds-unsafe-call-argument branch September 27, 2023 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants