Skip to content

Track Clang function types in the AST #27479

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 8 commits into from
Dec 4, 2019
Merged

Track Clang function types in the AST #27479

merged 8 commits into from
Dec 4, 2019

Conversation

varungandhi-apple
Copy link
Contributor

@varungandhi-apple varungandhi-apple commented Oct 2, 2019

The 3rd commit introduces a bunch of TODOs, most of which are resolved in the 4th commit.

Things that are implemented:

  1. ClangTypeConverter is available at the AST level. It is used both when resolving types (TypeResolution) and when building types (ASTBuilder).
  2. Including the clang types in the type equality tests.

Questions:

  1. It is not clear who/what should be maintaining ownership of the ClangTypeConverter in the ASTBuilder. There are a couple of TODOs related to this. ("Is this too expensive?").
  2. How should I further be testing this change?

Things that are not implemented yet but I plan to do as part of this PR (unless someone says I should make a follow-up PR about it):

  • Test cases -- right now, the main "test" is the whole test suite passes, i.e. we don't mess up type equality anywhere. added some trickier test cases
  • Setting the clang types in SILFunctionType. (punted to future PR)
  • Reporting differences in the clang type in diagnostics. (punted to future PR)

Since it has taken me much more time than anticipated to get to this point, I figured I'd try to get feedback sooner rather than later (even though a bunch of things are not implemented), especially given that this is a relatively large PR 😐.

@varungandhi-apple

This comment has been minimized.

@swift-ci

This comment has been minimized.

@varungandhi-apple

This comment has been minimized.

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@varungandhi-apple
Copy link
Contributor Author

varungandhi-apple commented Oct 2, 2019

Ah, there is a compilation failure due to the removed Builtin.UnknownObject.

@varungandhi-apple

This comment has been minimized.

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@varungandhi-apple

This comment has been minimized.

@varungandhi-apple
Copy link
Contributor Author

varungandhi-apple commented Oct 3, 2019

Ah we are crashing when compiling SwiftPM 🙁

@varungandhi-apple
Copy link
Contributor Author

We're compiling SwiftPM properly on Linux but not on OS X? 😦

@varungandhi-apple

This comment has been minimized.

@varungandhi-apple
Copy link
Contributor Author

varungandhi-apple commented Oct 17, 2019

The SwiftPM compilation crash is because of a type mismatch issue; we have a Clang type in one case and none in the other. Think I should put a more descriptive crash message there instead of just an llvm_unreachable.

@varungandhi-apple
Copy link
Contributor Author

Minimal test case. Only SIG_DFL is problematic, other signals seem to work ok.

// RUN: %target-swift-frontend -typecheck %s
// REQUIRES: OS=macosx

import Darwin

func f() {
  let s: sig_t? = SIG_DFL
}

@varungandhi-apple
Copy link
Contributor Author

varungandhi-apple commented Oct 18, 2019

Think I understand what the issue is. It has nothing to do with SIG_DFL and probably has everything to do with (de)serialization. We're not (de)serializing Clang types yet, so decls loaded from a different module don't have it. 🤦‍♂

The only way I see is disabling the clang function pointer check when comparing types.

However, that doesn't explain why code like let s: sig_t = SIG_IGN compiles but this doesn't. Like, how can the Optional make a difference?

Update: I talked to Robert about this and it is definitely puzzling behavior that the code with SIG_IGN compiles because the compiler shouldn't be able to magically convert one function type (which doesn't have a Clang type) to the other (which does) (or the other way around). I will file an issue for this.

@varungandhi-apple

This comment has been minimized.

@varungandhi-apple
Copy link
Contributor Author

I still need to add more test cases utilizing the new flag, but the core logic should be good now.

@varungandhi-apple

This comment has been minimized.

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@varungandhi-apple
Copy link
Contributor Author

The LLDB failure was fixed here: swiftlang/llvm-project#24

@swift-ci please test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@varungandhi-apple

This comment has been minimized.

@swift-ci

This comment has been minimized.

@varungandhi-apple
Copy link
Contributor Author

@swift-ci please test Linux platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a89e9dac36adf14ab1945aaaff69dc97fade2899

@varungandhi-apple
Copy link
Contributor Author

@swift-ci please smoke test Linux platform

@varungandhi-apple
Copy link
Contributor Author

@swift-ci please test Linux platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a89e9dac36adf14ab1945aaaff69dc97fade2899

@varungandhi-apple
Copy link
Contributor Author

The same Linux build failure seems to be happening with #28371 (build 17092) and #28374 (build 17094) as for us (builds 17093 and 17099).

@varungandhi-apple
Copy link
Contributor Author

@swift-ci please clean test Linux platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - a89e9dac36adf14ab1945aaaff69dc97fade2899

@varungandhi-apple
Copy link
Contributor Author

varungandhi-apple commented Nov 21, 2019

I don't understand why we'd see such an error because of this change.

[1/11] Compiling TSCclibc libc.c
[2/12] Compiling TSCLibc libc.swift
<unknown>:0: warning: missing submodule 'TSCclibc'
/home/buildnode/jenkins/workspace/swift-PR-Linux@2/branch-master/swiftpm/Sources/TSCLibc/libc.swift:20:19: error: no such module 'TSCclibc'
@_exported import TSCclibc
                  ^

@swift-ci please test Linux platform

@varungandhi-apple
Copy link
Contributor Author

Yasssss! Tests are passing. @rjmccall time for you to give this PR your blessings.

@@ -0,0 +1,36 @@
//- ClangSwiftTypeCorrespondence.cpp - Relations between Clang & Swift types -//
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a .cpp file, and there's a standard form of these header comments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there's a standard form of these header comments

I ran out of characters to add == signs around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you have any suggestions for rephrasing, I can do that. This is the best I could come up with to fit in 80 chars.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you're overthinking the filename and it could just be something like ClangTypeInfo.h - Swift-related properties of Clang types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think Info is very generic and doesn't hint at anything in particular.

We still don't store compute or store the type anywhere; we will do so in
later commits.
Note: The change in ASTBuilder::createFunctionType is functionally minor,
but we need the FunctionType::Params computed _before_ the ExtInfo, so we
need to shuffle a bunch of code around.
This should be a non-functional change because we shouldn't be converting
protocols which aren't ObjC.
@varungandhi-apple

This comment has been minimized.

@varungandhi-apple
Copy link
Contributor Author

@swift-ci please test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@varungandhi-apple
Copy link
Contributor Author

@rjmccall is this good to merge?

@rjmccall
Copy link
Contributor

rjmccall commented Dec 4, 2019

See my comment in the other PR about owned, but we can do that in a follow-up; I think this is fine to merge now.

@varungandhi-apple varungandhi-apple merged commit e7be41d into swiftlang:master Dec 4, 2019
@varungandhi-apple varungandhi-apple deleted the vg-track-clang-function-types branch December 4, 2019 16:47
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.

3 participants