Skip to content

Refactor ExtInfo to use the builder pattern for construction. #33118

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

Conversation

varungandhi-apple
Copy link
Contributor

@varungandhi-apple varungandhi-apple commented Jul 25, 2020

  • We could probably reduce some of the duplication with more helper methods that call intoBuilder() and build().
  • I don't feel particularly strongly about the method names.
  • git-clang-format had a bit of a field day with reformatting the surrounding code, so that's a bit unfortunate...
  • The first commit in present in a separate PR. [NFC] Rename ExtInfo::Uncommon to ExtInfo::ClangTypeInfo. #33117
  • The non-introduction of invariant checking is deliberate. I imagine something or the other is going to blow up when we introduce more checks, so we can do that one-by-one and refactor small amounts of code, instead of introducing the invariant checks and doing the refactoring in this PR (which is already somewhat big).

@varungandhi-apple
Copy link
Contributor Author

@varungandhi-apple varungandhi-apple force-pushed the vg-builder-pattern-ExtInfo branch 2 times, most recently from 7ebd1b4 to b56f000 Compare July 26, 2020 23:48
@varungandhi-apple

This comment has been minimized.

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@varungandhi-apple varungandhi-apple requested a review from CodaFi July 26, 2020 23:59
@varungandhi-apple

This comment has been minimized.

@varungandhi-apple

This comment has been minimized.

@varungandhi-apple varungandhi-apple force-pushed the vg-builder-pattern-ExtInfo branch from b56f000 to a93b5bf Compare July 28, 2020 02:28
@varungandhi-apple

This comment has been minimized.

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@varungandhi-apple varungandhi-apple force-pushed the vg-builder-pattern-ExtInfo branch from a93b5bf to b399a97 Compare July 28, 2020 04:08
@varungandhi-apple

This comment has been minimized.

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@varungandhi-apple varungandhi-apple force-pushed the vg-builder-pattern-ExtInfo branch 2 times, most recently from 0775c1e to 9c35c66 Compare July 31, 2020 04:44
@varungandhi-apple varungandhi-apple changed the title [DNM] Refactor ExtInfo to use the builder pattern for construction. Refactor ExtInfo to use the builder pattern for construction. Jul 31, 2020
@varungandhi-apple varungandhi-apple force-pushed the vg-builder-pattern-ExtInfo branch 2 times, most recently from e89d647 to 7187b8f Compare July 31, 2020 06:24
@varungandhi-apple varungandhi-apple marked this pull request as ready for review July 31, 2020 06:43
@varungandhi-apple

This comment has been minimized.

1 similar comment
@varungandhi-apple

This comment has been minimized.

Since the two ExtInfos share a common ClangTypeInfo, and C++ doesn't let us
forward declare nested classes, we need to hoist out AnyFunctionType::ExtInfo
and SILFunctionType::ExtInfo to the top-level.

We also add some convenience APIs on (AST|SIL)ExtInfo for frequently used
withXYZ methods. Note that all non-default construction still goes through the
builder's build() method.

We do not add any checks for invariants here; those will be added later.
In the future, we will remove the UseClangFunctionTypes language option, but we
temporarily need the scaffolding for equality checks to be consistent in all
places.
@varungandhi-apple varungandhi-apple force-pushed the vg-builder-pattern-ExtInfo branch from 7187b8f to 29188e3 Compare July 31, 2020 21:05
@varungandhi-apple
Copy link
Contributor Author

Marked a bunch of things constexpr.

@swift-ci please smoke test

@varungandhi-apple
Copy link
Contributor Author

@CodaFi any pending concerns/LGTY?

@varungandhi-apple varungandhi-apple merged commit 270b5dc into swiftlang:master Aug 3, 2020
@varungandhi-apple varungandhi-apple deleted the vg-builder-pattern-ExtInfo branch August 3, 2020 17:30
@davezarzycki
Copy link
Contributor

davezarzycki commented Aug 4, 2020

Hi @varungandhi-apple – Thanks for doing this. Why were a bunch of methods made constexpr? That keyword isn't "free" as far as compile times go so unless you actually need constant evaluation then inline is a better compiler hint. Did you mean to add inline?

@varungandhi-apple
Copy link
Contributor Author

I don't follow why it should cause additional compile times unless we actually use the constexpr function for compile-time evaluation... maybe I'm missing a piece of the puzzle here. Could you explain your line of reasoning?

@davezarzycki
Copy link
Contributor

davezarzycki commented Aug 4, 2020

You might want to double check with your colleagues at Apple, but I think I remember one of them pointing out that constexpr forces clang to interpret the code before lowering to LLVM IR. For most code, this interpretation adds little to no gains over what the LLVM optimizer can provide but layers of constexpr function calls can cause quite a bit of needless work inside of clang. So unless one actually need to use a function in a constant context (like the size of an array, bitfield sizing, enum constants, etc), then one should either use inline or trust the auto-inliner to do the right thing.

@CodaFi
Copy link
Contributor

CodaFi commented Aug 4, 2020

Constant-folding at IR-generation time can take care of a lot of this, certainly. But there aren't really wild layers of constexpr here. If Clang cannot handle a chain of bitwise constant evaluations without ballooning build-time performance, we need to file defect reports immediately.

@davezarzycki
Copy link
Contributor

I agree that these specific cases should be harmless.

I think the point this colleague was trying to make was educational: one should prefer inline over constexpr unless you NEED constexpr semantics because of aggregate compounding effects if a code base starts using constexpr all over the place.

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.

4 participants