-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
De-duplicate edges in typeinfer
instead of gf.c
#58117
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
Open
topolarity
wants to merge
3
commits into
JuliaLang:master
Choose a base branch
from
topolarity:ct/typeinfer-edge-dedupe
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1997,6 +1997,9 @@ JL_DLLEXPORT void jl_method_instance_add_backedge(jl_method_instance_t *callee, | |
jl_gc_wb(callee, backedges); | ||
} | ||
else { | ||
#ifndef JL_NDEBUG | ||
// It is the caller's (inference's) responsibility to de-duplicate edges. Here we are only | ||
// checking its work. | ||
size_t i = 0, l = jl_array_nrows(backedges); | ||
for (i = 0; i < l; i++) { | ||
// optimized version of while (i < l) i = get_next_edge(callee->backedges, i, &invokeTypes, &mi); | ||
|
@@ -2012,6 +2015,8 @@ JL_DLLEXPORT void jl_method_instance_add_backedge(jl_method_instance_t *callee, | |
break; | ||
} | ||
} | ||
assert(!found && "duplicate back-edge registered"); | ||
#endif | ||
} | ||
if (!found) | ||
push_edge(backedges, invokesig, caller); | ||
|
@@ -2037,14 +2042,20 @@ JL_DLLEXPORT void jl_method_table_add_backedge(jl_methtable_t *mt, jl_value_t *t | |
else { | ||
// check if the edge is already present and avoid adding a duplicate | ||
size_t i, l = jl_array_nrows(mt->backedges); | ||
#ifndef JL_NDEBUG | ||
// It is the caller's (inference's) responsibility to de-duplicate edges. Here we are only | ||
// checking its work. | ||
int found = 0; | ||
for (i = 1; i < l; i += 2) { | ||
if (jl_array_ptr_ref(mt->backedges, i) == (jl_value_t*)caller) { | ||
if (jl_types_equal(jl_array_ptr_ref(mt->backedges, i - 1), typ)) { | ||
JL_UNLOCK(&mt->writelock); | ||
return; | ||
found = 1; | ||
break; | ||
} | ||
} | ||
} | ||
assert(!found && "duplicate back-edge registered"); | ||
#endif | ||
// reuse an already cached instance of this type, if possible | ||
// TODO: use jl_cache_type_(tt) like cache_method does, instead of this linear scan? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's worth seeing if we can bypass this remaining linear scan in the MethodTable edge insertion. If I disable it manually, the timing drops to 440 milliseconds |
||
for (i = 1; i < l; i += 2) { | ||
|
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a race condition into the code (because of gc, threads, etc). Probably useful to know this scan is costly on some benchmarks though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify where the race condition is?
Do you mean that inference may simultaneously try to
store_backedges
for the same caller CI from two different threads?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see, we might be able to now assume that each CI is unique, while in older versions the MI were not expected to be unique