Skip to content

[SILOptimizer] shouldExpand can't expand address only types #15517

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

Merged
merged 1 commit into from
Mar 26, 2018

Conversation

shajrawi
Copy link

fix a bug wherein EnableExpandAll overrode that.

rdar://problem/33767770

@shajrawi
Copy link
Author

@swift-ci Please smoke test and merge

1 similar comment
@shajrawi
Copy link
Author

@swift-ci Please smoke test and merge

@shajrawi
Copy link
Author

@swift-ci Please clean smoke test OS X

@slavapestov
Copy link
Contributor

Test case?

@shajrawi
Copy link
Author

@slavapestov The current uses of shouldExpand all over the optimizer also check for resilience so all test cases will not trigger the buggy code path. I changed this check as a defensive measure while auditing the optimizer for resilience - in case someone calls this function without checking resilience in the future.

@slavapestov
Copy link
Contributor

In that case can you turn it into an assert instead? If we don't want people calling the function without checking resilience, let's assert instead of failing silently.

@shajrawi
Copy link
Author

I am not sure we don't want people calling it like that / prevent it: the function just tells the user if they should explode a type 'T' or not. I see no reason why calling it with an address only type should crash instead of saying: no, you can't explode this type.

@shajrawi
Copy link
Author

(it is, after all, just a utility function. Its name doesn't indicate that the compiler should panic just because someone called it as part of their heuristics for doing an optimization 'x' or not)

@shajrawi
Copy link
Author

@swift-ci Please clean smoke test Linux

@slavapestov
Copy link
Contributor

@shajrawi Either all callers should check for resilience and not call the function with resilient types, or the function should do the check and return false. Having both just creates confusion IMO.

@shajrawi
Copy link
Author

I think the function should do the check itself regarding your point above. without crashing for resilient types / guarding the user of course. especially if a user calls this heuristic on all types as an analysis before going forward with an optimization or not. the problem with that is we have cases like the one below:

  bool expand = shouldExpand(M, SrcType.getObjectType());
  using TypeExpansionKind = Lowering::TypeLowering::TypeExpansionKind;
  auto expansionKind = expand ? TypeExpansionKind::MostDerivedDescendents
                              : TypeExpansionKind::None;

  SILBuilderWithScope Builder(CA);

  // %new = load %0 : $*T
  LoadInst *New = Builder.createLoad(CA->getLoc(), Source,
                                     LoadOwnershipQualifier::Unqualified);

Wherein, being guarded by a pervious check, we know we can do a load even if the function returns false for code size reasons...

@shajrawi shajrawi merged commit 98ef683 into swiftlang:master Mar 26, 2018
@shajrawi shajrawi deleted the expand_all branch March 26, 2018 21:01
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